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, $wgContentHandlerUseDB;
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' );
73 if ( $wgContentHandlerUseDB ) {
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
) );
107 return $this->tokenFunctions
;
110 static $cachedTokens = array();
112 public static function resetTokenCache() {
113 ApiQueryInfo
::$cachedTokens = array();
116 public static function getEditToken( $pageid, $title ) {
117 // We could check for $title->userCan('edit') here,
118 // but that's too expensive for this purpose
119 // and would break caching
121 if ( !$wgUser->isAllowed( 'edit' ) ) {
125 // The token is always the same, let's exploit that
126 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
127 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
130 return ApiQueryInfo
::$cachedTokens['edit'];
133 public static function getDeleteToken( $pageid, $title ) {
135 if ( !$wgUser->isAllowed( 'delete' ) ) {
139 // The token is always the same, let's exploit that
140 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
141 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
144 return ApiQueryInfo
::$cachedTokens['delete'];
147 public static function getProtectToken( $pageid, $title ) {
149 if ( !$wgUser->isAllowed( 'protect' ) ) {
153 // The token is always the same, let's exploit that
154 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
155 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
158 return ApiQueryInfo
::$cachedTokens['protect'];
161 public static function getMoveToken( $pageid, $title ) {
163 if ( !$wgUser->isAllowed( 'move' ) ) {
167 // The token is always the same, let's exploit that
168 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
169 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
172 return ApiQueryInfo
::$cachedTokens['move'];
175 public static function getBlockToken( $pageid, $title ) {
177 if ( !$wgUser->isAllowed( 'block' ) ) {
181 // The token is always the same, let's exploit that
182 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
183 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
186 return ApiQueryInfo
::$cachedTokens['block'];
189 public static function getUnblockToken( $pageid, $title ) {
190 // Currently, this is exactly the same as the block token
191 return self
::getBlockToken( $pageid, $title );
194 public static function getEmailToken( $pageid, $title ) {
196 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailUser() ) {
200 // The token is always the same, let's exploit that
201 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
202 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
205 return ApiQueryInfo
::$cachedTokens['email'];
208 public static function getImportToken( $pageid, $title ) {
210 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
214 // The token is always the same, let's exploit that
215 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
216 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
219 return ApiQueryInfo
::$cachedTokens['import'];
222 public static function getWatchToken( $pageid, $title ) {
224 if ( !$wgUser->isLoggedIn() ) {
228 // The token is always the same, let's exploit that
229 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
230 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
233 return ApiQueryInfo
::$cachedTokens['watch'];
236 public static function getOptionsToken( $pageid, $title ) {
238 if ( !$wgUser->isLoggedIn() ) {
242 // The token is always the same, let's exploit that
243 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
244 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
247 return ApiQueryInfo
::$cachedTokens['options'];
250 public function execute() {
251 $this->params
= $this->extractRequestParams();
252 if ( !is_null( $this->params
['prop'] ) ) {
253 $prop = array_flip( $this->params
['prop'] );
254 $this->fld_protection
= isset( $prop['protection'] );
255 $this->fld_watched
= isset( $prop['watched'] );
256 $this->fld_watchers
= isset( $prop['watchers'] );
257 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
258 $this->fld_talkid
= isset( $prop['talkid'] );
259 $this->fld_subjectid
= isset( $prop['subjectid'] );
260 $this->fld_url
= isset( $prop['url'] );
261 $this->fld_readable
= isset( $prop['readable'] );
262 $this->fld_preload
= isset( $prop['preload'] );
263 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
266 $pageSet = $this->getPageSet();
267 $this->titles
= $pageSet->getGoodTitles();
268 $this->missing
= $pageSet->getMissingTitles();
269 $this->everything
= $this->titles +
$this->missing
;
270 $result = $this->getResult();
272 uasort( $this->everything
, array( 'Title', 'compare' ) );
273 if ( !is_null( $this->params
['continue'] ) ) {
274 // Throw away any titles we're gonna skip so they don't
276 $cont = explode( '|', $this->params
['continue'] );
277 $this->dieContinueUsageIf( count( $cont ) != 2 );
278 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
279 foreach ( $this->everything
as $pageid => $title ) {
280 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
283 unset( $this->titles
[$pageid] );
284 unset( $this->missing
[$pageid] );
285 unset( $this->everything
[$pageid] );
289 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
290 // when resolving redirects, no page will have this field
291 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
292 ?
$pageSet->getCustomField( 'page_is_redirect' )
294 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
296 global $wgDisableCounters;
298 if ( !$wgDisableCounters ) {
299 $this->pageCounter
= $pageSet->getCustomField( 'page_counter' );
301 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
302 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
303 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
305 // Get protection info if requested
306 if ( $this->fld_protection
) {
307 $this->getProtectionInfo();
310 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
311 $this->getWatchedInfo();
314 if ( $this->fld_watchers
) {
315 $this->getWatcherInfo();
318 // Run the talkid/subjectid query if requested
319 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
323 if ( $this->fld_displaytitle
) {
324 $this->getDisplayTitle();
327 /** @var $title Title */
328 foreach ( $this->everything
as $pageid => $title ) {
329 $pageInfo = $this->extractPageInfo( $pageid, $title );
330 $fit = $result->addValue( array(
333 ), $pageid, $pageInfo );
335 $this->setContinueEnumParameter( 'continue',
336 $title->getNamespace() . '|' .
344 * Get a result array with information about a title
345 * @param int $pageid Page ID (negative for missing titles)
346 * @param $title Title object
349 private function extractPageInfo( $pageid, $title ) {
351 $titleExists = $pageid > 0; //$title->exists() needs pageid, which is not set for all title objects
352 $ns = $title->getNamespace();
353 $dbkey = $title->getDBkey();
355 $pageInfo['contentmodel'] = $title->getContentModel();
357 if ( $titleExists ) {
358 global $wgDisableCounters;
360 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
361 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
362 $pageInfo['counter'] = $wgDisableCounters
364 : intval( $this->pageCounter
[$pageid] );
365 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
367 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
368 $pageInfo['redirect'] = '';
370 if ( $this->pageIsNew
[$pageid] ) {
371 $pageInfo['new'] = '';
375 if ( !is_null( $this->params
['token'] ) ) {
376 $tokenFunctions = $this->getTokenFunctions();
377 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
378 foreach ( $this->params
['token'] as $t ) {
379 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
380 if ( $val === false ) {
381 $this->setWarning( "Action '$t' is not allowed for the current user" );
383 $pageInfo[$t . 'token'] = $val;
388 if ( $this->fld_protection
) {
389 $pageInfo['protection'] = array();
390 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
391 $pageInfo['protection'] =
392 $this->protections
[$ns][$dbkey];
394 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
397 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
398 $pageInfo['watched'] = '';
401 if ( $this->fld_watchers
) {
402 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
403 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
404 } elseif ( $this->showZeroWatchers
) {
405 $pageInfo['watchers'] = 0;
409 if ( $this->fld_notificationtimestamp
) {
410 $pageInfo['notificationtimestamp'] = '';
411 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
412 $pageInfo['notificationtimestamp'] = 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 ) {
675 $this->watched
= array();
676 $this->notificationtimestamps
= array();
677 $db = $this->getDB();
679 $lb = new LinkBatch( $this->everything
);
681 $this->resetQueryParams();
682 $this->addTables( array( 'watchlist' ) );
683 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
684 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
685 $this->addWhere( array(
686 $lb->constructSet( 'wl', $db ),
687 'wl_user' => $user->getID()
690 $res = $this->select( __METHOD__
);
692 foreach ( $res as $row ) {
693 if ( $this->fld_watched
) {
694 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
696 if ( $this->fld_notificationtimestamp
) {
697 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] = $row->wl_notificationtimestamp
;
703 * Get the count of watchers and put it in $this->watchers
705 private function getWatcherInfo() {
706 global $wgUnwatchedPageThreshold;
708 if ( count( $this->everything
) == 0 ) {
712 $user = $this->getUser();
713 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
714 if ( !$canUnwatchedpages && !is_int( $wgUnwatchedPageThreshold ) ) {
718 $this->watchers
= array();
719 $this->showZeroWatchers
= $canUnwatchedpages;
720 $db = $this->getDB();
722 $lb = new LinkBatch( $this->everything
);
724 $this->resetQueryParams();
725 $this->addTables( array( 'watchlist' ) );
726 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
727 $this->addWhere( array(
728 $lb->constructSet( 'wl', $db )
730 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
731 if ( !$canUnwatchedpages ) {
732 $this->addOption( 'HAVING', "COUNT(*) >= $wgUnwatchedPageThreshold" );
735 $res = $this->select( __METHOD__
);
737 foreach ( $res as $row ) {
738 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
742 public function getCacheMode( $params ) {
743 $publicProps = array(
751 if ( !is_null( $params['prop'] ) ) {
752 foreach ( $params['prop'] as $prop ) {
753 if ( !in_array( $prop, $publicProps ) ) {
758 if ( !is_null( $params['token'] ) ) {
764 public function getAllowedParams() {
767 ApiBase
::PARAM_DFLT
=> null,
768 ApiBase
::PARAM_ISMULTI
=> true,
769 ApiBase
::PARAM_TYPE
=> array(
773 'watchers', # private
774 'notificationtimestamp', # private
777 'readable', # private
780 // If you add more properties here, please consider whether they
781 // need to be added to getCacheMode()
784 ApiBase
::PARAM_DFLT
=> null,
785 ApiBase
::PARAM_ISMULTI
=> true,
786 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
792 public function getParamDescription() {
795 'Which additional properties to get:',
796 ' protection - List the protection level of each page',
797 ' talkid - The page ID of the talk page for each non-talk page',
798 ' watched - List the watched status of each page',
799 ' watchers - The number of watchers, if allowed',
800 ' notificationtimestamp - The watchlist notification timestamp of each page',
801 ' subjectid - The page ID of the parent page for each talk page',
802 ' url - Gives a full URL to the page, and also an edit URL',
803 ' readable - Whether the user can read this page',
804 ' preload - Gives the text returned by EditFormPreloadText',
805 ' displaytitle - Gives the way the page title is actually displayed',
807 'token' => 'Request a token to perform a data-modifying action on a page',
808 'continue' => 'When more results are available, use this to continue',
812 public function getResultProperties() {
814 ApiBase
::PROP_LIST
=> false,
816 'touched' => 'timestamp',
817 'lastrevid' => 'integer',
819 ApiBase
::PROP_TYPE
=> 'integer',
820 ApiBase
::PROP_NULLABLE
=> true
822 'length' => 'integer',
823 'redirect' => 'boolean',
825 'starttimestamp' => array(
826 ApiBase
::PROP_TYPE
=> 'timestamp',
827 ApiBase
::PROP_NULLABLE
=> true
829 'contentmodel' => 'string',
832 'watched' => 'boolean'
836 ApiBase
::PROP_TYPE
=> 'integer',
837 ApiBase
::PROP_NULLABLE
=> true
840 'notificationtimestamp' => array(
841 'notificationtimestamp' => array(
842 ApiBase
::PROP_TYPE
=> 'timestamp',
843 ApiBase
::PROP_NULLABLE
=> true
848 ApiBase
::PROP_TYPE
=> 'integer',
849 ApiBase
::PROP_NULLABLE
=> true
852 'subjectid' => array(
853 'subjectid' => array(
854 ApiBase
::PROP_TYPE
=> 'integer',
855 ApiBase
::PROP_NULLABLE
=> true
859 'fullurl' => 'string',
860 'editurl' => 'string'
863 'readable' => 'boolean'
866 'preload' => 'string'
868 'displaytitle' => array(
869 'displaytitle' => 'string'
873 self
::addTokenProperties( $props, $this->getTokenFunctions() );
878 public function getDescription() {
879 return 'Get basic page information such as namespace, title, last touched date, ...';
882 public function getExamples() {
884 'api.php?action=query&prop=info&titles=Main%20Page',
885 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
889 public function getHelpUrls() {
890 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';