MediaWiki  REL1_20
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                 // add user name, if needed
00228                 if ( $this->fld_user ) {
00229                         $this->addTables( 'user' );
00230                         $this->addJoinConds( array( 'user' => Revision::userJoinCond() ) );
00231                         $this->addFields( Revision::selectUserFields() );
00232                 }
00233 
00234                 // Bug 24166 - API error when using rvprop=tags
00235                 $this->addTables( 'revision' );
00236 
00237                 if ( $enumRevMode ) {
00238                         // This is mostly to prevent parameter errors (and optimize SQL?)
00239                         if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) ) {
00240                                 $this->dieUsage( 'start and startid cannot be used together', 'badparams' );
00241                         }
00242 
00243                         if ( !is_null( $params['endid'] ) && !is_null( $params['end'] ) ) {
00244                                 $this->dieUsage( 'end and endid cannot be used together', 'badparams' );
00245                         }
00246 
00247                         if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
00248                                 $this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
00249                         }
00250 
00251                         // Continuing effectively uses startid. But we can't use rvstartid
00252                         // directly, because there is no way to tell the client to ''not''
00253                         // send rvstart if it sent it in the original query. So instead we
00254                         // send the continuation startid as rvcontinue, and ignore both
00255                         // rvstart and rvstartid when that is supplied.
00256                         if ( !is_null( $params['continue'] ) ) {
00257                                 $params['startid'] = $params['continue'];
00258                                 unset( $params['start'] );
00259                         }
00260 
00261                         // This code makes an assumption that sorting by rev_id and rev_timestamp produces
00262                         // the same result. This way users may request revisions starting at a given time,
00263                         // but to page through results use the rev_id returned after each page.
00264                         // Switching to rev_id removes the potential problem of having more than
00265                         // one row with the same timestamp for the same page.
00266                         // The order needs to be the same as start parameter to avoid SQL filesort.
00267                         if ( is_null( $params['startid'] ) && is_null( $params['endid'] ) ) {
00268                                 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
00269                                         $params['start'], $params['end'] );
00270                         } else {
00271                                 $this->addWhereRange( 'rev_id', $params['dir'],
00272                                         $params['startid'], $params['endid'] );
00273                                 // One of start and end can be set
00274                                 // If neither is set, this does nothing
00275                                 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
00276                                         $params['start'], $params['end'], false );
00277                         }
00278 
00279                         // must manually initialize unset limit
00280                         if ( is_null( $limit ) ) {
00281                                 $limit = 10;
00282                         }
00283                         $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
00284 
00285                         // There is only one ID, use it
00286                         $ids = array_keys( $pageSet->getGoodTitles() );
00287                         $this->addWhereFld( 'rev_page', reset( $ids ) );
00288 
00289                         if ( !is_null( $params['user'] ) ) {
00290                                 $this->addWhereFld( 'rev_user_text', $params['user'] );
00291                         } elseif ( !is_null( $params['excludeuser'] ) ) {
00292                                 $this->addWhere( 'rev_user_text != ' .
00293                                         $db->addQuotes( $params['excludeuser'] ) );
00294                         }
00295                         if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
00296                                 // Paranoia: avoid brute force searches (bug 17342)
00297                                 $this->addWhere( $db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
00298                         }
00299                 } elseif ( $revCount > 0 ) {
00300                         $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
00301                         $revs = $pageSet->getRevisionIDs();
00302                         if ( self::truncateArray( $revs, $max ) ) {
00303                                 $this->setWarning( "Too many values supplied for parameter 'revids': the limit is $max" );
00304                         }
00305 
00306                         // Get all revision IDs
00307                         $this->addWhereFld( 'rev_id', array_keys( $revs ) );
00308 
00309                         if ( !is_null( $params['continue'] ) ) {
00310                                 $this->addWhere( 'rev_id >= ' . intval( $params['continue'] ) );
00311                         }
00312                         $this->addOption( 'ORDER BY', 'rev_id' );
00313 
00314                         // assumption testing -- we should never get more then $revCount rows.
00315                         $limit = $revCount;
00316                 } elseif ( $pageCount > 0 ) {
00317                         $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
00318                         $titles = $pageSet->getGoodTitles();
00319                         if ( self::truncateArray( $titles, $max ) ) {
00320                                 $this->setWarning( "Too many values supplied for parameter 'titles': the limit is $max" );
00321                         }
00322 
00323                         // When working in multi-page non-enumeration mode,
00324                         // limit to the latest revision only
00325                         $this->addWhere( 'page_id=rev_page' );
00326                         $this->addWhere( 'page_latest=rev_id' );
00327 
00328                         // Get all page IDs
00329                         $this->addWhereFld( 'page_id', array_keys( $titles ) );
00330                         // Every time someone relies on equality propagation, god kills a kitten :)
00331                         $this->addWhereFld( 'rev_page', array_keys( $titles ) );
00332 
00333                         if ( !is_null( $params['continue'] ) ) {
00334                                 $cont = explode( '|', $params['continue'] );
00335                                 if ( count( $cont ) != 2 ) {
00336                                         $this->dieUsage( 'Invalid continue param. You should pass the original ' .
00337                                                         'value returned by the previous query', '_badcontinue' );
00338                                 }
00339                                 $pageid = intval( $cont[0] );
00340                                 $revid = intval( $cont[1] );
00341                                 $this->addWhere(
00342                                         "rev_page > $pageid OR " .
00343                                         "(rev_page = $pageid AND " .
00344                                         "rev_id >= $revid)"
00345                                 );
00346                         }
00347                         $this->addOption( 'ORDER BY', array(
00348                                 'rev_page',
00349                                 'rev_id'
00350                         ));
00351 
00352                         // assumption testing -- we should never get more then $pageCount rows.
00353                         $limit = $pageCount;
00354                 } else {
00355                         ApiBase::dieDebug( __METHOD__, 'param validation?' );
00356                 }
00357 
00358                 $this->addOption( 'LIMIT', $limit + 1 );
00359                 $this->addOption( 'USE INDEX', $index );
00360 
00361                 $count = 0;
00362                 $res = $this->select( __METHOD__ );
00363 
00364                 foreach ( $res as $row ) {
00365                         if ( ++ $count > $limit ) {
00366                                 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
00367                                 if ( !$enumRevMode ) {
00368                                         ApiBase::dieDebug( __METHOD__, 'Got more rows then expected' ); // bug report
00369                                 }
00370                                 $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
00371                                 break;
00372                         }
00373 
00374                         $fit = $this->addPageSubItem( $row->rev_page, $this->extractRowInfo( $row ), 'rev' );
00375                         if ( !$fit ) {
00376                                 if ( $enumRevMode ) {
00377                                         $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
00378                                 } elseif ( $revCount > 0 ) {
00379                                         $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
00380                                 } else {
00381                                         $this->setContinueEnumParameter( 'continue', intval( $row->rev_page ) .
00382                                                 '|' . intval( $row->rev_id ) );
00383                                 }
00384                                 break;
00385                         }
00386                 }
00387         }
00388 
00389         private function extractRowInfo( $row ) {
00390                 $revision = new Revision( $row );
00391                 $title = $revision->getTitle();
00392                 $vals = array();
00393 
00394                 if ( $this->fld_ids ) {
00395                         $vals['revid'] = intval( $revision->getId() );
00396                         // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
00397                         if ( !is_null( $revision->getParentId() ) ) {
00398                                 $vals['parentid'] = intval( $revision->getParentId() );
00399                         }
00400                 }
00401 
00402                 if ( $this->fld_flags && $revision->isMinor() ) {
00403                         $vals['minor'] = '';
00404                 }
00405 
00406                 if ( $this->fld_user || $this->fld_userid ) {
00407                         if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
00408                                 $vals['userhidden'] = '';
00409                         } else {
00410                                 if ( $this->fld_user ) {
00411                                         $vals['user'] = $revision->getUserText();
00412                                 }
00413                                 $userid = $revision->getUser();
00414                                 if ( !$userid ) {
00415                                         $vals['anon'] = '';
00416                                 }
00417 
00418                                 if ( $this->fld_userid ) {
00419                                         $vals['userid'] = $userid;
00420                                 }
00421                         }
00422                 }
00423 
00424                 if ( $this->fld_timestamp ) {
00425                         $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $revision->getTimestamp() );
00426                 }
00427 
00428                 if ( $this->fld_size ) {
00429                         if ( !is_null( $revision->getSize() ) ) {
00430                                 $vals['size'] = intval( $revision->getSize() );
00431                         } else {
00432                                 $vals['size'] = 0;
00433                         }
00434                 }
00435 
00436                 if ( $this->fld_sha1 ) {
00437                         if ( $revision->getSha1() != '' ) {
00438                                 $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
00439                         } else {
00440                                 $vals['sha1'] = '';
00441                         }
00442                 }
00443 
00444                 if ( $this->fld_comment || $this->fld_parsedcomment ) {
00445                         if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
00446                                 $vals['commenthidden'] = '';
00447                         } else {
00448                                 $comment = $revision->getComment();
00449 
00450                                 if ( $this->fld_comment ) {
00451                                         $vals['comment'] = $comment;
00452                                 }
00453 
00454                                 if ( $this->fld_parsedcomment ) {
00455                                         $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
00456                                 }
00457                         }
00458                 }
00459 
00460                 if ( $this->fld_tags ) {
00461                         if ( $row->ts_tags ) {
00462                                 $tags = explode( ',', $row->ts_tags );
00463                                 $this->getResult()->setIndexedTagName( $tags, 'tag' );
00464                                 $vals['tags'] = $tags;
00465                         } else {
00466                                 $vals['tags'] = array();
00467                         }
00468                 }
00469 
00470                 if ( !is_null( $this->token ) ) {
00471                         $tokenFunctions = $this->getTokenFunctions();
00472                         foreach ( $this->token as $t ) {
00473                                 $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
00474                                 if ( $val === false ) {
00475                                         $this->setWarning( "Action '$t' is not allowed for the current user" );
00476                                 } else {
00477                                         $vals[$t . 'token'] = $val;
00478                                 }
00479                         }
00480                 }
00481 
00482                 $text = null;
00483                 global $wgParser;
00484                 if ( $this->fld_content || !is_null( $this->difftotext ) ) {
00485                         $text = $revision->getText();
00486                         // Expand templates after getting section content because
00487                         // template-added sections don't count and Parser::preprocess()
00488                         // will have less input
00489                         if ( $this->section !== false ) {
00490                                 $text = $wgParser->getSection( $text, $this->section, false );
00491                                 if ( $text === false ) {
00492                                         $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
00493                                 }
00494                         }
00495                 }
00496                 if ( $this->fld_content && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
00497                         if ( $this->generateXML ) {
00498                                 $wgParser->startExternalParse( $title, ParserOptions::newFromContext( $this->getContext() ), OT_PREPROCESS );
00499                                 $dom = $wgParser->preprocessToDom( $text );
00500                                 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
00501                                         $xml = $dom->saveXML();
00502                                 } else {
00503                                         $xml = $dom->__toString();
00504                                 }
00505                                 $vals['parsetree'] = $xml;
00506 
00507                         }
00508                         if ( $this->expandTemplates && !$this->parseContent ) {
00509                                 $text = $wgParser->preprocess( $text, $title, ParserOptions::newFromContext( $this->getContext() ) );
00510                         }
00511                         if ( $this->parseContent ) {
00512                                 $text = $wgParser->parse( $text, $title, ParserOptions::newFromContext( $this->getContext() ) )->getText();
00513                         }
00514                         ApiResult::setContent( $vals, $text );
00515                 } elseif ( $this->fld_content ) {
00516                         $vals['texthidden'] = '';
00517                 }
00518 
00519                 if ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
00520                         global $wgAPIMaxUncachedDiffs;
00521                         static $n = 0; // Number of uncached diffs we've had
00522                         if ( $n < $wgAPIMaxUncachedDiffs ) {
00523                                 $vals['diff'] = array();
00524                                 $context = new DerivativeContext( $this->getContext() );
00525                                 $context->setTitle( $title );
00526                                 if ( !is_null( $this->difftotext ) ) {
00527                                         $engine = new DifferenceEngine( $context );
00528                                         $engine->setText( $text, $this->difftotext );
00529                                 } else {
00530                                         $engine = new DifferenceEngine( $context, $revision->getID(), $this->diffto );
00531                                         $vals['diff']['from'] = $engine->getOldid();
00532                                         $vals['diff']['to'] = $engine->getNewid();
00533                                 }
00534                                 $difftext = $engine->getDiffBody();
00535                                 ApiResult::setContent( $vals['diff'], $difftext );
00536                                 if ( !$engine->wasCacheHit() ) {
00537                                         $n++;
00538                                 }
00539                         } else {
00540                                 $vals['diff']['notcached'] = '';
00541                         }
00542                 }
00543                 return $vals;
00544         }
00545 
00546         public function getCacheMode( $params ) {
00547                 if ( isset( $params['token'] ) ) {
00548                         return 'private';
00549                 }
00550                 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
00551                         // formatComment() calls wfMessage() among other things
00552                         return 'anon-public-user-private';
00553                 }
00554                 return 'public';
00555         }
00556 
00557         public function getAllowedParams() {
00558                 return array(
00559                         'prop' => array(
00560                                 ApiBase::PARAM_ISMULTI => true,
00561                                 ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
00562                                 ApiBase::PARAM_TYPE => array(
00563                                         'ids',
00564                                         'flags',
00565                                         'timestamp',
00566                                         'user',
00567                                         'userid',
00568                                         'size',
00569                                         'sha1',
00570                                         'comment',
00571                                         'parsedcomment',
00572                                         'content',
00573                                         'tags'
00574                                 )
00575                         ),
00576                         'limit' => array(
00577                                 ApiBase::PARAM_TYPE => 'limit',
00578                                 ApiBase::PARAM_MIN => 1,
00579                                 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
00580                                 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
00581                         ),
00582                         'startid' => array(
00583                                 ApiBase::PARAM_TYPE => 'integer'
00584                         ),
00585                         'endid' => array(
00586                                 ApiBase::PARAM_TYPE => 'integer'
00587                         ),
00588                         'start' => array(
00589                                 ApiBase::PARAM_TYPE => 'timestamp'
00590                         ),
00591                         'end' => array(
00592                                 ApiBase::PARAM_TYPE => 'timestamp'
00593                         ),
00594                         'dir' => array(
00595                                 ApiBase::PARAM_DFLT => 'older',
00596                                 ApiBase::PARAM_TYPE => array(
00597                                         'newer',
00598                                         'older'
00599                                 )
00600                         ),
00601                         'user' => array(
00602                                 ApiBase::PARAM_TYPE => 'user'
00603                         ),
00604                         'excludeuser' => array(
00605                                 ApiBase::PARAM_TYPE => 'user'
00606                         ),
00607                         'tag' => null,
00608                         'expandtemplates' => false,
00609                         'generatexml' => false,
00610                         'parse' => false,
00611                         'section' => null,
00612                         'token' => array(
00613                                 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
00614                                 ApiBase::PARAM_ISMULTI => true
00615                         ),
00616                         'continue' => null,
00617                         'diffto' => null,
00618                         'difftotext' => null,
00619                 );
00620         }
00621 
00622         public function getParamDescription() {
00623                 $p = $this->getModulePrefix();
00624                 return array(
00625                         'prop' => array(
00626                                 'Which properties to get for each revision:',
00627                                 ' ids            - The ID of the revision',
00628                                 ' flags          - Revision flags (minor)',
00629                                 ' timestamp      - The timestamp of the revision',
00630                                 ' user           - User that made the revision',
00631                                 ' userid         - User id of revision creator',
00632                                 ' size           - Length (bytes) of the revision',
00633                                 ' sha1           - SHA-1 (base 16) of the revision',
00634                                 ' comment        - Comment by the user for revision',
00635                                 ' parsedcomment  - Parsed comment by the user for the revision',
00636                                 ' content        - Text of the revision',
00637                                 ' tags           - Tags for the revision',
00638                         ),
00639                         'limit' => 'Limit how many revisions will be returned (enum)',
00640                         'startid' => 'From which revision id to start enumeration (enum)',
00641                         'endid' => 'Stop revision enumeration on this revid (enum)',
00642                         'start' => 'From which revision timestamp to start enumeration (enum)',
00643                         'end' => 'Enumerate up to this timestamp (enum)',
00644                         'dir' => $this->getDirectionDescription( $p, ' (enum)' ),
00645                         'user' => 'Only include revisions made by user (enum)',
00646                         'excludeuser' => 'Exclude revisions made by user (enum)',
00647                         'expandtemplates' => 'Expand templates in revision content',
00648                         'generatexml' => 'Generate XML parse tree for revision content',
00649                         'parse' => 'Parse revision content. For performance reasons if this option is used, rvlimit is enforced to 1.',
00650                         'section' => 'Only retrieve the content of this section number',
00651                         'token' => 'Which tokens to obtain for each revision',
00652                         'continue' => 'When more results are available, use this to continue',
00653                         'diffto' => array( 'Revision ID to diff each revision to.',
00654                                 'Use "prev", "next" and "cur" for the previous, next and current revision respectively' ),
00655                         'difftotext' => array( 'Text to diff each revision to. Only diffs a limited number of revisions.',
00656                                 "Overrides {$p}diffto. If {$p}section is set, only that section will be diffed against this text" ),
00657                         'tag' => 'Only list revisions tagged with this tag',
00658                 );
00659         }
00660 
00661         public function getResultProperties() {
00662                 $props = array(
00663                         '' => array(),
00664                         'ids' => array(
00665                                 'revid' => 'integer',
00666                                 'parentid' => array(
00667                                         ApiBase::PROP_TYPE => 'integer',
00668                                         ApiBase::PROP_NULLABLE => true
00669                                 )
00670                         ),
00671                         'flags' => array(
00672                                 'minor' => 'boolean'
00673                         ),
00674                         'user' => array(
00675                                 'userhidden' => 'boolean',
00676                                 'user' => 'string',
00677                                 'anon' => 'boolean'
00678                         ),
00679                         'userid' => array(
00680                                 'userhidden' => 'boolean',
00681                                 'userid' => 'integer',
00682                                 'anon' => 'boolean'
00683                         ),
00684                         'timestamp' => array(
00685                                 'timestamp' => 'timestamp'
00686                         ),
00687                         'size' => array(
00688                                 'size' => 'integer'
00689                         ),
00690                         'sha1' => array(
00691                                 'sha1' => 'string'
00692                         ),
00693                         'comment' => array(
00694                                 'commenthidden' => 'boolean',
00695                                 'comment' => array(
00696                                         ApiBase::PROP_TYPE => 'string',
00697                                         ApiBase::PROP_NULLABLE => true
00698                                 )
00699                         ),
00700                         'parsedcomment' => array(
00701                                 'commenthidden' => 'boolean',
00702                                 'parsedcomment' => array(
00703                                         ApiBase::PROP_TYPE => 'string',
00704                                         ApiBase::PROP_NULLABLE => true
00705                                 )
00706                         ),
00707                         'content' => array(
00708                                 '*' => array(
00709                                         ApiBase::PROP_TYPE => 'string',
00710                                         ApiBase::PROP_NULLABLE => true
00711                                 ),
00712                                 'texthidden' => 'boolean'
00713                         )
00714                 );
00715 
00716                 self::addTokenProperties( $props, $this->getTokenFunctions() );
00717 
00718                 return $props;
00719         }
00720 
00721         public function getDescription() {
00722                 return array(
00723                         'Get revision information',
00724                         'May be used in several ways:',
00725                         ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter',
00726                         ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params',
00727                         ' 3) Get data about a set of revisions by setting their IDs with revids parameter',
00728                         'All parameters marked as (enum) may only be used with a single page (#2)'
00729                 );
00730         }
00731 
00732         public function getPossibleErrors() {
00733                 return array_merge( parent::getPossibleErrors(), array(
00734                         array( 'nosuchrevid', 'diffto' ),
00735                         array( 'code' => 'revids', 'info' => 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).' ),
00736                         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.' ),
00737                         array( 'code' => 'diffto', 'info' => 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"' ),
00738                         array( 'code' => 'badparams', 'info' => 'start and startid cannot be used together' ),
00739                         array( 'code' => 'badparams', 'info' => 'end and endid cannot be used together' ),
00740                         array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together' ),
00741                         array( 'code' => 'nosuchsection', 'info' => 'There is no section section in rID' ),
00742                 ) );
00743         }
00744 
00745         public function getExamples() {
00746                 return array(
00747                         'Get data with content for the last revision of titles "API" and "Main Page"',
00748                         '  api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content',
00749                         'Get last 5 revisions of the "Main Page"',
00750                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment',
00751                         'Get first 5 revisions of the "Main Page"',
00752                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer',
00753                         'Get first 5 revisions of the "Main Page" made after 2006-05-01',
00754                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
00755                         'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
00756                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
00757                         'Get first 5 revisions of the "Main Page" that were made by the user "MediaWiki default"',
00758                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvuser=MediaWiki%20default',
00759                 );
00760         }
00761 
00762         public function getHelpUrls() {
00763                 return 'https://www.mediawiki.org/wiki/API:Properties#revisions_.2F_rv';
00764         }
00765 
00766         public function getVersion() {
00767                 return __CLASS__ . ': $Id$';
00768         }
00769 }