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 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' );
423 $pageInfo['restrictiontypes'] = array();
424 if ( isset( $this->restrictionTypes
[$ns][$dbkey] ) ) {
425 $pageInfo['restrictiontypes'] =
426 $this->restrictionTypes
[$ns][$dbkey];
428 $this->getResult()->setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
431 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
432 $pageInfo['watched'] = '';
435 if ( $this->fld_watchers
) {
436 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
437 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
438 } elseif ( $this->showZeroWatchers
) {
439 $pageInfo['watchers'] = 0;
443 if ( $this->fld_notificationtimestamp
) {
444 $pageInfo['notificationtimestamp'] = '';
445 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
446 $pageInfo['notificationtimestamp'] =
447 wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
451 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
452 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
455 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
456 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
459 if ( $this->fld_url
) {
460 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
461 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
462 $pageInfo['canonicalurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CANONICAL
);
464 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
465 $pageInfo['readable'] = '';
468 if ( $this->fld_preload
) {
469 if ( $titleExists ) {
470 $pageInfo['preload'] = '';
473 Hooks
::run( 'EditFormPreloadText', array( &$text, &$title ) );
475 $pageInfo['preload'] = $text;
479 if ( $this->fld_displaytitle
) {
480 if ( isset( $this->displaytitles
[$pageid] ) ) {
481 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
483 $pageInfo['displaytitle'] = $title->getPrefixedText();
491 * Get information about protections and put it in $protections
493 private function getProtectionInfo() {
495 $this->protections
= array();
496 $db = $this->getDB();
498 // Get normal protections for existing titles
499 if ( count( $this->titles
) ) {
500 $this->resetQueryParams();
501 $this->addTables( 'page_restrictions' );
502 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
503 'pr_expiry', 'pr_cascade' ) );
504 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
506 $res = $this->select( __METHOD__
);
507 foreach ( $res as $row ) {
508 /** @var $title Title */
509 $title = $this->titles
[$row->pr_page
];
511 'type' => $row->pr_type
,
512 'level' => $row->pr_level
,
513 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
515 if ( $row->pr_cascade
) {
518 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
520 // Also check old restrictions
521 foreach ( $this->titles
as $pageId => $title ) {
522 if ( $this->pageRestrictions
[$pageId] ) {
523 $namespace = $title->getNamespace();
524 $dbKey = $title->getDBkey();
525 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
526 foreach ( $restrictions as $restrict ) {
527 $temp = explode( '=', trim( $restrict ) );
528 if ( count( $temp ) == 1 ) {
529 // old old format should be treated as edit/move restriction
530 $restriction = trim( $temp[0] );
532 if ( $restriction == '' ) {
535 $this->protections
[$namespace][$dbKey][] = array(
537 'level' => $restriction,
538 'expiry' => 'infinity',
540 $this->protections
[$namespace][$dbKey][] = array(
542 'level' => $restriction,
543 'expiry' => 'infinity',
546 $restriction = trim( $temp[1] );
547 if ( $restriction == '' ) {
550 $this->protections
[$namespace][$dbKey][] = array(
552 'level' => $restriction,
553 'expiry' => 'infinity',
561 // Get protections for missing titles
562 if ( count( $this->missing
) ) {
563 $this->resetQueryParams();
564 $lb = new LinkBatch( $this->missing
);
565 $this->addTables( 'protected_titles' );
566 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
567 $this->addWhere( $lb->constructSet( 'pt', $db ) );
568 $res = $this->select( __METHOD__
);
569 foreach ( $res as $row ) {
570 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
572 'level' => $row->pt_create_perm
,
573 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
578 // Separate good and missing titles into files and other pages
579 // and populate $this->restrictionTypes
580 $images = $others = array();
581 foreach ( $this->everything
as $title ) {
582 if ( $title->getNamespace() == NS_FILE
) {
583 $images[] = $title->getDBkey();
587 // Applicable protection types
588 $this->restrictionTypes
[$title->getNamespace()][$title->getDBkey()] =
589 array_values( $title->getRestrictionTypes() );
592 if ( count( $others ) ) {
593 // Non-images: check templatelinks
594 $lb = new LinkBatch( $others );
595 $this->resetQueryParams();
596 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
597 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
598 'page_title', 'page_namespace',
599 'tl_title', 'tl_namespace' ) );
600 $this->addWhere( $lb->constructSet( 'tl', $db ) );
601 $this->addWhere( 'pr_page = page_id' );
602 $this->addWhere( 'pr_page = tl_from' );
603 $this->addWhereFld( 'pr_cascade', 1 );
605 $res = $this->select( __METHOD__
);
606 foreach ( $res as $row ) {
607 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
608 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
609 'type' => $row->pr_type
,
610 'level' => $row->pr_level
,
611 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
612 'source' => $source->getPrefixedText()
617 if ( count( $images ) ) {
618 // Images: check imagelinks
619 $this->resetQueryParams();
620 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
621 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
622 'page_title', 'page_namespace', 'il_to' ) );
623 $this->addWhere( 'pr_page = page_id' );
624 $this->addWhere( 'pr_page = il_from' );
625 $this->addWhereFld( 'pr_cascade', 1 );
626 $this->addWhereFld( 'il_to', $images );
628 $res = $this->select( __METHOD__
);
629 foreach ( $res as $row ) {
630 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
631 $this->protections
[NS_FILE
][$row->il_to
][] = array(
632 'type' => $row->pr_type
,
633 'level' => $row->pr_level
,
634 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
635 'source' => $source->getPrefixedText()
642 * Get talk page IDs (if requested) and subject page IDs (if requested)
643 * and put them in $talkids and $subjectids
645 private function getTSIDs() {
646 $getTitles = $this->talkids
= $this->subjectids
= array();
649 foreach ( $this->everything
as $t ) {
650 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
651 if ( $this->fld_subjectid
) {
652 $getTitles[] = $t->getSubjectPage();
654 } elseif ( $this->fld_talkid
) {
655 $getTitles[] = $t->getTalkPage();
658 if ( !count( $getTitles ) ) {
662 $db = $this->getDB();
664 // Construct a custom WHERE clause that matches
665 // all titles in $getTitles
666 $lb = new LinkBatch( $getTitles );
667 $this->resetQueryParams();
668 $this->addTables( 'page' );
669 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
670 $this->addWhere( $lb->constructSet( 'page', $db ) );
671 $res = $this->select( __METHOD__
);
672 foreach ( $res as $row ) {
673 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
674 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
675 intval( $row->page_id
);
677 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
678 intval( $row->page_id
);
683 private function getDisplayTitle() {
684 $this->displaytitles
= array();
686 $pageIds = array_keys( $this->titles
);
688 if ( !count( $pageIds ) ) {
692 $this->resetQueryParams();
693 $this->addTables( 'page_props' );
694 $this->addFields( array( 'pp_page', 'pp_value' ) );
695 $this->addWhereFld( 'pp_page', $pageIds );
696 $this->addWhereFld( 'pp_propname', 'displaytitle' );
697 $res = $this->select( __METHOD__
);
699 foreach ( $res as $row ) {
700 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
705 * Get information about watched status and put it in $this->watched
706 * and $this->notificationtimestamps
708 private function getWatchedInfo() {
709 $user = $this->getUser();
711 if ( $user->isAnon() ||
count( $this->everything
) == 0
712 ||
!$user->isAllowed( 'viewmywatchlist' )
717 $this->watched
= array();
718 $this->notificationtimestamps
= array();
719 $db = $this->getDB();
721 $lb = new LinkBatch( $this->everything
);
723 $this->resetQueryParams();
724 $this->addTables( array( 'watchlist' ) );
725 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
726 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
727 $this->addWhere( array(
728 $lb->constructSet( 'wl', $db ),
729 'wl_user' => $user->getID()
732 $res = $this->select( __METHOD__
);
734 foreach ( $res as $row ) {
735 if ( $this->fld_watched
) {
736 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
738 if ( $this->fld_notificationtimestamp
) {
739 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] =
740 $row->wl_notificationtimestamp
;
746 * Get the count of watchers and put it in $this->watchers
748 private function getWatcherInfo() {
749 if ( count( $this->everything
) == 0 ) {
753 $user = $this->getUser();
754 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
755 $unwatchedPageThreshold = $this->getConfig()->get( 'UnwatchedPageThreshold' );
756 if ( !$canUnwatchedpages && !is_int( $unwatchedPageThreshold ) ) {
760 $this->watchers
= array();
761 $this->showZeroWatchers
= $canUnwatchedpages;
762 $db = $this->getDB();
764 $lb = new LinkBatch( $this->everything
);
766 $this->resetQueryParams();
767 $this->addTables( array( 'watchlist' ) );
768 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
769 $this->addWhere( array(
770 $lb->constructSet( 'wl', $db )
772 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
773 if ( !$canUnwatchedpages ) {
774 $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" );
777 $res = $this->select( __METHOD__
);
779 foreach ( $res as $row ) {
780 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
784 public function getCacheMode( $params ) {
785 $publicProps = array(
793 if ( !is_null( $params['prop'] ) ) {
794 foreach ( $params['prop'] as $prop ) {
795 if ( !in_array( $prop, $publicProps ) ) {
800 if ( !is_null( $params['token'] ) ) {
807 public function getAllowedParams() {
810 ApiBase
::PARAM_DFLT
=> null,
811 ApiBase
::PARAM_ISMULTI
=> true,
812 ApiBase
::PARAM_TYPE
=> array(
816 'watchers', # private
817 'notificationtimestamp', # private
820 'readable', # private
823 // If you add more properties here, please consider whether they
824 // need to be added to getCacheMode()
826 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> array(),
829 ApiBase
::PARAM_DEPRECATED
=> true,
830 ApiBase
::PARAM_DFLT
=> null,
831 ApiBase
::PARAM_ISMULTI
=> true,
832 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
835 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
840 protected function getExamplesMessages() {
842 'action=query&prop=info&titles=Main%20Page'
843 => 'apihelp-query+info-example-simple',
844 'action=query&prop=info&inprop=protection&titles=Main%20Page'
845 => 'apihelp-query+info-example-protection',
849 public function getHelpUrls() {
850 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';