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 JSON callback mode, no tokens can be obtained
94 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
98 $this->tokenFunctions
= array(
99 'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
100 'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
101 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
102 'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
103 'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
104 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
105 'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
106 'import' => array( 'ApiQueryInfo', 'getImportToken' ),
107 'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
109 Hooks
::run( 'APIQueryInfoTokens', array( &$this->tokenFunctions
) );
111 return $this->tokenFunctions
;
114 static protected $cachedTokens = array();
117 * @deprecated since 1.24
119 public static function resetTokenCache() {
120 ApiQueryInfo
::$cachedTokens = array();
124 * @deprecated since 1.24
126 public static function getEditToken( $pageid, $title ) {
127 // We could check for $title->userCan('edit') here,
128 // but that's too expensive for this purpose
129 // and would break caching
131 if ( !$wgUser->isAllowed( 'edit' ) ) {
135 // The token is always the same, let's exploit that
136 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
137 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
140 return ApiQueryInfo
::$cachedTokens['edit'];
144 * @deprecated since 1.24
146 public static function getDeleteToken( $pageid, $title ) {
148 if ( !$wgUser->isAllowed( 'delete' ) ) {
152 // The token is always the same, let's exploit that
153 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
154 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
157 return ApiQueryInfo
::$cachedTokens['delete'];
161 * @deprecated since 1.24
163 public static function getProtectToken( $pageid, $title ) {
165 if ( !$wgUser->isAllowed( 'protect' ) ) {
169 // The token is always the same, let's exploit that
170 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
171 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
174 return ApiQueryInfo
::$cachedTokens['protect'];
178 * @deprecated since 1.24
180 public static function getMoveToken( $pageid, $title ) {
182 if ( !$wgUser->isAllowed( 'move' ) ) {
186 // The token is always the same, let's exploit that
187 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
188 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
191 return ApiQueryInfo
::$cachedTokens['move'];
195 * @deprecated since 1.24
197 public static function getBlockToken( $pageid, $title ) {
199 if ( !$wgUser->isAllowed( 'block' ) ) {
203 // The token is always the same, let's exploit that
204 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
205 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
208 return ApiQueryInfo
::$cachedTokens['block'];
212 * @deprecated since 1.24
214 public static function getUnblockToken( $pageid, $title ) {
215 // Currently, this is exactly the same as the block token
216 return self
::getBlockToken( $pageid, $title );
220 * @deprecated since 1.24
222 public static function getEmailToken( $pageid, $title ) {
224 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailUser() ) {
228 // The token is always the same, let's exploit that
229 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
230 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
233 return ApiQueryInfo
::$cachedTokens['email'];
237 * @deprecated since 1.24
239 public static function getImportToken( $pageid, $title ) {
241 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
245 // The token is always the same, let's exploit that
246 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
247 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
250 return ApiQueryInfo
::$cachedTokens['import'];
254 * @deprecated since 1.24
256 public static function getWatchToken( $pageid, $title ) {
258 if ( !$wgUser->isLoggedIn() ) {
262 // The token is always the same, let's exploit that
263 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
264 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
267 return ApiQueryInfo
::$cachedTokens['watch'];
271 * @deprecated since 1.24
273 public static function getOptionsToken( $pageid, $title ) {
275 if ( !$wgUser->isLoggedIn() ) {
279 // The token is always the same, let's exploit that
280 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
281 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
284 return ApiQueryInfo
::$cachedTokens['options'];
287 public function execute() {
288 $this->params
= $this->extractRequestParams();
289 if ( !is_null( $this->params
['prop'] ) ) {
290 $prop = array_flip( $this->params
['prop'] );
291 $this->fld_protection
= isset( $prop['protection'] );
292 $this->fld_watched
= isset( $prop['watched'] );
293 $this->fld_watchers
= isset( $prop['watchers'] );
294 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
295 $this->fld_talkid
= isset( $prop['talkid'] );
296 $this->fld_subjectid
= isset( $prop['subjectid'] );
297 $this->fld_url
= isset( $prop['url'] );
298 $this->fld_readable
= isset( $prop['readable'] );
299 $this->fld_preload
= isset( $prop['preload'] );
300 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
303 $pageSet = $this->getPageSet();
304 $this->titles
= $pageSet->getGoodTitles();
305 $this->missing
= $pageSet->getMissingTitles();
306 $this->everything
= $this->titles +
$this->missing
;
307 $result = $this->getResult();
309 uasort( $this->everything
, array( 'Title', 'compare' ) );
310 if ( !is_null( $this->params
['continue'] ) ) {
311 // Throw away any titles we're gonna skip so they don't
313 $cont = explode( '|', $this->params
['continue'] );
314 $this->dieContinueUsageIf( count( $cont ) != 2 );
315 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
316 foreach ( $this->everything
as $pageid => $title ) {
317 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
320 unset( $this->titles
[$pageid] );
321 unset( $this->missing
[$pageid] );
322 unset( $this->everything
[$pageid] );
326 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
327 // when resolving redirects, no page will have this field
328 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
329 ?
$pageSet->getCustomField( 'page_is_redirect' )
331 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
333 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
334 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
335 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
337 // Get protection info if requested
338 if ( $this->fld_protection
) {
339 $this->getProtectionInfo();
342 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
343 $this->getWatchedInfo();
346 if ( $this->fld_watchers
) {
347 $this->getWatcherInfo();
350 // Run the talkid/subjectid query if requested
351 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
355 if ( $this->fld_displaytitle
) {
356 $this->getDisplayTitle();
359 /** @var $title Title */
360 foreach ( $this->everything
as $pageid => $title ) {
361 $pageInfo = $this->extractPageInfo( $pageid, $title );
362 $fit = $pageInfo !== null && $result->addValue( array(
365 ), $pageid, $pageInfo );
367 $this->setContinueEnumParameter( 'continue',
368 $title->getNamespace() . '|' .
376 * Get a result array with information about a title
377 * @param int $pageid Page ID (negative for missing titles)
378 * @param Title $title
381 private function extractPageInfo( $pageid, $title ) {
383 // $title->exists() needs pageid, which is not set for all title objects
384 $titleExists = $pageid > 0;
385 $ns = $title->getNamespace();
386 $dbkey = $title->getDBkey();
388 $pageInfo['contentmodel'] = $title->getContentModel();
389 $pageInfo['pagelanguage'] = $title->getPageLanguage()->getCode();
391 if ( $titleExists ) {
392 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
393 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
394 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
396 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
397 $pageInfo['redirect'] = '';
399 if ( $this->pageIsNew
[$pageid] ) {
400 $pageInfo['new'] = '';
404 if ( !is_null( $this->params
['token'] ) ) {
405 $tokenFunctions = $this->getTokenFunctions();
406 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
407 foreach ( $this->params
['token'] as $t ) {
408 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
409 if ( $val === false ) {
410 $this->setWarning( "Action '$t' is not allowed for the current user" );
412 $pageInfo[$t . 'token'] = $val;
417 if ( $this->fld_protection
) {
418 $pageInfo['protection'] = array();
419 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
420 $pageInfo['protection'] =
421 $this->protections
[$ns][$dbkey];
423 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
425 $pageInfo['restrictiontypes'] = array();
426 if ( isset( $this->restrictionTypes
[$ns][$dbkey] ) ) {
427 $pageInfo['restrictiontypes'] =
428 $this->restrictionTypes
[$ns][$dbkey];
430 $this->getResult()->setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
433 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
434 $pageInfo['watched'] = '';
437 if ( $this->fld_watchers
) {
438 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
439 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
440 } elseif ( $this->showZeroWatchers
) {
441 $pageInfo['watchers'] = 0;
445 if ( $this->fld_notificationtimestamp
) {
446 $pageInfo['notificationtimestamp'] = '';
447 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
448 $pageInfo['notificationtimestamp'] =
449 wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
453 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
454 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
457 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
458 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
461 if ( $this->fld_url
) {
462 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
463 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
464 $pageInfo['canonicalurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CANONICAL
);
466 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
467 $pageInfo['readable'] = '';
470 if ( $this->fld_preload
) {
471 if ( $titleExists ) {
472 $pageInfo['preload'] = '';
475 Hooks
::run( 'EditFormPreloadText', array( &$text, &$title ) );
477 $pageInfo['preload'] = $text;
481 if ( $this->fld_displaytitle
) {
482 if ( isset( $this->displaytitles
[$pageid] ) ) {
483 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
485 $pageInfo['displaytitle'] = $title->getPrefixedText();
489 if ( $this->params
['testactions'] ) {
490 $limit = $this->getMain()->canApiHighLimits() ? self
::LIMIT_SML1
: self
::LIMIT_SML2
;
491 if ( $this->countTestedActions
>= $limit ) {
492 return null; // force a continuation
495 $user = $this->getUser();
496 $pageInfo['actions'] = array();
497 foreach ( $this->params
['testactions'] as $action ) {
498 $this->countTestedActions++
;
499 if ( $title->userCan( $action, $user ) ) {
500 $pageInfo['actions'][$action] = '';
509 * Get information about protections and put it in $protections
511 private function getProtectionInfo() {
513 $this->protections
= array();
514 $db = $this->getDB();
516 // Get normal protections for existing titles
517 if ( count( $this->titles
) ) {
518 $this->resetQueryParams();
519 $this->addTables( 'page_restrictions' );
520 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
521 'pr_expiry', 'pr_cascade' ) );
522 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
524 $res = $this->select( __METHOD__
);
525 foreach ( $res as $row ) {
526 /** @var $title Title */
527 $title = $this->titles
[$row->pr_page
];
529 'type' => $row->pr_type
,
530 'level' => $row->pr_level
,
531 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
533 if ( $row->pr_cascade
) {
536 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
538 // Also check old restrictions
539 foreach ( $this->titles
as $pageId => $title ) {
540 if ( $this->pageRestrictions
[$pageId] ) {
541 $namespace = $title->getNamespace();
542 $dbKey = $title->getDBkey();
543 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
544 foreach ( $restrictions as $restrict ) {
545 $temp = explode( '=', trim( $restrict ) );
546 if ( count( $temp ) == 1 ) {
547 // old old format should be treated as edit/move restriction
548 $restriction = trim( $temp[0] );
550 if ( $restriction == '' ) {
553 $this->protections
[$namespace][$dbKey][] = array(
555 'level' => $restriction,
556 'expiry' => 'infinity',
558 $this->protections
[$namespace][$dbKey][] = array(
560 'level' => $restriction,
561 'expiry' => 'infinity',
564 $restriction = trim( $temp[1] );
565 if ( $restriction == '' ) {
568 $this->protections
[$namespace][$dbKey][] = array(
570 'level' => $restriction,
571 'expiry' => 'infinity',
579 // Get protections for missing titles
580 if ( count( $this->missing
) ) {
581 $this->resetQueryParams();
582 $lb = new LinkBatch( $this->missing
);
583 $this->addTables( 'protected_titles' );
584 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
585 $this->addWhere( $lb->constructSet( 'pt', $db ) );
586 $res = $this->select( __METHOD__
);
587 foreach ( $res as $row ) {
588 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
590 'level' => $row->pt_create_perm
,
591 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
596 // Separate good and missing titles into files and other pages
597 // and populate $this->restrictionTypes
598 $images = $others = array();
599 foreach ( $this->everything
as $title ) {
600 if ( $title->getNamespace() == NS_FILE
) {
601 $images[] = $title->getDBkey();
605 // Applicable protection types
606 $this->restrictionTypes
[$title->getNamespace()][$title->getDBkey()] =
607 array_values( $title->getRestrictionTypes() );
610 if ( count( $others ) ) {
611 // Non-images: check templatelinks
612 $lb = new LinkBatch( $others );
613 $this->resetQueryParams();
614 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
615 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
616 'page_title', 'page_namespace',
617 'tl_title', 'tl_namespace' ) );
618 $this->addWhere( $lb->constructSet( 'tl', $db ) );
619 $this->addWhere( 'pr_page = page_id' );
620 $this->addWhere( 'pr_page = tl_from' );
621 $this->addWhereFld( 'pr_cascade', 1 );
623 $res = $this->select( __METHOD__
);
624 foreach ( $res as $row ) {
625 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
626 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
627 'type' => $row->pr_type
,
628 'level' => $row->pr_level
,
629 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
630 'source' => $source->getPrefixedText()
635 if ( count( $images ) ) {
636 // Images: check imagelinks
637 $this->resetQueryParams();
638 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
639 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
640 'page_title', 'page_namespace', 'il_to' ) );
641 $this->addWhere( 'pr_page = page_id' );
642 $this->addWhere( 'pr_page = il_from' );
643 $this->addWhereFld( 'pr_cascade', 1 );
644 $this->addWhereFld( 'il_to', $images );
646 $res = $this->select( __METHOD__
);
647 foreach ( $res as $row ) {
648 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
649 $this->protections
[NS_FILE
][$row->il_to
][] = array(
650 'type' => $row->pr_type
,
651 'level' => $row->pr_level
,
652 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
653 'source' => $source->getPrefixedText()
660 * Get talk page IDs (if requested) and subject page IDs (if requested)
661 * and put them in $talkids and $subjectids
663 private function getTSIDs() {
664 $getTitles = $this->talkids
= $this->subjectids
= array();
667 foreach ( $this->everything
as $t ) {
668 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
669 if ( $this->fld_subjectid
) {
670 $getTitles[] = $t->getSubjectPage();
672 } elseif ( $this->fld_talkid
) {
673 $getTitles[] = $t->getTalkPage();
676 if ( !count( $getTitles ) ) {
680 $db = $this->getDB();
682 // Construct a custom WHERE clause that matches
683 // all titles in $getTitles
684 $lb = new LinkBatch( $getTitles );
685 $this->resetQueryParams();
686 $this->addTables( 'page' );
687 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
688 $this->addWhere( $lb->constructSet( 'page', $db ) );
689 $res = $this->select( __METHOD__
);
690 foreach ( $res as $row ) {
691 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
692 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
693 intval( $row->page_id
);
695 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
696 intval( $row->page_id
);
701 private function getDisplayTitle() {
702 $this->displaytitles
= array();
704 $pageIds = array_keys( $this->titles
);
706 if ( !count( $pageIds ) ) {
710 $this->resetQueryParams();
711 $this->addTables( 'page_props' );
712 $this->addFields( array( 'pp_page', 'pp_value' ) );
713 $this->addWhereFld( 'pp_page', $pageIds );
714 $this->addWhereFld( 'pp_propname', 'displaytitle' );
715 $res = $this->select( __METHOD__
);
717 foreach ( $res as $row ) {
718 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
723 * Get information about watched status and put it in $this->watched
724 * and $this->notificationtimestamps
726 private function getWatchedInfo() {
727 $user = $this->getUser();
729 if ( $user->isAnon() ||
count( $this->everything
) == 0
730 ||
!$user->isAllowed( 'viewmywatchlist' )
735 $this->watched
= array();
736 $this->notificationtimestamps
= array();
737 $db = $this->getDB();
739 $lb = new LinkBatch( $this->everything
);
741 $this->resetQueryParams();
742 $this->addTables( array( 'watchlist' ) );
743 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
744 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
745 $this->addWhere( array(
746 $lb->constructSet( 'wl', $db ),
747 'wl_user' => $user->getID()
750 $res = $this->select( __METHOD__
);
752 foreach ( $res as $row ) {
753 if ( $this->fld_watched
) {
754 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
756 if ( $this->fld_notificationtimestamp
) {
757 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] =
758 $row->wl_notificationtimestamp
;
764 * Get the count of watchers and put it in $this->watchers
766 private function getWatcherInfo() {
767 if ( count( $this->everything
) == 0 ) {
771 $user = $this->getUser();
772 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
773 $unwatchedPageThreshold = $this->getConfig()->get( 'UnwatchedPageThreshold' );
774 if ( !$canUnwatchedpages && !is_int( $unwatchedPageThreshold ) ) {
778 $this->watchers
= array();
779 $this->showZeroWatchers
= $canUnwatchedpages;
780 $db = $this->getDB();
782 $lb = new LinkBatch( $this->everything
);
784 $this->resetQueryParams();
785 $this->addTables( array( 'watchlist' ) );
786 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
787 $this->addWhere( array(
788 $lb->constructSet( 'wl', $db )
790 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
791 if ( !$canUnwatchedpages ) {
792 $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" );
795 $res = $this->select( __METHOD__
);
797 foreach ( $res as $row ) {
798 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
802 public function getCacheMode( $params ) {
803 $publicProps = array(
811 if ( !is_null( $params['prop'] ) ) {
812 foreach ( $params['prop'] as $prop ) {
813 if ( !in_array( $prop, $publicProps ) ) {
818 if ( !is_null( $params['token'] ) ) {
825 public function getAllowedParams() {
828 ApiBase
::PARAM_DFLT
=> null,
829 ApiBase
::PARAM_ISMULTI
=> true,
830 ApiBase
::PARAM_TYPE
=> array(
834 'watchers', # private
835 'notificationtimestamp', # private
838 'readable', # private
841 // If you add more properties here, please consider whether they
842 // need to be added to getCacheMode()
844 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> array(),
846 'testactions' => array(
847 ApiBase
::PARAM_TYPE
=> 'string',
848 ApiBase
::PARAM_ISMULTI
=> true,
851 ApiBase
::PARAM_DEPRECATED
=> true,
852 ApiBase
::PARAM_DFLT
=> null,
853 ApiBase
::PARAM_ISMULTI
=> true,
854 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
857 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
862 protected function getExamplesMessages() {
864 'action=query&prop=info&titles=Main%20Page'
865 => 'apihelp-query+info-example-simple',
866 'action=query&prop=info&inprop=protection&titles=Main%20Page'
867 => 'apihelp-query+info-example-protection',
871 public function getHelpUrls() {
872 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';