PageRenderTime 857ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/api/ApiQueryRevisions.php

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