DifferenceEngine: introduce setDiffLang() to change the language in which the diff...
authorRobin Pepermans <robin@users.mediawiki.org>
Sat, 23 Jul 2011 19:03:54 +0000 (19:03 +0000)
committerRobin Pepermans <robin@users.mediawiki.org>
Sat, 23 Jul 2011 19:03:54 +0000 (19:03 +0000)
Translate: set the the diff text according to the source language, on Special:PageTranslation and the translation messages. (Also fix direction of CSS class mw-translate-fuzzy).

includes/diff/DifferenceEngine.php

index aeb9b48..034f0da 100644 (file)
@@ -25,6 +25,7 @@ class DifferenceEngine {
        var $mOldid, $mNewid;
        var $mOldtitle, $mNewtitle, $mPagetitle;
        var $mOldtext, $mNewtext;
+       var $mDiffLang;
 
        /**
         * @var Title
@@ -74,6 +75,9 @@ class DifferenceEngine {
                }
                wfDebug( "DifferenceEngine old '$old' new '$new' rcid '$rcid'\n" );
 
+               # Default language in which the diff text is written.
+               $this->mDiffLang = $this->mTitle->getPageLanguage();
+
                if ( 'prev' === $new ) {
                        # Show diff between revision $old and the previous one.
                        # Get previous one from DB.
@@ -938,10 +942,9 @@ CONTROL;
         * @return string
         */
        function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
-               // shared.css sets diff in interface language/dir,
-               // but the actual content should be in the page language/dir
-               $pageLang = $this->mTitle->getPageLanguage();
-               $tableClass = 'diff diff-contentalign-' . htmlspecialchars( $pageLang->alignStart() );
+               // shared.css sets diff in interface language/dir, but the actual content
+               // is often in a different language, mostly the page content language/dir
+               $tableClass = 'diff diff-contentalign-' . htmlspecialchars( $this->mDiffLang->alignStart() );
                $header = "<table class='$tableClass'>";
                if ( $diff ) { // Safari/Chrome show broken output if cols not used
                        $header .= "
@@ -981,6 +984,15 @@ CONTROL;
                $this->mRevisionsLoaded = true;
        }
 
+       /**
+        * Set the language in which the diff text is written
+        * (Defaults to page content language).
+        * @since 1.19
+        */
+       function setDiffLang( $lang ) {
+               $this->mDiffLang = wfGetLangObj( $lang );
+       }
+
        /**
         * Load revision metadata for the specified articles. If newid is 0, then compare
         * the old article in oldid to the current article; if oldid is 0, then