wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / api / ApiQueryInfo.php
blob6f1e2e5bc7aa962f7c3c12b4f934971e70bad06a
1 <?php
2 /**
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
24 * @file
27 /**
28 * A query module to show basic page information.
30 * @ingroup API
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;
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' );
57 /**
58 * @param ApiPageSet $pageSet
59 * @return void
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' );
80 /**
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
94 // be obtained
95 if ( $this->lacksSameOriginSecurity() ) {
96 return array();
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
131 global $wgUser;
132 if ( !$wgUser->isAllowed( 'edit' ) ) {
133 return false;
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 ) {
148 global $wgUser;
149 if ( !$wgUser->isAllowed( 'delete' ) ) {
150 return false;
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 ) {
165 global $wgUser;
166 if ( !$wgUser->isAllowed( 'protect' ) ) {
167 return false;
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 ) {
182 global $wgUser;
183 if ( !$wgUser->isAllowed( 'move' ) ) {
184 return false;
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 ) {
199 global $wgUser;
200 if ( !$wgUser->isAllowed( 'block' ) ) {
201 return false;
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 ) {
224 global $wgUser;
225 if ( !$wgUser->canSendEmail() || $wgUser->isBlockedFromEmailuser() ) {
226 return false;
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 ) {
241 global $wgUser;
242 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
243 return false;
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 ) {
258 global $wgUser;
259 if ( !$wgUser->isLoggedIn() ) {
260 return false;
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 ) {
275 global $wgUser;
276 if ( !$wgUser->isLoggedIn() ) {
277 return false;
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
313 // clutter queries
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 ) {
319 break;
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' )
331 : array();
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 ) {
353 $this->getTSIDs();
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(
364 'query',
365 'pages'
366 ), $pageid, $pageInfo );
367 if ( !$fit ) {
368 $this->setContinueEnumParameter( 'continue',
369 $title->getNamespace() . '|' .
370 $title->getText() );
371 break;
377 * Get a result array with information about a title
378 * @param int $pageid Page ID (negative for missing titles)
379 * @param Title $title
380 * @return array|null
382 private function extractPageInfo( $pageid, $title ) {
383 $pageInfo = array();
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();
391 $pageLanguage = $title->getPageLanguage();
392 $pageInfo['pagelanguage'] = $pageLanguage->getCode();
393 $pageInfo['pagelanguagehtmlcode'] = $pageLanguage->getHtmlCode();
394 $pageInfo['pagelanguagedir'] = $pageLanguage->getDir();
396 if ( $titleExists ) {
397 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601, $this->pageTouched[$pageid] );
398 $pageInfo['lastrevid'] = intval( $this->pageLatest[$pageid] );
399 $pageInfo['length'] = intval( $this->pageLength[$pageid] );
401 if ( isset( $this->pageIsRedir[$pageid] ) && $this->pageIsRedir[$pageid] ) {
402 $pageInfo['redirect'] = true;
404 if ( $this->pageIsNew[$pageid] ) {
405 $pageInfo['new'] = true;
409 if ( !is_null( $this->params['token'] ) ) {
410 $tokenFunctions = $this->getTokenFunctions();
411 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601, time() );
412 foreach ( $this->params['token'] as $t ) {
413 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
414 if ( $val === false ) {
415 $this->setWarning( "Action '$t' is not allowed for the current user" );
416 } else {
417 $pageInfo[$t . 'token'] = $val;
422 if ( $this->fld_protection ) {
423 $pageInfo['protection'] = array();
424 if ( isset( $this->protections[$ns][$dbkey] ) ) {
425 $pageInfo['protection'] =
426 $this->protections[$ns][$dbkey];
428 ApiResult::setIndexedTagName( $pageInfo['protection'], 'pr' );
430 $pageInfo['restrictiontypes'] = array();
431 if ( isset( $this->restrictionTypes[$ns][$dbkey] ) ) {
432 $pageInfo['restrictiontypes'] =
433 $this->restrictionTypes[$ns][$dbkey];
435 ApiResult::setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
438 if ( $this->fld_watched ) {
439 $pageInfo['watched'] = isset( $this->watched[$ns][$dbkey] );
442 if ( $this->fld_watchers ) {
443 if ( isset( $this->watchers[$ns][$dbkey] ) ) {
444 $pageInfo['watchers'] = $this->watchers[$ns][$dbkey];
445 } elseif ( $this->showZeroWatchers ) {
446 $pageInfo['watchers'] = 0;
450 if ( $this->fld_notificationtimestamp ) {
451 $pageInfo['notificationtimestamp'] = '';
452 if ( isset( $this->notificationtimestamps[$ns][$dbkey] ) ) {
453 $pageInfo['notificationtimestamp'] =
454 wfTimestamp( TS_ISO_8601, $this->notificationtimestamps[$ns][$dbkey] );
458 if ( $this->fld_talkid && isset( $this->talkids[$ns][$dbkey] ) ) {
459 $pageInfo['talkid'] = $this->talkids[$ns][$dbkey];
462 if ( $this->fld_subjectid && isset( $this->subjectids[$ns][$dbkey] ) ) {
463 $pageInfo['subjectid'] = $this->subjectids[$ns][$dbkey];
466 if ( $this->fld_url ) {
467 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
468 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT );
469 $pageInfo['canonicalurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CANONICAL );
471 if ( $this->fld_readable ) {
472 $pageInfo['readable'] = $title->userCan( 'read', $this->getUser() );
475 if ( $this->fld_preload ) {
476 if ( $titleExists ) {
477 $pageInfo['preload'] = '';
478 } else {
479 $text = null;
480 Hooks::run( 'EditFormPreloadText', array( &$text, &$title ) );
482 $pageInfo['preload'] = $text;
486 if ( $this->fld_displaytitle ) {
487 if ( isset( $this->displaytitles[$pageid] ) ) {
488 $pageInfo['displaytitle'] = $this->displaytitles[$pageid];
489 } else {
490 $pageInfo['displaytitle'] = $title->getPrefixedText();
494 if ( $this->params['testactions'] ) {
495 $limit = $this->getMain()->canApiHighLimits() ? self::LIMIT_SML1 : self::LIMIT_SML2;
496 if ( $this->countTestedActions >= $limit ) {
497 return null; // force a continuation
500 $user = $this->getUser();
501 $pageInfo['actions'] = array();
502 foreach ( $this->params['testactions'] as $action ) {
503 $this->countTestedActions++;
504 $pageInfo['actions'][$action] = $title->userCan( $action, $user );
508 return $pageInfo;
512 * Get information about protections and put it in $protections
514 private function getProtectionInfo() {
515 global $wgContLang;
516 $this->protections = array();
517 $db = $this->getDB();
519 // Get normal protections for existing titles
520 if ( count( $this->titles ) ) {
521 $this->resetQueryParams();
522 $this->addTables( 'page_restrictions' );
523 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
524 'pr_expiry', 'pr_cascade' ) );
525 $this->addWhereFld( 'pr_page', array_keys( $this->titles ) );
527 $res = $this->select( __METHOD__ );
528 foreach ( $res as $row ) {
529 /** @var $title Title */
530 $title = $this->titles[$row->pr_page];
531 $a = array(
532 'type' => $row->pr_type,
533 'level' => $row->pr_level,
534 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 )
536 if ( $row->pr_cascade ) {
537 $a['cascade'] = true;
539 $this->protections[$title->getNamespace()][$title->getDBkey()][] = $a;
541 // Also check old restrictions
542 foreach ( $this->titles as $pageId => $title ) {
543 if ( $this->pageRestrictions[$pageId] ) {
544 $namespace = $title->getNamespace();
545 $dbKey = $title->getDBkey();
546 $restrictions = explode( ':', trim( $this->pageRestrictions[$pageId] ) );
547 foreach ( $restrictions as $restrict ) {
548 $temp = explode( '=', trim( $restrict ) );
549 if ( count( $temp ) == 1 ) {
550 // old old format should be treated as edit/move restriction
551 $restriction = trim( $temp[0] );
553 if ( $restriction == '' ) {
554 continue;
556 $this->protections[$namespace][$dbKey][] = array(
557 'type' => 'edit',
558 'level' => $restriction,
559 'expiry' => 'infinity',
561 $this->protections[$namespace][$dbKey][] = array(
562 'type' => 'move',
563 'level' => $restriction,
564 'expiry' => 'infinity',
566 } else {
567 $restriction = trim( $temp[1] );
568 if ( $restriction == '' ) {
569 continue;
571 $this->protections[$namespace][$dbKey][] = array(
572 'type' => $temp[0],
573 'level' => $restriction,
574 'expiry' => 'infinity',
582 // Get protections for missing titles
583 if ( count( $this->missing ) ) {
584 $this->resetQueryParams();
585 $lb = new LinkBatch( $this->missing );
586 $this->addTables( 'protected_titles' );
587 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
588 $this->addWhere( $lb->constructSet( 'pt', $db ) );
589 $res = $this->select( __METHOD__ );
590 foreach ( $res as $row ) {
591 $this->protections[$row->pt_namespace][$row->pt_title][] = array(
592 'type' => 'create',
593 'level' => $row->pt_create_perm,
594 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 )
599 // Separate good and missing titles into files and other pages
600 // and populate $this->restrictionTypes
601 $images = $others = array();
602 foreach ( $this->everything as $title ) {
603 if ( $title->getNamespace() == NS_FILE ) {
604 $images[] = $title->getDBkey();
605 } else {
606 $others[] = $title;
608 // Applicable protection types
609 $this->restrictionTypes[$title->getNamespace()][$title->getDBkey()] =
610 array_values( $title->getRestrictionTypes() );
613 if ( count( $others ) ) {
614 // Non-images: check templatelinks
615 $lb = new LinkBatch( $others );
616 $this->resetQueryParams();
617 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
618 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
619 'page_title', 'page_namespace',
620 'tl_title', 'tl_namespace' ) );
621 $this->addWhere( $lb->constructSet( 'tl', $db ) );
622 $this->addWhere( 'pr_page = page_id' );
623 $this->addWhere( 'pr_page = tl_from' );
624 $this->addWhereFld( 'pr_cascade', 1 );
626 $res = $this->select( __METHOD__ );
627 foreach ( $res as $row ) {
628 $source = Title::makeTitle( $row->page_namespace, $row->page_title );
629 $this->protections[$row->tl_namespace][$row->tl_title][] = array(
630 'type' => $row->pr_type,
631 'level' => $row->pr_level,
632 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
633 'source' => $source->getPrefixedText()
638 if ( count( $images ) ) {
639 // Images: check imagelinks
640 $this->resetQueryParams();
641 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
642 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
643 'page_title', 'page_namespace', 'il_to' ) );
644 $this->addWhere( 'pr_page = page_id' );
645 $this->addWhere( 'pr_page = il_from' );
646 $this->addWhereFld( 'pr_cascade', 1 );
647 $this->addWhereFld( 'il_to', $images );
649 $res = $this->select( __METHOD__ );
650 foreach ( $res as $row ) {
651 $source = Title::makeTitle( $row->page_namespace, $row->page_title );
652 $this->protections[NS_FILE][$row->il_to][] = array(
653 'type' => $row->pr_type,
654 'level' => $row->pr_level,
655 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
656 'source' => $source->getPrefixedText()
663 * Get talk page IDs (if requested) and subject page IDs (if requested)
664 * and put them in $talkids and $subjectids
666 private function getTSIDs() {
667 $getTitles = $this->talkids = $this->subjectids = array();
669 /** @var $t Title */
670 foreach ( $this->everything as $t ) {
671 if ( MWNamespace::isTalk( $t->getNamespace() ) ) {
672 if ( $this->fld_subjectid ) {
673 $getTitles[] = $t->getSubjectPage();
675 } elseif ( $this->fld_talkid ) {
676 $getTitles[] = $t->getTalkPage();
679 if ( !count( $getTitles ) ) {
680 return;
683 $db = $this->getDB();
685 // Construct a custom WHERE clause that matches
686 // all titles in $getTitles
687 $lb = new LinkBatch( $getTitles );
688 $this->resetQueryParams();
689 $this->addTables( 'page' );
690 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
691 $this->addWhere( $lb->constructSet( 'page', $db ) );
692 $res = $this->select( __METHOD__ );
693 foreach ( $res as $row ) {
694 if ( MWNamespace::isTalk( $row->page_namespace ) ) {
695 $this->talkids[MWNamespace::getSubject( $row->page_namespace )][$row->page_title] =
696 intval( $row->page_id );
697 } else {
698 $this->subjectids[MWNamespace::getTalk( $row->page_namespace )][$row->page_title] =
699 intval( $row->page_id );
704 private function getDisplayTitle() {
705 $this->displaytitles = array();
707 $pageIds = array_keys( $this->titles );
709 if ( !count( $pageIds ) ) {
710 return;
713 $this->resetQueryParams();
714 $this->addTables( 'page_props' );
715 $this->addFields( array( 'pp_page', 'pp_value' ) );
716 $this->addWhereFld( 'pp_page', $pageIds );
717 $this->addWhereFld( 'pp_propname', 'displaytitle' );
718 $res = $this->select( __METHOD__ );
720 foreach ( $res as $row ) {
721 $this->displaytitles[$row->pp_page] = $row->pp_value;
726 * Get information about watched status and put it in $this->watched
727 * and $this->notificationtimestamps
729 private function getWatchedInfo() {
730 $user = $this->getUser();
732 if ( $user->isAnon() || count( $this->everything ) == 0
733 || !$user->isAllowed( 'viewmywatchlist' )
735 return;
738 $this->watched = array();
739 $this->notificationtimestamps = array();
740 $db = $this->getDB();
742 $lb = new LinkBatch( $this->everything );
744 $this->resetQueryParams();
745 $this->addTables( array( 'watchlist' ) );
746 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
747 $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp );
748 $this->addWhere( array(
749 $lb->constructSet( 'wl', $db ),
750 'wl_user' => $user->getId()
751 ) );
753 $res = $this->select( __METHOD__ );
755 foreach ( $res as $row ) {
756 if ( $this->fld_watched ) {
757 $this->watched[$row->wl_namespace][$row->wl_title] = true;
759 if ( $this->fld_notificationtimestamp ) {
760 $this->notificationtimestamps[$row->wl_namespace][$row->wl_title] =
761 $row->wl_notificationtimestamp;
767 * Get the count of watchers and put it in $this->watchers
769 private function getWatcherInfo() {
770 if ( count( $this->everything ) == 0 ) {
771 return;
774 $user = $this->getUser();
775 $canUnwatchedpages = $user->isAllowed( 'unwatchedpages' );
776 $unwatchedPageThreshold = $this->getConfig()->get( 'UnwatchedPageThreshold' );
777 if ( !$canUnwatchedpages && !is_int( $unwatchedPageThreshold ) ) {
778 return;
781 $this->watchers = array();
782 $this->showZeroWatchers = $canUnwatchedpages;
783 $db = $this->getDB();
785 $lb = new LinkBatch( $this->everything );
787 $this->resetQueryParams();
788 $this->addTables( array( 'watchlist' ) );
789 $this->addFields( array( 'wl_title', 'wl_namespace', 'count' => 'COUNT(*)' ) );
790 $this->addWhere( array(
791 $lb->constructSet( 'wl', $db )
792 ) );
793 $this->addOption( 'GROUP BY', array( 'wl_namespace', 'wl_title' ) );
794 if ( !$canUnwatchedpages ) {
795 $this->addOption( 'HAVING', "COUNT(*) >= $unwatchedPageThreshold" );
798 $res = $this->select( __METHOD__ );
800 foreach ( $res as $row ) {
801 $this->watchers[$row->wl_namespace][$row->wl_title] = (int)$row->count;
805 public function getCacheMode( $params ) {
806 // Other props depend on something about the current user
807 $publicProps = array(
808 'protection',
809 'talkid',
810 'subjectid',
811 'url',
812 'preload',
813 'displaytitle',
815 if ( array_diff( (array)$params['prop'], $publicProps ) ) {
816 return 'private';
819 // testactions also depends on the current user
820 if ( $params['testactions'] ) {
821 return 'private';
824 if ( !is_null( $params['token'] ) ) {
825 return 'private';
828 return 'public';
831 public function getAllowedParams() {
832 return array(
833 'prop' => array(
834 ApiBase::PARAM_ISMULTI => true,
835 ApiBase::PARAM_TYPE => array(
836 'protection',
837 'talkid',
838 'watched', # private
839 'watchers', # private
840 'notificationtimestamp', # private
841 'subjectid',
842 'url',
843 'readable', # private
844 'preload',
845 'displaytitle',
846 // If you add more properties here, please consider whether they
847 // need to be added to getCacheMode()
849 ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
851 'testactions' => array(
852 ApiBase::PARAM_TYPE => 'string',
853 ApiBase::PARAM_ISMULTI => true,
855 'token' => array(
856 ApiBase::PARAM_DEPRECATED => true,
857 ApiBase::PARAM_ISMULTI => true,
858 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() )
860 'continue' => array(
861 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
866 protected function getExamplesMessages() {
867 return array(
868 'action=query&prop=info&titles=Main%20Page'
869 => 'apihelp-query+info-example-simple',
870 'action=query&prop=info&inprop=protection&titles=Main%20Page'
871 => 'apihelp-query+info-example-protection',
875 public function getHelpUrls() {
876 return 'https://www.mediawiki.org/wiki/API:Info';