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