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 foreach ( $this->everything
as $pageid => $title ) {
325 $pageInfo = $this->extractPageInfo( $pageid, $title );
326 $fit = $result->addValue( array(
329 ), $pageid, $pageInfo );
331 $this->setContinueEnumParameter( 'continue',
332 $title->getNamespace() . '|' .
340 * Get a result array with information about a title
341 * @param $pageid int Page ID (negative for missing titles)
342 * @param $title Title object
345 private function extractPageInfo( $pageid, $title ) {
347 $titleExists = $pageid > 0; //$title->exists() needs pageid, which is not set for all title objects
348 $ns = $title->getNamespace();
349 $dbkey = $title->getDBkey();
350 if ( $titleExists ) {
351 global $wgDisableCounters;
353 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
354 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
355 $pageInfo['counter'] = $wgDisableCounters
357 : intval( $this->pageCounter
[$pageid] );
358 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
360 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
361 $pageInfo['redirect'] = '';
363 if ( $this->pageIsNew
[$pageid] ) {
364 $pageInfo['new'] = '';
368 if ( !is_null( $this->params
['token'] ) ) {
369 $tokenFunctions = $this->getTokenFunctions();
370 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
371 foreach ( $this->params
['token'] as $t ) {
372 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
373 if ( $val === false ) {
374 $this->setWarning( "Action '$t' is not allowed for the current user" );
376 $pageInfo[$t . 'token'] = $val;
381 if ( $this->fld_protection
) {
382 $pageInfo['protection'] = array();
383 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
384 $pageInfo['protection'] =
385 $this->protections
[$ns][$dbkey];
387 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
390 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
391 $pageInfo['watched'] = '';
394 if ( $this->fld_watchers
) {
395 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
396 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
397 } elseif ( $this->showZeroWatchers
) {
398 $pageInfo['watchers'] = 0;
402 if ( $this->fld_notificationtimestamp
) {
403 $pageInfo['notificationtimestamp'] = '';
404 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
405 $pageInfo['notificationtimestamp'] = wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
409 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
410 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
413 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
414 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
417 if ( $this->fld_url
) {
418 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
419 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
421 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
422 $pageInfo['readable'] = '';
425 if ( $this->fld_preload
) {
426 if ( $titleExists ) {
427 $pageInfo['preload'] = '';
430 wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
432 $pageInfo['preload'] = $text;
436 if ( $this->fld_displaytitle
) {
437 if ( isset( $this->displaytitles
[$pageid] ) ) {
438 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
440 $pageInfo['displaytitle'] = $title->getPrefixedText();
448 * Get information about protections and put it in $protections
450 private function getProtectionInfo() {
452 $this->protections
= array();
453 $db = $this->getDB();
455 // Get normal protections for existing titles
456 if ( count( $this->titles
) ) {
457 $this->resetQueryParams();
458 $this->addTables( 'page_restrictions' );
459 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
460 'pr_expiry', 'pr_cascade' ) );
461 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
463 $res = $this->select( __METHOD__
);
464 foreach ( $res as $row ) {
465 $title = $this->titles
[$row->pr_page
];
467 'type' => $row->pr_type
,
468 'level' => $row->pr_level
,
469 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
471 if ( $row->pr_cascade
) {
474 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
476 // Also check old restrictions
477 foreach( $this->titles
as $pageId => $title ) {
478 if ( $this->pageRestrictions
[$pageId] ) {
479 $namespace = $title->getNamespace();
480 $dbKey = $title->getDBkey();
481 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
482 foreach ( $restrictions as $restrict ) {
483 $temp = explode( '=', trim( $restrict ) );
484 if ( count( $temp ) == 1 ) {
485 // old old format should be treated as edit/move restriction
486 $restriction = trim( $temp[0] );
488 if ( $restriction == '' ) {
491 $this->protections
[$namespace][$dbKey][] = array(
493 'level' => $restriction,
494 'expiry' => 'infinity',
496 $this->protections
[$namespace][$dbKey][] = array(
498 'level' => $restriction,
499 'expiry' => 'infinity',
502 $restriction = trim( $temp[1] );
503 if ( $restriction == '' ) {
506 $this->protections
[$namespace][$dbKey][] = array(
508 'level' => $restriction,
509 'expiry' => 'infinity',
517 // Get protections for missing titles
518 if ( count( $this->missing
) ) {
519 $this->resetQueryParams();
520 $lb = new LinkBatch( $this->missing
);
521 $this->addTables( 'protected_titles' );
522 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
523 $this->addWhere( $lb->constructSet( 'pt', $db ) );
524 $res = $this->select( __METHOD__
);
525 foreach ( $res as $row ) {
526 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
528 'level' => $row->pt_create_perm
,
529 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
534 // Cascading protections
535 $images = $others = array();
536 foreach ( $this->everything
as $title ) {
537 if ( $title->getNamespace() == NS_FILE
) {
538 $images[] = $title->getDBkey();
544 if ( count( $others ) ) {
545 // Non-images: check templatelinks
546 $lb = new LinkBatch( $others );
547 $this->resetQueryParams();
548 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
549 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
550 'page_title', 'page_namespace',
551 'tl_title', 'tl_namespace' ) );
552 $this->addWhere( $lb->constructSet( 'tl', $db ) );
553 $this->addWhere( 'pr_page = page_id' );
554 $this->addWhere( 'pr_page = tl_from' );
555 $this->addWhereFld( 'pr_cascade', 1 );
557 $res = $this->select( __METHOD__
);
558 foreach ( $res as $row ) {
559 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
560 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
561 'type' => $row->pr_type
,
562 'level' => $row->pr_level
,
563 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
564 'source' => $source->getPrefixedText()
569 if ( count( $images ) ) {
570 // Images: check imagelinks
571 $this->resetQueryParams();
572 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
573 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
574 'page_title', 'page_namespace', 'il_to' ) );
575 $this->addWhere( 'pr_page = page_id' );
576 $this->addWhere( 'pr_page = il_from' );
577 $this->addWhereFld( 'pr_cascade', 1 );
578 $this->addWhereFld( 'il_to', $images );
580 $res = $this->select( __METHOD__
);
581 foreach ( $res as $row ) {
582 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
583 $this->protections
[NS_FILE
][$row->il_to
][] = array(
584 'type' => $row->pr_type
,
585 'level' => $row->pr_level
,
586 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
587 'source' => $source->getPrefixedText()
594 * Get talk page IDs (if requested) and subject page IDs (if requested)
595 * and put them in $talkids and $subjectids
597 private function getTSIDs() {
598 $getTitles = $this->talkids
= $this->subjectids
= array();
600 foreach ( $this->everything
as $t ) {
601 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
602 if ( $this->fld_subjectid
) {
603 $getTitles[] = $t->getSubjectPage();
605 } elseif ( $this->fld_talkid
) {
606 $getTitles[] = $t->getTalkPage();
609 if ( !count( $getTitles ) ) {
613 $db = $this->getDB();
615 // Construct a custom WHERE clause that matches
616 // all titles in $getTitles
617 $lb = new LinkBatch( $getTitles );
618 $this->resetQueryParams();
619 $this->addTables( 'page' );
620 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
621 $this->addWhere( $lb->constructSet( 'page', $db ) );
622 $res = $this->select( __METHOD__
);
623 foreach ( $res as $row ) {
624 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
625 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
626 intval( $row->page_id
);
628 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
629 intval( $row->page_id
);
634 private function getDisplayTitle() {
635 $this->displaytitles
= array();
637 $pageIds = array_keys( $this->titles
);
639 if ( !count( $pageIds ) ) {
643 $this->resetQueryParams();
644 $this->addTables( 'page_props' );
645 $this->addFields( array( 'pp_page', 'pp_value' ) );
646 $this->addWhereFld( 'pp_page', $pageIds );
647 $this->addWhereFld( 'pp_propname', 'displaytitle' );
648 $res = $this->select( __METHOD__
);
650 foreach ( $res as $row ) {
651 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
656 * Get information about watched status and put it in $this->watched
657 * and $this->notificationtimestamps
659 private function getWatchedInfo() {
660 $user = $this->getUser();
662 if ( $user->isAnon() ||
count( $this->everything
) == 0 ) {
666 $this->watched
= array();
667 $this->notificationtimestamps
= array();
668 $db = $this->getDB();
670 $lb = new LinkBatch( $this->everything
);
672 $this->resetQueryParams();
673 $this->addTables( array( 'watchlist' ) );
674 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
675 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
676 $this->addWhere( array(
677 $lb->constructSet( 'wl', $db ),
678 'wl_user' => $user->getID()
681 $res = $this->select( __METHOD__
);
683 foreach ( $res as $row ) {
684 if ( $this->fld_watched
) {
685 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
687 if ( $this->fld_notificationtimestamp
) {
688 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] = $row->wl_notificationtimestamp
;
694 * Get the count of watchers and put it in $this->watchers
696 private function getWatcherInfo() {
697 global $wgUnwatchedPageThreshold;
699 if ( count( $this->everything
) == 0 ) {
703 $user = $this->getUser();
704 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
705 if ( !$canUnwatchedpages && !is_int( $wgUnwatchedPageThreshold ) ) {
709 $this->watchers
= array();
710 $this->showZeroWatchers
= $canUnwatchedpages;
711 $db = $this->getDB();
713 $lb = new LinkBatch( $this->everything
);
715 $this->resetQueryParams();
716 $this->addTables( array( 'watchlist' ) );
717 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
718 $this->addWhere( array(
719 $lb->constructSet( 'wl', $db )
721 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
722 if ( !$canUnwatchedpages ) {
723 $this->addOption( 'HAVING', "COUNT(*) >= $wgUnwatchedPageThreshold" );
726 $res = $this->select( __METHOD__
);
728 foreach ( $res as $row ) {
729 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
733 public function getCacheMode( $params ) {
734 $publicProps = array(
742 if ( !is_null( $params['prop'] ) ) {
743 foreach ( $params['prop'] as $prop ) {
744 if ( !in_array( $prop, $publicProps ) ) {
749 if ( !is_null( $params['token'] ) ) {
755 public function getAllowedParams() {
758 ApiBase
::PARAM_DFLT
=> null,
759 ApiBase
::PARAM_ISMULTI
=> true,
760 ApiBase
::PARAM_TYPE
=> array(
764 'watchers', # private
765 'notificationtimestamp', # private
768 'readable', # private
771 // If you add more properties here, please consider whether they
772 // need to be added to getCacheMode()
775 ApiBase
::PARAM_DFLT
=> null,
776 ApiBase
::PARAM_ISMULTI
=> true,
777 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
783 public function getParamDescription() {
786 'Which additional properties to get:',
787 ' protection - List the protection level of each page',
788 ' talkid - The page ID of the talk page for each non-talk page',
789 ' watched - List the watched status of each page',
790 ' watchers - The number of watchers, if allowed',
791 ' notificationtimestamp - The watchlist notification timestamp of each page',
792 ' subjectid - The page ID of the parent page for each talk page',
793 ' url - Gives a full URL to the page, and also an edit URL',
794 ' readable - Whether the user can read this page',
795 ' preload - Gives the text returned by EditFormPreloadText',
796 ' displaytitle - Gives the way the page title is actually displayed',
798 'token' => 'Request a token to perform a data-modifying action on a page',
799 'continue' => 'When more results are available, use this to continue',
803 public function getResultProperties() {
805 ApiBase
::PROP_LIST
=> false,
807 'touched' => 'timestamp',
808 'lastrevid' => 'integer',
810 ApiBase
::PROP_TYPE
=> 'integer',
811 ApiBase
::PROP_NULLABLE
=> true
813 'length' => 'integer',
814 'redirect' => 'boolean',
816 'starttimestamp' => array(
817 ApiBase
::PROP_TYPE
=> 'timestamp',
818 ApiBase
::PROP_NULLABLE
=> true
822 'watched' => 'boolean'
826 ApiBase
::PROP_TYPE
=> 'integer',
827 ApiBase
::PROP_NULLABLE
=> true
830 'notificationtimestamp' => array(
831 'notificationtimestamp' => array(
832 ApiBase
::PROP_TYPE
=> 'timestamp',
833 ApiBase
::PROP_NULLABLE
=> true
838 ApiBase
::PROP_TYPE
=> 'integer',
839 ApiBase
::PROP_NULLABLE
=> true
842 'subjectid' => array(
843 'subjectid' => array(
844 ApiBase
::PROP_TYPE
=> 'integer',
845 ApiBase
::PROP_NULLABLE
=> true
849 'fullurl' => 'string',
850 'editurl' => 'string'
853 'readable' => 'boolean'
856 'preload' => 'string'
858 'displaytitle' => array(
859 'displaytitle' => 'string'
863 self
::addTokenProperties( $props, $this->getTokenFunctions() );
868 public function getDescription() {
869 return 'Get basic page information such as namespace, title, last touched date, ...';
872 public function getExamples() {
874 'api.php?action=query&prop=info&titles=Main%20Page',
875 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
879 public function getHelpUrls() {
880 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';