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( $query, $moduleName ) {
52 parent
::__construct( $query, $moduleName, 'in' );
56 * @param $pageSet ApiPageSet
59 public function requestExtraData( $pageSet ) {
60 global $wgDisableCounters, $wgContentHandlerUseDB;
62 $pageSet->requestField( 'page_restrictions' );
63 // when resolving redirects, no page will have this field
64 if ( !$pageSet->isResolvingRedirects() ) {
65 $pageSet->requestField( 'page_is_redirect' );
67 $pageSet->requestField( 'page_is_new' );
68 if ( !$wgDisableCounters ) {
69 $pageSet->requestField( 'page_counter' );
71 $pageSet->requestField( 'page_touched' );
72 $pageSet->requestField( 'page_latest' );
73 $pageSet->requestField( 'page_len' );
74 if ( $wgContentHandlerUseDB ) {
75 $pageSet->requestField( 'page_content_model' );
80 * Get an array mapping token names to their handler functions.
81 * The prototype for a token function is func($pageid, $title)
82 * it should return a token or false (permission denied)
83 * @return array array(tokenname => function)
85 protected function getTokenFunctions() {
86 // Don't call the hooks twice
87 if ( isset( $this->tokenFunctions
) ) {
88 return $this->tokenFunctions
;
91 // If we're in JSON callback mode, no tokens can be obtained
92 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
96 $this->tokenFunctions
= array(
97 'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
98 'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
99 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
100 'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
101 'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
102 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
103 'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
104 'import' => array( 'ApiQueryInfo', 'getImportToken' ),
105 'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
107 wfRunHooks( 'APIQueryInfoTokens', array( &$this->tokenFunctions
) );
109 return $this->tokenFunctions
;
112 static protected $cachedTokens = array();
114 public static function resetTokenCache() {
115 ApiQueryInfo
::$cachedTokens = array();
118 public static function getEditToken( $pageid, $title ) {
119 // We could check for $title->userCan('edit') here,
120 // but that's too expensive for this purpose
121 // and would break caching
123 if ( !$wgUser->isAllowed( 'edit' ) ) {
127 // The token is always the same, let's exploit that
128 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
129 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
132 return ApiQueryInfo
::$cachedTokens['edit'];
135 public static function getDeleteToken( $pageid, $title ) {
137 if ( !$wgUser->isAllowed( 'delete' ) ) {
141 // The token is always the same, let's exploit that
142 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
143 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
146 return ApiQueryInfo
::$cachedTokens['delete'];
149 public static function getProtectToken( $pageid, $title ) {
151 if ( !$wgUser->isAllowed( 'protect' ) ) {
155 // The token is always the same, let's exploit that
156 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
157 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
160 return ApiQueryInfo
::$cachedTokens['protect'];
163 public static function getMoveToken( $pageid, $title ) {
165 if ( !$wgUser->isAllowed( 'move' ) ) {
169 // The token is always the same, let's exploit that
170 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
171 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
174 return ApiQueryInfo
::$cachedTokens['move'];
177 public static function getBlockToken( $pageid, $title ) {
179 if ( !$wgUser->isAllowed( 'block' ) ) {
183 // The token is always the same, let's exploit that
184 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
185 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
188 return ApiQueryInfo
::$cachedTokens['block'];
191 public static function getUnblockToken( $pageid, $title ) {
192 // Currently, this is exactly the same as the block token
193 return self
::getBlockToken( $pageid, $title );
196 public static function getEmailToken( $pageid, $title ) {
198 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailUser() ) {
202 // The token is always the same, let's exploit that
203 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
204 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
207 return ApiQueryInfo
::$cachedTokens['email'];
210 public static function getImportToken( $pageid, $title ) {
212 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
216 // The token is always the same, let's exploit that
217 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
218 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
221 return ApiQueryInfo
::$cachedTokens['import'];
224 public static function getWatchToken( $pageid, $title ) {
226 if ( !$wgUser->isLoggedIn() ) {
230 // The token is always the same, let's exploit that
231 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
232 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
235 return ApiQueryInfo
::$cachedTokens['watch'];
238 public static function getOptionsToken( $pageid, $title ) {
240 if ( !$wgUser->isLoggedIn() ) {
244 // The token is always the same, let's exploit that
245 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
246 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
249 return ApiQueryInfo
::$cachedTokens['options'];
252 public function execute() {
253 $this->params
= $this->extractRequestParams();
254 if ( !is_null( $this->params
['prop'] ) ) {
255 $prop = array_flip( $this->params
['prop'] );
256 $this->fld_protection
= isset( $prop['protection'] );
257 $this->fld_watched
= isset( $prop['watched'] );
258 $this->fld_watchers
= isset( $prop['watchers'] );
259 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
260 $this->fld_talkid
= isset( $prop['talkid'] );
261 $this->fld_subjectid
= isset( $prop['subjectid'] );
262 $this->fld_url
= isset( $prop['url'] );
263 $this->fld_readable
= isset( $prop['readable'] );
264 $this->fld_preload
= isset( $prop['preload'] );
265 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
268 $pageSet = $this->getPageSet();
269 $this->titles
= $pageSet->getGoodTitles();
270 $this->missing
= $pageSet->getMissingTitles();
271 $this->everything
= $this->titles +
$this->missing
;
272 $result = $this->getResult();
274 uasort( $this->everything
, array( 'Title', 'compare' ) );
275 if ( !is_null( $this->params
['continue'] ) ) {
276 // Throw away any titles we're gonna skip so they don't
278 $cont = explode( '|', $this->params
['continue'] );
279 $this->dieContinueUsageIf( count( $cont ) != 2 );
280 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
281 foreach ( $this->everything
as $pageid => $title ) {
282 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
285 unset( $this->titles
[$pageid] );
286 unset( $this->missing
[$pageid] );
287 unset( $this->everything
[$pageid] );
291 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
292 // when resolving redirects, no page will have this field
293 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
294 ?
$pageSet->getCustomField( 'page_is_redirect' )
296 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
298 global $wgDisableCounters;
300 if ( !$wgDisableCounters ) {
301 $this->pageCounter
= $pageSet->getCustomField( 'page_counter' );
303 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
304 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
305 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
307 // Get protection info if requested
308 if ( $this->fld_protection
) {
309 $this->getProtectionInfo();
312 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
313 $this->getWatchedInfo();
316 if ( $this->fld_watchers
) {
317 $this->getWatcherInfo();
320 // Run the talkid/subjectid query if requested
321 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
325 if ( $this->fld_displaytitle
) {
326 $this->getDisplayTitle();
329 /** @var $title Title */
330 foreach ( $this->everything
as $pageid => $title ) {
331 $pageInfo = $this->extractPageInfo( $pageid, $title );
332 $fit = $result->addValue( array(
335 ), $pageid, $pageInfo );
337 $this->setContinueEnumParameter( 'continue',
338 $title->getNamespace() . '|' .
346 * Get a result array with information about a title
347 * @param int $pageid Page ID (negative for missing titles)
348 * @param $title Title object
351 private function extractPageInfo( $pageid, $title ) {
353 // $title->exists() needs pageid, which is not set for all title objects
354 $titleExists = $pageid > 0;
355 $ns = $title->getNamespace();
356 $dbkey = $title->getDBkey();
358 $pageInfo['contentmodel'] = $title->getContentModel();
359 $pageInfo['pagelanguage'] = $title->getPageLanguage()->getCode();
361 if ( $titleExists ) {
362 global $wgDisableCounters;
364 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
365 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
366 $pageInfo['counter'] = $wgDisableCounters
368 : intval( $this->pageCounter
[$pageid] );
369 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
371 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
372 $pageInfo['redirect'] = '';
374 if ( $this->pageIsNew
[$pageid] ) {
375 $pageInfo['new'] = '';
379 if ( !is_null( $this->params
['token'] ) ) {
380 $tokenFunctions = $this->getTokenFunctions();
381 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
382 foreach ( $this->params
['token'] as $t ) {
383 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
384 if ( $val === false ) {
385 $this->setWarning( "Action '$t' is not allowed for the current user" );
387 $pageInfo[$t . 'token'] = $val;
392 if ( $this->fld_protection
) {
393 $pageInfo['protection'] = array();
394 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
395 $pageInfo['protection'] =
396 $this->protections
[$ns][$dbkey];
398 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
401 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
402 $pageInfo['watched'] = '';
405 if ( $this->fld_watchers
) {
406 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
407 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
408 } elseif ( $this->showZeroWatchers
) {
409 $pageInfo['watchers'] = 0;
413 if ( $this->fld_notificationtimestamp
) {
414 $pageInfo['notificationtimestamp'] = '';
415 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
416 $pageInfo['notificationtimestamp'] =
417 wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
421 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
422 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
425 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
426 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
429 if ( $this->fld_url
) {
430 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
431 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
433 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
434 $pageInfo['readable'] = '';
437 if ( $this->fld_preload
) {
438 if ( $titleExists ) {
439 $pageInfo['preload'] = '';
442 wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
444 $pageInfo['preload'] = $text;
448 if ( $this->fld_displaytitle
) {
449 if ( isset( $this->displaytitles
[$pageid] ) ) {
450 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
452 $pageInfo['displaytitle'] = $title->getPrefixedText();
460 * Get information about protections and put it in $protections
462 private function getProtectionInfo() {
464 $this->protections
= array();
465 $db = $this->getDB();
467 // Get normal protections for existing titles
468 if ( count( $this->titles
) ) {
469 $this->resetQueryParams();
470 $this->addTables( 'page_restrictions' );
471 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
472 'pr_expiry', 'pr_cascade' ) );
473 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
475 $res = $this->select( __METHOD__
);
476 foreach ( $res as $row ) {
477 /** @var $title Title */
478 $title = $this->titles
[$row->pr_page
];
480 'type' => $row->pr_type
,
481 'level' => $row->pr_level
,
482 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
484 if ( $row->pr_cascade
) {
487 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
489 // Also check old restrictions
490 foreach ( $this->titles
as $pageId => $title ) {
491 if ( $this->pageRestrictions
[$pageId] ) {
492 $namespace = $title->getNamespace();
493 $dbKey = $title->getDBkey();
494 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
495 foreach ( $restrictions as $restrict ) {
496 $temp = explode( '=', trim( $restrict ) );
497 if ( count( $temp ) == 1 ) {
498 // old old format should be treated as edit/move restriction
499 $restriction = trim( $temp[0] );
501 if ( $restriction == '' ) {
504 $this->protections
[$namespace][$dbKey][] = array(
506 'level' => $restriction,
507 'expiry' => 'infinity',
509 $this->protections
[$namespace][$dbKey][] = array(
511 'level' => $restriction,
512 'expiry' => 'infinity',
515 $restriction = trim( $temp[1] );
516 if ( $restriction == '' ) {
519 $this->protections
[$namespace][$dbKey][] = array(
521 'level' => $restriction,
522 'expiry' => 'infinity',
530 // Get protections for missing titles
531 if ( count( $this->missing
) ) {
532 $this->resetQueryParams();
533 $lb = new LinkBatch( $this->missing
);
534 $this->addTables( 'protected_titles' );
535 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
536 $this->addWhere( $lb->constructSet( 'pt', $db ) );
537 $res = $this->select( __METHOD__
);
538 foreach ( $res as $row ) {
539 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
541 'level' => $row->pt_create_perm
,
542 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
547 // Cascading protections
548 $images = $others = array();
549 foreach ( $this->everything
as $title ) {
550 if ( $title->getNamespace() == NS_FILE
) {
551 $images[] = $title->getDBkey();
557 if ( count( $others ) ) {
558 // Non-images: check templatelinks
559 $lb = new LinkBatch( $others );
560 $this->resetQueryParams();
561 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
562 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
563 'page_title', 'page_namespace',
564 'tl_title', 'tl_namespace' ) );
565 $this->addWhere( $lb->constructSet( 'tl', $db ) );
566 $this->addWhere( 'pr_page = page_id' );
567 $this->addWhere( 'pr_page = tl_from' );
568 $this->addWhereFld( 'pr_cascade', 1 );
570 $res = $this->select( __METHOD__
);
571 foreach ( $res as $row ) {
572 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
573 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
574 'type' => $row->pr_type
,
575 'level' => $row->pr_level
,
576 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
577 'source' => $source->getPrefixedText()
582 if ( count( $images ) ) {
583 // Images: check imagelinks
584 $this->resetQueryParams();
585 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
586 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
587 'page_title', 'page_namespace', 'il_to' ) );
588 $this->addWhere( 'pr_page = page_id' );
589 $this->addWhere( 'pr_page = il_from' );
590 $this->addWhereFld( 'pr_cascade', 1 );
591 $this->addWhereFld( 'il_to', $images );
593 $res = $this->select( __METHOD__
);
594 foreach ( $res as $row ) {
595 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
596 $this->protections
[NS_FILE
][$row->il_to
][] = array(
597 'type' => $row->pr_type
,
598 'level' => $row->pr_level
,
599 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
600 'source' => $source->getPrefixedText()
607 * Get talk page IDs (if requested) and subject page IDs (if requested)
608 * and put them in $talkids and $subjectids
610 private function getTSIDs() {
611 $getTitles = $this->talkids
= $this->subjectids
= array();
614 foreach ( $this->everything
as $t ) {
615 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
616 if ( $this->fld_subjectid
) {
617 $getTitles[] = $t->getSubjectPage();
619 } elseif ( $this->fld_talkid
) {
620 $getTitles[] = $t->getTalkPage();
623 if ( !count( $getTitles ) ) {
627 $db = $this->getDB();
629 // Construct a custom WHERE clause that matches
630 // all titles in $getTitles
631 $lb = new LinkBatch( $getTitles );
632 $this->resetQueryParams();
633 $this->addTables( 'page' );
634 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
635 $this->addWhere( $lb->constructSet( 'page', $db ) );
636 $res = $this->select( __METHOD__
);
637 foreach ( $res as $row ) {
638 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
639 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
640 intval( $row->page_id
);
642 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
643 intval( $row->page_id
);
648 private function getDisplayTitle() {
649 $this->displaytitles
= array();
651 $pageIds = array_keys( $this->titles
);
653 if ( !count( $pageIds ) ) {
657 $this->resetQueryParams();
658 $this->addTables( 'page_props' );
659 $this->addFields( array( 'pp_page', 'pp_value' ) );
660 $this->addWhereFld( 'pp_page', $pageIds );
661 $this->addWhereFld( 'pp_propname', 'displaytitle' );
662 $res = $this->select( __METHOD__
);
664 foreach ( $res as $row ) {
665 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
670 * Get information about watched status and put it in $this->watched
671 * and $this->notificationtimestamps
673 private function getWatchedInfo() {
674 $user = $this->getUser();
676 if ( $user->isAnon() ||
count( $this->everything
) == 0
677 ||
!$user->isAllowed( 'viewmywatchlist' )
682 $this->watched
= array();
683 $this->notificationtimestamps
= array();
684 $db = $this->getDB();
686 $lb = new LinkBatch( $this->everything
);
688 $this->resetQueryParams();
689 $this->addTables( array( 'watchlist' ) );
690 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
691 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
692 $this->addWhere( array(
693 $lb->constructSet( 'wl', $db ),
694 'wl_user' => $user->getID()
697 $res = $this->select( __METHOD__
);
699 foreach ( $res as $row ) {
700 if ( $this->fld_watched
) {
701 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
703 if ( $this->fld_notificationtimestamp
) {
704 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] =
705 $row->wl_notificationtimestamp
;
711 * Get the count of watchers and put it in $this->watchers
713 private function getWatcherInfo() {
714 global $wgUnwatchedPageThreshold;
716 if ( count( $this->everything
) == 0 ) {
720 $user = $this->getUser();
721 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
722 if ( !$canUnwatchedpages && !is_int( $wgUnwatchedPageThreshold ) ) {
726 $this->watchers
= array();
727 $this->showZeroWatchers
= $canUnwatchedpages;
728 $db = $this->getDB();
730 $lb = new LinkBatch( $this->everything
);
732 $this->resetQueryParams();
733 $this->addTables( array( 'watchlist' ) );
734 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
735 $this->addWhere( array(
736 $lb->constructSet( 'wl', $db )
738 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
739 if ( !$canUnwatchedpages ) {
740 $this->addOption( 'HAVING', "COUNT(*) >= $wgUnwatchedPageThreshold" );
743 $res = $this->select( __METHOD__
);
745 foreach ( $res as $row ) {
746 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
750 public function getCacheMode( $params ) {
751 $publicProps = array(
759 if ( !is_null( $params['prop'] ) ) {
760 foreach ( $params['prop'] as $prop ) {
761 if ( !in_array( $prop, $publicProps ) ) {
766 if ( !is_null( $params['token'] ) ) {
773 public function getAllowedParams() {
776 ApiBase
::PARAM_DFLT
=> null,
777 ApiBase
::PARAM_ISMULTI
=> true,
778 ApiBase
::PARAM_TYPE
=> array(
782 'watchers', # private
783 'notificationtimestamp', # private
786 'readable', # private
789 // If you add more properties here, please consider whether they
790 // need to be added to getCacheMode()
793 ApiBase
::PARAM_DFLT
=> null,
794 ApiBase
::PARAM_ISMULTI
=> true,
795 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
801 public function getParamDescription() {
804 'Which additional properties to get:',
805 ' protection - List the protection level of each page',
806 ' talkid - The page ID of the talk page for each non-talk page',
807 ' watched - List the watched status of each page',
808 ' watchers - The number of watchers, if allowed',
809 ' notificationtimestamp - The watchlist notification timestamp of each page',
810 ' subjectid - The page ID of the parent page for each talk page',
811 ' url - Gives a full URL to the page, and also an edit URL',
812 ' readable - Whether the user can read this page',
813 ' preload - Gives the text returned by EditFormPreloadText',
814 ' displaytitle - Gives the way the page title is actually displayed',
816 'token' => 'Request a token to perform a data-modifying action on a page',
817 'continue' => 'When more results are available, use this to continue',
821 public function getResultProperties() {
823 ApiBase
::PROP_LIST
=> false,
825 'touched' => 'timestamp',
826 'lastrevid' => 'integer',
828 ApiBase
::PROP_TYPE
=> 'integer',
829 ApiBase
::PROP_NULLABLE
=> true
831 'length' => 'integer',
832 'redirect' => 'boolean',
834 'starttimestamp' => array(
835 ApiBase
::PROP_TYPE
=> 'timestamp',
836 ApiBase
::PROP_NULLABLE
=> true
838 'contentmodel' => 'string',
841 'watched' => 'boolean'
845 ApiBase
::PROP_TYPE
=> 'integer',
846 ApiBase
::PROP_NULLABLE
=> true
849 'notificationtimestamp' => array(
850 'notificationtimestamp' => array(
851 ApiBase
::PROP_TYPE
=> 'timestamp',
852 ApiBase
::PROP_NULLABLE
=> true
857 ApiBase
::PROP_TYPE
=> 'integer',
858 ApiBase
::PROP_NULLABLE
=> true
861 'subjectid' => array(
862 'subjectid' => array(
863 ApiBase
::PROP_TYPE
=> 'integer',
864 ApiBase
::PROP_NULLABLE
=> true
868 'fullurl' => 'string',
869 'editurl' => 'string'
872 'readable' => 'boolean'
875 'preload' => 'string'
877 'displaytitle' => array(
878 'displaytitle' => 'string'
882 self
::addTokenProperties( $props, $this->getTokenFunctions() );
887 public function getDescription() {
888 return 'Get basic page information such as namespace, title, last touched date, ...';
891 public function getExamples() {
893 'api.php?action=query&prop=info&titles=Main%20Page',
894 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
898 public function getHelpUrls() {
899 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';