MediaWiki  REL1_19
ApiQueryRevisions.php
Go to the documentation of this file.
00001 <?php
00034 class ApiQueryRevisions extends ApiQueryBase {
00035 
00036         private $diffto, $difftotext, $expandTemplates, $generateXML, $section,
00037                 $token, $parseContent;
00038 
00039         public function __construct( $query, $moduleName ) {
00040                 parent::__construct( $query, $moduleName, 'rv' );
00041         }
00042 
00043         private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false,
00044                         $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
00045                         $fld_content = false, $fld_tags = false;
00046 
00047         private $tokenFunctions;
00048 
00049         protected function getTokenFunctions() {
00050                 // tokenname => function
00051                 // function prototype is func($pageid, $title, $rev)
00052                 // should return token or false
00053 
00054                 // Don't call the hooks twice
00055                 if ( isset( $this->tokenFunctions ) ) {
00056                         return $this->tokenFunctions;
00057                 }
00058 
00059                 // If we're in JSON callback mode, no tokens can be obtained
00060                 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
00061                         return array();
00062                 }
00063 
00064                 $this->tokenFunctions = array(
00065                         'rollback' => array( 'ApiQueryRevisions', 'getRollbackToken' )
00066                 );
00067                 wfRunHooks( 'APIQueryRevisionsTokens', array( &$this->tokenFunctions ) );
00068                 return $this->tokenFunctions;
00069         }
00070 
00077         public static function getRollbackToken( $pageid, $title, $rev ) {
00078                 global $wgUser;
00079                 if ( !$wgUser->isAllowed( 'rollback' ) ) {
00080                         return false;
00081                 }
00082                 return $wgUser->getEditToken(
00083                         array( $title->getPrefixedText(), $rev->getUserText() ) );
00084         }
00085 
00086         public function execute() {
00087                 $params = $this->extractRequestParams( false );
00088 
00089                 // If any of those parameters are used, work in 'enumeration' mode.
00090                 // Enum mode can only be used when exactly one page is provided.
00091                 // Enumerating revisions on multiple pages make it extremely
00092                 // difficult to manage continuations and require additional SQL indexes
00093                 $enumRevMode = ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ||
00094                                 !is_null( $params['limit'] ) || !is_null( $params['startid'] ) ||
00095                                 !is_null( $params['endid'] ) || $params['dir'] === 'newer' ||
00096                                 !is_null( $params['start'] ) || !is_null( $params['end'] ) );
00097 
00098 
00099                 $pageSet = $this->getPageSet();
00100                 $pageCount = $pageSet->getGoodTitleCount();
00101                 $revCount = $pageSet->getRevisionCount();
00102 
00103                 // Optimization -- nothing to do
00104                 if ( $revCount === 0 && $pageCount === 0 ) {
00105                         return;
00106                 }
00107 
00108                 if ( $revCount > 0 && $enumRevMode ) {
00109                         $this->dieUsage( 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids' );
00110                 }
00111 
00112                 if ( $pageCount > 1 && $enumRevMode ) {
00113                         $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' );
00114                 }
00115 
00116                 if ( !is_null( $params['difftotext'] ) ) {
00117                         $this->difftotext = $params['difftotext'];
00118                 } elseif ( !is_null( $params['diffto'] ) ) {
00119                         if ( $params['diffto'] == 'cur' ) {
00120                                 $params['diffto'] = 0;
00121                         }
00122                         if ( ( !ctype_digit( $params['diffto'] ) || $params['diffto'] < 0 )
00123                                         && $params['diffto'] != 'prev' && $params['diffto'] != 'next' ) {
00124                                 $this->dieUsage( 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto' );
00125                         }
00126                         // Check whether the revision exists and is readable,
00127                         // DifferenceEngine returns a rather ambiguous empty
00128                         // string if that's not the case
00129                         if ( $params['diffto'] != 0 ) {
00130                                 $difftoRev = Revision::newFromID( $params['diffto'] );
00131                                 if ( !$difftoRev ) {
00132                                         $this->dieUsageMsg( array( 'nosuchrevid', $params['diffto'] ) );
00133                                 }
00134                                 if ( $difftoRev->isDeleted( Revision::DELETED_TEXT ) ) {
00135                                         $this->setWarning( "Couldn't diff to r{$difftoRev->getID()}: content is hidden" );
00136                                         $params['diffto'] = null;
00137                                 }
00138                         }
00139                         $this->diffto = $params['diffto'];
00140                 }
00141 
00142                 $db = $this->getDB();
00143                 $this->addTables( 'page' );
00144                 $this->addFields( Revision::selectFields() );
00145                 $this->addWhere( 'page_id = rev_page' );
00146 
00147                 $prop = array_flip( $params['prop'] );
00148 
00149                 // Optional fields
00150                 $this->fld_ids = isset ( $prop['ids'] );
00151                 // $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
00152                 $this->fld_flags = isset ( $prop['flags'] );
00153                 $this->fld_timestamp = isset ( $prop['timestamp'] );
00154                 $this->fld_comment = isset ( $prop['comment'] );
00155                 $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
00156                 $this->fld_size = isset ( $prop['size'] );
00157                 $this->fld_sha1 = isset ( $prop['sha1'] );
00158                 $this->fld_userid = isset( $prop['userid'] );
00159                 $this->fld_user = isset ( $prop['user'] );
00160                 $this->token = $params['token'];
00161 
00162                 // Possible indexes used
00163                 $index = array();
00164 
00165                 $userMax = ( $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
00166                 $botMax  = ( $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
00167                 $limit = $params['limit'];
00168                 if ( $limit == 'max' ) {
00169                         $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
00170                         $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
00171                 }
00172 
00173                 if ( !is_null( $this->token ) || $pageCount > 0 ) {
00174                         $this->addFields( Revision::selectPageFields() );
00175                 }
00176 
00177                 if ( isset( $prop['tags'] ) ) {
00178                         $this->fld_tags = true;
00179                         $this->addTables( 'tag_summary' );
00180                         $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
00181                         $this->addFields( 'ts_tags' );
00182                 }
00183 
00184                 if ( !is_null( $params['tag'] ) ) {
00185                         $this->addTables( 'change_tag' );
00186                         $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
00187                         $this->addWhereFld( 'ct_tag' , $params['tag'] );
00188                         global $wgOldChangeTagsIndex;
00189                         $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
00190                 }
00191 
00192                 if ( isset( $prop['content'] ) || !is_null( $this->difftotext ) ) {
00193                         // For each page we will request, the user must have read rights for that page
00194                         foreach ( $pageSet->getGoodTitles() as $title ) {
00195                                 if ( !$title->userCan( 'read' ) ) {
00196                                         $this->dieUsage(
00197                                                 'The current user is not allowed to read ' . $title->getPrefixedText(),
00198                                                 'accessdenied' );
00199                                 }
00200                         }
00201 
00202                         $this->addTables( 'text' );
00203                         $this->addWhere( 'rev_text_id=old_id' );
00204                         $this->addFields( 'old_id' );
00205                         $this->addFields( Revision::selectTextFields() );
00206 
00207                         $this->fld_content = isset( $prop['content'] );
00208 
00209                         $this->expandTemplates = $params['expandtemplates'];
00210                         $this->generateXML = $params['generatexml'];
00211                         $this->parseContent = $params['parse'];
00212                         if ( $this->parseContent ) {
00213                                 // Must manually initialize unset limit
00214                                 if ( is_null( $limit ) ) {
00215                                         $limit = 1;
00216                                 }
00217                                 // We are only going to parse 1 revision per request
00218                                 $this->validateLimit( 'limit', $limit, 1, 1, 1 );
00219                         }
00220                         if ( isset( $params['section'] ) ) {
00221                                 $this->section = $params['section'];
00222                         } else {
00223                                 $this->section = false;
00224                         }
00225                 }
00226 
00227                 // Bug 24166 - API error when using rvprop=tags
00228                 $this->addTables( 'revision' );
00229 
00230                 if ( $enumRevMode ) {
00231                         // This is mostly to prevent parameter errors (and optimize SQL?)
00232                         if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) ) {
00233                                 $this->dieUsage( 'start and startid cannot be used together', 'badparams' );
00234                         }
00235 
00236                         if ( !is_null( $params['endid'] ) && !is_null( $params['end'] ) ) {
00237                                 $this->dieUsage( 'end and endid cannot be used together', 'badparams' );
00238                         }
00239 
00240                         if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
00241                                 $this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
00242                         }
00243 
00244                         // This code makes an assumption that sorting by rev_id and rev_timestamp produces
00245                         // the same result. This way users may request revisions starting at a given time,
00246                         // but to page through results use the rev_id returned after each page.
00247                         // Switching to rev_id removes the potential problem of having more than
00248                         // one row with the same timestamp for the same page.
00249                         // The order needs to be the same as start parameter to avoid SQL filesort.
00250                         if ( is_null( $params['startid'] ) && is_null( $params['endid'] ) ) {
00251                                 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
00252                                         $params['start'], $params['end'] );
00253                         } else {
00254                                 $this->addWhereRange( 'rev_id', $params['dir'],
00255                                         $params['startid'], $params['endid'] );
00256                                 // One of start and end can be set
00257                                 // If neither is set, this does nothing
00258                                 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
00259                                         $params['start'], $params['end'], false );
00260                         }
00261 
00262                         // must manually initialize unset limit
00263                         if ( is_null( $limit ) ) {
00264                                 $limit = 10;
00265                         }
00266                         $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
00267 
00268                         // There is only one ID, use it
00269                         $ids = array_keys( $pageSet->getGoodTitles() );
00270                         $this->addWhereFld( 'rev_page', reset( $ids ) );
00271 
00272                         if ( !is_null( $params['user'] ) ) {
00273                                 $this->addWhereFld( 'rev_user_text', $params['user'] );
00274                         } elseif ( !is_null( $params['excludeuser'] ) ) {
00275                                 $this->addWhere( 'rev_user_text != ' .
00276                                         $db->addQuotes( $params['excludeuser'] ) );
00277                         }
00278                         if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
00279                                 // Paranoia: avoid brute force searches (bug 17342)
00280                                 $this->addWhere( $db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
00281                         }
00282                 } elseif ( $revCount > 0 ) {
00283                         $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
00284                         $revs = $pageSet->getRevisionIDs();
00285                         if ( self::truncateArray( $revs, $max ) ) {
00286                                 $this->setWarning( "Too many values supplied for parameter 'revids': the limit is $max" );
00287                         }
00288 
00289                         // Get all revision IDs
00290                         $this->addWhereFld( 'rev_id', array_keys( $revs ) );
00291 
00292                         if ( !is_null( $params['continue'] ) ) {
00293                                 $this->addWhere( "rev_id >= '" . intval( $params['continue'] ) . "'" );
00294                         }
00295                         $this->addOption( 'ORDER BY', 'rev_id' );
00296 
00297                         // assumption testing -- we should never get more then $revCount rows.
00298                         $limit = $revCount;
00299                 } elseif ( $pageCount > 0 ) {
00300                         $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
00301                         $titles = $pageSet->getGoodTitles();
00302                         if ( self::truncateArray( $titles, $max ) ) {
00303                                 $this->setWarning( "Too many values supplied for parameter 'titles': the limit is $max" );
00304                         }
00305 
00306                         // When working in multi-page non-enumeration mode,
00307                         // limit to the latest revision only
00308                         $this->addWhere( 'page_id=rev_page' );
00309                         $this->addWhere( 'page_latest=rev_id' );
00310 
00311                         // Get all page IDs
00312                         $this->addWhereFld( 'page_id', array_keys( $titles ) );
00313                         // Every time someone relies on equality propagation, god kills a kitten :)
00314                         $this->addWhereFld( 'rev_page', array_keys( $titles ) );
00315 
00316                         if ( !is_null( $params['continue'] ) ) {
00317                                 $cont = explode( '|', $params['continue'] );
00318                                 if ( count( $cont ) != 2 ) {
00319                                         $this->dieUsage( 'Invalid continue param. You should pass the original ' .
00320                                                         'value returned by the previous query', '_badcontinue' );
00321                                 }
00322                                 $pageid = intval( $cont[0] );
00323                                 $revid = intval( $cont[1] );
00324                                 $this->addWhere(
00325                                         "rev_page > '$pageid' OR " .
00326                                         "(rev_page = '$pageid' AND " .
00327                                         "rev_id >= '$revid')"
00328                                 );
00329                         }
00330                         $this->addOption( 'ORDER BY', 'rev_page, rev_id' );
00331 
00332                         // assumption testing -- we should never get more then $pageCount rows.
00333                         $limit = $pageCount;
00334                 } else {
00335                         ApiBase::dieDebug( __METHOD__, 'param validation?' );
00336                 }
00337 
00338                 $this->addOption( 'LIMIT', $limit + 1 );
00339                 $this->addOption( 'USE INDEX', $index );
00340 
00341                 $count = 0;
00342                 $res = $this->select( __METHOD__ );
00343 
00344                 foreach ( $res as $row ) {
00345                         if ( ++ $count > $limit ) {
00346                                 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
00347                                 if ( !$enumRevMode ) {
00348                                         ApiBase::dieDebug( __METHOD__, 'Got more rows then expected' ); // bug report
00349                                 }
00350                                 $this->setContinueEnumParameter( 'startid', intval( $row->rev_id ) );
00351                                 break;
00352                         }
00353 
00354                         $fit = $this->addPageSubItem( $row->rev_page, $this->extractRowInfo( $row ), 'rev' );
00355                         if ( !$fit ) {
00356                                 if ( $enumRevMode ) {
00357                                         $this->setContinueEnumParameter( 'startid', intval( $row->rev_id ) );
00358                                 } elseif ( $revCount > 0 ) {
00359                                         $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
00360                                 } else {
00361                                         $this->setContinueEnumParameter( 'continue', intval( $row->rev_page ) .
00362                                                 '|' . intval( $row->rev_id ) );
00363                                 }
00364                                 break;
00365                         }
00366                 }
00367         }
00368 
00369         private function extractRowInfo( $row ) {
00370                 $revision = new Revision( $row );
00371                 $title = $revision->getTitle();
00372                 $vals = array();
00373 
00374                 if ( $this->fld_ids ) {
00375                         $vals['revid'] = intval( $revision->getId() );
00376                         // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
00377                         if ( !is_null( $revision->getParentId() ) ) {
00378                                 $vals['parentid'] = intval( $revision->getParentId() );
00379                         }
00380                 }
00381 
00382                 if ( $this->fld_flags && $revision->isMinor() ) {
00383                         $vals['minor'] = '';
00384                 }
00385 
00386                 if ( $this->fld_user || $this->fld_userid ) {
00387                         if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
00388                                 $vals['userhidden'] = '';
00389                         } else {
00390                                 if ( $this->fld_user ) {
00391                                         $vals['user'] = $revision->getUserText();
00392                                 }
00393                                 $userid = $revision->getUser();
00394                                 if ( !$userid ) {
00395                                         $vals['anon'] = '';
00396                                 }
00397 
00398                                 if ( $this->fld_userid ) {
00399                                         $vals['userid'] = $userid;
00400                                 }
00401                         }
00402                 }
00403 
00404                 if ( $this->fld_timestamp ) {
00405                         $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $revision->getTimestamp() );
00406                 }
00407 
00408                 if ( $this->fld_size ) {
00409                         if ( !is_null( $revision->getSize() ) ) {
00410                                 $vals['size'] = intval( $revision->getSize() );
00411                         } else {
00412                                 $vals['size'] = 0;
00413                         }
00414                 }
00415 
00416                 if ( $this->fld_sha1 ) {
00417                         if ( $revision->getSha1() != '' ) {
00418                                 $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
00419                         } else {
00420                                 $vals['sha1'] = '';
00421                         }
00422                 }
00423 
00424                 if ( $this->fld_comment || $this->fld_parsedcomment ) {
00425                         if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
00426                                 $vals['commenthidden'] = '';
00427                         } else {
00428                                 $comment = $revision->getComment();
00429 
00430                                 if ( $this->fld_comment ) {
00431                                         $vals['comment'] = $comment;
00432                                 }
00433 
00434                                 if ( $this->fld_parsedcomment ) {
00435                                         $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
00436                                 }
00437                         }
00438                 }
00439 
00440                 if ( $this->fld_tags ) {
00441                         if ( $row->ts_tags ) {
00442                                 $tags = explode( ',', $row->ts_tags );
00443                                 $this->getResult()->setIndexedTagName( $tags, 'tag' );
00444                                 $vals['tags'] = $tags;
00445                         } else {
00446                                 $vals['tags'] = array();
00447                         }
00448                 }
00449 
00450                 if ( !is_null( $this->token ) ) {
00451                         $tokenFunctions = $this->getTokenFunctions();
00452                         foreach ( $this->token as $t ) {
00453                                 $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
00454                                 if ( $val === false ) {
00455                                         $this->setWarning( "Action '$t' is not allowed for the current user" );
00456                                 } else {
00457                                         $vals[$t . 'token'] = $val;
00458                                 }
00459                         }
00460                 }
00461 
00462                 $text = null;
00463                 global $wgParser;
00464                 if ( $this->fld_content || !is_null( $this->difftotext ) ) {
00465                         $text = $revision->getText();
00466                         // Expand templates after getting section content because
00467                         // template-added sections don't count and Parser::preprocess()
00468                         // will have less input
00469                         if ( $this->section !== false ) {
00470                                 $text = $wgParser->getSection( $text, $this->section, false );
00471                                 if ( $text === false ) {
00472                                         $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
00473                                 }
00474                         }
00475                 }
00476                 if ( $this->fld_content && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
00477                         if ( $this->generateXML ) {
00478                                 $wgParser->startExternalParse( $title, ParserOptions::newFromContext( $this->getContext() ), OT_PREPROCESS );
00479                                 $dom = $wgParser->preprocessToDom( $text );
00480                                 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
00481                                         $xml = $dom->saveXML();
00482                                 } else {
00483                                         $xml = $dom->__toString();
00484                                 }
00485                                 $vals['parsetree'] = $xml;
00486 
00487                         }
00488                         if ( $this->expandTemplates && !$this->parseContent ) {
00489                                 $text = $wgParser->preprocess( $text, $title, ParserOptions::newFromContext( $this->getContext() ) );
00490                         }
00491                         if ( $this->parseContent ) {
00492                                 $text = $wgParser->parse( $text, $title, ParserOptions::newFromContext( $this->getContext() ) )->getText();
00493                         }
00494                         ApiResult::setContent( $vals, $text );
00495                 } elseif ( $this->fld_content ) {
00496                         $vals['texthidden'] = '';
00497                 }
00498 
00499                 if ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
00500                         global $wgAPIMaxUncachedDiffs;
00501                         static $n = 0; // Number of uncached diffs we've had
00502                         if ( $n < $wgAPIMaxUncachedDiffs ) {
00503                                 $vals['diff'] = array();
00504                                 $context = new DerivativeContext( $this->getContext() );
00505                                 $context->setTitle( $title );
00506                                 if ( !is_null( $this->difftotext ) ) {
00507                                         $engine = new DifferenceEngine( $context );
00508                                         $engine->setText( $text, $this->difftotext );
00509                                 } else {
00510                                         $engine = new DifferenceEngine( $context, $revision->getID(), $this->diffto );
00511                                         $vals['diff']['from'] = $engine->getOldid();
00512                                         $vals['diff']['to'] = $engine->getNewid();
00513                                 }
00514                                 $difftext = $engine->getDiffBody();
00515                                 ApiResult::setContent( $vals['diff'], $difftext );
00516                                 if ( !$engine->wasCacheHit() ) {
00517                                         $n++;
00518                                 }
00519                         } else {
00520                                 $vals['diff']['notcached'] = '';
00521                         }
00522                 }
00523                 return $vals;
00524         }
00525 
00526         public function getCacheMode( $params ) {
00527                 if ( isset( $params['token'] ) ) {
00528                         return 'private';
00529                 }
00530                 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
00531                         // formatComment() calls wfMsg() among other things
00532                         return 'anon-public-user-private';
00533                 }
00534                 return 'public';
00535         }
00536 
00537         public function getAllowedParams() {
00538                 return array(
00539                         'prop' => array(
00540                                 ApiBase::PARAM_ISMULTI => true,
00541                                 ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
00542                                 ApiBase::PARAM_TYPE => array(
00543                                         'ids',
00544                                         'flags',
00545                                         'timestamp',
00546                                         'user',
00547                                         'userid',
00548                                         'size',
00549                                         'sha1',
00550                                         'comment',
00551                                         'parsedcomment',
00552                                         'content',
00553                                         'tags'
00554                                 )
00555                         ),
00556                         'limit' => array(
00557                                 ApiBase::PARAM_TYPE => 'limit',
00558                                 ApiBase::PARAM_MIN => 1,
00559                                 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
00560                                 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
00561                         ),
00562                         'startid' => array(
00563                                 ApiBase::PARAM_TYPE => 'integer'
00564                         ),
00565                         'endid' => array(
00566                                 ApiBase::PARAM_TYPE => 'integer'
00567                         ),
00568                         'start' => array(
00569                                 ApiBase::PARAM_TYPE => 'timestamp'
00570                         ),
00571                         'end' => array(
00572                                 ApiBase::PARAM_TYPE => 'timestamp'
00573                         ),
00574                         'dir' => array(
00575                                 ApiBase::PARAM_DFLT => 'older',
00576                                 ApiBase::PARAM_TYPE => array(
00577                                         'newer',
00578                                         'older'
00579                                 )
00580                         ),
00581                         'user' => array(
00582                                 ApiBase::PARAM_TYPE => 'user'
00583                         ),
00584                         'excludeuser' => array(
00585                                 ApiBase::PARAM_TYPE => 'user'
00586                         ),
00587                         'tag' => null,
00588                         'expandtemplates' => false,
00589                         'generatexml' => false,
00590                         'parse' => false,
00591                         'section' => null,
00592                         'token' => array(
00593                                 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
00594                                 ApiBase::PARAM_ISMULTI => true
00595                         ),
00596                         'continue' => null,
00597                         'diffto' => null,
00598                         'difftotext' => null,
00599                 );
00600         }
00601 
00602         public function getParamDescription() {
00603                 $p = $this->getModulePrefix();
00604                 return array(
00605                         'prop' => array(
00606                                 'Which properties to get for each revision:',
00607                                 ' ids            - The ID of the revision',
00608                                 ' flags          - Revision flags (minor)',
00609                                 ' timestamp      - The timestamp of the revision',
00610                                 ' user           - User that made the revision',
00611                                 ' userid         - User id of revision creator',
00612                                 ' size           - Length (bytes) of the revision',
00613                                 ' sha1           - SHA-1 (base 16) of the revision',
00614                                 ' comment        - Comment by the user for revision',
00615                                 ' parsedcomment  - Parsed comment by the user for the revision',
00616                                 ' content        - Text of the revision',
00617                                 ' tags           - Tags for the revision',
00618                         ),
00619                         'limit' => 'Limit how many revisions will be returned (enum)',
00620                         'startid' => 'From which revision id to start enumeration (enum)',
00621                         'endid' => 'Stop revision enumeration on this revid (enum)',
00622                         'start' => 'From which revision timestamp to start enumeration (enum)',
00623                         'end' => 'Enumerate up to this timestamp (enum)',
00624                         'dir' => $this->getDirectionDescription( $p, ' (enum)' ),
00625                         'user' => 'Only include revisions made by user (enum)',
00626                         'excludeuser' => 'Exclude revisions made by user (enum)',
00627                         'expandtemplates' => 'Expand templates in revision content',
00628                         'generatexml' => 'Generate XML parse tree for revision content',
00629                         'parse' => 'Parse revision content. For performance reasons if this option is used, rvlimit is enforced to 1.',
00630                         'section' => 'Only retrieve the content of this section number',
00631                         'token' => 'Which tokens to obtain for each revision',
00632                         'continue' => 'When more results are available, use this to continue',
00633                         'diffto' => array( 'Revision ID to diff each revision to.',
00634                                 'Use "prev", "next" and "cur" for the previous, next and current revision respectively' ),
00635                         'difftotext' => array( 'Text to diff each revision to. Only diffs a limited number of revisions.',
00636                                 "Overrides {$p}diffto. If {$p}section is set, only that section will be diffed against this text" ),
00637                         'tag' => 'Only list revisions tagged with this tag',
00638                 );
00639         }
00640 
00641         public function getDescription() {
00642                 return array(
00643                         'Get revision information',
00644                         'May be used in several ways:',
00645                         ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter',
00646                         ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params',
00647                         ' 3) Get data about a set of revisions by setting their IDs with revids parameter',
00648                         'All parameters marked as (enum) may only be used with a single page (#2)'
00649                 );
00650         }
00651 
00652         public function getPossibleErrors() {
00653                 return array_merge( parent::getPossibleErrors(), array(
00654                         array( 'nosuchrevid', 'diffto' ),
00655                         array( 'code' => 'revids', 'info' => 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).' ),
00656                         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.' ),
00657                         array( 'code' => 'diffto', 'info' => 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"' ),
00658                         array( 'code' => 'badparams', 'info' => 'start and startid cannot be used together' ),
00659                         array( 'code' => 'badparams', 'info' => 'end and endid cannot be used together' ),
00660                         array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together' ),
00661                         array( 'code' => 'nosuchsection', 'info' => 'There is no section section in rID' ),
00662                 ) );
00663         }
00664 
00665         public function getExamples() {
00666                 return array(
00667                         'Get data with content for the last revision of titles "API" and "Main Page"',
00668                         '  api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content',
00669                         'Get last 5 revisions of the "Main Page"',
00670                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment',
00671                         'Get first 5 revisions of the "Main Page"',
00672                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer',
00673                         'Get first 5 revisions of the "Main Page" made after 2006-05-01',
00674                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
00675                         'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
00676                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
00677                         'Get first 5 revisions of the "Main Page" that were made by the user "MediaWiki default"',
00678                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvuser=MediaWiki%20default',
00679                 );
00680         }
00681 
00682         public function getHelpUrls() {
00683                 return 'https://www.mediawiki.org/wiki/API:Properties#revisions_.2F_rv';
00684         }
00685 
00686         public function getVersion() {
00687                 return __CLASS__ . ': $Id$';
00688         }
00689 }