PageRenderTime 66ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/api/ApiQueryRevisions.php

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