name
* (bug 11206) api.php should honor maxlag
* Added diff generation to prop=revisions
+* Added support for traditional, unified and array diffs to prop=revisions
=== Languages updated in 1.12 ===
'Diff' => 'includes/DifferenceEngine.php',
'MappedDiff' => 'includes/DifferenceEngine.php',
'DiffFormatter' => 'includes/DifferenceEngine.php',
+ 'UnifiedDiffFormatter' => 'includes/DifferenceEngine.php',
+ 'ArrayDiffFormatter' => 'includes/DifferenceEngine.php',
'DjVuImage' => 'includes/DjVuImage.php',
'_HWLDF_WordAccumulator' => 'includes/DifferenceEngine.php',
'WordLevelDiff' => 'includes/DifferenceEngine.php',
}
}
+/**
+ * A formatter that outputs unified diffs
+ * @addtogroup DifferenceEngine
+ */
+
+class UnifiedDiffFormatter extends DiffFormatter
+{
+ var $leading_context_lines = 2;
+ var $trailing_context_lines = 2;
+
+ function _added($lines) {
+ $this->_lines($lines, '+');
+ }
+ function _deleted($lines) {
+ $this->_lines($lines, '-');
+ }
+ function _changed($orig, $closing) {
+ $this->_deleted($orig);
+ $this->_added($closing);
+ }
+ function _block_header($xbeg, $xlen, $ybeg, $ylen) {
+ return "@@ -$xbeg,$xlen +$ybeg,$ylen @@";
+ }
+}
+
+/**
+ * A pseudo-formatter that just passes along the Diff::$edits array
+ * @addtogroup DifferenceEngine
+ */
+class ArrayDiffFormatter extends DiffFormatter
+{
+ function format($diff)
+ {
+ $oldline = 1;
+ $newline = 1;
+ $retval = array();
+ foreach($diff->edits as $edit)
+ switch($edit->type)
+ {
+ case 'add':
+ foreach($edit->closing as $l)
+ {
+ $retval[] = array(
+ 'action' => 'add',
+ 'new'=> $l,
+ 'newline' => $newline++
+ );
+ }
+ break;
+ case 'delete':
+ foreach($edit->orig as $l)
+ {
+ $retval[] = array(
+ 'action' => 'delete',
+ 'old' => $l,
+ 'oldline' => $oldline++,
+ );
+ }
+ break;
+ case 'change':
+ foreach($edit->orig as $i => $l)
+ {
+ $retval[] = array(
+ 'action' => 'change',
+ 'old' => $l,
+ 'new' => $edit->closing[$i],
+ 'oldline' => $oldline++,
+ 'newline' => $newline++,
+ );
+ }
+ break;
+ case 'copy':
+ $oldline += count($edit->orig);
+ $newline += count($edit->orig);
+ }
+ return $retval;
+ }
+}
/**
* Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
$fld_comment = false, $fld_user = false, $fld_content = false;
public function execute() {
- $limit = $startid = $endid = $start = $end = $dir = $prop = $user = $excludeuser = $diffto = $difftoprev = null;
+ $limit = $startid = $endid = $start = $end = $dir = $prop = $user = $excludeuser = $diffto = $difftoprev = $diffformat = null;
extract($this->extractRequestParams());
// If any of those parameters are used, work in 'enumeration' mode.
$this->fld_size = $this->addFieldsIf('rev_len', isset ($prop['size']));
if($diffto || $difftoprev)
- $this->formatter = new DiffFormatter;
+ switch($diffformat)
+ {
+ case 'traditional':
+ $this->formatter = new DiffFormatter;
+ break;
+ case 'unified':
+ $this->formatter = new UnifiedDiffFormatter;
+ break;
+ case 'array':
+ $this->formatter = new ArrayDiffFormatter;
+ }
if($diffto)
{
global $wgContLang;
$newText = explode("\n", $wgContLang->segmentForDiff($revtext));
$diff = new Diff($oldText, $newText);
$r['from'] = $previousRevID;
- ApiResult::setContent($r, $wgContLang->unsegmentForDiff($this->formatter->format($diff)));
+ $formatted = $this->formatter->format($diff);
+ if(!is_array($formatted))
+ ApiResult::setContent($r, $wgContLang->unsegmentForDiff($this->formatter->format($diff)));
+ else
+ {
+ $r['differences'] = $formatted;
+ $this->getResult()->setIndexedTagName($r['differences'], 'diff');
+ }
$this->diffArr[$revid] = $r;
$previousRevID = $revid;
ApiBase :: PARAM_TYPE => 'integer'
),
'difftoprev' => false,
+ 'diffformat' => array(
+ ApiBase :: PARAM_TYPE => array(
+ 'traditional',
+ 'unified',
+ 'array',
+ ),
+ ApiBase ::PARAM_DFLT => 'unified'
+ )
);
}
'expandtemplates' => 'expand templates in revision content',
'diffto' => 'Revision number to compare all revisions with',
'difftoprev' => 'Diff each revision to the previous one (enum)',
+ 'diffformat' => 'Format to use for diffs',
);
}