Merge "(bug 19195) Make user IDs more readily available with the API"
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
1 <?php
2 /**
3 *
4 *
5 * Created on Sep 25, 2006
6 *
7 * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
8 *
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.
13 *
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.
18 *
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
23 *
24 * @file
25 */
26
27 /**
28 * A query module to show basic page information.
29 *
30 * @ingroup API
31 */
32 class ApiQueryInfo extends ApiQueryBase {
33
34 private $fld_protection = false, $fld_talkid = false,
35 $fld_subjectid = false, $fld_url = false,
36 $fld_readable = false, $fld_watched = false,
37 $fld_preload = false, $fld_displaytitle = false;
38
39 private $params, $titles, $missing, $everything, $pageCounter;
40
41 private $pageRestrictions, $pageIsRedir, $pageIsNew, $pageTouched,
42 $pageLatest, $pageLength;
43
44 private $protections, $watched, $talkids, $subjectids, $displaytitles;
45
46 private $tokenFunctions;
47
48 public function __construct( $query, $moduleName ) {
49 parent::__construct( $query, $moduleName, 'in' );
50 }
51
52 /**
53 * @param $pageSet ApiPageSet
54 * @return void
55 */
56 public function requestExtraData( $pageSet ) {
57 global $wgDisableCounters;
58
59 $pageSet->requestField( 'page_restrictions' );
60 $pageSet->requestField( 'page_is_redirect' );
61 $pageSet->requestField( 'page_is_new' );
62 if ( !$wgDisableCounters ) {
63 $pageSet->requestField( 'page_counter' );
64 }
65 $pageSet->requestField( 'page_touched' );
66 $pageSet->requestField( 'page_latest' );
67 $pageSet->requestField( 'page_len' );
68 }
69
70 /**
71 * Get an array mapping token names to their handler functions.
72 * The prototype for a token function is func($pageid, $title)
73 * it should return a token or false (permission denied)
74 * @return array array(tokenname => function)
75 */
76 protected function getTokenFunctions() {
77 // Don't call the hooks twice
78 if ( isset( $this->tokenFunctions ) ) {
79 return $this->tokenFunctions;
80 }
81
82 // If we're in JSON callback mode, no tokens can be obtained
83 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
84 return array();
85 }
86
87 $this->tokenFunctions = array(
88 'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
89 'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
90 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
91 'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
92 'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
93 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
94 'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
95 'import' => array( 'ApiQueryInfo', 'getImportToken' ),
96 'watch' => array( 'ApiQueryInfo', 'getWatchToken'),
97 );
98 wfRunHooks( 'APIQueryInfoTokens', array( &$this->tokenFunctions ) );
99 return $this->tokenFunctions;
100 }
101
102 public static function getEditToken( $pageid, $title ) {
103 // We could check for $title->userCan('edit') here,
104 // but that's too expensive for this purpose
105 // and would break caching
106 global $wgUser;
107 if ( !$wgUser->isAllowed( 'edit' ) ) {
108 return false;
109 }
110
111 // The edit token is always the same, let's exploit that
112 static $cachedEditToken = null;
113 if ( !is_null( $cachedEditToken ) ) {
114 return $cachedEditToken;
115 }
116
117 $cachedEditToken = $wgUser->getEditToken();
118 return $cachedEditToken;
119 }
120
121 public static function getDeleteToken( $pageid, $title ) {
122 global $wgUser;
123 if ( !$wgUser->isAllowed( 'delete' ) ) {
124 return false;
125 }
126
127 static $cachedDeleteToken = null;
128 if ( !is_null( $cachedDeleteToken ) ) {
129 return $cachedDeleteToken;
130 }
131
132 $cachedDeleteToken = $wgUser->getEditToken();
133 return $cachedDeleteToken;
134 }
135
136 public static function getProtectToken( $pageid, $title ) {
137 global $wgUser;
138 if ( !$wgUser->isAllowed( 'protect' ) ) {
139 return false;
140 }
141
142 static $cachedProtectToken = null;
143 if ( !is_null( $cachedProtectToken ) ) {
144 return $cachedProtectToken;
145 }
146
147 $cachedProtectToken = $wgUser->getEditToken();
148 return $cachedProtectToken;
149 }
150
151 public static function getMoveToken( $pageid, $title ) {
152 global $wgUser;
153 if ( !$wgUser->isAllowed( 'move' ) ) {
154 return false;
155 }
156
157 static $cachedMoveToken = null;
158 if ( !is_null( $cachedMoveToken ) ) {
159 return $cachedMoveToken;
160 }
161
162 $cachedMoveToken = $wgUser->getEditToken();
163 return $cachedMoveToken;
164 }
165
166 public static function getBlockToken( $pageid, $title ) {
167 global $wgUser;
168 if ( !$wgUser->isAllowed( 'block' ) ) {
169 return false;
170 }
171
172 static $cachedBlockToken = null;
173 if ( !is_null( $cachedBlockToken ) ) {
174 return $cachedBlockToken;
175 }
176
177 $cachedBlockToken = $wgUser->getEditToken();
178 return $cachedBlockToken;
179 }
180
181 public static function getUnblockToken( $pageid, $title ) {
182 // Currently, this is exactly the same as the block token
183 return self::getBlockToken( $pageid, $title );
184 }
185
186 public static function getEmailToken( $pageid, $title ) {
187 global $wgUser;
188 if ( !$wgUser->canSendEmail() || $wgUser->isBlockedFromEmailUser() ) {
189 return false;
190 }
191
192 static $cachedEmailToken = null;
193 if ( !is_null( $cachedEmailToken ) ) {
194 return $cachedEmailToken;
195 }
196
197 $cachedEmailToken = $wgUser->getEditToken();
198 return $cachedEmailToken;
199 }
200
201 public static function getImportToken( $pageid, $title ) {
202 global $wgUser;
203 if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
204 return false;
205 }
206
207 static $cachedImportToken = null;
208 if ( !is_null( $cachedImportToken ) ) {
209 return $cachedImportToken;
210 }
211
212 $cachedImportToken = $wgUser->getEditToken();
213 return $cachedImportToken;
214 }
215
216 public static function getWatchToken( $pageid, $title ) {
217 global $wgUser;
218 if ( !$wgUser->isLoggedIn() ) {
219 return false;
220 }
221
222 static $cachedWatchToken = null;
223 if ( !is_null( $cachedWatchToken ) ) {
224 return $cachedWatchToken;
225 }
226
227 $cachedWatchToken = $wgUser->getEditToken( 'watch' );
228 return $cachedWatchToken;
229 }
230
231 public static function getOptionsToken( $pageid, $title ) {
232 global $wgUser;
233 if ( !$wgUser->isLoggedIn() ) {
234 return false;
235 }
236
237 static $cachedOptionsToken = null;
238 if ( !is_null( $cachedOptionsToken ) ) {
239 return $cachedOptionsToken;
240 }
241
242 $cachedOptionsToken = $wgUser->getEditToken();
243 return $cachedOptionsToken;
244 }
245
246 public function execute() {
247 $this->params = $this->extractRequestParams();
248 if ( !is_null( $this->params['prop'] ) ) {
249 $prop = array_flip( $this->params['prop'] );
250 $this->fld_protection = isset( $prop['protection'] );
251 $this->fld_watched = isset( $prop['watched'] );
252 $this->fld_talkid = isset( $prop['talkid'] );
253 $this->fld_subjectid = isset( $prop['subjectid'] );
254 $this->fld_url = isset( $prop['url'] );
255 $this->fld_readable = isset( $prop['readable'] );
256 $this->fld_preload = isset( $prop['preload'] );
257 $this->fld_displaytitle = isset( $prop['displaytitle'] );
258 }
259
260 $pageSet = $this->getPageSet();
261 $this->titles = $pageSet->getGoodTitles();
262 $this->missing = $pageSet->getMissingTitles();
263 $this->everything = $this->titles + $this->missing;
264 $result = $this->getResult();
265
266 uasort( $this->everything, array( 'Title', 'compare' ) );
267 if ( !is_null( $this->params['continue'] ) ) {
268 // Throw away any titles we're gonna skip so they don't
269 // clutter queries
270 $cont = explode( '|', $this->params['continue'] );
271 if ( count( $cont ) != 2 ) {
272 $this->dieUsage( 'Invalid continue param. You should pass the original ' .
273 'value returned by the previous query', '_badcontinue' );
274 }
275 $conttitle = Title::makeTitleSafe( $cont[0], $cont[1] );
276 foreach ( $this->everything as $pageid => $title ) {
277 if ( Title::compare( $title, $conttitle ) >= 0 ) {
278 break;
279 }
280 unset( $this->titles[$pageid] );
281 unset( $this->missing[$pageid] );
282 unset( $this->everything[$pageid] );
283 }
284 }
285
286 $this->pageRestrictions = $pageSet->getCustomField( 'page_restrictions' );
287 $this->pageIsRedir = $pageSet->getCustomField( 'page_is_redirect' );
288 $this->pageIsNew = $pageSet->getCustomField( 'page_is_new' );
289
290 global $wgDisableCounters;
291
292 if ( !$wgDisableCounters ) {
293 $this->pageCounter = $pageSet->getCustomField( 'page_counter' );
294 }
295 $this->pageTouched = $pageSet->getCustomField( 'page_touched' );
296 $this->pageLatest = $pageSet->getCustomField( 'page_latest' );
297 $this->pageLength = $pageSet->getCustomField( 'page_len' );
298
299 // Get protection info if requested
300 if ( $this->fld_protection ) {
301 $this->getProtectionInfo();
302 }
303
304 if ( $this->fld_watched ) {
305 $this->getWatchedInfo();
306 }
307
308 // Run the talkid/subjectid query if requested
309 if ( $this->fld_talkid || $this->fld_subjectid ) {
310 $this->getTSIDs();
311 }
312
313 if ( $this->fld_displaytitle ) {
314 $this->getDisplayTitle();
315 }
316
317 foreach ( $this->everything as $pageid => $title ) {
318 $pageInfo = $this->extractPageInfo( $pageid, $title );
319 $fit = $result->addValue( array(
320 'query',
321 'pages'
322 ), $pageid, $pageInfo );
323 if ( !$fit ) {
324 $this->setContinueEnumParameter( 'continue',
325 $title->getNamespace() . '|' .
326 $title->getText() );
327 break;
328 }
329 }
330 }
331
332 /**
333 * Get a result array with information about a title
334 * @param $pageid int Page ID (negative for missing titles)
335 * @param $title Title object
336 * @return array
337 */
338 private function extractPageInfo( $pageid, $title ) {
339 $pageInfo = array();
340 if ( $title->exists() ) {
341 global $wgDisableCounters;
342
343 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601, $this->pageTouched[$pageid] );
344 $pageInfo['lastrevid'] = intval( $this->pageLatest[$pageid] );
345 $pageInfo['counter'] = $wgDisableCounters
346 ? ""
347 : intval( $this->pageCounter[$pageid] );
348 $pageInfo['length'] = intval( $this->pageLength[$pageid] );
349
350 if ( $this->pageIsRedir[$pageid] ) {
351 $pageInfo['redirect'] = '';
352 }
353 if ( $this->pageIsNew[$pageid] ) {
354 $pageInfo['new'] = '';
355 }
356 }
357
358 if ( !is_null( $this->params['token'] ) ) {
359 $tokenFunctions = $this->getTokenFunctions();
360 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601, time() );
361 foreach ( $this->params['token'] as $t ) {
362 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
363 if ( $val === false ) {
364 $this->setWarning( "Action '$t' is not allowed for the current user" );
365 } else {
366 $pageInfo[$t . 'token'] = $val;
367 }
368 }
369 }
370
371 if ( $this->fld_protection ) {
372 $pageInfo['protection'] = array();
373 if ( isset( $this->protections[$title->getNamespace()][$title->getDBkey()] ) ) {
374 $pageInfo['protection'] =
375 $this->protections[$title->getNamespace()][$title->getDBkey()];
376 }
377 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
378 }
379
380 if ( $this->fld_watched && isset( $this->watched[$title->getNamespace()][$title->getDBkey()] ) ) {
381 $pageInfo['watched'] = '';
382 }
383
384 if ( $this->fld_talkid && isset( $this->talkids[$title->getNamespace()][$title->getDBkey()] ) ) {
385 $pageInfo['talkid'] = $this->talkids[$title->getNamespace()][$title->getDBkey()];
386 }
387
388 if ( $this->fld_subjectid && isset( $this->subjectids[$title->getNamespace()][$title->getDBkey()] ) ) {
389 $pageInfo['subjectid'] = $this->subjectids[$title->getNamespace()][$title->getDBkey()];
390 }
391
392 if ( $this->fld_url ) {
393 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
394 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT );
395 }
396 if ( $this->fld_readable && $title->userCan( 'read' ) ) {
397 $pageInfo['readable'] = '';
398 }
399
400 if ( $this->fld_preload ) {
401 if ( $title->exists() ) {
402 $pageInfo['preload'] = '';
403 } else {
404 $text = null;
405 wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
406
407 $pageInfo['preload'] = $text;
408 }
409 }
410
411 if ( $this->fld_displaytitle ) {
412 if ( isset( $this->displaytitles[$title->getArticleID()] ) ) {
413 $pageInfo['displaytitle'] = $this->displaytitles[$title->getArticleID()];
414 } else {
415 $pageInfo['displaytitle'] = $title->getPrefixedText();
416 }
417 }
418
419 return $pageInfo;
420 }
421
422 /**
423 * Get information about protections and put it in $protections
424 */
425 private function getProtectionInfo() {
426 global $wgContLang;
427 $this->protections = array();
428 $db = $this->getDB();
429
430 // Get normal protections for existing titles
431 if ( count( $this->titles ) ) {
432 $this->resetQueryParams();
433 $this->addTables( array( 'page_restrictions', 'page' ) );
434 $this->addWhere( 'page_id=pr_page' );
435 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
436 'pr_expiry', 'pr_cascade', 'page_namespace',
437 'page_title' ) );
438 $this->addWhereFld( 'pr_page', array_keys( $this->titles ) );
439
440 $res = $this->select( __METHOD__ );
441 foreach ( $res as $row ) {
442 $a = array(
443 'type' => $row->pr_type,
444 'level' => $row->pr_level,
445 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 )
446 );
447 if ( $row->pr_cascade ) {
448 $a['cascade'] = '';
449 }
450 $this->protections[$row->page_namespace][$row->page_title][] = $a;
451
452 // Also check old restrictions
453 if ( $this->pageRestrictions[$row->pr_page] ) {
454 $restrictions = explode( ':', trim( $this->pageRestrictions[$row->pr_page] ) );
455 foreach ( $restrictions as $restrict ) {
456 $temp = explode( '=', trim( $restrict ) );
457 if ( count( $temp ) == 1 ) {
458 // old old format should be treated as edit/move restriction
459 $restriction = trim( $temp[0] );
460
461 if ( $restriction == '' ) {
462 continue;
463 }
464 $this->protections[$row->page_namespace][$row->page_title][] = array(
465 'type' => 'edit',
466 'level' => $restriction,
467 'expiry' => 'infinity',
468 );
469 $this->protections[$row->page_namespace][$row->page_title][] = array(
470 'type' => 'move',
471 'level' => $restriction,
472 'expiry' => 'infinity',
473 );
474 } else {
475 $restriction = trim( $temp[1] );
476 if ( $restriction == '' ) {
477 continue;
478 }
479 $this->protections[$row->page_namespace][$row->page_title][] = array(
480 'type' => $temp[0],
481 'level' => $restriction,
482 'expiry' => 'infinity',
483 );
484 }
485 }
486 }
487 }
488 }
489
490 // Get protections for missing titles
491 if ( count( $this->missing ) ) {
492 $this->resetQueryParams();
493 $lb = new LinkBatch( $this->missing );
494 $this->addTables( 'protected_titles' );
495 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
496 $this->addWhere( $lb->constructSet( 'pt', $db ) );
497 $res = $this->select( __METHOD__ );
498 foreach ( $res as $row ) {
499 $this->protections[$row->pt_namespace][$row->pt_title][] = array(
500 'type' => 'create',
501 'level' => $row->pt_create_perm,
502 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 )
503 );
504 }
505 }
506
507 // Cascading protections
508 $images = $others = array();
509 foreach ( $this->everything as $title ) {
510 if ( $title->getNamespace() == NS_FILE ) {
511 $images[] = $title->getDBkey();
512 } else {
513 $others[] = $title;
514 }
515 }
516
517 if ( count( $others ) ) {
518 // Non-images: check templatelinks
519 $lb = new LinkBatch( $others );
520 $this->resetQueryParams();
521 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
522 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
523 'page_title', 'page_namespace',
524 'tl_title', 'tl_namespace' ) );
525 $this->addWhere( $lb->constructSet( 'tl', $db ) );
526 $this->addWhere( 'pr_page = page_id' );
527 $this->addWhere( 'pr_page = tl_from' );
528 $this->addWhereFld( 'pr_cascade', 1 );
529
530 $res = $this->select( __METHOD__ );
531 foreach ( $res as $row ) {
532 $source = Title::makeTitle( $row->page_namespace, $row->page_title );
533 $this->protections[$row->tl_namespace][$row->tl_title][] = array(
534 'type' => $row->pr_type,
535 'level' => $row->pr_level,
536 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
537 'source' => $source->getPrefixedText()
538 );
539 }
540 }
541
542 if ( count( $images ) ) {
543 // Images: check imagelinks
544 $this->resetQueryParams();
545 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
546 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
547 'page_title', 'page_namespace', 'il_to' ) );
548 $this->addWhere( 'pr_page = page_id' );
549 $this->addWhere( 'pr_page = il_from' );
550 $this->addWhereFld( 'pr_cascade', 1 );
551 $this->addWhereFld( 'il_to', $images );
552
553 $res = $this->select( __METHOD__ );
554 foreach ( $res as $row ) {
555 $source = Title::makeTitle( $row->page_namespace, $row->page_title );
556 $this->protections[NS_FILE][$row->il_to][] = array(
557 'type' => $row->pr_type,
558 'level' => $row->pr_level,
559 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
560 'source' => $source->getPrefixedText()
561 );
562 }
563 }
564 }
565
566 /**
567 * Get talk page IDs (if requested) and subject page IDs (if requested)
568 * and put them in $talkids and $subjectids
569 */
570 private function getTSIDs() {
571 $getTitles = $this->talkids = $this->subjectids = array();
572
573 foreach ( $this->everything as $t ) {
574 if ( MWNamespace::isTalk( $t->getNamespace() ) ) {
575 if ( $this->fld_subjectid ) {
576 $getTitles[] = $t->getSubjectPage();
577 }
578 } elseif ( $this->fld_talkid ) {
579 $getTitles[] = $t->getTalkPage();
580 }
581 }
582 if ( !count( $getTitles ) ) {
583 return;
584 }
585
586 $db = $this->getDB();
587
588 // Construct a custom WHERE clause that matches
589 // all titles in $getTitles
590 $lb = new LinkBatch( $getTitles );
591 $this->resetQueryParams();
592 $this->addTables( 'page' );
593 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
594 $this->addWhere( $lb->constructSet( 'page', $db ) );
595 $res = $this->select( __METHOD__ );
596 foreach ( $res as $row ) {
597 if ( MWNamespace::isTalk( $row->page_namespace ) ) {
598 $this->talkids[MWNamespace::getSubject( $row->page_namespace )][$row->page_title] =
599 intval( $row->page_id );
600 } else {
601 $this->subjectids[MWNamespace::getTalk( $row->page_namespace )][$row->page_title] =
602 intval( $row->page_id );
603 }
604 }
605 }
606
607 private function getDisplayTitle() {
608 $this->displaytitles = array();
609
610 $pageIds = array_keys( $this->titles );
611
612 if ( !count( $pageIds ) ) {
613 return;
614 }
615
616 $this->resetQueryParams();
617 $this->addTables( 'page_props' );
618 $this->addFields( array( 'pp_page', 'pp_value' ) );
619 $this->addWhereFld( 'pp_page', $pageIds );
620 $this->addWhereFld( 'pp_propname', 'displaytitle' );
621 $res = $this->select( __METHOD__ );
622
623 foreach ( $res as $row ) {
624 $this->displaytitles[$row->pp_page] = $row->pp_value;
625 }
626 }
627
628 /**
629 * Get information about watched status and put it in $this->watched
630 */
631 private function getWatchedInfo() {
632 $user = $this->getUser();
633
634 if ( $user->isAnon() || count( $this->everything ) == 0 ) {
635 return;
636 }
637
638 $this->watched = array();
639 $db = $this->getDB();
640
641 $lb = new LinkBatch( $this->everything );
642
643 $this->resetQueryParams();
644 $this->addTables( array( 'watchlist' ) );
645 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
646 $this->addWhere( array(
647 $lb->constructSet( 'wl', $db ),
648 'wl_user' => $user->getID()
649 ) );
650
651 $res = $this->select( __METHOD__ );
652
653 foreach ( $res as $row ) {
654 $this->watched[$row->wl_namespace][$row->wl_title] = true;
655 }
656 }
657
658 public function getCacheMode( $params ) {
659 $publicProps = array(
660 'protection',
661 'talkid',
662 'subjectid',
663 'url',
664 'preload',
665 'displaytitle',
666 );
667 if ( !is_null( $params['prop'] ) ) {
668 foreach ( $params['prop'] as $prop ) {
669 if ( !in_array( $prop, $publicProps ) ) {
670 return 'private';
671 }
672 }
673 }
674 if ( !is_null( $params['token'] ) ) {
675 return 'private';
676 }
677 return 'public';
678 }
679
680 public function getAllowedParams() {
681 return array(
682 'prop' => array(
683 ApiBase::PARAM_DFLT => null,
684 ApiBase::PARAM_ISMULTI => true,
685 ApiBase::PARAM_TYPE => array(
686 'protection',
687 'talkid',
688 'watched', # private
689 'subjectid',
690 'url',
691 'readable', # private
692 'preload',
693 'displaytitle',
694 // If you add more properties here, please consider whether they
695 // need to be added to getCacheMode()
696 ) ),
697 'token' => array(
698 ApiBase::PARAM_DFLT => null,
699 ApiBase::PARAM_ISMULTI => true,
700 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() )
701 ),
702 'continue' => null,
703 );
704 }
705
706 public function getParamDescription() {
707 return array(
708 'prop' => array(
709 'Which additional properties to get:',
710 ' protection - List the protection level of each page',
711 ' talkid - The page ID of the talk page for each non-talk page',
712 ' watched - List the watched status of each page',
713 ' subjectid - The page ID of the parent page for each talk page',
714 ' url - Gives a full URL to the page, and also an edit URL',
715 ' readable - Whether the user can read this page',
716 ' preload - Gives the text returned by EditFormPreloadText',
717 ' displaytitle - Gives the way the page title is actually displayed',
718 ),
719 'token' => 'Request a token to perform a data-modifying action on a page',
720 'continue' => 'When more results are available, use this to continue',
721 );
722 }
723
724 public function getDescription() {
725 return 'Get basic page information such as namespace, title, last touched date, ...';
726 }
727
728 public function getPossibleErrors() {
729 return array_merge( parent::getPossibleErrors(), array(
730 array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
731 ) );
732 }
733
734 public function getExamples() {
735 return array(
736 'api.php?action=query&prop=info&titles=Main%20Page',
737 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
738 );
739 }
740
741 public function getHelpUrls() {
742 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';
743 }
744
745 public function getVersion() {
746 return __CLASS__ . ': $Id$';
747 }
748 }