Merge "Double the size of the target input field of Special:Contributions"
[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 $titleExists = $pageid > 0; //$title->exists() needs pageid, which is not set for all title objects
341 $ns = $title->getNamespace();
342 $dbkey = $title->getDBkey();
343 if ( $titleExists ) {
344 global $wgDisableCounters;
345
346 $pageInfo['touched'] = wfTimestamp( TS_ISO_8601, $this->pageTouched[$pageid] );
347 $pageInfo['lastrevid'] = intval( $this->pageLatest[$pageid] );
348 $pageInfo['counter'] = $wgDisableCounters
349 ? ""
350 : intval( $this->pageCounter[$pageid] );
351 $pageInfo['length'] = intval( $this->pageLength[$pageid] );
352
353 if ( $this->pageIsRedir[$pageid] ) {
354 $pageInfo['redirect'] = '';
355 }
356 if ( $this->pageIsNew[$pageid] ) {
357 $pageInfo['new'] = '';
358 }
359 }
360
361 if ( !is_null( $this->params['token'] ) ) {
362 $tokenFunctions = $this->getTokenFunctions();
363 $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601, time() );
364 foreach ( $this->params['token'] as $t ) {
365 $val = call_user_func( $tokenFunctions[$t], $pageid, $title );
366 if ( $val === false ) {
367 $this->setWarning( "Action '$t' is not allowed for the current user" );
368 } else {
369 $pageInfo[$t . 'token'] = $val;
370 }
371 }
372 }
373
374 if ( $this->fld_protection ) {
375 $pageInfo['protection'] = array();
376 if ( isset( $this->protections[$ns][$dbkey] ) ) {
377 $pageInfo['protection'] =
378 $this->protections[$ns][$dbkey];
379 }
380 $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
381 }
382
383 if ( $this->fld_watched && isset( $this->watched[$ns][$dbkey] ) ) {
384 $pageInfo['watched'] = '';
385 }
386
387 if ( $this->fld_talkid && isset( $this->talkids[$ns][$dbkey] ) ) {
388 $pageInfo['talkid'] = $this->talkids[$ns][$dbkey];
389 }
390
391 if ( $this->fld_subjectid && isset( $this->subjectids[$ns][$dbkey] ) ) {
392 $pageInfo['subjectid'] = $this->subjectids[$ns][$dbkey];
393 }
394
395 if ( $this->fld_url ) {
396 $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
397 $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT );
398 }
399 if ( $this->fld_readable && $title->userCan( 'read' ) ) {
400 $pageInfo['readable'] = '';
401 }
402
403 if ( $this->fld_preload ) {
404 if ( $titleExists ) {
405 $pageInfo['preload'] = '';
406 } else {
407 $text = null;
408 wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
409
410 $pageInfo['preload'] = $text;
411 }
412 }
413
414 if ( $this->fld_displaytitle ) {
415 if ( isset( $this->displaytitles[$pageid] ) ) {
416 $pageInfo['displaytitle'] = $this->displaytitles[$pageid];
417 } else {
418 $pageInfo['displaytitle'] = $title->getPrefixedText();
419 }
420 }
421
422 return $pageInfo;
423 }
424
425 /**
426 * Get information about protections and put it in $protections
427 */
428 private function getProtectionInfo() {
429 global $wgContLang;
430 $this->protections = array();
431 $db = $this->getDB();
432
433 // Get normal protections for existing titles
434 if ( count( $this->titles ) ) {
435 $this->resetQueryParams();
436 $this->addTables( array( 'page_restrictions', 'page' ) );
437 $this->addWhere( 'page_id=pr_page' );
438 $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
439 'pr_expiry', 'pr_cascade', 'page_namespace',
440 'page_title' ) );
441 $this->addWhereFld( 'pr_page', array_keys( $this->titles ) );
442
443 $res = $this->select( __METHOD__ );
444 foreach ( $res as $row ) {
445 $a = array(
446 'type' => $row->pr_type,
447 'level' => $row->pr_level,
448 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 )
449 );
450 if ( $row->pr_cascade ) {
451 $a['cascade'] = '';
452 }
453 $this->protections[$row->page_namespace][$row->page_title][] = $a;
454
455 // Also check old restrictions
456 if ( $this->pageRestrictions[$row->pr_page] ) {
457 $restrictions = explode( ':', trim( $this->pageRestrictions[$row->pr_page] ) );
458 foreach ( $restrictions as $restrict ) {
459 $temp = explode( '=', trim( $restrict ) );
460 if ( count( $temp ) == 1 ) {
461 // old old format should be treated as edit/move restriction
462 $restriction = trim( $temp[0] );
463
464 if ( $restriction == '' ) {
465 continue;
466 }
467 $this->protections[$row->page_namespace][$row->page_title][] = array(
468 'type' => 'edit',
469 'level' => $restriction,
470 'expiry' => 'infinity',
471 );
472 $this->protections[$row->page_namespace][$row->page_title][] = array(
473 'type' => 'move',
474 'level' => $restriction,
475 'expiry' => 'infinity',
476 );
477 } else {
478 $restriction = trim( $temp[1] );
479 if ( $restriction == '' ) {
480 continue;
481 }
482 $this->protections[$row->page_namespace][$row->page_title][] = array(
483 'type' => $temp[0],
484 'level' => $restriction,
485 'expiry' => 'infinity',
486 );
487 }
488 }
489 }
490 }
491 }
492
493 // Get protections for missing titles
494 if ( count( $this->missing ) ) {
495 $this->resetQueryParams();
496 $lb = new LinkBatch( $this->missing );
497 $this->addTables( 'protected_titles' );
498 $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
499 $this->addWhere( $lb->constructSet( 'pt', $db ) );
500 $res = $this->select( __METHOD__ );
501 foreach ( $res as $row ) {
502 $this->protections[$row->pt_namespace][$row->pt_title][] = array(
503 'type' => 'create',
504 'level' => $row->pt_create_perm,
505 'expiry' => $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 )
506 );
507 }
508 }
509
510 // Cascading protections
511 $images = $others = array();
512 foreach ( $this->everything as $title ) {
513 if ( $title->getNamespace() == NS_FILE ) {
514 $images[] = $title->getDBkey();
515 } else {
516 $others[] = $title;
517 }
518 }
519
520 if ( count( $others ) ) {
521 // Non-images: check templatelinks
522 $lb = new LinkBatch( $others );
523 $this->resetQueryParams();
524 $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
525 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
526 'page_title', 'page_namespace',
527 'tl_title', 'tl_namespace' ) );
528 $this->addWhere( $lb->constructSet( 'tl', $db ) );
529 $this->addWhere( 'pr_page = page_id' );
530 $this->addWhere( 'pr_page = tl_from' );
531 $this->addWhereFld( 'pr_cascade', 1 );
532
533 $res = $this->select( __METHOD__ );
534 foreach ( $res as $row ) {
535 $source = Title::makeTitle( $row->page_namespace, $row->page_title );
536 $this->protections[$row->tl_namespace][$row->tl_title][] = array(
537 'type' => $row->pr_type,
538 'level' => $row->pr_level,
539 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
540 'source' => $source->getPrefixedText()
541 );
542 }
543 }
544
545 if ( count( $images ) ) {
546 // Images: check imagelinks
547 $this->resetQueryParams();
548 $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
549 $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
550 'page_title', 'page_namespace', 'il_to' ) );
551 $this->addWhere( 'pr_page = page_id' );
552 $this->addWhere( 'pr_page = il_from' );
553 $this->addWhereFld( 'pr_cascade', 1 );
554 $this->addWhereFld( 'il_to', $images );
555
556 $res = $this->select( __METHOD__ );
557 foreach ( $res as $row ) {
558 $source = Title::makeTitle( $row->page_namespace, $row->page_title );
559 $this->protections[NS_FILE][$row->il_to][] = array(
560 'type' => $row->pr_type,
561 'level' => $row->pr_level,
562 'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 ),
563 'source' => $source->getPrefixedText()
564 );
565 }
566 }
567 }
568
569 /**
570 * Get talk page IDs (if requested) and subject page IDs (if requested)
571 * and put them in $talkids and $subjectids
572 */
573 private function getTSIDs() {
574 $getTitles = $this->talkids = $this->subjectids = array();
575
576 foreach ( $this->everything as $t ) {
577 if ( MWNamespace::isTalk( $t->getNamespace() ) ) {
578 if ( $this->fld_subjectid ) {
579 $getTitles[] = $t->getSubjectPage();
580 }
581 } elseif ( $this->fld_talkid ) {
582 $getTitles[] = $t->getTalkPage();
583 }
584 }
585 if ( !count( $getTitles ) ) {
586 return;
587 }
588
589 $db = $this->getDB();
590
591 // Construct a custom WHERE clause that matches
592 // all titles in $getTitles
593 $lb = new LinkBatch( $getTitles );
594 $this->resetQueryParams();
595 $this->addTables( 'page' );
596 $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
597 $this->addWhere( $lb->constructSet( 'page', $db ) );
598 $res = $this->select( __METHOD__ );
599 foreach ( $res as $row ) {
600 if ( MWNamespace::isTalk( $row->page_namespace ) ) {
601 $this->talkids[MWNamespace::getSubject( $row->page_namespace )][$row->page_title] =
602 intval( $row->page_id );
603 } else {
604 $this->subjectids[MWNamespace::getTalk( $row->page_namespace )][$row->page_title] =
605 intval( $row->page_id );
606 }
607 }
608 }
609
610 private function getDisplayTitle() {
611 $this->displaytitles = array();
612
613 $pageIds = array_keys( $this->titles );
614
615 if ( !count( $pageIds ) ) {
616 return;
617 }
618
619 $this->resetQueryParams();
620 $this->addTables( 'page_props' );
621 $this->addFields( array( 'pp_page', 'pp_value' ) );
622 $this->addWhereFld( 'pp_page', $pageIds );
623 $this->addWhereFld( 'pp_propname', 'displaytitle' );
624 $res = $this->select( __METHOD__ );
625
626 foreach ( $res as $row ) {
627 $this->displaytitles[$row->pp_page] = $row->pp_value;
628 }
629 }
630
631 /**
632 * Get information about watched status and put it in $this->watched
633 */
634 private function getWatchedInfo() {
635 $user = $this->getUser();
636
637 if ( $user->isAnon() || count( $this->everything ) == 0 ) {
638 return;
639 }
640
641 $this->watched = array();
642 $db = $this->getDB();
643
644 $lb = new LinkBatch( $this->everything );
645
646 $this->resetQueryParams();
647 $this->addTables( array( 'watchlist' ) );
648 $this->addFields( array( 'wl_title', 'wl_namespace' ) );
649 $this->addWhere( array(
650 $lb->constructSet( 'wl', $db ),
651 'wl_user' => $user->getID()
652 ) );
653
654 $res = $this->select( __METHOD__ );
655
656 foreach ( $res as $row ) {
657 $this->watched[$row->wl_namespace][$row->wl_title] = true;
658 }
659 }
660
661 public function getCacheMode( $params ) {
662 $publicProps = array(
663 'protection',
664 'talkid',
665 'subjectid',
666 'url',
667 'preload',
668 'displaytitle',
669 );
670 if ( !is_null( $params['prop'] ) ) {
671 foreach ( $params['prop'] as $prop ) {
672 if ( !in_array( $prop, $publicProps ) ) {
673 return 'private';
674 }
675 }
676 }
677 if ( !is_null( $params['token'] ) ) {
678 return 'private';
679 }
680 return 'public';
681 }
682
683 public function getAllowedParams() {
684 return array(
685 'prop' => array(
686 ApiBase::PARAM_DFLT => null,
687 ApiBase::PARAM_ISMULTI => true,
688 ApiBase::PARAM_TYPE => array(
689 'protection',
690 'talkid',
691 'watched', # private
692 'subjectid',
693 'url',
694 'readable', # private
695 'preload',
696 'displaytitle',
697 // If you add more properties here, please consider whether they
698 // need to be added to getCacheMode()
699 ) ),
700 'token' => array(
701 ApiBase::PARAM_DFLT => null,
702 ApiBase::PARAM_ISMULTI => true,
703 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() )
704 ),
705 'continue' => null,
706 );
707 }
708
709 public function getParamDescription() {
710 return array(
711 'prop' => array(
712 'Which additional properties to get:',
713 ' protection - List the protection level of each page',
714 ' talkid - The page ID of the talk page for each non-talk page',
715 ' watched - List the watched status of each page',
716 ' subjectid - The page ID of the parent page for each talk page',
717 ' url - Gives a full URL to the page, and also an edit URL',
718 ' readable - Whether the user can read this page',
719 ' preload - Gives the text returned by EditFormPreloadText',
720 ' displaytitle - Gives the way the page title is actually displayed',
721 ),
722 'token' => 'Request a token to perform a data-modifying action on a page',
723 'continue' => 'When more results are available, use this to continue',
724 );
725 }
726
727 public function getResultProperties() {
728 $props = array(
729 ApiBase::PROP_LIST => false,
730 '' => array(
731 'touched' => 'timestamp',
732 'lastrevid' => 'integer',
733 'counter' => array(
734 ApiBase::PROP_TYPE => 'integer',
735 ApiBase::PROP_NULLABLE => true
736 ),
737 'length' => 'integer',
738 'redirect' => 'boolean',
739 'new' => 'boolean',
740 'starttimestamp' => array(
741 ApiBase::PROP_TYPE => 'timestamp',
742 ApiBase::PROP_NULLABLE => true
743 )
744 ),
745 'watched' => array(
746 'watched' => 'boolean'
747 ),
748 'talkid' => array(
749 'talkid' => array(
750 ApiBase::PROP_TYPE => 'integer',
751 ApiBase::PROP_NULLABLE => true
752 )
753 ),
754 'subjectid' => array(
755 'subjectid' => array(
756 ApiBase::PROP_TYPE => 'integer',
757 ApiBase::PROP_NULLABLE => true
758 )
759 ),
760 'url' => array(
761 'fullurl' => 'string',
762 'editurl' => 'string'
763 ),
764 'readable' => array(
765 'readable' => 'boolean'
766 ),
767 'preload' => array(
768 'preload' => 'string'
769 ),
770 'displaytitle' => array(
771 'displaytitle' => 'string'
772 )
773 );
774
775 self::addTokenProperties( $props, $this->getTokenFunctions() );
776
777 return $props;
778 }
779
780 public function getDescription() {
781 return 'Get basic page information such as namespace, title, last touched date, ...';
782 }
783
784 public function getPossibleErrors() {
785 return array_merge( parent::getPossibleErrors(), array(
786 array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
787 ) );
788 }
789
790 public function getExamples() {
791 return array(
792 'api.php?action=query&prop=info&titles=Main%20Page',
793 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
794 );
795 }
796
797 public function getHelpUrls() {
798 return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';
799 }
800
801 public function getVersion() {
802 return __CLASS__ . ': $Id$';
803 }
804 }