r59894 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59893‎ | r59894 | r59895 >
Date:18:34, 9 December 2009
Author:catrope
Status:ok
Tags:
Comment:
API: Add rvdifftotext parameter to prop=revisions to allow diffing to a fixed text instead of a revision
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -100,10 +100,13 @@
101101 if ($pageCount > 1 && $enumRevMode)
102102 $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');
103103
104 - if (!is_null($params['diffto'])) {
 104+ $this->diffto = $this->difftotext = null;
 105+ if (!is_null($params['difftotext'])) {
 106+ $this->difftotext = $params['difftotext'];
 107+ } else if (!is_null($params['diffto'])) {
105108 if ($params['diffto'] == 'cur')
106109 $params['diffto'] = 0;
107 - if ((!ctype_digit($params['diffto']) || $params['diffto'] < 0)
 110+ if ((!ctype_digit($params['diffto']) || $params['diffto'] < 0)
108111 && $params['diffto'] != 'prev' && $params['diffto'] != 'next')
109112 $this->dieUsage('rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto');
110113 // Check whether the revision exists and is readable,
@@ -118,6 +121,7 @@
119122 $params['diffto'] = null;
120123 }
121124 }
 125+ $this->diffto = $params['diffto'];
122126 }
123127
124128 $db = $this->getDB();
@@ -136,7 +140,6 @@
137141 $this->fld_size = isset ($prop['size']);
138142 $this->fld_user = isset ($prop['user']);
139143 $this->token = $params['token'];
140 - $this->diffto = $params['diffto'];
141144
142145 if ( !is_null($this->token) || $pageCount > 0) {
143146 $this->addFields( Revision::selectPageFields() );
@@ -155,7 +158,7 @@
156159 $this->addWhereFld('ct_tag' , $params['tag']);
157160 }
158161
159 - if (isset ($prop['content'])) {
 162+ if (isset($prop['content']) || !is_null($this->difftotext)) {
160163
161164 // For each page we will request, the user must have read rights for that page
162165 foreach ($pageSet->getGoodTitles() as $title) {
@@ -170,7 +173,7 @@
171174 $this->addFields('old_id');
172175 $this->addFields(Revision::selectTextFields());
173176
174 - $this->fld_content = true;
 177+ $this->fld_content = isset($prop['content']);
175178
176179 $this->expandTemplates = $params['expandtemplates'];
177180 $this->generateXML = $params['generatexml'];
@@ -389,7 +392,8 @@
390393 }
391394 }
392395
393 - if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
 396+ $text = null;
 397+ if ($this->fld_content || !is_null($this->difftotext)) {
394398 global $wgParser;
395399 $text = $revision->getText();
396400 # Expand templates after getting section content because
@@ -400,6 +404,8 @@
401405 if($text === false)
402406 $this->dieUsage("There is no section {$this->section} in r".$revision->getId(), 'nosuchsection');
403407 }
 408+ }
 409+ if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
404410 if ($this->generateXML) {
405411 $wgParser->startExternalParse( $title, new ParserOptions(), OT_PREPROCESS );
406412 $dom = $wgParser->preprocessToDom( $text );
@@ -419,14 +425,20 @@
420426 $vals['texthidden'] = '';
421427 }
422428
423 - if (!is_null($this->diffto)) {
 429+ if (!is_null($this->diffto) || !is_null($this->difftotext)) {
424430 global $wgAPIMaxUncachedDiffs;
425 - static $n = 0; // Numer of uncached diffs we've had
426 - if($n< $wgAPIMaxUncachedDiffs) {
427 - $engine = new DifferenceEngine($title, $revision->getID(), $this->diffto);
 431+ static $n = 0; // Number of uncached diffs we've had
 432+ if($n < $wgAPIMaxUncachedDiffs) {
 433+ $vals['diff'] = array();
 434+ if(!is_null($this->difftotext)) {
 435+ $engine = new DifferenceEngine($title);
 436+ $engine->setText($text, $this->difftotext);
 437+ } else {
 438+ $engine = new DifferenceEngine($title, $revision->getID(), $this->diffto);
 439+ $vals['diff']['from'] = $engine->getOldid();
 440+ $vals['diff']['to'] = $engine->getNewid();
 441+ }
428442 $difftext = $engine->getDiffBody();
429 - $vals['diff']['from'] = $engine->getOldid();
430 - $vals['diff']['to'] = $engine->getNewid();
431443 ApiResult::setContent($vals['diff'], $difftext);
432444 if(!$engine->wasCacheHit())
433445 $n++;
@@ -494,6 +506,7 @@
495507 ),
496508 'continue' => null,
497509 'diffto' => null,
 510+ 'difftotext' => null,
498511 );
499512 }
500513
@@ -515,6 +528,8 @@
516529 'continue' => 'When more results are available, use this to continue',
517530 'diffto' => array('Revision ID to diff each revision to.',
518531 'Use "prev", "next" and "cur" for the previous, next and current revision respectively.'),
 532+ 'difftotext' => array('Text to diff each revision to. Only diffs a limited number of revisions.',
 533+ 'Overrides diffto. If rvsection is set, only that section will be diffed against this text.'),
519534 'tag' => 'Only list revisions tagged with this tag',
520535 );
521536 }

Status & tagging log