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, $talkids, $subjectids, $displaytitles;
46 private $showZeroWatchers = false;
48 private $tokenFunctions;
50 public function __construct( $query, $moduleName ) {
51 parent
::__construct( $query, $moduleName, 'in' );
55 * @param $pageSet ApiPageSet
58 public function requestExtraData( $pageSet ) {
59 global $wgDisableCounters;
61 $pageSet->requestField( 'page_restrictions' );
62 // when resolving redirects, no page will have this field
63 if ( !$pageSet->isResolvingRedirects() ) {
64 $pageSet->requestField( 'page_is_redirect' );
66 $pageSet->requestField( 'page_is_new' );
67 if ( !$wgDisableCounters ) {
68 $pageSet->requestField( 'page_counter' );
70 $pageSet->requestField( 'page_touched' );
71 $pageSet->requestField( 'page_latest' );
72 $pageSet->requestField( 'page_len' );
76 * Get an array mapping token names to their handler functions.
77 * The prototype for a token function is func($pageid, $title)
78 * it should return a token or false (permission denied)
79 * @return array array(tokenname => function)
81 protected function getTokenFunctions() {
82 // Don't call the hooks twice
83 if ( isset( $this->tokenFunctions
) ) {
84 return $this->tokenFunctions
;
87 // If we're in JSON callback mode, no tokens can be obtained
88 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
92 $this->tokenFunctions
= array(
93 'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
94 'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
95 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
96 'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
97 'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
98 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
99 'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
100 'import' => array( 'ApiQueryInfo', 'getImportToken' ),
101 'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
103 wfRunHooks( 'APIQueryInfoTokens', array( &$this->tokenFunctions
) );
104 return $this->tokenFunctions
;
107 static $cachedTokens = array();
109 public static function resetTokenCache() {
110 ApiQueryInfo
::$cachedTokens = array();
113 public static function getEditToken( $pageid, $title ) {
114 // We could check for $title->userCan('edit') here,
115 // but that's too expensive for this purpose
116 // and would break caching
118 if ( !$wgUser->isAllowed( 'edit' ) ) {
122 // The token is always the same, let's exploit that
123 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
124 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
127 return ApiQueryInfo
::$cachedTokens['edit'];
130 public static function getDeleteToken( $pageid, $title ) {
132 if ( !$wgUser->isAllowed( 'delete' ) ) {
136 // The token is always the same, let's exploit that
137 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
138 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
141 return ApiQueryInfo
::$cachedTokens['delete'];
144 public static function getProtectToken( $pageid, $title ) {
146 if ( !$wgUser->isAllowed( 'protect' ) ) {
150 // The token is always the same, let's exploit that
151 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
152 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
155 return ApiQueryInfo
::$cachedTokens['protect'];
158 public static function getMoveToken( $pageid, $title ) {
160 if ( !$wgUser->isAllowed( 'move' ) ) {
164 // The token is always the same, let's exploit that
165 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
166 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
169 return ApiQueryInfo
::$cachedTokens['move'];
172 public static function getBlockToken( $pageid, $title ) {
174 if ( !$wgUser->isAllowed( 'block' ) ) {
178 // The token is always the same, let's exploit that
179 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
180 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
183 return ApiQueryInfo
::$cachedTokens['block'];
186 public static function getUnblockToken( $pageid, $title ) {
187 // Currently, this is exactly the same as the block token
188 return self
::getBlockToken( $pageid, $title );
191 public static function getEmailToken( $pageid, $title ) {
193 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailUser() ) {
197 // The token is always the same, let's exploit that
198 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
199 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
202 return ApiQueryInfo
::$cachedTokens['email'];
205 public static function getImportToken( $pageid, $title ) {
207 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
211 // The token is always the same, let's exploit that
212 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
213 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
216 return ApiQueryInfo
::$cachedTokens['import'];
219 public static function getWatchToken( $pageid, $title ) {
221 if ( !$wgUser->isLoggedIn() ) {
225 // The token is always the same, let's exploit that
226 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
227 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
230 return ApiQueryInfo
::$cachedTokens['watch'];
233 public static function getOptionsToken( $pageid, $title ) {
235 if ( !$wgUser->isLoggedIn() ) {
239 // The token is always the same, let's exploit that
240 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
241 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
244 return ApiQueryInfo
::$cachedTokens['options'];
247 public function execute() {
248 $this->params
= $this->extractRequestParams();
249 if ( !is_null( $this->params
['prop'] ) ) {
250 $prop = array_flip( $this->params
['prop'] );
251 $this->fld_protection
= isset( $prop['protection'] );
252 $this->fld_watched
= isset( $prop['watched'] );
253 $this->fld_watchers
= isset( $prop['watchers'] );
254 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
255 $this->fld_talkid
= isset( $prop['talkid'] );
256 $this->fld_subjectid
= isset( $prop['subjectid'] );
257 $this->fld_url
= isset( $prop['url'] );
258 $this->fld_readable
= isset( $prop['readable'] );
259 $this->fld_preload
= isset( $prop['preload'] );
260 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
263 $pageSet = $this->getPageSet();
264 $this->titles
= $pageSet->getGoodTitles();
265 $this->missing
= $pageSet->getMissingTitles();
266 $this->everything
= $this->titles +
$this->missing
;
267 $result = $this->getResult();
269 uasort( $this->everything
, array( 'Title', 'compare' ) );
270 if ( !is_null( $this->params
['continue'] ) ) {
271 // Throw away any titles we're gonna skip so they don't
273 $cont = explode( '|', $this->params
['continue'] );
274 $this->dieContinueUsageIf( count( $cont ) != 2 );
275 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
276 foreach ( $this->everything
as $pageid => $title ) {
277 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
280 unset( $this->titles
[$pageid] );
281 unset( $this->missing
[$pageid] );
282 unset( $this->everything
[$pageid] );
286 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
287 // when resolving redirects, no page will have this field
288 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
289 ?
$pageSet->getCustomField( 'page_is_redirect' )
291 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
293 global $wgDisableCounters;
295 if ( !$wgDisableCounters ) {
296 $this->pageCounter
= $pageSet->getCustomField( 'page_counter' );
298 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
299 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
300 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
302 // Get protection info if requested
303 if ( $this->fld_protection
) {
304 $this->getProtectionInfo();
307 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
308 $this->getWatchedInfo();
311 if ( $this->fld_watchers
) {
312 $this->getWatcherInfo();
315 // Run the talkid/subjectid query if requested
316 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
320 if ( $this->fld_displaytitle
) {
321 $this->getDisplayTitle();
324 /** @var $title Title */
325 foreach ( $this->everything
as $pageid => $title ) {
326 $pageInfo = $this->extractPageInfo( $pageid, $title );
327 $fit = $result->addValue( array(
330 ), $pageid, $pageInfo );
332 $this->setContinueEnumParameter( 'continue',
333 $title->getNamespace() . '|' .
341 * Get a result array with information about a title
342 * @param int $pageid Page ID (negative for missing titles)
343 * @param $title Title object
346 private function extractPageInfo( $pageid, $title ) {
348 $titleExists = $pageid > 0; //$title->exists() needs pageid, which is not set for all title objects
349 $ns = $title->getNamespace();
350 $dbkey = $title->getDBkey();
351 if ( $titleExists ) {
352 global $wgDisableCounters;
354 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
355 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
356 $pageInfo['counter'] = $wgDisableCounters
358 : intval( $this->pageCounter
[$pageid] );
359 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
361 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
362 $pageInfo['redirect'] = '';
364 if ( $this->pageIsNew
[$pageid] ) {
365 $pageInfo['new'] = '';
369 if ( !is_null( $this->params
['token'] ) ) {
370 $tokenFunctions = $this->getTokenFunctions();
371 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
372 foreach ( $this->params
['token'] as $t ) {
373 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
374 if ( $val === false ) {
375 $this->setWarning( "Action '$t' is not allowed for the current user" );
377 $pageInfo[$t . 'token'] = $val;
382 if ( $this->fld_protection
) {
383 $pageInfo['protection'] = array();
384 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
385 $pageInfo['protection'] =
386 $this->protections
[$ns][$dbkey];
388 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
391 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
392 $pageInfo['watched'] = '';
395 if ( $this->fld_watchers
) {
396 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
397 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
398 } elseif ( $this->showZeroWatchers
) {
399 $pageInfo['watchers'] = 0;
403 if ( $this->fld_notificationtimestamp
) {
404 $pageInfo['notificationtimestamp'] = '';
405 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
406 $pageInfo['notificationtimestamp'] = wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
410 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
411 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
414 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
415 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
418 if ( $this->fld_url
) {
419 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
420 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
422 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
423 $pageInfo['readable'] = '';
426 if ( $this->fld_preload
) {
427 if ( $titleExists ) {
428 $pageInfo['preload'] = '';
431 wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
433 $pageInfo['preload'] = $text;
437 if ( $this->fld_displaytitle
) {
438 if ( isset( $this->displaytitles
[$pageid] ) ) {
439 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
441 $pageInfo['displaytitle'] = $title->getPrefixedText();
449 * Get information about protections and put it in $protections
451 private function getProtectionInfo() {
453 $this->protections
= array();
454 $db = $this->getDB();
456 // Get normal protections for existing titles
457 if ( count( $this->titles
) ) {
458 $this->resetQueryParams();
459 $this->addTables( 'page_restrictions' );
460 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
461 'pr_expiry', 'pr_cascade' ) );
462 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
464 $res = $this->select( __METHOD__
);
465 foreach ( $res as $row ) {
466 /** @var $title Title */
467 $title = $this->titles
[$row->pr_page
];
469 'type' => $row->pr_type
,
470 'level' => $row->pr_level
,
471 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
473 if ( $row->pr_cascade
) {
476 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
478 // Also check old restrictions
479 foreach ( $this->titles
as $pageId => $title ) {
480 if ( $this->pageRestrictions
[$pageId] ) {
481 $namespace = $title->getNamespace();
482 $dbKey = $title->getDBkey();
483 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
484 foreach ( $restrictions as $restrict ) {
485 $temp = explode( '=', trim( $restrict ) );
486 if ( count( $temp ) == 1 ) {
487 // old old format should be treated as edit/move restriction
488 $restriction = trim( $temp[0] );
490 if ( $restriction == '' ) {
493 $this->protections
[$namespace][$dbKey][] = array(
495 'level' => $restriction,
496 'expiry' => 'infinity',
498 $this->protections
[$namespace][$dbKey][] = array(
500 'level' => $restriction,
501 'expiry' => 'infinity',
504 $restriction = trim( $temp[1] );
505 if ( $restriction == '' ) {
508 $this->protections
[$namespace][$dbKey][] = array(
510 'level' => $restriction,
511 'expiry' => 'infinity',
519 // Get protections for missing titles
520 if ( count( $this->missing
) ) {
521 $this->resetQueryParams();
522 $lb = new LinkBatch( $this->missing
);
523 $this->addTables( 'protected_titles' );
524 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
525 $this->addWhere( $lb->constructSet( 'pt', $db ) );
526 $res = $this->select( __METHOD__
);
527 foreach ( $res as $row ) {
528 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
530 'level' => $row->pt_create_perm
,
531 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
536 // Cascading protections
537 $images = $others = array();
538 foreach ( $this->everything
as $title ) {
539 if ( $title->getNamespace() == NS_FILE
) {
540 $images[] = $title->getDBkey();
546 if ( count( $others ) ) {
547 // Non-images: check templatelinks
548 $lb = new LinkBatch( $others );
549 $this->resetQueryParams();
550 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
551 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
552 'page_title', 'page_namespace',
553 'tl_title', 'tl_namespace' ) );
554 $this->addWhere( $lb->constructSet( 'tl', $db ) );
555 $this->addWhere( 'pr_page = page_id' );
556 $this->addWhere( 'pr_page = tl_from' );
557 $this->addWhereFld( 'pr_cascade', 1 );
559 $res = $this->select( __METHOD__
);
560 foreach ( $res as $row ) {
561 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
562 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
563 'type' => $row->pr_type
,
564 'level' => $row->pr_level
,
565 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
566 'source' => $source->getPrefixedText()
571 if ( count( $images ) ) {
572 // Images: check imagelinks
573 $this->resetQueryParams();
574 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
575 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
576 'page_title', 'page_namespace', 'il_to' ) );
577 $this->addWhere( 'pr_page = page_id' );
578 $this->addWhere( 'pr_page = il_from' );
579 $this->addWhereFld( 'pr_cascade', 1 );
580 $this->addWhereFld( 'il_to', $images );
582 $res = $this->select( __METHOD__
);
583 foreach ( $res as $row ) {
584 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
585 $this->protections
[NS_FILE
][$row->il_to
][] = array(
586 'type' => $row->pr_type
,
587 'level' => $row->pr_level
,
588 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
589 'source' => $source->getPrefixedText()
596 * Get talk page IDs (if requested) and subject page IDs (if requested)
597 * and put them in $talkids and $subjectids
599 private function getTSIDs() {
600 $getTitles = $this->talkids
= $this->subjectids
= array();
603 foreach ( $this->everything
as $t ) {
604 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
605 if ( $this->fld_subjectid
) {
606 $getTitles[] = $t->getSubjectPage();
608 } elseif ( $this->fld_talkid
) {
609 $getTitles[] = $t->getTalkPage();
612 if ( !count( $getTitles ) ) {
616 $db = $this->getDB();
618 // Construct a custom WHERE clause that matches
619 // all titles in $getTitles
620 $lb = new LinkBatch( $getTitles );
621 $this->resetQueryParams();
622 $this->addTables( 'page' );
623 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
624 $this->addWhere( $lb->constructSet( 'page', $db ) );
625 $res = $this->select( __METHOD__
);
626 foreach ( $res as $row ) {
627 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
628 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
629 intval( $row->page_id
);
631 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
632 intval( $row->page_id
);
637 private function getDisplayTitle() {
638 $this->displaytitles
= array();
640 $pageIds = array_keys( $this->titles
);
642 if ( !count( $pageIds ) ) {
646 $this->resetQueryParams();
647 $this->addTables( 'page_props' );
648 $this->addFields( array( 'pp_page', 'pp_value' ) );
649 $this->addWhereFld( 'pp_page', $pageIds );
650 $this->addWhereFld( 'pp_propname', 'displaytitle' );
651 $res = $this->select( __METHOD__
);
653 foreach ( $res as $row ) {
654 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
659 * Get information about watched status and put it in $this->watched
660 * and $this->notificationtimestamps
662 private function getWatchedInfo() {
663 $user = $this->getUser();
665 if ( $user->isAnon() ||
count( $this->everything
) == 0 ) {
669 $this->watched
= array();
670 $this->notificationtimestamps
= array();
671 $db = $this->getDB();
673 $lb = new LinkBatch( $this->everything
);
675 $this->resetQueryParams();
676 $this->addTables( array( 'watchlist' ) );
677 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
678 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
679 $this->addWhere( array(
680 $lb->constructSet( 'wl', $db ),
681 'wl_user' => $user->getID()
684 $res = $this->select( __METHOD__
);
686 foreach ( $res as $row ) {
687 if ( $this->fld_watched
) {
688 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
690 if ( $this->fld_notificationtimestamp
) {
691 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] = $row->wl_notificationtimestamp
;
697 * Get the count of watchers and put it in $this->watchers
699 private function getWatcherInfo() {
700 global $wgUnwatchedPageThreshold;
702 if ( count( $this->everything
) == 0 ) {
706 $user = $this->getUser();
707 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
708 if ( !$canUnwatchedpages && !is_int( $wgUnwatchedPageThreshold ) ) {
712 $this->watchers
= array();
713 $this->showZeroWatchers
= $canUnwatchedpages;
714 $db = $this->getDB();
716 $lb = new LinkBatch( $this->everything
);
718 $this->resetQueryParams();
719 $this->addTables( array( 'watchlist' ) );
720 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
721 $this->addWhere( array(
722 $lb->constructSet( 'wl', $db )
724 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
725 if ( !$canUnwatchedpages ) {
726 $this->addOption( 'HAVING', "COUNT(*) >= $wgUnwatchedPageThreshold" );
729 $res = $this->select( __METHOD__
);
731 foreach ( $res as $row ) {
732 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
736 public function getCacheMode( $params ) {
737 $publicProps = array(
745 if ( !is_null( $params['prop'] ) ) {
746 foreach ( $params['prop'] as $prop ) {
747 if ( !in_array( $prop, $publicProps ) ) {
752 if ( !is_null( $params['token'] ) ) {
758 public function getAllowedParams() {
761 ApiBase
::PARAM_DFLT
=> null,
762 ApiBase
::PARAM_ISMULTI
=> true,
763 ApiBase
::PARAM_TYPE
=> array(
767 'watchers', # private
768 'notificationtimestamp', # private
771 'readable', # private
774 // If you add more properties here, please consider whether they
775 // need to be added to getCacheMode()
778 ApiBase
::PARAM_DFLT
=> null,
779 ApiBase
::PARAM_ISMULTI
=> true,
780 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
786 public function getParamDescription() {
789 'Which additional properties to get:',
790 ' protection - List the protection level of each page',
791 ' talkid - The page ID of the talk page for each non-talk page',
792 ' watched - List the watched status of each page',
793 ' watchers - The number of watchers, if allowed',
794 ' notificationtimestamp - The watchlist notification timestamp of each page',
795 ' subjectid - The page ID of the parent page for each talk page',
796 ' url - Gives a full URL to the page, and also an edit URL',
797 ' readable - Whether the user can read this page',
798 ' preload - Gives the text returned by EditFormPreloadText',
799 ' displaytitle - Gives the way the page title is actually displayed',
801 'token' => 'Request a token to perform a data-modifying action on a page',
802 'continue' => 'When more results are available, use this to continue',
806 public function getResultProperties() {
808 ApiBase
::PROP_LIST
=> false,
810 'touched' => 'timestamp',
811 'lastrevid' => 'integer',
813 ApiBase
::PROP_TYPE
=> 'integer',
814 ApiBase
::PROP_NULLABLE
=> true
816 'length' => 'integer',
817 'redirect' => 'boolean',
819 'starttimestamp' => array(
820 ApiBase
::PROP_TYPE
=> 'timestamp',
821 ApiBase
::PROP_NULLABLE
=> true
825 'watched' => 'boolean'
829 ApiBase
::PROP_TYPE
=> 'integer',
830 ApiBase
::PROP_NULLABLE
=> true
833 'notificationtimestamp' => array(
834 'notificationtimestamp' => array(
835 ApiBase
::PROP_TYPE
=> 'timestamp',
836 ApiBase
::PROP_NULLABLE
=> true
841 ApiBase
::PROP_TYPE
=> 'integer',
842 ApiBase
::PROP_NULLABLE
=> true
845 'subjectid' => array(
846 'subjectid' => array(
847 ApiBase
::PROP_TYPE
=> 'integer',
848 ApiBase
::PROP_NULLABLE
=> true
852 'fullurl' => 'string',
853 'editurl' => 'string'
856 'readable' => 'boolean'
859 'preload' => 'string'
861 'displaytitle' => array(
862 'displaytitle' => 'string'
866 self
::addTokenProperties( $props, $this->getTokenFunctions() );
871 public function getDescription() {
872 return 'Get basic page information such as namespace, title, last touched date, ...';
875 public function getExamples() {
877 'api.php?action=query&prop=info&titles=Main%20Page',
878 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
882 public function getHelpUrls() {
883 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';