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
) );
108 return $this->tokenFunctions
;
111 static $cachedTokens = array();
113 public static function resetTokenCache() {
114 ApiQueryInfo
::$cachedTokens = array();
117 public static function getEditToken( $pageid, $title ) {
118 // We could check for $title->userCan('edit') here,
119 // but that's too expensive for this purpose
120 // and would break caching
122 if ( !$wgUser->isAllowed( 'edit' ) ) {
126 // The token is always the same, let's exploit that
127 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
128 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
131 return ApiQueryInfo
::$cachedTokens['edit'];
134 public static function getDeleteToken( $pageid, $title ) {
136 if ( !$wgUser->isAllowed( 'delete' ) ) {
140 // The token is always the same, let's exploit that
141 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
142 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
145 return ApiQueryInfo
::$cachedTokens['delete'];
148 public static function getProtectToken( $pageid, $title ) {
150 if ( !$wgUser->isAllowed( 'protect' ) ) {
154 // The token is always the same, let's exploit that
155 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
156 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
159 return ApiQueryInfo
::$cachedTokens['protect'];
162 public static function getMoveToken( $pageid, $title ) {
164 if ( !$wgUser->isAllowed( 'move' ) ) {
168 // The token is always the same, let's exploit that
169 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
170 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
173 return ApiQueryInfo
::$cachedTokens['move'];
176 public static function getBlockToken( $pageid, $title ) {
178 if ( !$wgUser->isAllowed( 'block' ) ) {
182 // The token is always the same, let's exploit that
183 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
184 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
187 return ApiQueryInfo
::$cachedTokens['block'];
190 public static function getUnblockToken( $pageid, $title ) {
191 // Currently, this is exactly the same as the block token
192 return self
::getBlockToken( $pageid, $title );
195 public static function getEmailToken( $pageid, $title ) {
197 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailUser() ) {
201 // The token is always the same, let's exploit that
202 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
203 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
206 return ApiQueryInfo
::$cachedTokens['email'];
209 public static function getImportToken( $pageid, $title ) {
211 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
215 // The token is always the same, let's exploit that
216 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
217 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
220 return ApiQueryInfo
::$cachedTokens['import'];
223 public static function getWatchToken( $pageid, $title ) {
225 if ( !$wgUser->isLoggedIn() ) {
229 // The token is always the same, let's exploit that
230 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
231 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
234 return ApiQueryInfo
::$cachedTokens['watch'];
237 public static function getOptionsToken( $pageid, $title ) {
239 if ( !$wgUser->isLoggedIn() ) {
243 // The token is always the same, let's exploit that
244 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
245 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
248 return ApiQueryInfo
::$cachedTokens['options'];
251 public function execute() {
252 $this->params
= $this->extractRequestParams();
253 if ( !is_null( $this->params
['prop'] ) ) {
254 $prop = array_flip( $this->params
['prop'] );
255 $this->fld_protection
= isset( $prop['protection'] );
256 $this->fld_watched
= isset( $prop['watched'] );
257 $this->fld_watchers
= isset( $prop['watchers'] );
258 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
259 $this->fld_talkid
= isset( $prop['talkid'] );
260 $this->fld_subjectid
= isset( $prop['subjectid'] );
261 $this->fld_url
= isset( $prop['url'] );
262 $this->fld_readable
= isset( $prop['readable'] );
263 $this->fld_preload
= isset( $prop['preload'] );
264 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
267 $pageSet = $this->getPageSet();
268 $this->titles
= $pageSet->getGoodTitles();
269 $this->missing
= $pageSet->getMissingTitles();
270 $this->everything
= $this->titles +
$this->missing
;
271 $result = $this->getResult();
273 uasort( $this->everything
, array( 'Title', 'compare' ) );
274 if ( !is_null( $this->params
['continue'] ) ) {
275 // Throw away any titles we're gonna skip so they don't
277 $cont = explode( '|', $this->params
['continue'] );
278 $this->dieContinueUsageIf( count( $cont ) != 2 );
279 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
280 foreach ( $this->everything
as $pageid => $title ) {
281 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
284 unset( $this->titles
[$pageid] );
285 unset( $this->missing
[$pageid] );
286 unset( $this->everything
[$pageid] );
290 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
291 // when resolving redirects, no page will have this field
292 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
293 ?
$pageSet->getCustomField( 'page_is_redirect' )
295 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
297 global $wgDisableCounters;
299 if ( !$wgDisableCounters ) {
300 $this->pageCounter
= $pageSet->getCustomField( 'page_counter' );
302 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
303 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
304 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
306 // Get protection info if requested
307 if ( $this->fld_protection
) {
308 $this->getProtectionInfo();
311 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
312 $this->getWatchedInfo();
315 if ( $this->fld_watchers
) {
316 $this->getWatcherInfo();
319 // Run the talkid/subjectid query if requested
320 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
324 if ( $this->fld_displaytitle
) {
325 $this->getDisplayTitle();
328 /** @var $title Title */
329 foreach ( $this->everything
as $pageid => $title ) {
330 $pageInfo = $this->extractPageInfo( $pageid, $title );
331 $fit = $result->addValue( array(
334 ), $pageid, $pageInfo );
336 $this->setContinueEnumParameter( 'continue',
337 $title->getNamespace() . '|' .
345 * Get a result array with information about a title
346 * @param int $pageid Page ID (negative for missing titles)
347 * @param $title Title object
350 private function extractPageInfo( $pageid, $title ) {
352 $titleExists = $pageid > 0; //$title->exists() needs pageid, which is not set for all title objects
353 $ns = $title->getNamespace();
354 $dbkey = $title->getDBkey();
356 $pageInfo['contentmodel'] = $title->getContentModel();
357 $pageInfo['pagelanguage'] = $title->getPageLanguage()->getCode();
359 if ( $titleExists ) {
360 global $wgDisableCounters;
362 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
363 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
364 $pageInfo['counter'] = $wgDisableCounters
366 : intval( $this->pageCounter
[$pageid] );
367 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
369 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
370 $pageInfo['redirect'] = '';
372 if ( $this->pageIsNew
[$pageid] ) {
373 $pageInfo['new'] = '';
377 if ( !is_null( $this->params
['token'] ) ) {
378 $tokenFunctions = $this->getTokenFunctions();
379 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
380 foreach ( $this->params
['token'] as $t ) {
381 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
382 if ( $val === false ) {
383 $this->setWarning( "Action '$t' is not allowed for the current user" );
385 $pageInfo[$t . 'token'] = $val;
390 if ( $this->fld_protection
) {
391 $pageInfo['protection'] = array();
392 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
393 $pageInfo['protection'] =
394 $this->protections
[$ns][$dbkey];
396 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
399 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
400 $pageInfo['watched'] = '';
403 if ( $this->fld_watchers
) {
404 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
405 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
406 } elseif ( $this->showZeroWatchers
) {
407 $pageInfo['watchers'] = 0;
411 if ( $this->fld_notificationtimestamp
) {
412 $pageInfo['notificationtimestamp'] = '';
413 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
414 $pageInfo['notificationtimestamp'] = wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
418 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
419 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
422 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
423 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
426 if ( $this->fld_url
) {
427 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
428 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
430 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
431 $pageInfo['readable'] = '';
434 if ( $this->fld_preload
) {
435 if ( $titleExists ) {
436 $pageInfo['preload'] = '';
439 wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
441 $pageInfo['preload'] = $text;
445 if ( $this->fld_displaytitle
) {
446 if ( isset( $this->displaytitles
[$pageid] ) ) {
447 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
449 $pageInfo['displaytitle'] = $title->getPrefixedText();
457 * Get information about protections and put it in $protections
459 private function getProtectionInfo() {
461 $this->protections
= array();
462 $db = $this->getDB();
464 // Get normal protections for existing titles
465 if ( count( $this->titles
) ) {
466 $this->resetQueryParams();
467 $this->addTables( 'page_restrictions' );
468 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
469 'pr_expiry', 'pr_cascade' ) );
470 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
472 $res = $this->select( __METHOD__
);
473 foreach ( $res as $row ) {
474 /** @var $title Title */
475 $title = $this->titles
[$row->pr_page
];
477 'type' => $row->pr_type
,
478 'level' => $row->pr_level
,
479 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
481 if ( $row->pr_cascade
) {
484 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
486 // Also check old restrictions
487 foreach ( $this->titles
as $pageId => $title ) {
488 if ( $this->pageRestrictions
[$pageId] ) {
489 $namespace = $title->getNamespace();
490 $dbKey = $title->getDBkey();
491 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
492 foreach ( $restrictions as $restrict ) {
493 $temp = explode( '=', trim( $restrict ) );
494 if ( count( $temp ) == 1 ) {
495 // old old format should be treated as edit/move restriction
496 $restriction = trim( $temp[0] );
498 if ( $restriction == '' ) {
501 $this->protections
[$namespace][$dbKey][] = array(
503 'level' => $restriction,
504 'expiry' => 'infinity',
506 $this->protections
[$namespace][$dbKey][] = array(
508 'level' => $restriction,
509 'expiry' => 'infinity',
512 $restriction = trim( $temp[1] );
513 if ( $restriction == '' ) {
516 $this->protections
[$namespace][$dbKey][] = array(
518 'level' => $restriction,
519 'expiry' => 'infinity',
527 // Get protections for missing titles
528 if ( count( $this->missing
) ) {
529 $this->resetQueryParams();
530 $lb = new LinkBatch( $this->missing
);
531 $this->addTables( 'protected_titles' );
532 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
533 $this->addWhere( $lb->constructSet( 'pt', $db ) );
534 $res = $this->select( __METHOD__
);
535 foreach ( $res as $row ) {
536 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
538 'level' => $row->pt_create_perm
,
539 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
544 // Cascading protections
545 $images = $others = array();
546 foreach ( $this->everything
as $title ) {
547 if ( $title->getNamespace() == NS_FILE
) {
548 $images[] = $title->getDBkey();
554 if ( count( $others ) ) {
555 // Non-images: check templatelinks
556 $lb = new LinkBatch( $others );
557 $this->resetQueryParams();
558 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
559 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
560 'page_title', 'page_namespace',
561 'tl_title', 'tl_namespace' ) );
562 $this->addWhere( $lb->constructSet( 'tl', $db ) );
563 $this->addWhere( 'pr_page = page_id' );
564 $this->addWhere( 'pr_page = tl_from' );
565 $this->addWhereFld( 'pr_cascade', 1 );
567 $res = $this->select( __METHOD__
);
568 foreach ( $res as $row ) {
569 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
570 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
571 'type' => $row->pr_type
,
572 'level' => $row->pr_level
,
573 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
574 'source' => $source->getPrefixedText()
579 if ( count( $images ) ) {
580 // Images: check imagelinks
581 $this->resetQueryParams();
582 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
583 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
584 'page_title', 'page_namespace', 'il_to' ) );
585 $this->addWhere( 'pr_page = page_id' );
586 $this->addWhere( 'pr_page = il_from' );
587 $this->addWhereFld( 'pr_cascade', 1 );
588 $this->addWhereFld( 'il_to', $images );
590 $res = $this->select( __METHOD__
);
591 foreach ( $res as $row ) {
592 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
593 $this->protections
[NS_FILE
][$row->il_to
][] = array(
594 'type' => $row->pr_type
,
595 'level' => $row->pr_level
,
596 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
597 'source' => $source->getPrefixedText()
604 * Get talk page IDs (if requested) and subject page IDs (if requested)
605 * and put them in $talkids and $subjectids
607 private function getTSIDs() {
608 $getTitles = $this->talkids
= $this->subjectids
= array();
611 foreach ( $this->everything
as $t ) {
612 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
613 if ( $this->fld_subjectid
) {
614 $getTitles[] = $t->getSubjectPage();
616 } elseif ( $this->fld_talkid
) {
617 $getTitles[] = $t->getTalkPage();
620 if ( !count( $getTitles ) ) {
624 $db = $this->getDB();
626 // Construct a custom WHERE clause that matches
627 // all titles in $getTitles
628 $lb = new LinkBatch( $getTitles );
629 $this->resetQueryParams();
630 $this->addTables( 'page' );
631 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
632 $this->addWhere( $lb->constructSet( 'page', $db ) );
633 $res = $this->select( __METHOD__
);
634 foreach ( $res as $row ) {
635 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
636 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
637 intval( $row->page_id
);
639 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
640 intval( $row->page_id
);
645 private function getDisplayTitle() {
646 $this->displaytitles
= array();
648 $pageIds = array_keys( $this->titles
);
650 if ( !count( $pageIds ) ) {
654 $this->resetQueryParams();
655 $this->addTables( 'page_props' );
656 $this->addFields( array( 'pp_page', 'pp_value' ) );
657 $this->addWhereFld( 'pp_page', $pageIds );
658 $this->addWhereFld( 'pp_propname', 'displaytitle' );
659 $res = $this->select( __METHOD__
);
661 foreach ( $res as $row ) {
662 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
667 * Get information about watched status and put it in $this->watched
668 * and $this->notificationtimestamps
670 private function getWatchedInfo() {
671 $user = $this->getUser();
673 if ( $user->isAnon() ||
count( $this->everything
) == 0
674 ||
!$user->isAllowed( 'viewmywatchlist' )
679 $this->watched
= array();
680 $this->notificationtimestamps
= array();
681 $db = $this->getDB();
683 $lb = new LinkBatch( $this->everything
);
685 $this->resetQueryParams();
686 $this->addTables( array( 'watchlist' ) );
687 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
688 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
689 $this->addWhere( array(
690 $lb->constructSet( 'wl', $db ),
691 'wl_user' => $user->getID()
694 $res = $this->select( __METHOD__
);
696 foreach ( $res as $row ) {
697 if ( $this->fld_watched
) {
698 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
700 if ( $this->fld_notificationtimestamp
) {
701 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] = $row->wl_notificationtimestamp
;
707 * Get the count of watchers and put it in $this->watchers
709 private function getWatcherInfo() {
710 global $wgUnwatchedPageThreshold;
712 if ( count( $this->everything
) == 0 ) {
716 $user = $this->getUser();
717 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
718 if ( !$canUnwatchedpages && !is_int( $wgUnwatchedPageThreshold ) ) {
722 $this->watchers
= array();
723 $this->showZeroWatchers
= $canUnwatchedpages;
724 $db = $this->getDB();
726 $lb = new LinkBatch( $this->everything
);
728 $this->resetQueryParams();
729 $this->addTables( array( 'watchlist' ) );
730 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
731 $this->addWhere( array(
732 $lb->constructSet( 'wl', $db )
734 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
735 if ( !$canUnwatchedpages ) {
736 $this->addOption( 'HAVING', "COUNT(*) >= $wgUnwatchedPageThreshold" );
739 $res = $this->select( __METHOD__
);
741 foreach ( $res as $row ) {
742 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
746 public function getCacheMode( $params ) {
747 $publicProps = array(
755 if ( !is_null( $params['prop'] ) ) {
756 foreach ( $params['prop'] as $prop ) {
757 if ( !in_array( $prop, $publicProps ) ) {
762 if ( !is_null( $params['token'] ) ) {
769 public function getAllowedParams() {
772 ApiBase
::PARAM_DFLT
=> null,
773 ApiBase
::PARAM_ISMULTI
=> true,
774 ApiBase
::PARAM_TYPE
=> array(
778 'watchers', # private
779 'notificationtimestamp', # private
782 'readable', # private
785 // If you add more properties here, please consider whether they
786 // need to be added to getCacheMode()
789 ApiBase
::PARAM_DFLT
=> null,
790 ApiBase
::PARAM_ISMULTI
=> true,
791 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
797 public function getParamDescription() {
800 'Which additional properties to get:',
801 ' protection - List the protection level of each page',
802 ' talkid - The page ID of the talk page for each non-talk page',
803 ' watched - List the watched status of each page',
804 ' watchers - The number of watchers, if allowed',
805 ' notificationtimestamp - The watchlist notification timestamp of each page',
806 ' subjectid - The page ID of the parent page for each talk page',
807 ' url - Gives a full URL to the page, and also an edit URL',
808 ' readable - Whether the user can read this page',
809 ' preload - Gives the text returned by EditFormPreloadText',
810 ' displaytitle - Gives the way the page title is actually displayed',
812 'token' => 'Request a token to perform a data-modifying action on a page',
813 'continue' => 'When more results are available, use this to continue',
817 public function getResultProperties() {
819 ApiBase
::PROP_LIST
=> false,
821 'touched' => 'timestamp',
822 'lastrevid' => 'integer',
824 ApiBase
::PROP_TYPE
=> 'integer',
825 ApiBase
::PROP_NULLABLE
=> true
827 'length' => 'integer',
828 'redirect' => 'boolean',
830 'starttimestamp' => array(
831 ApiBase
::PROP_TYPE
=> 'timestamp',
832 ApiBase
::PROP_NULLABLE
=> true
834 'contentmodel' => 'string',
837 'watched' => 'boolean'
841 ApiBase
::PROP_TYPE
=> 'integer',
842 ApiBase
::PROP_NULLABLE
=> true
845 'notificationtimestamp' => array(
846 'notificationtimestamp' => array(
847 ApiBase
::PROP_TYPE
=> 'timestamp',
848 ApiBase
::PROP_NULLABLE
=> true
853 ApiBase
::PROP_TYPE
=> 'integer',
854 ApiBase
::PROP_NULLABLE
=> true
857 'subjectid' => array(
858 'subjectid' => array(
859 ApiBase
::PROP_TYPE
=> 'integer',
860 ApiBase
::PROP_NULLABLE
=> true
864 'fullurl' => 'string',
865 'editurl' => 'string'
868 'readable' => 'boolean'
871 'preload' => 'string'
873 'displaytitle' => array(
874 'displaytitle' => 'string'
878 self
::addTokenProperties( $props, $this->getTokenFunctions() );
883 public function getDescription() {
884 return 'Get basic page information such as namespace, title, last touched date, ...';
887 public function getExamples() {
889 'api.php?action=query&prop=info&titles=Main%20Page',
890 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
894 public function getHelpUrls() {
895 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';