]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/api/ApiQueryRevisions.php
MediaWiki 1.17.4
[autoinstalls/mediawiki.git] / includes / api / ApiQueryRevisions.php
1 <?php
2 /**
3  * API for MediaWiki 1.8+
4  *
5  * Created on Sep 7, 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 if ( !defined( 'MEDIAWIKI' ) ) {
28         // Eclipse helper - will be ignored in production
29         require_once( 'ApiQueryBase.php' );
30 }
31
32 /**
33  * A query action to enumerate revisions of a given page, or show top revisions of multiple pages.
34  * Various pieces of information may be shown - flags, comments, and the actual wiki markup of the rev.
35  * In the enumeration mode, ranges of revisions may be requested and filtered.
36  *
37  * @ingroup API
38  */
39 class ApiQueryRevisions extends ApiQueryBase {
40
41         private $diffto, $difftotext, $expandTemplates, $generateXML, $section,
42                 $token;
43
44         public function __construct( $query, $moduleName ) {
45                 parent::__construct( $query, $moduleName, 'rv' );
46         }
47
48         private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false,
49                         $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
50                         $fld_content = false, $fld_tags = false;
51
52         private $tokenFunctions;
53
54         protected function getTokenFunctions() {
55                 // tokenname => function
56                 // function prototype is func($pageid, $title, $rev)
57                 // should return token or false
58
59                 // Don't call the hooks twice
60                 if ( isset( $this->tokenFunctions ) ) {
61                         return $this->tokenFunctions;
62                 }
63
64                 // If we're in JSON callback mode, no tokens can be obtained
65                 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
66                         return array();
67                 }
68
69                 $this->tokenFunctions = array(
70                         'rollback' => array( 'ApiQueryRevisions', 'getRollbackToken' )
71                 );
72                 wfRunHooks( 'APIQueryRevisionsTokens', array( &$this->tokenFunctions ) );
73                 return $this->tokenFunctions;
74         }
75
76         public static function getRollbackToken( $pageid, $title, $rev ) {
77                 global $wgUser;
78                 if ( !$wgUser->isAllowed( 'rollback' ) ) {
79                         return false;
80                 }
81                 return $wgUser->editToken( array( $title->getPrefixedText(),
82                                                 $rev->getUserText() ) );
83         }
84
85         public function execute() {
86                 $params = $this->extractRequestParams( false );
87
88                 // If any of those parameters are used, work in 'enumeration' mode.
89                 // Enum mode can only be used when exactly one page is provided.
90                 // Enumerating revisions on multiple pages make it extremely
91                 // difficult to manage continuations and require additional SQL indexes
92                 $enumRevMode = ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ||
93                                 !is_null( $params['limit'] ) || !is_null( $params['startid'] ) ||
94                                 !is_null( $params['endid'] ) || $params['dir'] === 'newer' ||
95                                 !is_null( $params['start'] ) || !is_null( $params['end'] ) );
96
97
98                 $pageSet = $this->getPageSet();
99                 $pageCount = $pageSet->getGoodTitleCount();
100                 $revCount = $pageSet->getRevisionCount();
101
102                 // Optimization -- nothing to do
103                 if ( $revCount === 0 && $pageCount === 0 ) {
104                         return;
105                 }
106
107                 if ( $revCount > 0 && $enumRevMode ) {
108                         $this->dieUsage( 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids' );
109                 }
110
111                 if ( $pageCount > 1 && $enumRevMode ) {
112                         $this->dieUsage( 'titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.', 'multpages' );
113                 }
114
115                 if ( !is_null( $params['difftotext'] ) ) {
116                         $this->difftotext = $params['difftotext'];
117                 } elseif ( !is_null( $params['diffto'] ) ) {
118                         if ( $params['diffto'] == 'cur' ) {
119                                 $params['diffto'] = 0;
120                         }
121                         if ( ( !ctype_digit( $params['diffto'] ) || $params['diffto'] < 0 )
122                                         && $params['diffto'] != 'prev' && $params['diffto'] != 'next' )
123                         {
124                                 $this->dieUsage( 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto' );
125                         }
126                         // Check whether the revision exists and is readable,
127                         // DifferenceEngine returns a rather ambiguous empty
128                         // string if that's not the case
129                         if ( $params['diffto'] != 0 ) {
130                                 $difftoRev = Revision::newFromID( $params['diffto'] );
131                                 if ( !$difftoRev ) {
132                                         $this->dieUsageMsg( array( 'nosuchrevid', $params['diffto'] ) );
133                                 }
134                                 if ( $difftoRev->isDeleted( Revision::DELETED_TEXT ) ) {
135                                         $this->setWarning( "Couldn't diff to r{$difftoRev->getID()}: content is hidden" );
136                                         $params['diffto'] = null;
137                                 }
138                         }
139                         $this->diffto = $params['diffto'];
140                 }
141
142                 $db = $this->getDB();
143                 $this->addTables( 'page' );
144                 $this->addFields( Revision::selectFields() );
145                 $this->addWhere( 'page_id = rev_page' );
146
147                 $prop = array_flip( $params['prop'] );
148
149                 // Optional fields
150                 $this->fld_ids = isset ( $prop['ids'] );
151                 // $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
152                 $this->fld_flags = isset ( $prop['flags'] );
153                 $this->fld_timestamp = isset ( $prop['timestamp'] );
154                 $this->fld_comment = isset ( $prop['comment'] );
155                 $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
156                 $this->fld_size = isset ( $prop['size'] );
157                 $this->fld_userid = isset( $prop['userid'] );
158                 $this->fld_user = isset ( $prop['user'] );
159                 $this->token = $params['token'];
160
161                 // Possible indexes used
162                 $index = array();
163
164                 $userMax = ( $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
165                 $botMax  = ( $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
166                 $limit = $params['limit'];
167                 if ( $limit == 'max' ) {
168                         $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
169                         $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
170                 }
171
172                 
173                 if ( !is_null( $this->token ) || $pageCount > 0 ) {
174                         $this->addFields( Revision::selectPageFields() );
175                 }
176
177                 if ( isset( $prop['tags'] ) ) {
178                         $this->fld_tags = true;
179                         $this->addTables( 'tag_summary' );
180                         $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
181                         $this->addFields( 'ts_tags' );
182                 }
183
184                 if ( !is_null( $params['tag'] ) ) {
185                         $this->addTables( 'change_tag' );
186                         $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
187                         $this->addWhereFld( 'ct_tag' , $params['tag'] );
188                         global $wgOldChangeTagsIndex;
189                         $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
190                 }
191
192                 if ( isset( $prop['content'] ) || !is_null( $this->difftotext ) ) {
193                         // For each page we will request, the user must have read rights for that page
194                         foreach ( $pageSet->getGoodTitles() as $title ) {
195                                 if ( !$title->userCanRead() ) {
196                                         $this->dieUsage(
197                                                 'The current user is not allowed to read ' . $title->getPrefixedText(),
198                                                 'accessdenied' );
199                                 }
200                         }
201
202                         $this->addTables( 'text' );
203                         $this->addWhere( 'rev_text_id=old_id' );
204                         $this->addFields( 'old_id' );
205                         $this->addFields( Revision::selectTextFields() );
206
207                         $this->fld_content = isset( $prop['content'] );
208
209                         $this->expandTemplates = $params['expandtemplates'];
210                         $this->generateXML = $params['generatexml'];
211                         $this->parseContent = $params['parse'];
212                         if ( $this->parseContent ) {
213                                 // Must manually initialize unset limit
214                                 if ( is_null( $limit ) ) {
215                                         $limit = 1;
216                                 }
217                                 // We are only going to parse 1 revision per request
218                                 $this->validateLimit( 'limit', $limit, 1, 1, 1 );
219                         }
220                         if ( isset( $params['section'] ) ) {
221                                 $this->section = $params['section'];
222                         } else {
223                                 $this->section = false;
224                         }
225                 }
226
227                 //Bug 24166 - API error when using rvprop=tags
228                 $this->addTables( 'revision' );
229
230
231                 if ( $enumRevMode ) {
232                         // This is mostly to prevent parameter errors (and optimize SQL?)
233                         if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) ) {
234                                 $this->dieUsage( 'start and startid cannot be used together', 'badparams' );
235                         }
236
237                         if ( !is_null( $params['endid'] ) && !is_null( $params['end'] ) ) {
238                                 $this->dieUsage( 'end and endid cannot be used together', 'badparams' );
239                         }
240
241                         if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
242                                 $this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
243                         }
244
245                         // This code makes an assumption that sorting by rev_id and rev_timestamp produces
246                         // the same result. This way users may request revisions starting at a given time,
247                         // but to page through results use the rev_id returned after each page.
248                         // Switching to rev_id removes the potential problem of having more than
249                         // one row with the same timestamp for the same page.
250                         // The order needs to be the same as start parameter to avoid SQL filesort.
251                         if ( is_null( $params['startid'] ) && is_null( $params['endid'] ) ) {
252                                 $this->addWhereRange( 'rev_timestamp', $params['dir'],
253                                         $params['start'], $params['end'] );
254                         } else {
255                                 $this->addWhereRange( 'rev_id', $params['dir'],
256                                         $params['startid'], $params['endid'] );
257                                 // One of start and end can be set
258                                 // If neither is set, this does nothing
259                                 $this->addWhereRange( 'rev_timestamp', $params['dir'],
260                                         $params['start'], $params['end'], false );
261                         }
262
263                         // must manually initialize unset limit
264                         if ( is_null( $limit ) ) {
265                                 $limit = 10;
266                         }
267                         $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
268
269                         // There is only one ID, use it
270                         $ids = array_keys( $pageSet->getGoodTitles() );
271                         $this->addWhereFld( 'rev_page', reset( $ids ) );
272
273                         if ( !is_null( $params['user'] ) ) {
274                                 $this->addWhereFld( 'rev_user_text', $params['user'] );
275                         } elseif ( !is_null( $params['excludeuser'] ) ) {
276                                 $this->addWhere( 'rev_user_text != ' .
277                                         $db->addQuotes( $params['excludeuser'] ) );
278                         }
279                         if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
280                                 // Paranoia: avoid brute force searches (bug 17342)
281                                 $this->addWhere( $db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
282                         }
283                 } elseif ( $revCount > 0 ) {
284                         $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
285                         $revs = $pageSet->getRevisionIDs();
286                         if ( self::truncateArray( $revs, $max ) ) {
287                                 $this->setWarning( "Too many values supplied for parameter 'revids': the limit is $max" );
288                         }
289
290                         // Get all revision IDs
291                         $this->addWhereFld( 'rev_id', array_keys( $revs ) );
292
293                         if ( !is_null( $params['continue'] ) ) {
294                                 $this->addWhere( "rev_id >= '" . intval( $params['continue'] ) . "'" );
295                         }
296                         $this->addOption( 'ORDER BY', 'rev_id' );
297
298                         // assumption testing -- we should never get more then $revCount rows.
299                         $limit = $revCount;
300                 } elseif ( $pageCount > 0 ) {
301                         $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
302                         $titles = $pageSet->getGoodTitles();
303                         if ( self::truncateArray( $titles, $max ) ) {
304                                 $this->setWarning( "Too many values supplied for parameter 'titles': the limit is $max" );
305                         }
306
307                         // When working in multi-page non-enumeration mode,
308                         // limit to the latest revision only
309                         $this->addWhere( 'page_id=rev_page' );
310                         $this->addWhere( 'page_latest=rev_id' );
311
312                         // Get all page IDs
313                         $this->addWhereFld( 'page_id', array_keys( $titles ) );
314                         // Every time someone relies on equality propagation, god kills a kitten :)
315                         $this->addWhereFld( 'rev_page', array_keys( $titles ) );
316
317                         if ( !is_null( $params['continue'] ) ) {
318                                 $cont = explode( '|', $params['continue'] );
319                                 if ( count( $cont ) != 2 ) {
320                                         $this->dieUsage( 'Invalid continue param. You should pass the original ' .
321                                                         'value returned by the previous query', '_badcontinue' );
322                                 }
323                                 $pageid = intval( $cont[0] );
324                                 $revid = intval( $cont[1] );
325                                 $this->addWhere(
326                                         "rev_page > '$pageid' OR " .
327                                         "(rev_page = '$pageid' AND " .
328                                         "rev_id >= '$revid')"
329                                 );
330                         }
331                         $this->addOption( 'ORDER BY', 'rev_page, rev_id' );
332
333                         // assumption testing -- we should never get more then $pageCount rows.
334                         $limit = $pageCount;
335                 } else {
336                         ApiBase::dieDebug( __METHOD__, 'param validation?' );
337                 }
338
339                 $this->addOption( 'LIMIT', $limit + 1 );
340                 $this->addOption( 'USE INDEX', $index );
341
342                 $count = 0;
343                 $res = $this->select( __METHOD__ );
344
345                 foreach ( $res as $row ) {
346                         if ( ++ $count > $limit ) {
347                                 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
348                                 if ( !$enumRevMode ) {
349                                         ApiBase::dieDebug( __METHOD__, 'Got more rows then expected' ); // bug report
350                                 }
351                                 $this->setContinueEnumParameter( 'startid', intval( $row->rev_id ) );
352                                 break;
353                         }
354
355                         $fit = $this->addPageSubItem( $row->rev_page, $this->extractRowInfo( $row ), 'rev' );
356                         if ( !$fit ) {
357                                 if ( $enumRevMode ) {
358                                         $this->setContinueEnumParameter( 'startid', intval( $row->rev_id ) );
359                                 } elseif ( $revCount > 0 ) {
360                                         $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
361                                 } else {
362                                         $this->setContinueEnumParameter( 'continue', intval( $row->rev_page ) .
363                                                 '|' . intval( $row->rev_id ) );
364                                 }
365                                 break;
366                         }
367                 }
368         }
369
370         private function extractRowInfo( $row ) {
371                 $revision = new Revision( $row );
372                 $title = $revision->getTitle();
373                 $vals = array();
374
375                 if ( $this->fld_ids ) {
376                         $vals['revid'] = intval( $revision->getId() );
377                         // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
378                         if ( !is_null( $revision->getParentId() ) ) {
379                                 $vals['parentid'] = intval( $revision->getParentId() );
380                         }
381                 }
382
383                 if ( $this->fld_flags && $revision->isMinor() ) {
384                         $vals['minor'] = '';
385                 }
386
387                 if ( $this->fld_user || $this->fld_userid ) {
388                         if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
389                                 $vals['userhidden'] = '';
390                         } else {
391                                 if ( $this->fld_user ) {
392                                         $vals['user'] = $revision->getUserText();
393                                 }
394                                 $userid = $revision->getUser();
395                                 if ( !$userid ) {
396                                         $vals['anon'] = '';
397                                 }
398
399                                 if ( $this->fld_userid ) {
400                                         $vals['userid'] = $userid;
401                                 }
402                         }
403                 }
404
405                 if ( $this->fld_timestamp ) {
406                         $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $revision->getTimestamp() );
407                 }
408
409                 if ( $this->fld_size && !is_null( $revision->getSize() ) ) {
410                         $vals['size'] = intval( $revision->getSize() );
411                 }
412
413                 if ( $this->fld_comment || $this->fld_parsedcomment ) {
414                         if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
415                                 $vals['commenthidden'] = '';
416                         } else {
417                                 $comment = $revision->getComment();
418
419                                 if ( $this->fld_comment ) {
420                                         $vals['comment'] = $comment;
421                                 }
422
423                                 if ( $this->fld_parsedcomment ) {
424                                         global $wgUser;
425                                         $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $comment, $title );
426                                 }
427                         }
428                 }
429
430                 if ( $this->fld_tags ) {
431                         if ( $row->ts_tags ) {
432                                 $tags = explode( ',', $row->ts_tags );
433                                 $this->getResult()->setIndexedTagName( $tags, 'tag' );
434                                 $vals['tags'] = $tags;
435                         } else {
436                                 $vals['tags'] = array();
437                         }
438                 }
439
440                 if ( !is_null( $this->token ) ) {
441                         $tokenFunctions = $this->getTokenFunctions();
442                         foreach ( $this->token as $t ) {
443                                 $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
444                                 if ( $val === false ) {
445                                         $this->setWarning( "Action '$t' is not allowed for the current user" );
446                                 } else {
447                                         $vals[$t . 'token'] = $val;
448                                 }
449                         }
450                 }
451
452                 $text = null;
453                 global $wgParser;
454                 if ( $this->fld_content || !is_null( $this->difftotext ) ) {
455                         $text = $revision->getText();
456                         // Expand templates after getting section content because
457                         // template-added sections don't count and Parser::preprocess()
458                         // will have less input
459                         if ( $this->section !== false ) {
460                                 $text = $wgParser->getSection( $text, $this->section, false );
461                                 if ( $text === false ) {
462                                         $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
463                                 }
464                         }
465                 }
466                 if ( $this->fld_content && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
467                         if ( $this->generateXML ) {
468                                 $wgParser->startExternalParse( $title, new ParserOptions(), OT_PREPROCESS );
469                                 $dom = $wgParser->preprocessToDom( $text );
470                                 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
471                                         $xml = $dom->saveXML();
472                                 } else {
473                                         $xml = $dom->__toString();
474                                 }
475                                 $vals['parsetree'] = $xml;
476
477                         }
478                         if ( $this->expandTemplates && !$this->parseContent ) {
479                                 $text = $wgParser->preprocess( $text, $title, new ParserOptions() );
480                         }
481                         if ( $this->parseContent ) {
482                                 global $wgEnableParserCache;
483                         
484                                 $popts = new ParserOptions();
485                                 $popts->setTidy( true );
486                                 
487                                 $articleObj = new Article( $title );
488
489                                 $p_result = false;
490                                 $pcache = ParserCache::singleton();
491                                 if ( $wgEnableParserCache ) {
492                                         $p_result = $pcache->get( $articleObj, $popts );
493                                 }
494                                 if ( !$p_result ) {
495                                         $p_result = $wgParser->parse( $text, $title, $popts );
496
497                                         if ( $wgEnableParserCache ) {
498                                                 $pcache->save( $p_result, $articleObj, $popts );
499                                         }
500                                 }
501                                 
502                                 $text = $p_result->getText();
503                         }
504                         ApiResult::setContent( $vals, $text );
505                 } elseif ( $this->fld_content ) {
506                         $vals['texthidden'] = '';
507                 }
508
509                 if ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
510                         global $wgAPIMaxUncachedDiffs;
511                         static $n = 0; // Number of uncached diffs we've had
512                         if ( $n < $wgAPIMaxUncachedDiffs ) {
513                                 $vals['diff'] = array();
514                                 if ( !is_null( $this->difftotext ) ) {
515                                         $engine = new DifferenceEngine( $title );
516                                         $engine->setText( $text, $this->difftotext );
517                                 } else {
518                                         $engine = new DifferenceEngine( $title, $revision->getID(), $this->diffto );
519                                         $vals['diff']['from'] = $engine->getOldid();
520                                         $vals['diff']['to'] = $engine->getNewid();
521                                 }
522                                 $difftext = $engine->getDiffBody();
523                                 ApiResult::setContent( $vals['diff'], $difftext );
524                                 if ( !$engine->wasCacheHit() ) {
525                                         $n++;
526                                 }
527                         } else {
528                                 $vals['diff']['notcached'] = '';
529                         }
530                 }
531                 return $vals;
532         }
533
534         public function getCacheMode( $params ) {
535                 if ( isset( $params['token'] ) ) {
536                         return 'private';
537                 }
538                 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
539                         // formatComment() calls wfMsg() among other things
540                         return 'anon-public-user-private';
541                 }
542                 return 'public';
543         }
544
545         public function getAllowedParams() {
546                 return array(
547                         'prop' => array(
548                                 ApiBase::PARAM_ISMULTI => true,
549                                 ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
550                                 ApiBase::PARAM_TYPE => array(
551                                         'ids',
552                                         'flags',
553                                         'timestamp',
554                                         'user',
555                                         'userid',
556                                         'size',
557                                         'comment',
558                                         'parsedcomment',
559                                         'content',
560                                         'tags'
561                                 )
562                         ),
563                         'limit' => array(
564                                 ApiBase::PARAM_TYPE => 'limit',
565                                 ApiBase::PARAM_MIN => 1,
566                                 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
567                                 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
568                         ),
569                         'startid' => array(
570                                 ApiBase::PARAM_TYPE => 'integer'
571                         ),
572                         'endid' => array(
573                                 ApiBase::PARAM_TYPE => 'integer'
574                         ),
575                         'start' => array(
576                                 ApiBase::PARAM_TYPE => 'timestamp'
577                         ),
578                         'end' => array(
579                                 ApiBase::PARAM_TYPE => 'timestamp'
580                         ),
581                         'dir' => array(
582                                 ApiBase::PARAM_DFLT => 'older',
583                                 ApiBase::PARAM_TYPE => array(
584                                         'newer',
585                                         'older'
586                                 )
587                         ),
588                         'user' => array(
589                                 ApiBase::PARAM_TYPE => 'user'
590                         ),
591                         'excludeuser' => array(
592                                 ApiBase::PARAM_TYPE => 'user'
593                         ),
594                         'tag' => null,
595                         'expandtemplates' => false,
596                         'generatexml' => false,
597                         'parse' => false,
598                         'section' => null,
599                         'token' => array(
600                                 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
601                                 ApiBase::PARAM_ISMULTI => true
602                         ),
603                         'continue' => null,
604                         'diffto' => null,
605                         'difftotext' => null,
606                 );
607         }
608
609         public function getParamDescription() {
610                 $p = $this->getModulePrefix();
611                 return array(
612                         'prop' => array(
613                                 'Which properties to get for each revision:',
614                                 ' ids            - The ID of the revision',
615                                 ' flags          - Revision flags (minor)',
616                                 ' timestamp      - The timestamp of the revision',
617                                 ' user           - User that made the revision',
618                                 ' userid         - User id of revision creator',
619                                 ' size           - Length of the revision',
620                                 ' comment        - Comment by the user for revision',
621                                 ' parsedcomment  - Parsed comment by the user for the revision',
622                                 ' content        - Text of the revision',
623                                 ' tags           - Tags for the revision',
624                         ),
625                         'limit' => 'Limit how many revisions will be returned (enum)',
626                         'startid' => 'From which revision id to start enumeration (enum)',
627                         'endid' => 'Stop revision enumeration on this revid (enum)',
628                         'start' => 'From which revision timestamp to start enumeration (enum)',
629                         'end' => 'Enumerate up to this timestamp (enum)',
630                         'dir' => 'Direction of enumeration - towards "newer" or "older" revisions (enum)',
631                         'user' => 'Only include revisions made by user',
632                         'excludeuser' => 'Exclude revisions made by user',
633                         'expandtemplates' => 'Expand templates in revision content',
634                         'generatexml' => 'Generate XML parse tree for revision content',
635                         'parse' => 'Parse revision content. For performance reasons if this option is used, rvlimit is enforced to 1.',
636                         'section' => 'Only retrieve the content of this section number',
637                         'token' => 'Which tokens to obtain for each revision',
638                         'continue' => 'When more results are available, use this to continue',
639                         'diffto' => array( 'Revision ID to diff each revision to.',
640                                 'Use "prev", "next" and "cur" for the previous, next and current revision respectively' ),
641                         'difftotext' => array( 'Text to diff each revision to. Only diffs a limited number of revisions.',
642                                 "Overrides {$p}diffto. If {$p}section is set, only that section will be diffed against this text" ),
643                         'tag' => 'Only list revisions tagged with this tag',
644                 );
645         }
646
647         public function getDescription() {
648                 return array(
649                         'Get revision information',
650                         'This module may be used in several ways:',
651                         ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter',
652                         ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params',
653                         ' 3) Get data about a set of revisions by setting their IDs with revids parameter',
654                         'All parameters marked as (enum) may only be used with a single page (#2)'
655                 );
656         }
657
658         public function getPossibleErrors() {
659                 return array_merge( parent::getPossibleErrors(), array(
660                         array( 'nosuchrevid', 'diffto' ),
661                         array( 'code' => 'revids', 'info' => 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).' ),
662                         array( 'code' => 'multpages', 'info' => 'titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.' ),
663                         array( 'code' => 'diffto', 'info' => 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"' ),
664                         array( 'code' => 'badparams', 'info' => 'start and startid cannot be used together' ),
665                         array( 'code' => 'badparams', 'info' => 'end and endid cannot be used together' ),
666                         array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together' ),
667                         array( 'code' => 'nosuchsection', 'info' => 'There is no section section in rID' ),
668                 ) );
669         }
670
671         protected function getExamples() {
672                 return array(
673                         'Get data with content for the last revision of titles "API" and "Main Page":',
674                         '  api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content',
675                         'Get last 5 revisions of the "Main Page":',
676                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment',
677                         'Get first 5 revisions of the "Main Page":',
678                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer',
679                         'Get first 5 revisions of the "Main Page" made after 2006-05-01:',
680                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
681                         'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
682                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
683                         'Get first 5 revisions of the "Main Page" that were made by the user "MediaWiki default"',
684                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvuser=MediaWiki%20default',
685                 );
686         }
687
688         public function getVersion() {
689                 return __CLASS__ . ': $Id$';
690         }
691 }