5 * Created on Sep 25, 2006
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
28 * A query module to show basic page information.
32 class ApiQueryInfo
extends ApiQueryBase
{
34 private $fld_protection = false, $fld_talkid = false,
35 $fld_subjectid = false, $fld_url = false,
36 $fld_readable = false, $fld_watched = false, $fld_watchers = false,
37 $fld_notificationtimestamp = false,
38 $fld_preload = false, $fld_displaytitle = false;
40 private $params, $titles, $missing, $everything, $pageCounter;
42 private $pageRestrictions, $pageIsRedir, $pageIsNew, $pageTouched,
43 $pageLatest, $pageLength;
45 private $protections, $watched, $watchers, $notificationtimestamps,
46 $talkids, $subjectids, $displaytitles;
47 private $showZeroWatchers = false;
49 private $tokenFunctions;
51 public function __construct( ApiQuery
$query, $moduleName ) {
52 parent
::__construct( $query, $moduleName, 'in' );
56 * @param ApiPageSet $pageSet
59 public function requestExtraData( $pageSet ) {
60 $pageSet->requestField( 'page_restrictions' );
61 // when resolving redirects, no page will have this field
62 if ( !$pageSet->isResolvingRedirects() ) {
63 $pageSet->requestField( 'page_is_redirect' );
65 $pageSet->requestField( 'page_is_new' );
66 $config = $this->getConfig();
67 if ( !$config->get( 'DisableCounters' ) ) {
68 $pageSet->requestField( 'page_counter' );
70 $pageSet->requestField( 'page_touched' );
71 $pageSet->requestField( 'page_latest' );
72 $pageSet->requestField( 'page_len' );
73 if ( $config->get( 'ContentHandlerUseDB' ) ) {
74 $pageSet->requestField( 'page_content_model' );
79 * Get an array mapping token names to their handler functions.
80 * The prototype for a token function is func($pageid, $title)
81 * it should return a token or false (permission denied)
82 * @return array Array(tokenname => function)
84 protected function getTokenFunctions() {
85 // Don't call the hooks twice
86 if ( isset( $this->tokenFunctions
) ) {
87 return $this->tokenFunctions
;
90 // If we're in JSON callback mode, no tokens can be obtained
91 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
95 $this->tokenFunctions
= array(
96 'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
97 'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
98 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
99 'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
100 'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
101 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
102 'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
103 'import' => array( 'ApiQueryInfo', 'getImportToken' ),
104 'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
106 wfRunHooks( 'APIQueryInfoTokens', array( &$this->tokenFunctions
) );
108 return $this->tokenFunctions
;
111 static protected $cachedTokens = array();
113 public static function resetTokenCache() {
114 ApiQueryInfo
::$cachedTokens = array();
117 public static function getEditToken( $pageid, $title ) {
118 // We could check for $title->userCan('edit') here,
119 // but that's too expensive for this purpose
120 // and would break caching
122 if ( !$wgUser->isAllowed( 'edit' ) ) {
126 // The token is always the same, let's exploit that
127 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
128 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
131 return ApiQueryInfo
::$cachedTokens['edit'];
134 public static function getDeleteToken( $pageid, $title ) {
136 if ( !$wgUser->isAllowed( 'delete' ) ) {
140 // The token is always the same, let's exploit that
141 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
142 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
145 return ApiQueryInfo
::$cachedTokens['delete'];
148 public static function getProtectToken( $pageid, $title ) {
150 if ( !$wgUser->isAllowed( 'protect' ) ) {
154 // The token is always the same, let's exploit that
155 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
156 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
159 return ApiQueryInfo
::$cachedTokens['protect'];
162 public static function getMoveToken( $pageid, $title ) {
164 if ( !$wgUser->isAllowed( 'move' ) ) {
168 // The token is always the same, let's exploit that
169 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
170 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
173 return ApiQueryInfo
::$cachedTokens['move'];
176 public static function getBlockToken( $pageid, $title ) {
178 if ( !$wgUser->isAllowed( 'block' ) ) {
182 // The token is always the same, let's exploit that
183 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
184 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
187 return ApiQueryInfo
::$cachedTokens['block'];
190 public static function getUnblockToken( $pageid, $title ) {
191 // Currently, this is exactly the same as the block token
192 return self
::getBlockToken( $pageid, $title );
195 public static function getEmailToken( $pageid, $title ) {
197 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailUser() ) {
201 // The token is always the same, let's exploit that
202 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
203 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
206 return ApiQueryInfo
::$cachedTokens['email'];
209 public static function getImportToken( $pageid, $title ) {
211 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
215 // The token is always the same, let's exploit that
216 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
217 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
220 return ApiQueryInfo
::$cachedTokens['import'];
223 public static function getWatchToken( $pageid, $title ) {
225 if ( !$wgUser->isLoggedIn() ) {
229 // The token is always the same, let's exploit that
230 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
231 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
234 return ApiQueryInfo
::$cachedTokens['watch'];
237 public static function getOptionsToken( $pageid, $title ) {
239 if ( !$wgUser->isLoggedIn() ) {
243 // The token is always the same, let's exploit that
244 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
245 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
248 return ApiQueryInfo
::$cachedTokens['options'];
251 public function execute() {
252 $this->params
= $this->extractRequestParams();
253 if ( !is_null( $this->params
['prop'] ) ) {
254 $prop = array_flip( $this->params
['prop'] );
255 $this->fld_protection
= isset( $prop['protection'] );
256 $this->fld_watched
= isset( $prop['watched'] );
257 $this->fld_watchers
= isset( $prop['watchers'] );
258 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
259 $this->fld_talkid
= isset( $prop['talkid'] );
260 $this->fld_subjectid
= isset( $prop['subjectid'] );
261 $this->fld_url
= isset( $prop['url'] );
262 $this->fld_readable
= isset( $prop['readable'] );
263 $this->fld_preload
= isset( $prop['preload'] );
264 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
267 $pageSet = $this->getPageSet();
268 $this->titles
= $pageSet->getGoodTitles();
269 $this->missing
= $pageSet->getMissingTitles();
270 $this->everything
= $this->titles +
$this->missing
;
271 $result = $this->getResult();
273 uasort( $this->everything
, array( 'Title', 'compare' ) );
274 if ( !is_null( $this->params
['continue'] ) ) {
275 // Throw away any titles we're gonna skip so they don't
277 $cont = explode( '|', $this->params
['continue'] );
278 $this->dieContinueUsageIf( count( $cont ) != 2 );
279 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
280 foreach ( $this->everything
as $pageid => $title ) {
281 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
284 unset( $this->titles
[$pageid] );
285 unset( $this->missing
[$pageid] );
286 unset( $this->everything
[$pageid] );
290 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
291 // when resolving redirects, no page will have this field
292 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
293 ?
$pageSet->getCustomField( 'page_is_redirect' )
295 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
297 if ( !$this->getConfig()->get( 'DisableCounters' ) ) {
298 $this->pageCounter
= $pageSet->getCustomField( 'page_counter' );
300 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
301 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
302 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
304 // Get protection info if requested
305 if ( $this->fld_protection
) {
306 $this->getProtectionInfo();
309 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
310 $this->getWatchedInfo();
313 if ( $this->fld_watchers
) {
314 $this->getWatcherInfo();
317 // Run the talkid/subjectid query if requested
318 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
322 if ( $this->fld_displaytitle
) {
323 $this->getDisplayTitle();
326 /** @var $title Title */
327 foreach ( $this->everything
as $pageid => $title ) {
328 $pageInfo = $this->extractPageInfo( $pageid, $title );
329 $fit = $result->addValue( array(
332 ), $pageid, $pageInfo );
334 $this->setContinueEnumParameter( 'continue',
335 $title->getNamespace() . '|' .
343 * Get a result array with information about a title
344 * @param int $pageid Page ID (negative for missing titles)
345 * @param Title $title
348 private function extractPageInfo( $pageid, $title ) {
350 // $title->exists() needs pageid, which is not set for all title objects
351 $titleExists = $pageid > 0;
352 $ns = $title->getNamespace();
353 $dbkey = $title->getDBkey();
355 $pageInfo['contentmodel'] = $title->getContentModel();
356 $pageInfo['pagelanguage'] = $title->getPageLanguage()->getCode();
358 if ( $titleExists ) {
359 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
360 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
361 $pageInfo['counter'] = $this->getConfig()->get( 'DisableCounters' )
363 : intval( $this->pageCounter
[$pageid] );
364 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
366 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
367 $pageInfo['redirect'] = '';
369 if ( $this->pageIsNew
[$pageid] ) {
370 $pageInfo['new'] = '';
374 if ( !is_null( $this->params
['token'] ) ) {
375 $tokenFunctions = $this->getTokenFunctions();
376 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
377 foreach ( $this->params
['token'] as $t ) {
378 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
379 if ( $val === false ) {
380 $this->setWarning( "Action '$t' is not allowed for the current user" );
382 $pageInfo[$t . 'token'] = $val;
387 if ( $this->fld_protection
) {
388 $pageInfo['protection'] = array();
389 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
390 $pageInfo['protection'] =
391 $this->protections
[$ns][$dbkey];
393 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
396 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
397 $pageInfo['watched'] = '';
400 if ( $this->fld_watchers
) {
401 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
402 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
403 } elseif ( $this->showZeroWatchers
) {
404 $pageInfo['watchers'] = 0;
408 if ( $this->fld_notificationtimestamp
) {
409 $pageInfo['notificationtimestamp'] = '';
410 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
411 $pageInfo['notificationtimestamp'] =
412 wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
416 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
417 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
420 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
421 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
424 if ( $this->fld_url
) {
425 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
426 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
428 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
429 $pageInfo['readable'] = '';
432 if ( $this->fld_preload
) {
433 if ( $titleExists ) {
434 $pageInfo['preload'] = '';
437 wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
439 $pageInfo['preload'] = $text;
443 if ( $this->fld_displaytitle
) {
444 if ( isset( $this->displaytitles
[$pageid] ) ) {
445 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
447 $pageInfo['displaytitle'] = $title->getPrefixedText();
455 * Get information about protections and put it in $protections
457 private function getProtectionInfo() {
459 $this->protections
= array();
460 $db = $this->getDB();
462 // Get normal protections for existing titles
463 if ( count( $this->titles
) ) {
464 $this->resetQueryParams();
465 $this->addTables( 'page_restrictions' );
466 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
467 'pr_expiry', 'pr_cascade' ) );
468 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
470 $res = $this->select( __METHOD__
);
471 foreach ( $res as $row ) {
472 /** @var $title Title */
473 $title = $this->titles
[$row->pr_page
];
475 'type' => $row->pr_type
,
476 'level' => $row->pr_level
,
477 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
479 if ( $row->pr_cascade
) {
482 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
484 // Also check old restrictions
485 foreach ( $this->titles
as $pageId => $title ) {
486 if ( $this->pageRestrictions
[$pageId] ) {
487 $namespace = $title->getNamespace();
488 $dbKey = $title->getDBkey();
489 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
490 foreach ( $restrictions as $restrict ) {
491 $temp = explode( '=', trim( $restrict ) );
492 if ( count( $temp ) == 1 ) {
493 // old old format should be treated as edit/move restriction
494 $restriction = trim( $temp[0] );
496 if ( $restriction == '' ) {
499 $this->protections
[$namespace][$dbKey][] = array(
501 'level' => $restriction,
502 'expiry' => 'infinity',
504 $this->protections
[$namespace][$dbKey][] = array(
506 'level' => $restriction,
507 'expiry' => 'infinity',
510 $restriction = trim( $temp[1] );
511 if ( $restriction == '' ) {
514 $this->protections
[$namespace][$dbKey][] = array(
516 'level' => $restriction,
517 'expiry' => 'infinity',
525 // Get protections for missing titles
526 if ( count( $this->missing
) ) {
527 $this->resetQueryParams();
528 $lb = new LinkBatch( $this->missing
);
529 $this->addTables( 'protected_titles' );
530 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
531 $this->addWhere( $lb->constructSet( 'pt', $db ) );
532 $res = $this->select( __METHOD__
);
533 foreach ( $res as $row ) {
534 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
536 'level' => $row->pt_create_perm
,
537 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
542 // Cascading protections
543 $images = $others = array();
544 foreach ( $this->everything
as $title ) {
545 if ( $title->getNamespace() == NS_FILE
) {
546 $images[] = $title->getDBkey();
552 if ( count( $others ) ) {
553 // Non-images: check templatelinks
554 $lb = new LinkBatch( $others );
555 $this->resetQueryParams();
556 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
557 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
558 'page_title', 'page_namespace',
559 'tl_title', 'tl_namespace' ) );
560 $this->addWhere( $lb->constructSet( 'tl', $db ) );
561 $this->addWhere( 'pr_page = page_id' );
562 $this->addWhere( 'pr_page = tl_from' );
563 $this->addWhereFld( 'pr_cascade', 1 );
565 $res = $this->select( __METHOD__
);
566 foreach ( $res as $row ) {
567 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
568 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
569 'type' => $row->pr_type
,
570 'level' => $row->pr_level
,
571 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
572 'source' => $source->getPrefixedText()
577 if ( count( $images ) ) {
578 // Images: check imagelinks
579 $this->resetQueryParams();
580 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
581 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
582 'page_title', 'page_namespace', 'il_to' ) );
583 $this->addWhere( 'pr_page = page_id' );
584 $this->addWhere( 'pr_page = il_from' );
585 $this->addWhereFld( 'pr_cascade', 1 );
586 $this->addWhereFld( 'il_to', $images );
588 $res = $this->select( __METHOD__
);
589 foreach ( $res as $row ) {
590 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
591 $this->protections
[NS_FILE
][$row->il_to
][] = array(
592 'type' => $row->pr_type
,
593 'level' => $row->pr_level
,
594 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
595 'source' => $source->getPrefixedText()
602 * Get talk page IDs (if requested) and subject page IDs (if requested)
603 * and put them in $talkids and $subjectids
605 private function getTSIDs() {
606 $getTitles = $this->talkids
= $this->subjectids
= array();
609 foreach ( $this->everything
as $t ) {
610 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
611 if ( $this->fld_subjectid
) {
612 $getTitles[] = $t->getSubjectPage();
614 } elseif ( $this->fld_talkid
) {
615 $getTitles[] = $t->getTalkPage();
618 if ( !count( $getTitles ) ) {
622 $db = $this->getDB();
624 // Construct a custom WHERE clause that matches
625 // all titles in $getTitles
626 $lb = new LinkBatch( $getTitles );
627 $this->resetQueryParams();
628 $this->addTables( 'page' );
629 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
630 $this->addWhere( $lb->constructSet( 'page', $db ) );
631 $res = $this->select( __METHOD__
);
632 foreach ( $res as $row ) {
633 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
634 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
635 intval( $row->page_id
);
637 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
638 intval( $row->page_id
);
643 private function getDisplayTitle() {
644 $this->displaytitles
= array();
646 $pageIds = array_keys( $this->titles
);
648 if ( !count( $pageIds ) ) {
652 $this->resetQueryParams();
653 $this->addTables( 'page_props' );
654 $this->addFields( array( 'pp_page', 'pp_value' ) );
655 $this->addWhereFld( 'pp_page', $pageIds );
656 $this->addWhereFld( 'pp_propname', 'displaytitle' );
657 $res = $this->select( __METHOD__
);
659 foreach ( $res as $row ) {
660 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
665 * Get information about watched status and put it in $this->watched
666 * and $this->notificationtimestamps
668 private function getWatchedInfo() {
669 $user = $this->getUser();
671 if ( $user->isAnon() ||
count( $this->everything
) == 0
672 ||
!$user->isAllowed( 'viewmywatchlist' )
677 $this->watched
= array();
678 $this->notificationtimestamps
= array();
679 $db = $this->getDB();
681 $lb = new LinkBatch( $this->everything
);
683 $this->resetQueryParams();
684 $this->addTables( array( 'watchlist' ) );
685 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
686 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
687 $this->addWhere( array(
688 $lb->constructSet( 'wl', $db ),
689 'wl_user' => $user->getID()
692 $res = $this->select( __METHOD__
);
694 foreach ( $res as $row ) {
695 if ( $this->fld_watched
) {
696 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
698 if ( $this->fld_notificationtimestamp
) {
699 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] =
700 $row->wl_notificationtimestamp
;
706 * Get the count of watchers and put it in $this->watchers
708 private function getWatcherInfo() {
709 if ( count( $this->everything
) == 0 ) {
713 $user = $this->getUser();
714 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
715 $unwatchedPageThreshold = $this->getConfig()->get( 'UnwatchedPageThreshold' );
716 if ( !$canUnwatchedpages && !is_int( $unwatchedPageThreshold ) ) {
720 $this->watchers
= array();
721 $this->showZeroWatchers
= $canUnwatchedpages;
722 $db = $this->getDB();
724 $lb = new LinkBatch( $this->everything
);
726 $this->resetQueryParams();
727 $this->addTables( array( 'watchlist' ) );
728 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
729 $this->addWhere( array(
730 $lb->constructSet( 'wl', $db )
732 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
733 if ( !$canUnwatchedpages ) {
734 $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" );
737 $res = $this->select( __METHOD__
);
739 foreach ( $res as $row ) {
740 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
744 public function getCacheMode( $params ) {
745 $publicProps = array(
753 if ( !is_null( $params['prop'] ) ) {
754 foreach ( $params['prop'] as $prop ) {
755 if ( !in_array( $prop, $publicProps ) ) {
760 if ( !is_null( $params['token'] ) ) {
767 public function getAllowedParams() {
770 ApiBase
::PARAM_DFLT
=> null,
771 ApiBase
::PARAM_ISMULTI
=> true,
772 ApiBase
::PARAM_TYPE
=> array(
776 'watchers', # private
777 'notificationtimestamp', # private
780 'readable', # private
783 // If you add more properties here, please consider whether they
784 // need to be added to getCacheMode()
787 ApiBase
::PARAM_DFLT
=> null,
788 ApiBase
::PARAM_ISMULTI
=> true,
789 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
795 public function getParamDescription() {
798 'Which additional properties to get:',
799 ' protection - List the protection level of each page',
800 ' talkid - The page ID of the talk page for each non-talk page',
801 ' watched - List the watched status of each page',
802 ' watchers - The number of watchers, if allowed',
803 ' notificationtimestamp - The watchlist notification timestamp of each page',
804 ' subjectid - The page ID of the parent page for each talk page',
805 ' url - Gives a full URL to the page, and also an edit URL',
806 ' readable - Whether the user can read this page',
807 ' preload - Gives the text returned by EditFormPreloadText',
808 ' displaytitle - Gives the way the page title is actually displayed',
810 'token' => 'Request a token to perform a data-modifying action on a page',
811 'continue' => 'When more results are available, use this to continue',
815 public function getResultProperties() {
817 ApiBase
::PROP_LIST
=> false,
819 'touched' => 'timestamp',
820 'lastrevid' => 'integer',
822 ApiBase
::PROP_TYPE
=> 'integer',
823 ApiBase
::PROP_NULLABLE
=> true
825 'length' => 'integer',
826 'redirect' => 'boolean',
828 'starttimestamp' => array(
829 ApiBase
::PROP_TYPE
=> 'timestamp',
830 ApiBase
::PROP_NULLABLE
=> true
832 'contentmodel' => 'string',
835 'watched' => 'boolean'
839 ApiBase
::PROP_TYPE
=> 'integer',
840 ApiBase
::PROP_NULLABLE
=> true
843 'notificationtimestamp' => array(
844 'notificationtimestamp' => array(
845 ApiBase
::PROP_TYPE
=> 'timestamp',
846 ApiBase
::PROP_NULLABLE
=> true
851 ApiBase
::PROP_TYPE
=> 'integer',
852 ApiBase
::PROP_NULLABLE
=> true
855 'subjectid' => array(
856 'subjectid' => array(
857 ApiBase
::PROP_TYPE
=> 'integer',
858 ApiBase
::PROP_NULLABLE
=> true
862 'fullurl' => 'string',
863 'editurl' => 'string'
866 'readable' => 'boolean'
869 'preload' => 'string'
871 'displaytitle' => array(
872 'displaytitle' => 'string'
876 self
::addTokenProperties( $props, $this->getTokenFunctions() );
881 public function getDescription() {
882 return 'Get basic page information such as namespace, title, last touched date, ...';
885 public function getExamples() {
887 'api.php?action=query&prop=info&titles=Main%20Page',
888 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
892 public function getHelpUrls() {
893 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';