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,
46 $talkids, $subjectids, $displaytitles;
47 private $showZeroWatchers = false;
49 private $tokenFunctions;
51 public function __construct( ApiQuery
$query, $moduleName ) {
52 parent
::__construct( $query, $moduleName, 'in' );
56 * @param ApiPageSet $pageSet
59 public function requestExtraData( $pageSet ) {
60 $pageSet->requestField( 'page_restrictions' );
61 // If the pageset is resolving redirects we won't get page_is_redirect.
62 // But we can't know for sure until the pageset is executed (revids may
63 // turn it off), so request it unconditionally.
64 $pageSet->requestField( 'page_is_redirect' );
65 $pageSet->requestField( 'page_is_new' );
66 $config = $this->getConfig();
67 $pageSet->requestField( 'page_touched' );
68 $pageSet->requestField( 'page_latest' );
69 $pageSet->requestField( 'page_len' );
70 if ( $config->get( 'ContentHandlerUseDB' ) ) {
71 $pageSet->requestField( 'page_content_model' );
73 if ( $config->get( 'PageLanguageUseDB' ) ) {
74 $pageSet->requestField( 'page_lang' );
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 * @deprecated since 1.24
83 * @return array Array(tokenname => function)
85 protected function getTokenFunctions() {
86 // Don't call the hooks twice
87 if ( isset( $this->tokenFunctions
) ) {
88 return $this->tokenFunctions
;
91 // If we're in JSON callback mode, no tokens can be obtained
92 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
96 $this->tokenFunctions
= array(
97 'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
98 'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
99 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
100 'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
101 'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
102 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
103 'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
104 'import' => array( 'ApiQueryInfo', 'getImportToken' ),
105 'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
107 Hooks
::run( 'APIQueryInfoTokens', array( &$this->tokenFunctions
) );
109 return $this->tokenFunctions
;
112 static protected $cachedTokens = array();
115 * @deprecated since 1.24
117 public static function resetTokenCache() {
118 ApiQueryInfo
::$cachedTokens = array();
122 * @deprecated since 1.24
124 public static function getEditToken( $pageid, $title ) {
125 // We could check for $title->userCan('edit') here,
126 // but that's too expensive for this purpose
127 // and would break caching
129 if ( !$wgUser->isAllowed( 'edit' ) ) {
133 // The token is always the same, let's exploit that
134 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
135 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
138 return ApiQueryInfo
::$cachedTokens['edit'];
142 * @deprecated since 1.24
144 public static function getDeleteToken( $pageid, $title ) {
146 if ( !$wgUser->isAllowed( 'delete' ) ) {
150 // The token is always the same, let's exploit that
151 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
152 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
155 return ApiQueryInfo
::$cachedTokens['delete'];
159 * @deprecated since 1.24
161 public static function getProtectToken( $pageid, $title ) {
163 if ( !$wgUser->isAllowed( 'protect' ) ) {
167 // The token is always the same, let's exploit that
168 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
169 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
172 return ApiQueryInfo
::$cachedTokens['protect'];
176 * @deprecated since 1.24
178 public static function getMoveToken( $pageid, $title ) {
180 if ( !$wgUser->isAllowed( 'move' ) ) {
184 // The token is always the same, let's exploit that
185 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
186 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
189 return ApiQueryInfo
::$cachedTokens['move'];
193 * @deprecated since 1.24
195 public static function getBlockToken( $pageid, $title ) {
197 if ( !$wgUser->isAllowed( 'block' ) ) {
201 // The token is always the same, let's exploit that
202 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
203 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
206 return ApiQueryInfo
::$cachedTokens['block'];
210 * @deprecated since 1.24
212 public static function getUnblockToken( $pageid, $title ) {
213 // Currently, this is exactly the same as the block token
214 return self
::getBlockToken( $pageid, $title );
218 * @deprecated since 1.24
220 public static function getEmailToken( $pageid, $title ) {
222 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailUser() ) {
226 // The token is always the same, let's exploit that
227 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
228 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
231 return ApiQueryInfo
::$cachedTokens['email'];
235 * @deprecated since 1.24
237 public static function getImportToken( $pageid, $title ) {
239 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
243 // The token is always the same, let's exploit that
244 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
245 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
248 return ApiQueryInfo
::$cachedTokens['import'];
252 * @deprecated since 1.24
254 public static function getWatchToken( $pageid, $title ) {
256 if ( !$wgUser->isLoggedIn() ) {
260 // The token is always the same, let's exploit that
261 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
262 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
265 return ApiQueryInfo
::$cachedTokens['watch'];
269 * @deprecated since 1.24
271 public static function getOptionsToken( $pageid, $title ) {
273 if ( !$wgUser->isLoggedIn() ) {
277 // The token is always the same, let's exploit that
278 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
279 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
282 return ApiQueryInfo
::$cachedTokens['options'];
285 public function execute() {
286 $this->params
= $this->extractRequestParams();
287 if ( !is_null( $this->params
['prop'] ) ) {
288 $prop = array_flip( $this->params
['prop'] );
289 $this->fld_protection
= isset( $prop['protection'] );
290 $this->fld_watched
= isset( $prop['watched'] );
291 $this->fld_watchers
= isset( $prop['watchers'] );
292 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
293 $this->fld_talkid
= isset( $prop['talkid'] );
294 $this->fld_subjectid
= isset( $prop['subjectid'] );
295 $this->fld_url
= isset( $prop['url'] );
296 $this->fld_readable
= isset( $prop['readable'] );
297 $this->fld_preload
= isset( $prop['preload'] );
298 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
301 $pageSet = $this->getPageSet();
302 $this->titles
= $pageSet->getGoodTitles();
303 $this->missing
= $pageSet->getMissingTitles();
304 $this->everything
= $this->titles +
$this->missing
;
305 $result = $this->getResult();
307 uasort( $this->everything
, array( 'Title', 'compare' ) );
308 if ( !is_null( $this->params
['continue'] ) ) {
309 // Throw away any titles we're gonna skip so they don't
311 $cont = explode( '|', $this->params
['continue'] );
312 $this->dieContinueUsageIf( count( $cont ) != 2 );
313 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
314 foreach ( $this->everything
as $pageid => $title ) {
315 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
318 unset( $this->titles
[$pageid] );
319 unset( $this->missing
[$pageid] );
320 unset( $this->everything
[$pageid] );
324 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
325 // when resolving redirects, no page will have this field
326 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
327 ?
$pageSet->getCustomField( 'page_is_redirect' )
329 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
331 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
332 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
333 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
335 // Get protection info if requested
336 if ( $this->fld_protection
) {
337 $this->getProtectionInfo();
340 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
341 $this->getWatchedInfo();
344 if ( $this->fld_watchers
) {
345 $this->getWatcherInfo();
348 // Run the talkid/subjectid query if requested
349 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
353 if ( $this->fld_displaytitle
) {
354 $this->getDisplayTitle();
357 /** @var $title Title */
358 foreach ( $this->everything
as $pageid => $title ) {
359 $pageInfo = $this->extractPageInfo( $pageid, $title );
360 $fit = $result->addValue( array(
363 ), $pageid, $pageInfo );
365 $this->setContinueEnumParameter( 'continue',
366 $title->getNamespace() . '|' .
374 * Get a result array with information about a title
375 * @param int $pageid Page ID (negative for missing titles)
376 * @param Title $title
379 private function extractPageInfo( $pageid, $title ) {
381 // $title->exists() needs pageid, which is not set for all title objects
382 $titleExists = $pageid > 0;
383 $ns = $title->getNamespace();
384 $dbkey = $title->getDBkey();
386 $pageInfo['contentmodel'] = $title->getContentModel();
387 $pageInfo['pagelanguage'] = $title->getPageLanguage()->getCode();
389 if ( $titleExists ) {
390 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
391 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
392 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
394 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
395 $pageInfo['redirect'] = '';
397 if ( $this->pageIsNew
[$pageid] ) {
398 $pageInfo['new'] = '';
402 if ( !is_null( $this->params
['token'] ) ) {
403 $tokenFunctions = $this->getTokenFunctions();
404 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
405 foreach ( $this->params
['token'] as $t ) {
406 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
407 if ( $val === false ) {
408 $this->setWarning( "Action '$t' is not allowed for the current user" );
410 $pageInfo[$t . 'token'] = $val;
415 if ( $this->fld_protection
) {
416 $pageInfo['protection'] = array();
417 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
418 $pageInfo['protection'] =
419 $this->protections
[$ns][$dbkey];
421 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
424 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
425 $pageInfo['watched'] = '';
428 if ( $this->fld_watchers
) {
429 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
430 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
431 } elseif ( $this->showZeroWatchers
) {
432 $pageInfo['watchers'] = 0;
436 if ( $this->fld_notificationtimestamp
) {
437 $pageInfo['notificationtimestamp'] = '';
438 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
439 $pageInfo['notificationtimestamp'] =
440 wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
444 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
445 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
448 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
449 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
452 if ( $this->fld_url
) {
453 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
454 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
455 $pageInfo['canonicalurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CANONICAL
);
457 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
458 $pageInfo['readable'] = '';
461 if ( $this->fld_preload
) {
462 if ( $titleExists ) {
463 $pageInfo['preload'] = '';
466 Hooks
::run( 'EditFormPreloadText', array( &$text, &$title ) );
468 $pageInfo['preload'] = $text;
472 if ( $this->fld_displaytitle
) {
473 if ( isset( $this->displaytitles
[$pageid] ) ) {
474 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
476 $pageInfo['displaytitle'] = $title->getPrefixedText();
484 * Get information about protections and put it in $protections
486 private function getProtectionInfo() {
488 $this->protections
= array();
489 $db = $this->getDB();
491 // Get normal protections for existing titles
492 if ( count( $this->titles
) ) {
493 $this->resetQueryParams();
494 $this->addTables( 'page_restrictions' );
495 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
496 'pr_expiry', 'pr_cascade' ) );
497 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
499 $res = $this->select( __METHOD__
);
500 foreach ( $res as $row ) {
501 /** @var $title Title */
502 $title = $this->titles
[$row->pr_page
];
504 'type' => $row->pr_type
,
505 'level' => $row->pr_level
,
506 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
508 if ( $row->pr_cascade
) {
511 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
513 // Also check old restrictions
514 foreach ( $this->titles
as $pageId => $title ) {
515 if ( $this->pageRestrictions
[$pageId] ) {
516 $namespace = $title->getNamespace();
517 $dbKey = $title->getDBkey();
518 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
519 foreach ( $restrictions as $restrict ) {
520 $temp = explode( '=', trim( $restrict ) );
521 if ( count( $temp ) == 1 ) {
522 // old old format should be treated as edit/move restriction
523 $restriction = trim( $temp[0] );
525 if ( $restriction == '' ) {
528 $this->protections
[$namespace][$dbKey][] = array(
530 'level' => $restriction,
531 'expiry' => 'infinity',
533 $this->protections
[$namespace][$dbKey][] = array(
535 'level' => $restriction,
536 'expiry' => 'infinity',
539 $restriction = trim( $temp[1] );
540 if ( $restriction == '' ) {
543 $this->protections
[$namespace][$dbKey][] = array(
545 'level' => $restriction,
546 'expiry' => 'infinity',
554 // Get protections for missing titles
555 if ( count( $this->missing
) ) {
556 $this->resetQueryParams();
557 $lb = new LinkBatch( $this->missing
);
558 $this->addTables( 'protected_titles' );
559 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
560 $this->addWhere( $lb->constructSet( 'pt', $db ) );
561 $res = $this->select( __METHOD__
);
562 foreach ( $res as $row ) {
563 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
565 'level' => $row->pt_create_perm
,
566 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
571 // Cascading protections
572 $images = $others = array();
573 foreach ( $this->everything
as $title ) {
574 if ( $title->getNamespace() == NS_FILE
) {
575 $images[] = $title->getDBkey();
581 if ( count( $others ) ) {
582 // Non-images: check templatelinks
583 $lb = new LinkBatch( $others );
584 $this->resetQueryParams();
585 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
586 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
587 'page_title', 'page_namespace',
588 'tl_title', 'tl_namespace' ) );
589 $this->addWhere( $lb->constructSet( 'tl', $db ) );
590 $this->addWhere( 'pr_page = page_id' );
591 $this->addWhere( 'pr_page = tl_from' );
592 $this->addWhereFld( 'pr_cascade', 1 );
594 $res = $this->select( __METHOD__
);
595 foreach ( $res as $row ) {
596 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
597 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
598 'type' => $row->pr_type
,
599 'level' => $row->pr_level
,
600 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
601 'source' => $source->getPrefixedText()
606 if ( count( $images ) ) {
607 // Images: check imagelinks
608 $this->resetQueryParams();
609 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
610 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
611 'page_title', 'page_namespace', 'il_to' ) );
612 $this->addWhere( 'pr_page = page_id' );
613 $this->addWhere( 'pr_page = il_from' );
614 $this->addWhereFld( 'pr_cascade', 1 );
615 $this->addWhereFld( 'il_to', $images );
617 $res = $this->select( __METHOD__
);
618 foreach ( $res as $row ) {
619 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
620 $this->protections
[NS_FILE
][$row->il_to
][] = array(
621 'type' => $row->pr_type
,
622 'level' => $row->pr_level
,
623 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
624 'source' => $source->getPrefixedText()
631 * Get talk page IDs (if requested) and subject page IDs (if requested)
632 * and put them in $talkids and $subjectids
634 private function getTSIDs() {
635 $getTitles = $this->talkids
= $this->subjectids
= array();
638 foreach ( $this->everything
as $t ) {
639 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
640 if ( $this->fld_subjectid
) {
641 $getTitles[] = $t->getSubjectPage();
643 } elseif ( $this->fld_talkid
) {
644 $getTitles[] = $t->getTalkPage();
647 if ( !count( $getTitles ) ) {
651 $db = $this->getDB();
653 // Construct a custom WHERE clause that matches
654 // all titles in $getTitles
655 $lb = new LinkBatch( $getTitles );
656 $this->resetQueryParams();
657 $this->addTables( 'page' );
658 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
659 $this->addWhere( $lb->constructSet( 'page', $db ) );
660 $res = $this->select( __METHOD__
);
661 foreach ( $res as $row ) {
662 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
663 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
664 intval( $row->page_id
);
666 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
667 intval( $row->page_id
);
672 private function getDisplayTitle() {
673 $this->displaytitles
= array();
675 $pageIds = array_keys( $this->titles
);
677 if ( !count( $pageIds ) ) {
681 $this->resetQueryParams();
682 $this->addTables( 'page_props' );
683 $this->addFields( array( 'pp_page', 'pp_value' ) );
684 $this->addWhereFld( 'pp_page', $pageIds );
685 $this->addWhereFld( 'pp_propname', 'displaytitle' );
686 $res = $this->select( __METHOD__
);
688 foreach ( $res as $row ) {
689 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
694 * Get information about watched status and put it in $this->watched
695 * and $this->notificationtimestamps
697 private function getWatchedInfo() {
698 $user = $this->getUser();
700 if ( $user->isAnon() ||
count( $this->everything
) == 0
701 ||
!$user->isAllowed( 'viewmywatchlist' )
706 $this->watched
= array();
707 $this->notificationtimestamps
= array();
708 $db = $this->getDB();
710 $lb = new LinkBatch( $this->everything
);
712 $this->resetQueryParams();
713 $this->addTables( array( 'watchlist' ) );
714 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
715 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
716 $this->addWhere( array(
717 $lb->constructSet( 'wl', $db ),
718 'wl_user' => $user->getID()
721 $res = $this->select( __METHOD__
);
723 foreach ( $res as $row ) {
724 if ( $this->fld_watched
) {
725 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
727 if ( $this->fld_notificationtimestamp
) {
728 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] =
729 $row->wl_notificationtimestamp
;
735 * Get the count of watchers and put it in $this->watchers
737 private function getWatcherInfo() {
738 if ( count( $this->everything
) == 0 ) {
742 $user = $this->getUser();
743 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
744 $unwatchedPageThreshold = $this->getConfig()->get( 'UnwatchedPageThreshold' );
745 if ( !$canUnwatchedpages && !is_int( $unwatchedPageThreshold ) ) {
749 $this->watchers
= array();
750 $this->showZeroWatchers
= $canUnwatchedpages;
751 $db = $this->getDB();
753 $lb = new LinkBatch( $this->everything
);
755 $this->resetQueryParams();
756 $this->addTables( array( 'watchlist' ) );
757 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
758 $this->addWhere( array(
759 $lb->constructSet( 'wl', $db )
761 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
762 if ( !$canUnwatchedpages ) {
763 $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" );
766 $res = $this->select( __METHOD__
);
768 foreach ( $res as $row ) {
769 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
773 public function getCacheMode( $params ) {
774 $publicProps = array(
782 if ( !is_null( $params['prop'] ) ) {
783 foreach ( $params['prop'] as $prop ) {
784 if ( !in_array( $prop, $publicProps ) ) {
789 if ( !is_null( $params['token'] ) ) {
796 public function getAllowedParams() {
799 ApiBase
::PARAM_DFLT
=> null,
800 ApiBase
::PARAM_ISMULTI
=> true,
801 ApiBase
::PARAM_TYPE
=> array(
805 'watchers', # private
806 'notificationtimestamp', # private
809 'readable', # private
812 // If you add more properties here, please consider whether they
813 // need to be added to getCacheMode()
815 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> array(),
818 ApiBase
::PARAM_DEPRECATED
=> true,
819 ApiBase
::PARAM_DFLT
=> null,
820 ApiBase
::PARAM_ISMULTI
=> true,
821 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
824 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
829 protected function getExamplesMessages() {
831 'action=query&prop=info&titles=Main%20Page'
832 => 'apihelp-query+info-example-simple',
833 'action=query&prop=info&inprop=protection&titles=Main%20Page'
834 => 'apihelp-query+info-example-protection',
838 public function getHelpUrls() {
839 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';