Simplified i18n for HTMLDiff
authorGuy Van den Broeck <guyvdb@users.mediawiki.org>
Thu, 21 Aug 2008 18:32:53 +0000 (18:32 +0000)
committerGuy Van den Broeck <guyvdb@users.mediawiki.org>
Thu, 21 Aug 2008 18:32:53 +0000 (18:32 +0000)
includes/HTMLDiff.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc
skins/common/diff.css

index 1073af9..34bdc33 100644 (file)
@@ -1059,7 +1059,7 @@ class AncestorComparator {
                $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;
@@ -1075,85 +1075,69 @@ class AncestorComparator {
 
 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) {
@@ -1169,28 +1153,13 @@ class ChangeText {
 
        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 {
@@ -1241,82 +1210,68 @@ class TagToString {
        }
 
        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 );
        }
 }
 
@@ -1327,23 +1282,19 @@ class NoContentTagToString extends TagToString {
        }
 
        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('.');
        }
 }
 
@@ -1355,7 +1306,7 @@ class AnchorToString extends TagToString {
 
        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);
@@ -1437,7 +1388,7 @@ class HTMLOutput{
 
                                        //tooltip
                                        $handler->startElement('span', array('class' => 'tip'));
-                                       $handler->characters($mod->changes);
+                                       $handler->html($mod->changes);
                                        $handler->endElement('span');
 
                                        $changeStarted = true;
@@ -1529,7 +1480,11 @@ class EchoingContentHandler {
        }
 
        function characters($chars){
-               echo $chars;
+               echo htmlspecialchars($chars);
+       }
+
+       function html($html){
+               echo $html;
        }
 
 }
@@ -1553,4 +1508,8 @@ class DelegatingContentHandler {
        function characters($chars){
                $this->delegate->addHtml(htmlspecialchars($chars));
        }
+
+       function html($html){
+               $this->delegate->addHtml($html);
+       }
 }
index 4ce2c84..12cd590 100644 (file)
@@ -1331,91 +1331,59 @@ Note that using the navigation links will reset this column.',
 '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',
index 9951184..d7cc8f5 100644 (file)
@@ -691,8 +691,7 @@ $wgMessageStructure = array(
                'visualcomparison',
                'wikicodecomparison',
                'editundo',
-               'diff-multi',
-               'diff-movedto',
+               'diff-multi','diff-movedto',
                'diff-styleadded',
                'diff-added',
                'diff-changedto',
@@ -706,65 +705,33 @@ $wgMessageStructure = array(
                'diff-with',
                'diff-width',
                'diff-height',
-               'diff-html-article',
-               'diff-html',
-               'diff-body-article',
-               'diff-body',
-               'diff-p-article',
                'diff-p',
-               'diff-blockquote-article',
                'diff-blockquote',
-               'diff-h1-article',
                'diff-h1',
-               'diff-h2-article',
                'diff-h2',
-               'diff-h3-article',
                'diff-h3',
-               'diff-h4-article',
                'diff-h4',
-               'diff-h5-article',
                'diff-h5',
-               'diff-pre-article',
                'diff-pre',
-               'diff-div-article',
                'diff-div',
-               'diff-ul-article',
                'diff-ul',
-               'diff-ol-article',
                'diff-ol',
-               'diff-li-article',
                'diff-li',
-               'diff-table-article',
                'diff-table',
-               'diff-tbody-article',
                'diff-tbody',
-               'diff-tr-article',
                'diff-tr',
-               'diff-td-article',
                'diff-td',
-               'diff-th-article',
                'diff-th',
-               'diff-br-article',
                'diff-br',
-               'diff-hr-article',
                'diff-hr',
-               'diff-code-article',
                'diff-code',
-               'diff-dl-article',
                'diff-dl',
-               'diff-dt-article',
                'diff-dt',
-               'diff-dd-article',
                'diff-dd',
-               'diff-input-article',
                'diff-input',
-               'diff-form-article',
                'diff-form',
-               'diff-img-article',
                'diff-img',
-               'diff-span-article',
                'diff-span',
-               'diff-a-article',
                'diff-a',
                'diff-i',
                'diff-b',
index 23de785..9caa83e 100644 (file)
@@ -135,10 +135,7 @@ span.diff-html-changed:hover span.tip {
   padding: 3px 7px 4px 6px;
   border: 1px solid #336;
   background-color: #f7f7ee;
-  font-family: arial, helvetica, sans-serif;
   font-size: 10px;
-  font-weight: normal;
-  color: #000;
   text-align: left;
 }