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