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 // when resolving redirects, no page will have this field
62 if ( !$pageSet->isResolvingRedirects() ) {
63 $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' );
76 * Get an array mapping token names to their handler functions.
77 * The prototype for a token function is func($pageid, $title)
78 * it should return a token or false (permission denied)
79 * @deprecated since 1.24
80 * @return array Array(tokenname => function)
82 protected function getTokenFunctions() {
83 // Don't call the hooks twice
84 if ( isset( $this->tokenFunctions
) ) {
85 return $this->tokenFunctions
;
88 // If we're in JSON callback mode, no tokens can be obtained
89 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
93 $this->tokenFunctions
= array(
94 'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
95 'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
96 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
97 'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
98 'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
99 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
100 'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
101 'import' => array( 'ApiQueryInfo', 'getImportToken' ),
102 'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
104 wfRunHooks( 'APIQueryInfoTokens', array( &$this->tokenFunctions
) );
106 return $this->tokenFunctions
;
109 static protected $cachedTokens = array();
112 * @deprecated since 1.24
114 public static function resetTokenCache() {
115 ApiQueryInfo
::$cachedTokens = array();
119 * @deprecated since 1.24
121 public static function getEditToken( $pageid, $title ) {
122 // We could check for $title->userCan('edit') here,
123 // but that's too expensive for this purpose
124 // and would break caching
126 if ( !$wgUser->isAllowed( 'edit' ) ) {
130 // The token is always the same, let's exploit that
131 if ( !isset( ApiQueryInfo
::$cachedTokens['edit'] ) ) {
132 ApiQueryInfo
::$cachedTokens['edit'] = $wgUser->getEditToken();
135 return ApiQueryInfo
::$cachedTokens['edit'];
139 * @deprecated since 1.24
141 public static function getDeleteToken( $pageid, $title ) {
143 if ( !$wgUser->isAllowed( 'delete' ) ) {
147 // The token is always the same, let's exploit that
148 if ( !isset( ApiQueryInfo
::$cachedTokens['delete'] ) ) {
149 ApiQueryInfo
::$cachedTokens['delete'] = $wgUser->getEditToken();
152 return ApiQueryInfo
::$cachedTokens['delete'];
156 * @deprecated since 1.24
158 public static function getProtectToken( $pageid, $title ) {
160 if ( !$wgUser->isAllowed( 'protect' ) ) {
164 // The token is always the same, let's exploit that
165 if ( !isset( ApiQueryInfo
::$cachedTokens['protect'] ) ) {
166 ApiQueryInfo
::$cachedTokens['protect'] = $wgUser->getEditToken();
169 return ApiQueryInfo
::$cachedTokens['protect'];
173 * @deprecated since 1.24
175 public static function getMoveToken( $pageid, $title ) {
177 if ( !$wgUser->isAllowed( 'move' ) ) {
181 // The token is always the same, let's exploit that
182 if ( !isset( ApiQueryInfo
::$cachedTokens['move'] ) ) {
183 ApiQueryInfo
::$cachedTokens['move'] = $wgUser->getEditToken();
186 return ApiQueryInfo
::$cachedTokens['move'];
190 * @deprecated since 1.24
192 public static function getBlockToken( $pageid, $title ) {
194 if ( !$wgUser->isAllowed( 'block' ) ) {
198 // The token is always the same, let's exploit that
199 if ( !isset( ApiQueryInfo
::$cachedTokens['block'] ) ) {
200 ApiQueryInfo
::$cachedTokens['block'] = $wgUser->getEditToken();
203 return ApiQueryInfo
::$cachedTokens['block'];
207 * @deprecated since 1.24
209 public static function getUnblockToken( $pageid, $title ) {
210 // Currently, this is exactly the same as the block token
211 return self
::getBlockToken( $pageid, $title );
215 * @deprecated since 1.24
217 public static function getEmailToken( $pageid, $title ) {
219 if ( !$wgUser->canSendEmail() ||
$wgUser->isBlockedFromEmailUser() ) {
223 // The token is always the same, let's exploit that
224 if ( !isset( ApiQueryInfo
::$cachedTokens['email'] ) ) {
225 ApiQueryInfo
::$cachedTokens['email'] = $wgUser->getEditToken();
228 return ApiQueryInfo
::$cachedTokens['email'];
232 * @deprecated since 1.24
234 public static function getImportToken( $pageid, $title ) {
236 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
240 // The token is always the same, let's exploit that
241 if ( !isset( ApiQueryInfo
::$cachedTokens['import'] ) ) {
242 ApiQueryInfo
::$cachedTokens['import'] = $wgUser->getEditToken();
245 return ApiQueryInfo
::$cachedTokens['import'];
249 * @deprecated since 1.24
251 public static function getWatchToken( $pageid, $title ) {
253 if ( !$wgUser->isLoggedIn() ) {
257 // The token is always the same, let's exploit that
258 if ( !isset( ApiQueryInfo
::$cachedTokens['watch'] ) ) {
259 ApiQueryInfo
::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
262 return ApiQueryInfo
::$cachedTokens['watch'];
266 * @deprecated since 1.24
268 public static function getOptionsToken( $pageid, $title ) {
270 if ( !$wgUser->isLoggedIn() ) {
274 // The token is always the same, let's exploit that
275 if ( !isset( ApiQueryInfo
::$cachedTokens['options'] ) ) {
276 ApiQueryInfo
::$cachedTokens['options'] = $wgUser->getEditToken();
279 return ApiQueryInfo
::$cachedTokens['options'];
282 public function execute() {
283 $this->params
= $this->extractRequestParams();
284 if ( !is_null( $this->params
['prop'] ) ) {
285 $prop = array_flip( $this->params
['prop'] );
286 $this->fld_protection
= isset( $prop['protection'] );
287 $this->fld_watched
= isset( $prop['watched'] );
288 $this->fld_watchers
= isset( $prop['watchers'] );
289 $this->fld_notificationtimestamp
= isset( $prop['notificationtimestamp'] );
290 $this->fld_talkid
= isset( $prop['talkid'] );
291 $this->fld_subjectid
= isset( $prop['subjectid'] );
292 $this->fld_url
= isset( $prop['url'] );
293 $this->fld_readable
= isset( $prop['readable'] );
294 $this->fld_preload
= isset( $prop['preload'] );
295 $this->fld_displaytitle
= isset( $prop['displaytitle'] );
298 $pageSet = $this->getPageSet();
299 $this->titles
= $pageSet->getGoodTitles();
300 $this->missing
= $pageSet->getMissingTitles();
301 $this->everything
= $this->titles +
$this->missing
;
302 $result = $this->getResult();
304 uasort( $this->everything
, array( 'Title', 'compare' ) );
305 if ( !is_null( $this->params
['continue'] ) ) {
306 // Throw away any titles we're gonna skip so they don't
308 $cont = explode( '|', $this->params
['continue'] );
309 $this->dieContinueUsageIf( count( $cont ) != 2 );
310 $conttitle = Title
::makeTitleSafe( $cont[0], $cont[1] );
311 foreach ( $this->everything
as $pageid => $title ) {
312 if ( Title
::compare( $title, $conttitle ) >= 0 ) {
315 unset( $this->titles
[$pageid] );
316 unset( $this->missing
[$pageid] );
317 unset( $this->everything
[$pageid] );
321 $this->pageRestrictions
= $pageSet->getCustomField( 'page_restrictions' );
322 // when resolving redirects, no page will have this field
323 $this->pageIsRedir
= !$pageSet->isResolvingRedirects()
324 ?
$pageSet->getCustomField( 'page_is_redirect' )
326 $this->pageIsNew
= $pageSet->getCustomField( 'page_is_new' );
328 $this->pageTouched
= $pageSet->getCustomField( 'page_touched' );
329 $this->pageLatest
= $pageSet->getCustomField( 'page_latest' );
330 $this->pageLength
= $pageSet->getCustomField( 'page_len' );
332 // Get protection info if requested
333 if ( $this->fld_protection
) {
334 $this->getProtectionInfo();
337 if ( $this->fld_watched ||
$this->fld_notificationtimestamp
) {
338 $this->getWatchedInfo();
341 if ( $this->fld_watchers
) {
342 $this->getWatcherInfo();
345 // Run the talkid/subjectid query if requested
346 if ( $this->fld_talkid ||
$this->fld_subjectid
) {
350 if ( $this->fld_displaytitle
) {
351 $this->getDisplayTitle();
354 /** @var $title Title */
355 foreach ( $this->everything
as $pageid => $title ) {
356 $pageInfo = $this->extractPageInfo( $pageid, $title );
357 $fit = $result->addValue( array(
360 ), $pageid, $pageInfo );
362 $this->setContinueEnumParameter( 'continue',
363 $title->getNamespace() . '|' .
371 * Get a result array with information about a title
372 * @param int $pageid Page ID (negative for missing titles)
373 * @param Title $title
376 private function extractPageInfo( $pageid, $title ) {
378 // $title->exists() needs pageid, which is not set for all title objects
379 $titleExists = $pageid > 0;
380 $ns = $title->getNamespace();
381 $dbkey = $title->getDBkey();
383 $pageInfo['contentmodel'] = $title->getContentModel();
384 $pageInfo['pagelanguage'] = $title->getPageLanguage()->getCode();
386 if ( $titleExists ) {
387 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601
, $this->pageTouched
[$pageid] );
388 $pageInfo['lastrevid'] = intval( $this->pageLatest
[$pageid] );
389 $pageInfo['length'] = intval( $this->pageLength
[$pageid] );
391 if ( isset( $this->pageIsRedir
[$pageid] ) && $this->pageIsRedir
[$pageid] ) {
392 $pageInfo['redirect'] = '';
394 if ( $this->pageIsNew
[$pageid] ) {
395 $pageInfo['new'] = '';
399 if ( !is_null( $this->params
['token'] ) ) {
400 $tokenFunctions = $this->getTokenFunctions();
401 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601
, time() );
402 foreach ( $this->params
['token'] as $t ) {
403 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
404 if ( $val === false ) {
405 $this->setWarning( "Action '$t' is not allowed for the current user" );
407 $pageInfo[$t . 'token'] = $val;
412 if ( $this->fld_protection
) {
413 $pageInfo['protection'] = array();
414 if ( isset( $this->protections
[$ns][$dbkey] ) ) {
415 $pageInfo['protection'] =
416 $this->protections
[$ns][$dbkey];
418 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
421 if ( $this->fld_watched
&& isset( $this->watched
[$ns][$dbkey] ) ) {
422 $pageInfo['watched'] = '';
425 if ( $this->fld_watchers
) {
426 if ( isset( $this->watchers
[$ns][$dbkey] ) ) {
427 $pageInfo['watchers'] = $this->watchers
[$ns][$dbkey];
428 } elseif ( $this->showZeroWatchers
) {
429 $pageInfo['watchers'] = 0;
433 if ( $this->fld_notificationtimestamp
) {
434 $pageInfo['notificationtimestamp'] = '';
435 if ( isset( $this->notificationtimestamps
[$ns][$dbkey] ) ) {
436 $pageInfo['notificationtimestamp'] =
437 wfTimestamp( TS_ISO_8601
, $this->notificationtimestamps
[$ns][$dbkey] );
441 if ( $this->fld_talkid
&& isset( $this->talkids
[$ns][$dbkey] ) ) {
442 $pageInfo['talkid'] = $this->talkids
[$ns][$dbkey];
445 if ( $this->fld_subjectid
&& isset( $this->subjectids
[$ns][$dbkey] ) ) {
446 $pageInfo['subjectid'] = $this->subjectids
[$ns][$dbkey];
449 if ( $this->fld_url
) {
450 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
451 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT
);
452 $pageInfo['canonicalurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CANONICAL
);
454 if ( $this->fld_readable
&& $title->userCan( 'read', $this->getUser() ) ) {
455 $pageInfo['readable'] = '';
458 if ( $this->fld_preload
) {
459 if ( $titleExists ) {
460 $pageInfo['preload'] = '';
463 wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
465 $pageInfo['preload'] = $text;
469 if ( $this->fld_displaytitle
) {
470 if ( isset( $this->displaytitles
[$pageid] ) ) {
471 $pageInfo['displaytitle'] = $this->displaytitles
[$pageid];
473 $pageInfo['displaytitle'] = $title->getPrefixedText();
481 * Get information about protections and put it in $protections
483 private function getProtectionInfo() {
485 $this->protections
= array();
486 $db = $this->getDB();
488 // Get normal protections for existing titles
489 if ( count( $this->titles
) ) {
490 $this->resetQueryParams();
491 $this->addTables( 'page_restrictions' );
492 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
493 'pr_expiry', 'pr_cascade' ) );
494 $this->addWhereFld( 'pr_page', array_keys( $this->titles
) );
496 $res = $this->select( __METHOD__
);
497 foreach ( $res as $row ) {
498 /** @var $title Title */
499 $title = $this->titles
[$row->pr_page
];
501 'type' => $row->pr_type
,
502 'level' => $row->pr_level
,
503 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
)
505 if ( $row->pr_cascade
) {
508 $this->protections
[$title->getNamespace()][$title->getDBkey()][] = $a;
510 // Also check old restrictions
511 foreach ( $this->titles
as $pageId => $title ) {
512 if ( $this->pageRestrictions
[$pageId] ) {
513 $namespace = $title->getNamespace();
514 $dbKey = $title->getDBkey();
515 $restrictions = explode( ':', trim( $this->pageRestrictions
[$pageId] ) );
516 foreach ( $restrictions as $restrict ) {
517 $temp = explode( '=', trim( $restrict ) );
518 if ( count( $temp ) == 1 ) {
519 // old old format should be treated as edit/move restriction
520 $restriction = trim( $temp[0] );
522 if ( $restriction == '' ) {
525 $this->protections
[$namespace][$dbKey][] = array(
527 'level' => $restriction,
528 'expiry' => 'infinity',
530 $this->protections
[$namespace][$dbKey][] = array(
532 'level' => $restriction,
533 'expiry' => 'infinity',
536 $restriction = trim( $temp[1] );
537 if ( $restriction == '' ) {
540 $this->protections
[$namespace][$dbKey][] = array(
542 'level' => $restriction,
543 'expiry' => 'infinity',
551 // Get protections for missing titles
552 if ( count( $this->missing
) ) {
553 $this->resetQueryParams();
554 $lb = new LinkBatch( $this->missing
);
555 $this->addTables( 'protected_titles' );
556 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
557 $this->addWhere( $lb->constructSet( 'pt', $db ) );
558 $res = $this->select( __METHOD__
);
559 foreach ( $res as $row ) {
560 $this->protections
[$row->pt_namespace
][$row->pt_title
][] = array(
562 'level' => $row->pt_create_perm
,
563 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
)
568 // Cascading protections
569 $images = $others = array();
570 foreach ( $this->everything
as $title ) {
571 if ( $title->getNamespace() == NS_FILE
) {
572 $images[] = $title->getDBkey();
578 if ( count( $others ) ) {
579 // Non-images: check templatelinks
580 $lb = new LinkBatch( $others );
581 $this->resetQueryParams();
582 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
583 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
584 'page_title', 'page_namespace',
585 'tl_title', 'tl_namespace' ) );
586 $this->addWhere( $lb->constructSet( 'tl', $db ) );
587 $this->addWhere( 'pr_page = page_id' );
588 $this->addWhere( 'pr_page = tl_from' );
589 $this->addWhereFld( 'pr_cascade', 1 );
591 $res = $this->select( __METHOD__
);
592 foreach ( $res as $row ) {
593 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
594 $this->protections
[$row->tl_namespace
][$row->tl_title
][] = array(
595 'type' => $row->pr_type
,
596 'level' => $row->pr_level
,
597 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
598 'source' => $source->getPrefixedText()
603 if ( count( $images ) ) {
604 // Images: check imagelinks
605 $this->resetQueryParams();
606 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
607 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
608 'page_title', 'page_namespace', 'il_to' ) );
609 $this->addWhere( 'pr_page = page_id' );
610 $this->addWhere( 'pr_page = il_from' );
611 $this->addWhereFld( 'pr_cascade', 1 );
612 $this->addWhereFld( 'il_to', $images );
614 $res = $this->select( __METHOD__
);
615 foreach ( $res as $row ) {
616 $source = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
617 $this->protections
[NS_FILE
][$row->il_to
][] = array(
618 'type' => $row->pr_type
,
619 'level' => $row->pr_level
,
620 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry
, TS_ISO_8601
),
621 'source' => $source->getPrefixedText()
628 * Get talk page IDs (if requested) and subject page IDs (if requested)
629 * and put them in $talkids and $subjectids
631 private function getTSIDs() {
632 $getTitles = $this->talkids
= $this->subjectids
= array();
635 foreach ( $this->everything
as $t ) {
636 if ( MWNamespace
::isTalk( $t->getNamespace() ) ) {
637 if ( $this->fld_subjectid
) {
638 $getTitles[] = $t->getSubjectPage();
640 } elseif ( $this->fld_talkid
) {
641 $getTitles[] = $t->getTalkPage();
644 if ( !count( $getTitles ) ) {
648 $db = $this->getDB();
650 // Construct a custom WHERE clause that matches
651 // all titles in $getTitles
652 $lb = new LinkBatch( $getTitles );
653 $this->resetQueryParams();
654 $this->addTables( 'page' );
655 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
656 $this->addWhere( $lb->constructSet( 'page', $db ) );
657 $res = $this->select( __METHOD__
);
658 foreach ( $res as $row ) {
659 if ( MWNamespace
::isTalk( $row->page_namespace
) ) {
660 $this->talkids
[MWNamespace
::getSubject( $row->page_namespace
)][$row->page_title
] =
661 intval( $row->page_id
);
663 $this->subjectids
[MWNamespace
::getTalk( $row->page_namespace
)][$row->page_title
] =
664 intval( $row->page_id
);
669 private function getDisplayTitle() {
670 $this->displaytitles
= array();
672 $pageIds = array_keys( $this->titles
);
674 if ( !count( $pageIds ) ) {
678 $this->resetQueryParams();
679 $this->addTables( 'page_props' );
680 $this->addFields( array( 'pp_page', 'pp_value' ) );
681 $this->addWhereFld( 'pp_page', $pageIds );
682 $this->addWhereFld( 'pp_propname', 'displaytitle' );
683 $res = $this->select( __METHOD__
);
685 foreach ( $res as $row ) {
686 $this->displaytitles
[$row->pp_page
] = $row->pp_value
;
691 * Get information about watched status and put it in $this->watched
692 * and $this->notificationtimestamps
694 private function getWatchedInfo() {
695 $user = $this->getUser();
697 if ( $user->isAnon() ||
count( $this->everything
) == 0
698 ||
!$user->isAllowed( 'viewmywatchlist' )
703 $this->watched
= array();
704 $this->notificationtimestamps
= array();
705 $db = $this->getDB();
707 $lb = new LinkBatch( $this->everything
);
709 $this->resetQueryParams();
710 $this->addTables( array( 'watchlist' ) );
711 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
712 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp
);
713 $this->addWhere( array(
714 $lb->constructSet( 'wl', $db ),
715 'wl_user' => $user->getID()
718 $res = $this->select( __METHOD__
);
720 foreach ( $res as $row ) {
721 if ( $this->fld_watched
) {
722 $this->watched
[$row->wl_namespace
][$row->wl_title
] = true;
724 if ( $this->fld_notificationtimestamp
) {
725 $this->notificationtimestamps
[$row->wl_namespace
][$row->wl_title
] =
726 $row->wl_notificationtimestamp
;
732 * Get the count of watchers and put it in $this->watchers
734 private function getWatcherInfo() {
735 if ( count( $this->everything
) == 0 ) {
739 $user = $this->getUser();
740 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
741 $unwatchedPageThreshold = $this->getConfig()->get( 'UnwatchedPageThreshold' );
742 if ( !$canUnwatchedpages && !is_int( $unwatchedPageThreshold ) ) {
746 $this->watchers
= array();
747 $this->showZeroWatchers
= $canUnwatchedpages;
748 $db = $this->getDB();
750 $lb = new LinkBatch( $this->everything
);
752 $this->resetQueryParams();
753 $this->addTables( array( 'watchlist' ) );
754 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
755 $this->addWhere( array(
756 $lb->constructSet( 'wl', $db )
758 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
759 if ( !$canUnwatchedpages ) {
760 $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" );
763 $res = $this->select( __METHOD__
);
765 foreach ( $res as $row ) {
766 $this->watchers
[$row->wl_namespace
][$row->wl_title
] = (int)$row->count
;
770 public function getCacheMode( $params ) {
771 $publicProps = array(
779 if ( !is_null( $params['prop'] ) ) {
780 foreach ( $params['prop'] as $prop ) {
781 if ( !in_array( $prop, $publicProps ) ) {
786 if ( !is_null( $params['token'] ) ) {
793 public function getAllowedParams() {
796 ApiBase
::PARAM_DFLT
=> null,
797 ApiBase
::PARAM_ISMULTI
=> true,
798 ApiBase
::PARAM_TYPE
=> array(
802 'watchers', # private
803 'notificationtimestamp', # private
806 'readable', # private
809 // If you add more properties here, please consider whether they
810 // need to be added to getCacheMode()
813 ApiBase
::PARAM_DEPRECATED
=> true,
814 ApiBase
::PARAM_DFLT
=> null,
815 ApiBase
::PARAM_ISMULTI
=> true,
816 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() )
819 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
824 protected function getExamplesMessages() {
826 'action=query&prop=info&titles=Main%20Page'
827 => 'apihelp-query+info-example-simple',
828 'action=query&prop=info&inprop=protection&titles=Main%20Page'
829 => 'apihelp-query+info-example-protection',
833 public function getHelpUrls() {
834 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';