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;
49 private $pageRestrictions, $pageIsRedir, $pageIsNew, $pageTouched,
50 $pageLatest, $pageLength;
52 private $protections, $restrictionTypes, $watched, $watchers, $notificationtimestamps,
53 $talkids, $subjectids, $displaytitles;
54 private $showZeroWatchers = false;
56 private $tokenFunctions;
58 private $countTestedActions = 0;
60 public function __construct( ApiQuery
$query, $moduleName ) {
61 parent
::__construct( $query, $moduleName, 'in' );
65 * @param ApiPageSet $pageSet
68 public function requestExtraData( $pageSet ) {
69 $pageSet->requestField( 'page_restrictions' );
70 // If the pageset is resolving redirects we won't get page_is_redirect.
71 // But we can't know for sure until the pageset is executed (revids may
72 // turn it off), so request it unconditionally.
73 $pageSet->requestField( 'page_is_redirect' );
74 $pageSet->requestField( 'page_is_new' );
75 $config = $this->getConfig();
76 $pageSet->requestField( 'page_touched' );
77 $pageSet->requestField( 'page_latest' );
78 $pageSet->requestField( 'page_len' );
79 if ( $config->get( 'ContentHandlerUseDB' ) ) {
80 $pageSet->requestField( 'page_content_model' );
82 if ( $config->get( 'PageLanguageUseDB' ) ) {
83 $pageSet->requestField( 'page_lang' );
88 * Get an array mapping token names to their handler functions.
89 * The prototype for a token function is func($pageid, $title)
90 * it should return a token or false (permission denied)
91 * @deprecated since 1.24
92 * @return array Array(tokenname => function)
94 protected function getTokenFunctions() {
95 // Don't call the hooks twice
96 if ( isset( $this->tokenFunctions
) ) {
97 return $this->tokenFunctions
;
100 // If we're in a mode that breaks the same-origin policy, no tokens can
102 if ( $this->lacksSameOriginSecurity() ) {
106 $this->tokenFunctions
= array(
107 'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
108 'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
109 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
110 'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
111 'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
112 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
113 'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
114 'import' => array( 'ApiQueryInfo', 'getImportToken' ),
115 'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
117 Hooks
::run( 'APIQueryInfoTokens', array( &$this->tokenFunctions
) );
119 return $this->tokenFunctions
;
122 static protected $cachedTokens = array();
125 * @deprecated since 1.24
127 public static function resetTokenCache() {
128 ApiQueryInfo
::$cachedTokens = array();
132 * @deprecated since 1.24
134 public static function getEditToken( $pageid, $title ) {
135 // We could check for $title->userCan('edit') here,
136 // but that's too expensive for this purpose
137 // and would break caching
139 if ( !$wgUser->isAllowed( 'edit' ) ) {
143 // The token is always the same, let's exploit that
144 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
145 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
148 return ApiQueryInfo
::$cachedTokens['edit'];
152 * @deprecated since 1.24
154 public static function getDeleteToken( $pageid, $title ) {
156 if ( !$wgUser->isAllowed( 'delete' ) ) {
160 // The token is always the same, let's exploit that
161 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
162 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
165 return ApiQueryInfo
::$cachedTokens['delete'];
169 * @deprecated since 1.24
171 public static function getProtectToken( $pageid, $title ) {
173 if ( !$wgUser->isAllowed( 'protect' ) ) {
177 // The token is always the same, let's exploit that
178 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
179 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
182 return ApiQueryInfo
::$cachedTokens['protect'];
186 * @deprecated since 1.24
188 public static function getMoveToken( $pageid, $title ) {
190 if ( !$wgUser->isAllowed( 'move' ) ) {
194 // The token is always the same, let's exploit that
195 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
196 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
199 return ApiQueryInfo
::$cachedTokens['move'];
203 * @deprecated since 1.24
205 public static function getBlockToken( $pageid, $title ) {
207 if ( !$wgUser->isAllowed( 'block' ) ) {
211 // The token is always the same, let's exploit that
212 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
213 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
216 return ApiQueryInfo
::$cachedTokens['block'];
220 * @deprecated since 1.24
222 public static function getUnblockToken( $pageid, $title ) {
223 // Currently, this is exactly the same as the block token
224 return self
::getBlockToken( $pageid, $title );
228 * @deprecated since 1.24
230 public static function getEmailToken( $pageid, $title ) {
232 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailuser() ) {
236 // The token is always the same, let's exploit that
237 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
238 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
241 return ApiQueryInfo
::$cachedTokens['email'];
245 * @deprecated since 1.24
247 public static function getImportToken( $pageid, $title ) {
249 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
253 // The token is always the same, let's exploit that
254 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
255 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
258 return ApiQueryInfo
::$cachedTokens['import'];
262 * @deprecated since 1.24
264 public static function getWatchToken( $pageid, $title ) {
266 if ( !$wgUser->isLoggedIn() ) {
270 // The token is always the same, let's exploit that
271 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
272 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
275 return ApiQueryInfo
::$cachedTokens['watch'];
279 * @deprecated since 1.24
281 public static function getOptionsToken( $pageid, $title ) {
283 if ( !$wgUser->isLoggedIn() ) {
287 // The token is always the same, let's exploit that
288 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
289 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
292 return ApiQueryInfo
::$cachedTokens['options'];
295 public function execute() {
296 $this->params
= $this->extractRequestParams();
297 if ( !is_null( $this->params
['prop'] ) ) {
298 $prop = array_flip( $this->params
['prop'] );
299 $this->fld_protection
= isset( $prop['protection'] );
300 $this->fld_watched
= isset( $prop['watched'] );
301 $this->fld_watchers
= isset( $prop['watchers'] );
302 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
303 $this->fld_talkid
= isset( $prop['talkid'] );
304 $this->fld_subjectid
= isset( $prop['subjectid'] );
305 $this->fld_url
= isset( $prop['url'] );
306 $this->fld_readable
= isset( $prop['readable'] );
307 $this->fld_preload
= isset( $prop['preload'] );
308 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
311 $pageSet = $this->getPageSet();
312 $this->titles
= $pageSet->getGoodTitles();
313 $this->missing
= $pageSet->getMissingTitles();
314 $this->everything
= $this->titles +
$this->missing
;
315 $result = $this->getResult();
317 uasort( $this->everything
, array( 'Title', 'compare' ) );
318 if ( !is_null( $this->params
['continue'] ) ) {
319 // Throw away any titles we're gonna skip so they don't
321 $cont = explode( '|', $this->params
['continue'] );
322 $this->dieContinueUsageIf( count( $cont ) != 2 );
323 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
324 foreach ( $this->everything
as $pageid => $title ) {
325 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
328 unset( $this->titles
[$pageid] );
329 unset( $this->missing
[$pageid] );
330 unset( $this->everything
[$pageid] );
334 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
335 // when resolving redirects, no page will have this field
336 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
337 ?
$pageSet->getCustomField( 'page_is_redirect' )
339 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
341 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
342 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
343 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
345 // Get protection info if requested
346 if ( $this->fld_protection
) {
347 $this->getProtectionInfo();
350 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
351 $this->getWatchedInfo();
354 if ( $this->fld_watchers
) {
355 $this->getWatcherInfo();
358 // Run the talkid/subjectid query if requested
359 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
363 if ( $this->fld_displaytitle
) {
364 $this->getDisplayTitle();
367 /** @var $title Title */
368 foreach ( $this->everything
as $pageid => $title ) {
369 $pageInfo = $this->extractPageInfo( $pageid, $title );
370 $fit = $pageInfo !== null && $result->addValue( array(
373 ), $pageid, $pageInfo );
375 $this->setContinueEnumParameter( 'continue',
376 $title->getNamespace() . '|' .
384 * Get a result array with information about a title
385 * @param int $pageid Page ID (negative for missing titles)
386 * @param Title $title
389 private function extractPageInfo( $pageid, $title ) {
391 // $title->exists() needs pageid, which is not set for all title objects
392 $titleExists = $pageid > 0;
393 $ns = $title->getNamespace();
394 $dbkey = $title->getDBkey();
396 $pageInfo['contentmodel'] = $title->getContentModel();
398 $pageLanguage = $title->getPageLanguage();
399 $pageInfo['pagelanguage'] = $pageLanguage->getCode();
400 $pageInfo['pagelanguagehtmlcode'] = $pageLanguage->getHtmlCode();
401 $pageInfo['pagelanguagedir'] = $pageLanguage->getDir();
403 if ( $titleExists ) {
404 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
405 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
406 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
408 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
409 $pageInfo['redirect'] = true;
411 if ( $this->pageIsNew
[$pageid] ) {
412 $pageInfo['new'] = true;
416 if ( !is_null( $this->params
['token'] ) ) {
417 $tokenFunctions = $this->getTokenFunctions();
418 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
419 foreach ( $this->params
['token'] as $t ) {
420 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
421 if ( $val === false ) {
422 $this->setWarning( "Action '$t' is not allowed for the current user" );
424 $pageInfo[$t . 'token'] = $val;
429 if ( $this->fld_protection
) {
430 $pageInfo['protection'] = array();
431 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
432 $pageInfo['protection'] =
433 $this->protections
[$ns][$dbkey];
435 ApiResult
::setIndexedTagName( $pageInfo['protection'], 'pr' );
437 $pageInfo['restrictiontypes'] = array();
438 if ( isset( $this->restrictionTypes
[$ns][$dbkey] ) ) {
439 $pageInfo['restrictiontypes'] =
440 $this->restrictionTypes
[$ns][$dbkey];
442 ApiResult
::setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
445 if ( $this->fld_watched
) {
446 $pageInfo['watched'] = isset( $this->watched
[$ns][$dbkey] );
449 if ( $this->fld_watchers
) {
450 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
451 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
452 } elseif ( $this->showZeroWatchers
) {
453 $pageInfo['watchers'] = 0;
457 if ( $this->fld_notificationtimestamp
) {
458 $pageInfo['notificationtimestamp'] = '';
459 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
460 $pageInfo['notificationtimestamp'] =
461 wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
465 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
466 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
469 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
470 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
473 if ( $this->fld_url
) {
474 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
475 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
476 $pageInfo['canonicalurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CANONICAL
);
478 if ( $this->fld_readable
) {
479 $pageInfo['readable'] = $title->userCan( 'read', $this->getUser() );
482 if ( $this->fld_preload
) {
483 if ( $titleExists ) {
484 $pageInfo['preload'] = '';
487 Hooks
::run( 'EditFormPreloadText', array( &$text, &$title ) );
489 $pageInfo['preload'] = $text;
493 if ( $this->fld_displaytitle
) {
494 if ( isset( $this->displaytitles
[$pageid] ) ) {
495 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
497 $pageInfo['displaytitle'] = $title->getPrefixedText();
501 if ( $this->params
['testactions'] ) {
502 $limit = $this->getMain()->canApiHighLimits() ? self
::LIMIT_SML1
: self
::LIMIT_SML2
;
503 if ( $this->countTestedActions
>= $limit ) {
504 return null; // force a continuation
507 $user = $this->getUser();
508 $pageInfo['actions'] = array();
509 foreach ( $this->params
['testactions'] as $action ) {
510 $this->countTestedActions++
;
511 $pageInfo['actions'][$action] = $title->userCan( $action, $user );
519 * Get information about protections and put it in $protections
521 private function getProtectionInfo() {
523 $this->protections
= array();
524 $db = $this->getDB();
526 // Get normal protections for existing titles
527 if ( count( $this->titles
) ) {
528 $this->resetQueryParams();
529 $this->addTables( 'page_restrictions' );
530 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
531 'pr_expiry', 'pr_cascade' ) );
532 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
534 $res = $this->select( __METHOD__
);
535 foreach ( $res as $row ) {
536 /** @var $title Title */
537 $title = $this->titles
[$row->pr_page
];
539 'type' => $row->pr_type
,
540 'level' => $row->pr_level
,
541 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
543 if ( $row->pr_cascade
) {
544 $a['cascade'] = true;
546 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
548 // Also check old restrictions
549 foreach ( $this->titles
as $pageId => $title ) {
550 if ( $this->pageRestrictions
[$pageId] ) {
551 $namespace = $title->getNamespace();
552 $dbKey = $title->getDBkey();
553 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
554 foreach ( $restrictions as $restrict ) {
555 $temp = explode( '=', trim( $restrict ) );
556 if ( count( $temp ) == 1 ) {
557 // old old format should be treated as edit/move restriction
558 $restriction = trim( $temp[0] );
560 if ( $restriction == '' ) {
563 $this->protections
[$namespace][$dbKey][] = array(
565 'level' => $restriction,
566 'expiry' => 'infinity',
568 $this->protections
[$namespace][$dbKey][] = array(
570 'level' => $restriction,
571 'expiry' => 'infinity',
574 $restriction = trim( $temp[1] );
575 if ( $restriction == '' ) {
578 $this->protections
[$namespace][$dbKey][] = array(
580 'level' => $restriction,
581 'expiry' => 'infinity',
589 // Get protections for missing titles
590 if ( count( $this->missing
) ) {
591 $this->resetQueryParams();
592 $lb = new LinkBatch( $this->missing
);
593 $this->addTables( 'protected_titles' );
594 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
595 $this->addWhere( $lb->constructSet( 'pt', $db ) );
596 $res = $this->select( __METHOD__
);
597 foreach ( $res as $row ) {
598 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
600 'level' => $row->pt_create_perm
,
601 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
606 // Separate good and missing titles into files and other pages
607 // and populate $this->restrictionTypes
608 $images = $others = array();
609 foreach ( $this->everything
as $title ) {
610 if ( $title->getNamespace() == NS_FILE
) {
611 $images[] = $title->getDBkey();
615 // Applicable protection types
616 $this->restrictionTypes
[$title->getNamespace()][$title->getDBkey()] =
617 array_values( $title->getRestrictionTypes() );
620 if ( count( $others ) ) {
621 // Non-images: check templatelinks
622 $lb = new LinkBatch( $others );
623 $this->resetQueryParams();
624 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
625 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
626 'page_title', 'page_namespace',
627 'tl_title', 'tl_namespace' ) );
628 $this->addWhere( $lb->constructSet( 'tl', $db ) );
629 $this->addWhere( 'pr_page = page_id' );
630 $this->addWhere( 'pr_page = tl_from' );
631 $this->addWhereFld( 'pr_cascade', 1 );
633 $res = $this->select( __METHOD__
);
634 foreach ( $res as $row ) {
635 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
636 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
637 'type' => $row->pr_type
,
638 'level' => $row->pr_level
,
639 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
640 'source' => $source->getPrefixedText()
645 if ( count( $images ) ) {
646 // Images: check imagelinks
647 $this->resetQueryParams();
648 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
649 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
650 'page_title', 'page_namespace', 'il_to' ) );
651 $this->addWhere( 'pr_page = page_id' );
652 $this->addWhere( 'pr_page = il_from' );
653 $this->addWhereFld( 'pr_cascade', 1 );
654 $this->addWhereFld( 'il_to', $images );
656 $res = $this->select( __METHOD__
);
657 foreach ( $res as $row ) {
658 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
659 $this->protections
[NS_FILE
][$row->il_to
][] = array(
660 'type' => $row->pr_type
,
661 'level' => $row->pr_level
,
662 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
663 'source' => $source->getPrefixedText()
670 * Get talk page IDs (if requested) and subject page IDs (if requested)
671 * and put them in $talkids and $subjectids
673 private function getTSIDs() {
674 $getTitles = $this->talkids
= $this->subjectids
= array();
677 foreach ( $this->everything
as $t ) {
678 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
679 if ( $this->fld_subjectid
) {
680 $getTitles[] = $t->getSubjectPage();
682 } elseif ( $this->fld_talkid
) {
683 $getTitles[] = $t->getTalkPage();
686 if ( !count( $getTitles ) ) {
690 $db = $this->getDB();
692 // Construct a custom WHERE clause that matches
693 // all titles in $getTitles
694 $lb = new LinkBatch( $getTitles );
695 $this->resetQueryParams();
696 $this->addTables( 'page' );
697 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
698 $this->addWhere( $lb->constructSet( 'page', $db ) );
699 $res = $this->select( __METHOD__
);
700 foreach ( $res as $row ) {
701 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
702 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
703 intval( $row->page_id
);
705 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
706 intval( $row->page_id
);
711 private function getDisplayTitle() {
712 $this->displaytitles
= array();
714 $pageIds = array_keys( $this->titles
);
716 if ( !count( $pageIds ) ) {
720 $this->resetQueryParams();
721 $this->addTables( 'page_props' );
722 $this->addFields( array( 'pp_page', 'pp_value' ) );
723 $this->addWhereFld( 'pp_page', $pageIds );
724 $this->addWhereFld( 'pp_propname', 'displaytitle' );
725 $res = $this->select( __METHOD__
);
727 foreach ( $res as $row ) {
728 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
733 * Get information about watched status and put it in $this->watched
734 * and $this->notificationtimestamps
736 private function getWatchedInfo() {
737 $user = $this->getUser();
739 if ( $user->isAnon() ||
count( $this->everything
) == 0
740 ||
!$user->isAllowed( 'viewmywatchlist' )
745 $this->watched
= array();
746 $this->notificationtimestamps
= array();
747 $db = $this->getDB();
749 $lb = new LinkBatch( $this->everything
);
751 $this->resetQueryParams();
752 $this->addTables( array( 'watchlist' ) );
753 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
754 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
755 $this->addWhere( array(
756 $lb->constructSet( 'wl', $db ),
757 'wl_user' => $user->getId()
760 $res = $this->select( __METHOD__
);
762 foreach ( $res as $row ) {
763 if ( $this->fld_watched
) {
764 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
766 if ( $this->fld_notificationtimestamp
) {
767 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] =
768 $row->wl_notificationtimestamp
;
774 * Get the count of watchers and put it in $this->watchers
776 private function getWatcherInfo() {
777 if ( count( $this->everything
) == 0 ) {
781 $user = $this->getUser();
782 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
783 $unwatchedPageThreshold = $this->getConfig()->get( 'UnwatchedPageThreshold' );
784 if ( !$canUnwatchedpages && !is_int( $unwatchedPageThreshold ) ) {
788 $this->watchers
= array();
789 $this->showZeroWatchers
= $canUnwatchedpages;
790 $db = $this->getDB();
792 $lb = new LinkBatch( $this->everything
);
794 $this->resetQueryParams();
795 $this->addTables( array( 'watchlist' ) );
796 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
797 $this->addWhere( array(
798 $lb->constructSet( 'wl', $db )
800 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
801 if ( !$canUnwatchedpages ) {
802 $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" );
805 $res = $this->select( __METHOD__
);
807 foreach ( $res as $row ) {
808 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
812 public function getCacheMode( $params ) {
813 // Other props depend on something about the current user
814 $publicProps = array(
822 if ( array_diff( (array)$params['prop'], $publicProps ) ) {
826 // testactions also depends on the current user
827 if ( $params['testactions'] ) {
831 if ( !is_null( $params['token'] ) ) {
838 public function getAllowedParams() {
841 ApiBase
::PARAM_ISMULTI
=> true,
842 ApiBase
::PARAM_TYPE
=> array(
846 'watchers', # private
847 'notificationtimestamp', # private
850 'readable', # private
853 // If you add more properties here, please consider whether they
854 // need to be added to getCacheMode()
856 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> array(),
858 'testactions' => array(
859 ApiBase
::PARAM_TYPE
=> 'string',
860 ApiBase
::PARAM_ISMULTI
=> true,
863 ApiBase
::PARAM_DEPRECATED
=> true,
864 ApiBase
::PARAM_ISMULTI
=> true,
865 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
868 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
873 protected function getExamplesMessages() {
875 'action=query&prop=info&titles=Main%20Page'
876 => 'apihelp-query+info-example-simple',
877 'action=query&prop=info&inprop=protection&titles=Main%20Page'
878 => 'apihelp-query+info-example-protection',
882 public function getHelpUrls() {
883 return 'https://www.mediawiki.org/wiki/API:Info';