Index: trunk/phase3/includes/api/ApiQueryRevisions.php |
— | — | @@ -100,10 +100,13 @@ |
101 | 101 | if ($pageCount > 1 && $enumRevMode) |
102 | 102 | $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'); |
103 | 103 | |
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'])) { |
105 | 108 | if ($params['diffto'] == 'cur') |
106 | 109 | $params['diffto'] = 0; |
107 | | - if ((!ctype_digit($params['diffto']) || $params['diffto'] < 0) |
| 110 | + if ((!ctype_digit($params['diffto']) || $params['diffto'] < 0) |
108 | 111 | && $params['diffto'] != 'prev' && $params['diffto'] != 'next') |
109 | 112 | $this->dieUsage('rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto'); |
110 | 113 | // Check whether the revision exists and is readable, |
— | — | @@ -118,6 +121,7 @@ |
119 | 122 | $params['diffto'] = null; |
120 | 123 | } |
121 | 124 | } |
| 125 | + $this->diffto = $params['diffto']; |
122 | 126 | } |
123 | 127 | |
124 | 128 | $db = $this->getDB(); |
— | — | @@ -136,7 +140,6 @@ |
137 | 141 | $this->fld_size = isset ($prop['size']); |
138 | 142 | $this->fld_user = isset ($prop['user']); |
139 | 143 | $this->token = $params['token']; |
140 | | - $this->diffto = $params['diffto']; |
141 | 144 | |
142 | 145 | if ( !is_null($this->token) || $pageCount > 0) { |
143 | 146 | $this->addFields( Revision::selectPageFields() ); |
— | — | @@ -155,7 +158,7 @@ |
156 | 159 | $this->addWhereFld('ct_tag' , $params['tag']); |
157 | 160 | } |
158 | 161 | |
159 | | - if (isset ($prop['content'])) { |
| 162 | + if (isset($prop['content']) || !is_null($this->difftotext)) { |
160 | 163 | |
161 | 164 | // For each page we will request, the user must have read rights for that page |
162 | 165 | foreach ($pageSet->getGoodTitles() as $title) { |
— | — | @@ -170,7 +173,7 @@ |
171 | 174 | $this->addFields('old_id'); |
172 | 175 | $this->addFields(Revision::selectTextFields()); |
173 | 176 | |
174 | | - $this->fld_content = true; |
| 177 | + $this->fld_content = isset($prop['content']); |
175 | 178 | |
176 | 179 | $this->expandTemplates = $params['expandtemplates']; |
177 | 180 | $this->generateXML = $params['generatexml']; |
— | — | @@ -389,7 +392,8 @@ |
390 | 393 | } |
391 | 394 | } |
392 | 395 | |
393 | | - if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) { |
| 396 | + $text = null; |
| 397 | + if ($this->fld_content || !is_null($this->difftotext)) { |
394 | 398 | global $wgParser; |
395 | 399 | $text = $revision->getText(); |
396 | 400 | # Expand templates after getting section content because |
— | — | @@ -400,6 +404,8 @@ |
401 | 405 | if($text === false) |
402 | 406 | $this->dieUsage("There is no section {$this->section} in r".$revision->getId(), 'nosuchsection'); |
403 | 407 | } |
| 408 | + } |
| 409 | + if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) { |
404 | 410 | if ($this->generateXML) { |
405 | 411 | $wgParser->startExternalParse( $title, new ParserOptions(), OT_PREPROCESS ); |
406 | 412 | $dom = $wgParser->preprocessToDom( $text ); |
— | — | @@ -419,14 +425,20 @@ |
420 | 426 | $vals['texthidden'] = ''; |
421 | 427 | } |
422 | 428 | |
423 | | - if (!is_null($this->diffto)) { |
| 429 | + if (!is_null($this->diffto) || !is_null($this->difftotext)) { |
424 | 430 | 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 | + } |
428 | 442 | $difftext = $engine->getDiffBody(); |
429 | | - $vals['diff']['from'] = $engine->getOldid(); |
430 | | - $vals['diff']['to'] = $engine->getNewid(); |
431 | 443 | ApiResult::setContent($vals['diff'], $difftext); |
432 | 444 | if(!$engine->wasCacheHit()) |
433 | 445 | $n++; |
— | — | @@ -494,6 +506,7 @@ |
495 | 507 | ), |
496 | 508 | 'continue' => null, |
497 | 509 | 'diffto' => null, |
| 510 | + 'difftotext' => null, |
498 | 511 | ); |
499 | 512 | } |
500 | 513 | |
— | — | @@ -515,6 +528,8 @@ |
516 | 529 | 'continue' => 'When more results are available, use this to continue', |
517 | 530 | 'diffto' => array('Revision ID to diff each revision to.', |
518 | 531 | '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.'), |
519 | 534 | 'tag' => 'Only list revisions tagged with this tag', |
520 | 535 | ); |
521 | 536 | } |