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'] = true;
400 if ( $this->pageIsNew
[$pageid] ) {
401 $pageInfo['new'] = true;
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 ApiResult
::setIndexedTagName( $pageInfo['protection'], 'pr' );
426 $pageInfo['restrictiontypes'] = array();
427 if ( isset( $this->restrictionTypes
[$ns][$dbkey] ) ) {
428 $pageInfo['restrictiontypes'] =
429 $this->restrictionTypes
[$ns][$dbkey];
431 ApiResult
::setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
434 if ( $this->fld_watched
) {
435 $pageInfo['watched'] = isset( $this->watched
[$ns][$dbkey] );
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
) {
468 $pageInfo['readable'] = $title->userCan( 'read', $this->getUser() );
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 $pageInfo['actions'][$action] = $title->userCan( $action, $user );
508 * Get information about protections and put it in $protections
510 private function getProtectionInfo() {
512 $this->protections
= array();
513 $db = $this->getDB();
515 // Get normal protections for existing titles
516 if ( count( $this->titles
) ) {
517 $this->resetQueryParams();
518 $this->addTables( 'page_restrictions' );
519 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
520 'pr_expiry', 'pr_cascade' ) );
521 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
523 $res = $this->select( __METHOD__
);
524 foreach ( $res as $row ) {
525 /** @var $title Title */
526 $title = $this->titles
[$row->pr_page
];
528 'type' => $row->pr_type
,
529 'level' => $row->pr_level
,
530 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
532 if ( $row->pr_cascade
) {
533 $a['cascade'] = true;
535 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
537 // Also check old restrictions
538 foreach ( $this->titles
as $pageId => $title ) {
539 if ( $this->pageRestrictions
[$pageId] ) {
540 $namespace = $title->getNamespace();
541 $dbKey = $title->getDBkey();
542 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
543 foreach ( $restrictions as $restrict ) {
544 $temp = explode( '=', trim( $restrict ) );
545 if ( count( $temp ) == 1 ) {
546 // old old format should be treated as edit/move restriction
547 $restriction = trim( $temp[0] );
549 if ( $restriction == '' ) {
552 $this->protections
[$namespace][$dbKey][] = array(
554 'level' => $restriction,
555 'expiry' => 'infinity',
557 $this->protections
[$namespace][$dbKey][] = array(
559 'level' => $restriction,
560 'expiry' => 'infinity',
563 $restriction = trim( $temp[1] );
564 if ( $restriction == '' ) {
567 $this->protections
[$namespace][$dbKey][] = array(
569 'level' => $restriction,
570 'expiry' => 'infinity',
578 // Get protections for missing titles
579 if ( count( $this->missing
) ) {
580 $this->resetQueryParams();
581 $lb = new LinkBatch( $this->missing
);
582 $this->addTables( 'protected_titles' );
583 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
584 $this->addWhere( $lb->constructSet( 'pt', $db ) );
585 $res = $this->select( __METHOD__
);
586 foreach ( $res as $row ) {
587 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
589 'level' => $row->pt_create_perm
,
590 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
595 // Separate good and missing titles into files and other pages
596 // and populate $this->restrictionTypes
597 $images = $others = array();
598 foreach ( $this->everything
as $title ) {
599 if ( $title->getNamespace() == NS_FILE
) {
600 $images[] = $title->getDBkey();
604 // Applicable protection types
605 $this->restrictionTypes
[$title->getNamespace()][$title->getDBkey()] =
606 array_values( $title->getRestrictionTypes() );
609 if ( count( $others ) ) {
610 // Non-images: check templatelinks
611 $lb = new LinkBatch( $others );
612 $this->resetQueryParams();
613 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
614 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
615 'page_title', 'page_namespace',
616 'tl_title', 'tl_namespace' ) );
617 $this->addWhere( $lb->constructSet( 'tl', $db ) );
618 $this->addWhere( 'pr_page = page_id' );
619 $this->addWhere( 'pr_page = tl_from' );
620 $this->addWhereFld( 'pr_cascade', 1 );
622 $res = $this->select( __METHOD__
);
623 foreach ( $res as $row ) {
624 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
625 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
626 'type' => $row->pr_type
,
627 'level' => $row->pr_level
,
628 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
629 'source' => $source->getPrefixedText()
634 if ( count( $images ) ) {
635 // Images: check imagelinks
636 $this->resetQueryParams();
637 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
638 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
639 'page_title', 'page_namespace', 'il_to' ) );
640 $this->addWhere( 'pr_page = page_id' );
641 $this->addWhere( 'pr_page = il_from' );
642 $this->addWhereFld( 'pr_cascade', 1 );
643 $this->addWhereFld( 'il_to', $images );
645 $res = $this->select( __METHOD__
);
646 foreach ( $res as $row ) {
647 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
648 $this->protections
[NS_FILE
][$row->il_to
][] = array(
649 'type' => $row->pr_type
,
650 'level' => $row->pr_level
,
651 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
652 'source' => $source->getPrefixedText()
659 * Get talk page IDs (if requested) and subject page IDs (if requested)
660 * and put them in $talkids and $subjectids
662 private function getTSIDs() {
663 $getTitles = $this->talkids
= $this->subjectids
= array();
666 foreach ( $this->everything
as $t ) {
667 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
668 if ( $this->fld_subjectid
) {
669 $getTitles[] = $t->getSubjectPage();
671 } elseif ( $this->fld_talkid
) {
672 $getTitles[] = $t->getTalkPage();
675 if ( !count( $getTitles ) ) {
679 $db = $this->getDB();
681 // Construct a custom WHERE clause that matches
682 // all titles in $getTitles
683 $lb = new LinkBatch( $getTitles );
684 $this->resetQueryParams();
685 $this->addTables( 'page' );
686 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
687 $this->addWhere( $lb->constructSet( 'page', $db ) );
688 $res = $this->select( __METHOD__
);
689 foreach ( $res as $row ) {
690 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
691 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
692 intval( $row->page_id
);
694 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
695 intval( $row->page_id
);
700 private function getDisplayTitle() {
701 $this->displaytitles
= array();
703 $pageIds = array_keys( $this->titles
);
705 if ( !count( $pageIds ) ) {
709 $this->resetQueryParams();
710 $this->addTables( 'page_props' );
711 $this->addFields( array( 'pp_page', 'pp_value' ) );
712 $this->addWhereFld( 'pp_page', $pageIds );
713 $this->addWhereFld( 'pp_propname', 'displaytitle' );
714 $res = $this->select( __METHOD__
);
716 foreach ( $res as $row ) {
717 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
722 * Get information about watched status and put it in $this->watched
723 * and $this->notificationtimestamps
725 private function getWatchedInfo() {
726 $user = $this->getUser();
728 if ( $user->isAnon() ||
count( $this->everything
) == 0
729 ||
!$user->isAllowed( 'viewmywatchlist' )
734 $this->watched
= array();
735 $this->notificationtimestamps
= array();
736 $db = $this->getDB();
738 $lb = new LinkBatch( $this->everything
);
740 $this->resetQueryParams();
741 $this->addTables( array( 'watchlist' ) );
742 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
743 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
744 $this->addWhere( array(
745 $lb->constructSet( 'wl', $db ),
746 'wl_user' => $user->getID()
749 $res = $this->select( __METHOD__
);
751 foreach ( $res as $row ) {
752 if ( $this->fld_watched
) {
753 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
755 if ( $this->fld_notificationtimestamp
) {
756 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] =
757 $row->wl_notificationtimestamp
;
763 * Get the count of watchers and put it in $this->watchers
765 private function getWatcherInfo() {
766 if ( count( $this->everything
) == 0 ) {
770 $user = $this->getUser();
771 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
772 $unwatchedPageThreshold = $this->getConfig()->get( 'UnwatchedPageThreshold' );
773 if ( !$canUnwatchedpages && !is_int( $unwatchedPageThreshold ) ) {
777 $this->watchers
= array();
778 $this->showZeroWatchers
= $canUnwatchedpages;
779 $db = $this->getDB();
781 $lb = new LinkBatch( $this->everything
);
783 $this->resetQueryParams();
784 $this->addTables( array( 'watchlist' ) );
785 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
786 $this->addWhere( array(
787 $lb->constructSet( 'wl', $db )
789 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
790 if ( !$canUnwatchedpages ) {
791 $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" );
794 $res = $this->select( __METHOD__
);
796 foreach ( $res as $row ) {
797 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
801 public function getCacheMode( $params ) {
802 $publicProps = array(
810 if ( !is_null( $params['prop'] ) ) {
811 foreach ( $params['prop'] as $prop ) {
812 if ( !in_array( $prop, $publicProps ) ) {
817 if ( !is_null( $params['token'] ) ) {
824 public function getAllowedParams() {
827 ApiBase
::PARAM_DFLT
=> null,
828 ApiBase
::PARAM_ISMULTI
=> true,
829 ApiBase
::PARAM_TYPE
=> array(
833 'watchers', # private
834 'notificationtimestamp', # private
837 'readable', # private
840 // If you add more properties here, please consider whether they
841 // need to be added to getCacheMode()
843 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> array(),
845 'testactions' => array(
846 ApiBase
::PARAM_TYPE
=> 'string',
847 ApiBase
::PARAM_ISMULTI
=> true,
850 ApiBase
::PARAM_DEPRECATED
=> true,
851 ApiBase
::PARAM_DFLT
=> null,
852 ApiBase
::PARAM_ISMULTI
=> true,
853 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
856 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
861 protected function getExamplesMessages() {
863 'action=query&prop=info&titles=Main%20Page'
864 => 'apihelp-query+info-example-simple',
865 'action=query&prop=info&inprop=protection&titles=Main%20Page'
866 => 'apihelp-query+info-example-protection',
870 public function getHelpUrls() {
871 return 'https://www.mediawiki.org/wiki/API:Info';