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, $restrictionTypes, $watched, $watchers, $notificationtimestamps,
46 $talkids, $subjectids, $displaytitles;
47 private $showZeroWatchers = false;
49 private $tokenFunctions;
51 private $countTestedActions = 0;
53 public function __construct( ApiQuery
$query, $moduleName ) {
54 parent
::__construct( $query, $moduleName, 'in' );
58 * @param ApiPageSet $pageSet
61 public function requestExtraData( $pageSet ) {
62 $pageSet->requestField( 'page_restrictions' );
63 // If the pageset is resolving redirects we won't get page_is_redirect.
64 // But we can't know for sure until the pageset is executed (revids may
65 // turn it off), so request it unconditionally.
66 $pageSet->requestField( 'page_is_redirect' );
67 $pageSet->requestField( 'page_is_new' );
68 $config = $this->getConfig();
69 $pageSet->requestField( 'page_touched' );
70 $pageSet->requestField( 'page_latest' );
71 $pageSet->requestField( 'page_len' );
72 if ( $config->get( 'ContentHandlerUseDB' ) ) {
73 $pageSet->requestField( 'page_content_model' );
75 if ( $config->get( 'PageLanguageUseDB' ) ) {
76 $pageSet->requestField( 'page_lang' );
81 * Get an array mapping token names to their handler functions.
82 * The prototype for a token function is func($pageid, $title)
83 * it should return a token or false (permission denied)
84 * @deprecated since 1.24
85 * @return array Array(tokenname => function)
87 protected function getTokenFunctions() {
88 // Don't call the hooks twice
89 if ( isset( $this->tokenFunctions
) ) {
90 return $this->tokenFunctions
;
93 // If we're in a mode that breaks the same-origin policy, no tokens can
95 if ( $this->lacksSameOriginSecurity() ) {
99 $this->tokenFunctions
= array(
100 'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
101 'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
102 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
103 'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
104 'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
105 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
106 'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
107 'import' => array( 'ApiQueryInfo', 'getImportToken' ),
108 'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
110 Hooks
::run( 'APIQueryInfoTokens', array( &$this->tokenFunctions
) );
112 return $this->tokenFunctions
;
115 static protected $cachedTokens = array();
118 * @deprecated since 1.24
120 public static function resetTokenCache() {
121 ApiQueryInfo
::$cachedTokens = array();
125 * @deprecated since 1.24
127 public static function getEditToken( $pageid, $title ) {
128 // We could check for $title->userCan('edit') here,
129 // but that's too expensive for this purpose
130 // and would break caching
132 if ( !$wgUser->isAllowed( 'edit' ) ) {
136 // The token is always the same, let's exploit that
137 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
138 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
141 return ApiQueryInfo
::$cachedTokens['edit'];
145 * @deprecated since 1.24
147 public static function getDeleteToken( $pageid, $title ) {
149 if ( !$wgUser->isAllowed( 'delete' ) ) {
153 // The token is always the same, let's exploit that
154 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
155 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
158 return ApiQueryInfo
::$cachedTokens['delete'];
162 * @deprecated since 1.24
164 public static function getProtectToken( $pageid, $title ) {
166 if ( !$wgUser->isAllowed( 'protect' ) ) {
170 // The token is always the same, let's exploit that
171 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
172 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
175 return ApiQueryInfo
::$cachedTokens['protect'];
179 * @deprecated since 1.24
181 public static function getMoveToken( $pageid, $title ) {
183 if ( !$wgUser->isAllowed( 'move' ) ) {
187 // The token is always the same, let's exploit that
188 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
189 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
192 return ApiQueryInfo
::$cachedTokens['move'];
196 * @deprecated since 1.24
198 public static function getBlockToken( $pageid, $title ) {
200 if ( !$wgUser->isAllowed( 'block' ) ) {
204 // The token is always the same, let's exploit that
205 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
206 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
209 return ApiQueryInfo
::$cachedTokens['block'];
213 * @deprecated since 1.24
215 public static function getUnblockToken( $pageid, $title ) {
216 // Currently, this is exactly the same as the block token
217 return self
::getBlockToken( $pageid, $title );
221 * @deprecated since 1.24
223 public static function getEmailToken( $pageid, $title ) {
225 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailUser() ) {
229 // The token is always the same, let's exploit that
230 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
231 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
234 return ApiQueryInfo
::$cachedTokens['email'];
238 * @deprecated since 1.24
240 public static function getImportToken( $pageid, $title ) {
242 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
246 // The token is always the same, let's exploit that
247 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
248 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
251 return ApiQueryInfo
::$cachedTokens['import'];
255 * @deprecated since 1.24
257 public static function getWatchToken( $pageid, $title ) {
259 if ( !$wgUser->isLoggedIn() ) {
263 // The token is always the same, let's exploit that
264 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
265 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
268 return ApiQueryInfo
::$cachedTokens['watch'];
272 * @deprecated since 1.24
274 public static function getOptionsToken( $pageid, $title ) {
276 if ( !$wgUser->isLoggedIn() ) {
280 // The token is always the same, let's exploit that
281 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
282 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
285 return ApiQueryInfo
::$cachedTokens['options'];
288 public function execute() {
289 $this->params
= $this->extractRequestParams();
290 if ( !is_null( $this->params
['prop'] ) ) {
291 $prop = array_flip( $this->params
['prop'] );
292 $this->fld_protection
= isset( $prop['protection'] );
293 $this->fld_watched
= isset( $prop['watched'] );
294 $this->fld_watchers
= isset( $prop['watchers'] );
295 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
296 $this->fld_talkid
= isset( $prop['talkid'] );
297 $this->fld_subjectid
= isset( $prop['subjectid'] );
298 $this->fld_url
= isset( $prop['url'] );
299 $this->fld_readable
= isset( $prop['readable'] );
300 $this->fld_preload
= isset( $prop['preload'] );
301 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
304 $pageSet = $this->getPageSet();
305 $this->titles
= $pageSet->getGoodTitles();
306 $this->missing
= $pageSet->getMissingTitles();
307 $this->everything
= $this->titles +
$this->missing
;
308 $result = $this->getResult();
310 uasort( $this->everything
, array( 'Title', 'compare' ) );
311 if ( !is_null( $this->params
['continue'] ) ) {
312 // Throw away any titles we're gonna skip so they don't
314 $cont = explode( '|', $this->params
['continue'] );
315 $this->dieContinueUsageIf( count( $cont ) != 2 );
316 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
317 foreach ( $this->everything
as $pageid => $title ) {
318 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
321 unset( $this->titles
[$pageid] );
322 unset( $this->missing
[$pageid] );
323 unset( $this->everything
[$pageid] );
327 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
328 // when resolving redirects, no page will have this field
329 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
330 ?
$pageSet->getCustomField( 'page_is_redirect' )
332 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
334 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
335 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
336 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
338 // Get protection info if requested
339 if ( $this->fld_protection
) {
340 $this->getProtectionInfo();
343 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
344 $this->getWatchedInfo();
347 if ( $this->fld_watchers
) {
348 $this->getWatcherInfo();
351 // Run the talkid/subjectid query if requested
352 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
356 if ( $this->fld_displaytitle
) {
357 $this->getDisplayTitle();
360 /** @var $title Title */
361 foreach ( $this->everything
as $pageid => $title ) {
362 $pageInfo = $this->extractPageInfo( $pageid, $title );
363 $fit = $pageInfo !== null && $result->addValue( array(
366 ), $pageid, $pageInfo );
368 $this->setContinueEnumParameter( 'continue',
369 $title->getNamespace() . '|' .
377 * Get a result array with information about a title
378 * @param int $pageid Page ID (negative for missing titles)
379 * @param Title $title
382 private function extractPageInfo( $pageid, $title ) {
384 // $title->exists() needs pageid, which is not set for all title objects
385 $titleExists = $pageid > 0;
386 $ns = $title->getNamespace();
387 $dbkey = $title->getDBkey();
389 $pageInfo['contentmodel'] = $title->getContentModel();
390 $pageInfo['pagelanguage'] = $title->getPageLanguage()->getCode();
392 if ( $titleExists ) {
393 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
394 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
395 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
397 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
398 $pageInfo['redirect'] = '';
400 if ( $this->pageIsNew
[$pageid] ) {
401 $pageInfo['new'] = '';
405 if ( !is_null( $this->params
['token'] ) ) {
406 $tokenFunctions = $this->getTokenFunctions();
407 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
408 foreach ( $this->params
['token'] as $t ) {
409 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
410 if ( $val === false ) {
411 $this->setWarning( "Action '$t' is not allowed for the current user" );
413 $pageInfo[$t . 'token'] = $val;
418 if ( $this->fld_protection
) {
419 $pageInfo['protection'] = array();
420 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
421 $pageInfo['protection'] =
422 $this->protections
[$ns][$dbkey];
424 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
426 $pageInfo['restrictiontypes'] = array();
427 if ( isset( $this->restrictionTypes
[$ns][$dbkey] ) ) {
428 $pageInfo['restrictiontypes'] =
429 $this->restrictionTypes
[$ns][$dbkey];
431 $this->getResult()->setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
434 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
435 $pageInfo['watched'] = '';
438 if ( $this->fld_watchers
) {
439 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
440 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
441 } elseif ( $this->showZeroWatchers
) {
442 $pageInfo['watchers'] = 0;
446 if ( $this->fld_notificationtimestamp
) {
447 $pageInfo['notificationtimestamp'] = '';
448 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
449 $pageInfo['notificationtimestamp'] =
450 wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
454 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
455 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
458 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
459 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
462 if ( $this->fld_url
) {
463 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
464 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
465 $pageInfo['canonicalurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CANONICAL
);
467 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
468 $pageInfo['readable'] = '';
471 if ( $this->fld_preload
) {
472 if ( $titleExists ) {
473 $pageInfo['preload'] = '';
476 Hooks
::run( 'EditFormPreloadText', array( &$text, &$title ) );
478 $pageInfo['preload'] = $text;
482 if ( $this->fld_displaytitle
) {
483 if ( isset( $this->displaytitles
[$pageid] ) ) {
484 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
486 $pageInfo['displaytitle'] = $title->getPrefixedText();
490 if ( $this->params
['testactions'] ) {
491 $limit = $this->getMain()->canApiHighLimits() ? self
::LIMIT_SML1
: self
::LIMIT_SML2
;
492 if ( $this->countTestedActions
>= $limit ) {
493 return null; // force a continuation
496 $user = $this->getUser();
497 $pageInfo['actions'] = array();
498 foreach ( $this->params
['testactions'] as $action ) {
499 $this->countTestedActions++
;
500 if ( $title->userCan( $action, $user ) ) {
501 $pageInfo['actions'][$action] = '';
510 * Get information about protections and put it in $protections
512 private function getProtectionInfo() {
514 $this->protections
= array();
515 $db = $this->getDB();
517 // Get normal protections for existing titles
518 if ( count( $this->titles
) ) {
519 $this->resetQueryParams();
520 $this->addTables( 'page_restrictions' );
521 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
522 'pr_expiry', 'pr_cascade' ) );
523 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
525 $res = $this->select( __METHOD__
);
526 foreach ( $res as $row ) {
527 /** @var $title Title */
528 $title = $this->titles
[$row->pr_page
];
530 'type' => $row->pr_type
,
531 'level' => $row->pr_level
,
532 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
534 if ( $row->pr_cascade
) {
537 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
539 // Also check old restrictions
540 foreach ( $this->titles
as $pageId => $title ) {
541 if ( $this->pageRestrictions
[$pageId] ) {
542 $namespace = $title->getNamespace();
543 $dbKey = $title->getDBkey();
544 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
545 foreach ( $restrictions as $restrict ) {
546 $temp = explode( '=', trim( $restrict ) );
547 if ( count( $temp ) == 1 ) {
548 // old old format should be treated as edit/move restriction
549 $restriction = trim( $temp[0] );
551 if ( $restriction == '' ) {
554 $this->protections
[$namespace][$dbKey][] = array(
556 'level' => $restriction,
557 'expiry' => 'infinity',
559 $this->protections
[$namespace][$dbKey][] = array(
561 'level' => $restriction,
562 'expiry' => 'infinity',
565 $restriction = trim( $temp[1] );
566 if ( $restriction == '' ) {
569 $this->protections
[$namespace][$dbKey][] = array(
571 'level' => $restriction,
572 'expiry' => 'infinity',
580 // Get protections for missing titles
581 if ( count( $this->missing
) ) {
582 $this->resetQueryParams();
583 $lb = new LinkBatch( $this->missing
);
584 $this->addTables( 'protected_titles' );
585 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
586 $this->addWhere( $lb->constructSet( 'pt', $db ) );
587 $res = $this->select( __METHOD__
);
588 foreach ( $res as $row ) {
589 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
591 'level' => $row->pt_create_perm
,
592 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
597 // Separate good and missing titles into files and other pages
598 // and populate $this->restrictionTypes
599 $images = $others = array();
600 foreach ( $this->everything
as $title ) {
601 if ( $title->getNamespace() == NS_FILE
) {
602 $images[] = $title->getDBkey();
606 // Applicable protection types
607 $this->restrictionTypes
[$title->getNamespace()][$title->getDBkey()] =
608 array_values( $title->getRestrictionTypes() );
611 if ( count( $others ) ) {
612 // Non-images: check templatelinks
613 $lb = new LinkBatch( $others );
614 $this->resetQueryParams();
615 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
616 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
617 'page_title', 'page_namespace',
618 'tl_title', 'tl_namespace' ) );
619 $this->addWhere( $lb->constructSet( 'tl', $db ) );
620 $this->addWhere( 'pr_page = page_id' );
621 $this->addWhere( 'pr_page = tl_from' );
622 $this->addWhereFld( 'pr_cascade', 1 );
624 $res = $this->select( __METHOD__
);
625 foreach ( $res as $row ) {
626 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
627 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
628 'type' => $row->pr_type
,
629 'level' => $row->pr_level
,
630 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
631 'source' => $source->getPrefixedText()
636 if ( count( $images ) ) {
637 // Images: check imagelinks
638 $this->resetQueryParams();
639 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
640 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
641 'page_title', 'page_namespace', 'il_to' ) );
642 $this->addWhere( 'pr_page = page_id' );
643 $this->addWhere( 'pr_page = il_from' );
644 $this->addWhereFld( 'pr_cascade', 1 );
645 $this->addWhereFld( 'il_to', $images );
647 $res = $this->select( __METHOD__
);
648 foreach ( $res as $row ) {
649 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
650 $this->protections
[NS_FILE
][$row->il_to
][] = array(
651 'type' => $row->pr_type
,
652 'level' => $row->pr_level
,
653 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
654 'source' => $source->getPrefixedText()
661 * Get talk page IDs (if requested) and subject page IDs (if requested)
662 * and put them in $talkids and $subjectids
664 private function getTSIDs() {
665 $getTitles = $this->talkids
= $this->subjectids
= array();
668 foreach ( $this->everything
as $t ) {
669 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
670 if ( $this->fld_subjectid
) {
671 $getTitles[] = $t->getSubjectPage();
673 } elseif ( $this->fld_talkid
) {
674 $getTitles[] = $t->getTalkPage();
677 if ( !count( $getTitles ) ) {
681 $db = $this->getDB();
683 // Construct a custom WHERE clause that matches
684 // all titles in $getTitles
685 $lb = new LinkBatch( $getTitles );
686 $this->resetQueryParams();
687 $this->addTables( 'page' );
688 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
689 $this->addWhere( $lb->constructSet( 'page', $db ) );
690 $res = $this->select( __METHOD__
);
691 foreach ( $res as $row ) {
692 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
693 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
694 intval( $row->page_id
);
696 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
697 intval( $row->page_id
);
702 private function getDisplayTitle() {
703 $this->displaytitles
= array();
705 $pageIds = array_keys( $this->titles
);
707 if ( !count( $pageIds ) ) {
711 $this->resetQueryParams();
712 $this->addTables( 'page_props' );
713 $this->addFields( array( 'pp_page', 'pp_value' ) );
714 $this->addWhereFld( 'pp_page', $pageIds );
715 $this->addWhereFld( 'pp_propname', 'displaytitle' );
716 $res = $this->select( __METHOD__
);
718 foreach ( $res as $row ) {
719 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
724 * Get information about watched status and put it in $this->watched
725 * and $this->notificationtimestamps
727 private function getWatchedInfo() {
728 $user = $this->getUser();
730 if ( $user->isAnon() ||
count( $this->everything
) == 0
731 ||
!$user->isAllowed( 'viewmywatchlist' )
736 $this->watched
= array();
737 $this->notificationtimestamps
= array();
738 $db = $this->getDB();
740 $lb = new LinkBatch( $this->everything
);
742 $this->resetQueryParams();
743 $this->addTables( array( 'watchlist' ) );
744 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
745 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
746 $this->addWhere( array(
747 $lb->constructSet( 'wl', $db ),
748 'wl_user' => $user->getID()
751 $res = $this->select( __METHOD__
);
753 foreach ( $res as $row ) {
754 if ( $this->fld_watched
) {
755 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
757 if ( $this->fld_notificationtimestamp
) {
758 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] =
759 $row->wl_notificationtimestamp
;
765 * Get the count of watchers and put it in $this->watchers
767 private function getWatcherInfo() {
768 if ( count( $this->everything
) == 0 ) {
772 $user = $this->getUser();
773 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
774 $unwatchedPageThreshold = $this->getConfig()->get( 'UnwatchedPageThreshold' );
775 if ( !$canUnwatchedpages && !is_int( $unwatchedPageThreshold ) ) {
779 $this->watchers
= array();
780 $this->showZeroWatchers
= $canUnwatchedpages;
781 $db = $this->getDB();
783 $lb = new LinkBatch( $this->everything
);
785 $this->resetQueryParams();
786 $this->addTables( array( 'watchlist' ) );
787 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
788 $this->addWhere( array(
789 $lb->constructSet( 'wl', $db )
791 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
792 if ( !$canUnwatchedpages ) {
793 $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" );
796 $res = $this->select( __METHOD__
);
798 foreach ( $res as $row ) {
799 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
803 public function getCacheMode( $params ) {
804 $publicProps = array(
812 if ( !is_null( $params['prop'] ) ) {
813 foreach ( $params['prop'] as $prop ) {
814 if ( !in_array( $prop, $publicProps ) ) {
819 if ( !is_null( $params['token'] ) ) {
826 public function getAllowedParams() {
829 ApiBase
::PARAM_DFLT
=> null,
830 ApiBase
::PARAM_ISMULTI
=> true,
831 ApiBase
::PARAM_TYPE
=> array(
835 'watchers', # private
836 'notificationtimestamp', # private
839 'readable', # private
842 // If you add more properties here, please consider whether they
843 // need to be added to getCacheMode()
845 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> array(),
847 'testactions' => array(
848 ApiBase
::PARAM_TYPE
=> 'string',
849 ApiBase
::PARAM_ISMULTI
=> true,
852 ApiBase
::PARAM_DEPRECATED
=> true,
853 ApiBase
::PARAM_DFLT
=> null,
854 ApiBase
::PARAM_ISMULTI
=> true,
855 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
858 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
863 protected function getExamplesMessages() {
865 'action=query&prop=info&titles=Main%20Page'
866 => 'apihelp-query+info-example-simple',
867 'action=query&prop=info&inprop=protection&titles=Main%20Page'
868 => 'apihelp-query+info-example-protection',
872 public function getHelpUrls() {
873 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';