if ($pageCount > 1 && $enumRevMode)
$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');
- if (!is_null($params['diffto'])) {
+ $this->diffto = $this->difftotext = null;
+ if (!is_null($params['difftotext'])) {
+ $this->difftotext = $params['difftotext'];
+ } else if (!is_null($params['diffto'])) {
if ($params['diffto'] == 'cur')
$params['diffto'] = 0;
- if ((!ctype_digit($params['diffto']) || $params['diffto'] < 0)
+ if ((!ctype_digit($params['diffto']) || $params['diffto'] < 0)
&& $params['diffto'] != 'prev' && $params['diffto'] != 'next')
$this->dieUsage('rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto');
// Check whether the revision exists and is readable,
$params['diffto'] = null;
}
}
+ $this->diffto = $params['diffto'];
}
$db = $this->getDB();
$this->fld_size = isset ($prop['size']);
$this->fld_user = isset ($prop['user']);
$this->token = $params['token'];
- $this->diffto = $params['diffto'];
if ( !is_null($this->token) || $pageCount > 0) {
$this->addFields( Revision::selectPageFields() );
$this->addWhereFld('ct_tag' , $params['tag']);
}
- if (isset ($prop['content'])) {
+ if (isset($prop['content']) || !is_null($this->difftotext)) {
// For each page we will request, the user must have read rights for that page
foreach ($pageSet->getGoodTitles() as $title) {
$this->addFields('old_id');
$this->addFields(Revision::selectTextFields());
- $this->fld_content = true;
+ $this->fld_content = isset($prop['content']);
$this->expandTemplates = $params['expandtemplates'];
$this->generateXML = $params['generatexml'];
}
}
- if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
+ $text = null;
+ if ($this->fld_content || !is_null($this->difftotext)) {
global $wgParser;
$text = $revision->getText();
# Expand templates after getting section content because
if($text === false)
$this->dieUsage("There is no section {$this->section} in r".$revision->getId(), 'nosuchsection');
}
+ }
+ if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
if ($this->generateXML) {
$wgParser->startExternalParse( $title, new ParserOptions(), OT_PREPROCESS );
$dom = $wgParser->preprocessToDom( $text );
$vals['texthidden'] = '';
}
- if (!is_null($this->diffto)) {
+ if (!is_null($this->diffto) || !is_null($this->difftotext)) {
global $wgAPIMaxUncachedDiffs;
- static $n = 0; // Numer of uncached diffs we've had
- if($n< $wgAPIMaxUncachedDiffs) {
- $engine = new DifferenceEngine($title, $revision->getID(), $this->diffto);
+ static $n = 0; // Number of uncached diffs we've had
+ if($n < $wgAPIMaxUncachedDiffs) {
+ $vals['diff'] = array();
+ if(!is_null($this->difftotext)) {
+ $engine = new DifferenceEngine($title);
+ $engine->setText($text, $this->difftotext);
+ } else {
+ $engine = new DifferenceEngine($title, $revision->getID(), $this->diffto);
+ $vals['diff']['from'] = $engine->getOldid();
+ $vals['diff']['to'] = $engine->getNewid();
+ }
$difftext = $engine->getDiffBody();
- $vals['diff']['from'] = $engine->getOldid();
- $vals['diff']['to'] = $engine->getNewid();
ApiResult::setContent($vals['diff'], $difftext);
if(!$engine->wasCacheHit())
$n++;
),
'continue' => null,
'diffto' => null,
+ 'difftotext' => null,
);
}
'continue' => 'When more results are available, use this to continue',
'diffto' => array('Revision ID to diff each revision to.',
'Use "prev", "next" and "cur" for the previous, next and current revision respectively.'),
+ 'difftotext' => array('Text to diff each revision to. Only diffs a limited number of revisions.',
+ 'Overrides diffto. If rvsection is set, only that section will be diffed against this text.'),
'tag' => 'Only list revisions tagged with this tag',
);
}