$result = new AncestorComparatorResult();
$diffengine = new WikiDiff3(10000, 1.35);
- $differences = $diffengine->diff_range($this->ancestorsText, $other->ancestorsText);
+ $differences = $diffengine->diff_range($other->ancestorsText,$this->ancestorsText);
if (count($differences) == 0){
return $result;
class ChangeTextGenerator {
- private $new;
- private $old;
+ private $ancestorComparator;
+ private $other;
private $factory;
- function __construct(AncestorComparator $old, AncestorComparator $new) {
- $this->new = $new;
- $this->old = $old;
+ function __construct(AncestorComparator $ancestorComparator, AncestorComparator $other) {
+ $this->ancestorComparator = $ancestorComparator;
+ $this->other = $other;
$this->factory = new TagToStringFactory();
}
public function getChanged(/*array*/ $differences) {
$txt = new ChangeText;
-
$rootlistopened = false;
-
if (count($differences) > 1) {
$txt->addHtml('<ul class="changelist">');
$rootlistopened = true;
}
-
$nbDifferences = count($differences);
for ($j = 0; $j < $nbDifferences; ++$j) {
$d = $differences[$j];
-
$lvl1listopened = false;
-
if ($rootlistopened) {
$txt->addHtml('<li>');
}
-
if ($d->leftlength + $d->rightlength > 1) {
$txt->addHtml('<ul class="changelist">');
$lvl1listopened = true;
}
-
// left are the old ones
for ($i = $d->leftstart; $i < $d->leftend; ++$i) {
if ($lvl1listopened){
$txt->addHtml('<li>');
}
// add a bullet for a old tag
- $this->addTagOld($txt, $this->old->ancestors[$i]);
-
+ $this->addTagOld($txt, $this->other->ancestors[$i]);
if ($lvl1listopened){
$txt->addHtml('</li>');
}
}
-
// right are the new ones
for ($i = $d->rightstart; $i < $d->rightend; ++$i) {
if ($lvl1listopened){
$txt->addHtml('<li>');
}
-
// add a bullet for a new tag
- $this->addTagNew($txt, $this->new->ancestors[$i]);
+ $this->addTagNew($txt, $this->ancestorComparator->ancestors[$i]);
if ($lvl1listopened){
$txt->addHtml('</li>');
}
-
}
-
if ($lvl1listopened) {
$txt->addHtml('</ul>');
}
-
if ($rootlistopened) {
$txt->addHtml('</li>');
}
}
-
if ($rootlistopened) {
$txt->addHtml('</ul>');
}
-
return $txt;
-
}
private function addTagOld(ChangeText $txt, TagNode $ancestor) {
private $txt = "";
- const newLine = "<br/>";
-
- public function addText($s) {
- $s = $this->clean($s);
- $this->txt .= $s;
- }
-
public function addHtml($s) {
$this->txt .= $s;
}
- public function addNewLine() {
- $this->addHtml(self::newLine);
- }
-
public function toString() {
return $this->txt;
}
-
- private function clean($s) {
- return htmlspecialchars($s);
- }
}
class TagToStringFactory {
}
public function getRemovedDescription(ChangeText $txt) {
+ $tagDescription = wfMsgExt('diff-' . $this->node->qName, 'parseinline' );
+ if(!$tagDescription){
+ $tagDescription = $this->node->qName;
+ }
if ($this->sem == TagToStringFactory::MOVED) {
- $txt->addText( $this->getString('diff-movedoutof') . ' ' . strtolower( $this->getString('diff-' . $this->node->qName . '-article') ) . ' ');
- $txt->addHtml('<b>');
- $txt->addText(strtolower( $this->getString('diff-' . $this->node->qName) ));
- $txt->addHtml('</b>');
+ $txt->addHtml( wfMsgExt( 'diff-movedoutof' , 'parseinline' ) . ' ' . $tagDescription );
} else if ($this->sem == TagToStringFactory::STYLE) {
- $txt->addHtml('<b>');
- $txt->addText( $this->getString('diff-' . $this->node->qName) );
- $txt->addHtml('</b>');
- $txt->addText(' ' . strtolower( $this->getString('diff-styleremoved') ) );
+ $txt->addHtml($tagDescription . ' ' . wfMsgExt( 'diff-styleremoved' , 'parseinline' ) );
} else {
- $txt->addHtml('<b>');
- $txt->addText( $this->getString('diff-' . $this->node->qName) );
- $txt->addHtml('</b>');
- $txt->addText(' ' . strtolower( $this->getString('diff-removed') ) );
+ $txt->addHtml($tagDescription . ' ' . wfMsgExt( 'diff-removed' , 'parseinline' ) );
}
$this->addAttributes($txt, $this->node->attributes);
- $txt->addText('.');
+ $txt->addHtml('.');
}
public function getAddedDescription(ChangeText $txt) {
+ $tagDescription = wfMsgExt('diff-' . $this->node->qName, 'parseinline' );
+ if(!$tagDescription){
+ $tagDescription = $this->node->qName;
+ }
if ($this->sem == TagToStringFactory::MOVED) {
- $txt->addText( $this->getString('diff-movedto') . ' ' . strtolower( $this->getString('diff-' . $this->node->qName . '-article') ) . ' ');
- $txt->addHtml('<b>');
- $txt->addText(strtolower( $this->getString('diff-' . $this->node->qName) ));
- $txt->addHtml('</b>');
+ $txt->addHtml( wfMsgExt( 'diff-movedto' , 'parseinline' ) . ' ' . $tagDescription);
} else if ($this->sem == TagToStringFactory::STYLE) {
- $txt->addHtml('<b>');
- $txt->addText( $this->getString('diff-' . $this->node->qName) );
- $txt->addHtml('</b>');
- $txt->addText(' ' . strtolower( $this->getString('diff-styleadded') ) );
+ $txt->addHtml($tagDescription . ' ' . wfMsgExt( 'diff-styleadded', 'parseinline' ) );
} else {
- $txt->addHtml('<b>');
- $txt->addText( $this->getString('diff-' . $this->node->qName) );
- $txt->addHtml('</b>');
- $txt->addText(' ' . strtolower( $this->getString('diff-added') ) );
+ $txt->addHtml($tagDescription . ' ' . wfMsgExt( 'diff-added', 'parseinline' ) );
}
$this->addAttributes($txt, $this->node->attributes);
- $txt->addText('.');
+ $txt->addHtml('.');
}
protected function addAttributes(ChangeText $txt, array $attributes) {
if (count($attributes) < 1) {
return;
}
-
$firstOne = true;
- $lastKey = null;
- foreach ($attributes as $key => &$attr) {
- $lastKey = $key;
+ $nbAttributes_min_1 = count($attributes)-1;
+ $keys = array_keys($attributes);
+ for ($i=0;$i<$nbAttributes_min_1;$i++) {
+ $key = $keys[$i];
+ $attr = $attributes[$key];
if($firstOne) {
$firstOne = false;
- $txt->addText(' ' . strtolower( $this->getString('diff-with') )
- . ' ' . $this->translateArgument($key) . ' '
- . $attr);
+ $txt->addHtml(' ' . wfMsgExt('diff-with', 'parseinline' ) . ' ' . $this->translateArgument($key) . ' '
+ . htmlspecialchars($attr));
continue;
}
- $txt->addText(', ' . $this->translateArgument($key) . ' '
- . $attr);
+ $txt->addHtml(', ' . $this->translateArgument($key) . ' ' . htmlspecialchars($attr));
}
- if (count($attributes) > 1) {
- $txt->addText(' '
- . strtolower( $this->getString('diff-and') )
- . ' '
- . $this->translateArgument($lastKey) . ' '
- . $attributes[$lastKey]);
+ if ($nbAttributes_min_1 > 0) {
+ $txt->addHtml(' ' . wfMsgExt('diff-and', 'parseinline' ) . ' ' . $this->translateArgument($keys[$nbAttributes_min_1]) . ' '
+ . htmlspecialchars($attributes[$keys[$nbAttributes_min_1]]));
}
}
protected function translateArgument($name) {
- return strtolower( $this->getString('diff-' . strtolower( $name ) ) );
- }
-
- public function getString($key) {
- return htmlspecialchars( wfMsgNoTrans( $key ) );
+ $translation = wfMsgExt('diff-' . $name, 'parseinline' );
+ if(!$translation){
+ $translation = $name;
+ }
+ return htmlspecialchars( $translation );
}
}
}
public function getAddedDescription(ChangeText $txt) {
- $txt.addText( $this->getString('diff-changedto') . ' ' + strtolower( $this->getString('diff-' . $this->node->qName . '-article') ) . ' ');
- $txt.addHtml('<b>');
- $txt.addText(strtolower( $this->getString('diff-' . $this->node->qName) ));
- $txt.addHtml('</b>');
-
+ $tagDescription = wfMsgExt('diff-' . $this->node->qName, 'parseinline' );
+ if(!$tagDescription){
+ $tagDescription = $this->node->qName;
+ }
+ $txt->addHtml( wfMsgExt('diff-changedto', 'parseinline' ) . ' ' . $tagDescription);
$this->addAttributes($txt, $this->node->attributes);
- $txt.addText('.');
+ $txt->addHtml('.');
}
public function getRemovedDescription(ChangeText $txt) {
- $txt.addText( $this->getString('diff-changedfrom') . ' ' + strtolower( $this->getString('diff-' . $this->node->qName . '-article') ) . ' ');
- $txt.addHtml('<b>');
- $txt.addText(strtolower( $this->getString('diff-' . $this->node->qName) ));
- $txt.addHtml('</b>');
-
+ $txt->addHtml( wfMsgExt('diff-changedfrom', 'parseinline' ) . ' ' . $tagDescription);
$this->addAttributes($txt, $this->node->attributes);
- $txt.addText('.');
+ $txt->addHtml('.');
}
}
protected function addAttributes(ChangeText $txt, array $attributes) {
if (array_key_exists('href', $attributes)) {
- $txt->addText(' ' . strtolower( $this->getString('diff-withdestination') ) . ' ' . $attributes['href']);
+ $txt->addHtml(' ' . wfMsgExt( 'diff-withdestination', 'parseinline' ) . ' ' . htmlspecialchars($attributes['href']));
unset($attributes['href']);
}
parent::addAttributes($txt, $attributes);
//tooltip
$handler->startElement('span', array('class' => 'tip'));
- $handler->characters($mod->changes);
+ $handler->html($mod->changes);
$handler->endElement('span');
$changeStarted = true;
}
function characters($chars){
- echo $chars;
+ echo htmlspecialchars($chars);
+ }
+
+ function html($html){
+ echo $html;
}
}
function characters($chars){
$this->delegate->addHtml(htmlspecialchars($chars));
}
+
+ function html($html){
+ $this->delegate->addHtml($html);
+ }
}
'wikicodecomparison' => 'Wikitext comparison',
'editundo' => 'undo',
'diff-multi' => '({{PLURAL:$1|One intermediate revision|$1 intermediate revisions}} not shown.)',
-'diff-movedto' => 'Moved to',
-'diff-styleadded' => 'Style added',
-'diff-added' => 'Added',
-'diff-changedto' => 'Changed to',
-'diff-movedoutof' => 'Moved out of',
-'diff-styleremoved' => 'Style removed',
-'diff-removed' => 'Removed',
-'diff-changedfrom' => 'Changed from',
-'diff-src' => 'Source',
-'diff-withdestination' => 'With destination',
-'diff-and' => 'And',
-'diff-with' => 'With',
-'diff-width' => 'Width',
-'diff-height' => 'Height',
-'diff-html-article' => 'A',
-'diff-html' => 'Html page',
-'diff-body-article' => 'A',
-'diff-body' => 'Html document',
-'diff-p-article' => 'A',
-'diff-p' => 'Paragraph',
-'diff-blockquote-article' => 'A',
-'diff-blockquote' => 'Quote',
-'diff-h1-article' => 'A',
-'diff-h1' => 'Heading (level 1)',
-'diff-h2-article' => 'A',
-'diff-h2' => 'Heading (level 2)',
-'diff-h3-article' => 'A',
-'diff-h3' => 'Heading (level 3)',
-'diff-h4-article' => 'A',
-'diff-h4' => 'Heading (level 4)',
-'diff-h5-article' => 'A',
-'diff-h5' => 'Heading (level 5)',
-'diff-pre-article' => 'A',
-'diff-pre' => 'Preformatted block',
-'diff-div-article' => 'A',
-'diff-div' => 'Division',
-'diff-ul-article' => 'An',
-'diff-ul' => 'Unordered list',
-'diff-ol-article' => 'An',
-'diff-ol' => 'Ordered list',
-'diff-li-article' => 'A',
-'diff-li' => 'List item',
-'diff-table-article' => 'A',
-'diff-table' => 'Table',
-'diff-tbody-article' => 'A',
-'diff-tbody' => "Table's content",
-'diff-tr-article' => 'A',
-'diff-tr' => 'Row',
-'diff-td-article' => 'A',
-'diff-td' => 'Cell',
-'diff-th-article' => 'A',
-'diff-th' => 'Header',
-'diff-br-article' => 'A',
-'diff-br' => 'Break',
-'diff-hr-article' => 'A',
-'diff-hr' => 'Horizontal rule',
-'diff-code-article' => 'A',
-'diff-code' => 'Computer code block',
-'diff-dl-article' => 'A',
-'diff-dl' => 'Definition list',
-'diff-dt-article' => 'A',
-'diff-dt' => 'Definition term',
-'diff-dd-article' => 'A',
-'diff-dd' => 'Definition',
-'diff-input-article' => 'An',
-'diff-input' => 'Input',
-'diff-form-article' => 'A',
-'diff-form' => 'Form',
-'diff-img-article' => 'An',
-'diff-img' => 'Image',
-'diff-span-article' => 'A',
-'diff-span' => 'Span',
-'diff-a-article' => 'A',
-'diff-a' => 'Link',
-'diff-i' => 'Italics',
-'diff-b' => 'Bold',
-'diff-strong' => 'Strong',
-'diff-em' => 'Emphasis',
-'diff-font' => 'Font',
-'diff-big' => 'Big',
-'diff-del' => 'Deleted',
-'diff-tt' => 'Fixed width',
-'diff-sub' => 'Subscript',
-'diff-sup' => 'Superscript',
-'diff-strike' => 'Strikethrough',
+'diff-movedto' => 'moved to',
+'diff-styleadded' => 'style added',
+'diff-added' => 'added',
+'diff-changedto' => 'changed to',
+'diff-movedoutof' => 'moved out of',
+'diff-styleremoved' => 'style removed',
+'diff-removed' => 'removed',
+'diff-changedfrom' => 'changed from',
+'diff-src' => 'source',
+'diff-withdestination' => 'with destination',
+'diff-and' => 'and',
+'diff-with' => 'with',
+'diff-width' => 'width',
+'diff-height' => 'height',
+'diff-p' => "a '''paragraph'''",
+'diff-blockquote' => "a '''quote'''",
+'diff-h1' => "a '''heading (level 1)'''",
+'diff-h2' => "a '''heading (level 2)'''",
+'diff-h3' => "a '''heading (level 3)'''",
+'diff-h4' => "a '''heading (level 4)'''",
+'diff-h5' => "a '''heading (level 5)'''",
+'diff-pre' => "a '''preformatted block'''",
+'diff-div' => "a '''division'''",
+'diff-ul' => "an '''unordered list'''",
+'diff-ol' => "an '''ordered list'''",
+'diff-li' => "a '''list item'''",
+'diff-table' => "a '''table'''",
+'diff-tbody' => "a '''table's content'''",
+'diff-tr' => "a '''row'''",
+'diff-td' => "a '''cell'''",
+'diff-th' => "a '''header'''",
+'diff-br' => "a '''break'''",
+'diff-hr' => "a '''horizontal rule'''",
+'diff-code' => "a '''computer code block'''",
+'diff-dl' => "a '''definition list'''",
+'diff-dt' => "a '''definition term'''",
+'diff-dd' => "a '''definition'''",
+'diff-input' => "an '''input'''",
+'diff-form' => "a '''form'''",
+'diff-img' => "an '''image'''",
+'diff-span' => "a '''span'''",
+'diff-a' => "a '''link'''",
+'diff-i' => "'''italics'''",
+'diff-b' => "'''bold'''",
+'diff-strong' => "'''strong'''",
+'diff-em' => "'''emphasis'''",
+'diff-font' => "'''font'''",
+'diff-big' => "'''big'''",
+'diff-del' => "'''deleted'''",
+'diff-tt' => "'''fixed width'''",
+'diff-sub' => "'''subscript'''",
+'diff-sup' => "'''superscript'''",
+'diff-strike' => "'''strikethrough'''",
# Search results
'searchresults' => 'Search results',