Merge "Localisation updates from http://translatewiki.net."
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 9 Nov 2013 09:20:31 +0000 (09:20 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 9 Nov 2013 09:20:31 +0000 (09:20 +0000)
21 files changed:
docs/memcached.txt
includes/Article.php
includes/AutoLoader.php
includes/SkinTemplate.php
includes/api/ApiBase.php
includes/api/ApiProtect.php
includes/api/ApiQuerySiteinfo.php
includes/api/ApiUpload.php
includes/diff/ArrayDiffFormatter.php [new file with mode: 0644]
includes/diff/DairikiDiff.php
includes/diff/DiffFormatter.php [new file with mode: 0644]
includes/diff/DifferenceEngine.php
includes/diff/TableDiffFormatter.php [new file with mode: 0644]
includes/diff/UnifiedDiffFormatter.php [new file with mode: 0644]
includes/filebackend/SwiftFileBackend.php
includes/specials/SpecialSearch.php
includes/specials/SpecialUpload.php
includes/specials/SpecialWatchlist.php
maintenance/backup.inc
maintenance/backupTextPass.inc
resources/mediawiki.special/mediawiki.special.search.css

index 16c5760..e5c597d 100644 (file)
@@ -105,7 +105,7 @@ Date Formatter:
        expiry: one hour
 
 Difference Engine:
-       key: $wgDBname:diff:version:{MW_DIFF_VERSION}:oldid:$old:newid:$new
+       key: $wgDBname:diff:version:{DifferenceEngine::CACHE_VERSION}:oldid:$old:newid:$new
        ex: wikidb:diff:version:1.11a:oldid:1:newid:2
        stores: body of a difference
        cleared by: nothing
index a6afd8e..701dae9 100644 (file)
@@ -812,7 +812,7 @@ class Article implements Page {
                $de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
 
                // DifferenceEngine directly fetched the revision:
-               $this->mRevIdFetched = $de->mNewid;
+               $this->mRevIdFetched = $de->getNewid();
                $de->showDiffPage( $diffOnly );
 
                // Run view updates for the newer revision being diffed (and shown below the diff if not $diffOnly)
index 29d2209..f73f24b 100644 (file)
@@ -505,21 +505,21 @@ $wgAutoloadLocalClasses = array(
        'ViewCountUpdate' => 'includes/deferred/ViewCountUpdate.php',
 
        # includes/diff
-       '_DiffEngine' => 'includes/diff/DairikiDiff.php',
-       '_DiffOp' => 'includes/diff/DairikiDiff.php',
-       '_DiffOp_Add' => 'includes/diff/DairikiDiff.php',
-       '_DiffOp_Change' => 'includes/diff/DairikiDiff.php',
-       '_DiffOp_Copy' => 'includes/diff/DairikiDiff.php',
-       '_DiffOp_Delete' => 'includes/diff/DairikiDiff.php',
-       '_HWLDF_WordAccumulator' => 'includes/diff/DairikiDiff.php',
-       'ArrayDiffFormatter' => 'includes/diff/DairikiDiff.php',
+       'DiffEngine' => 'includes/diff/DairikiDiff.php',
+       'DiffOp' => 'includes/diff/DairikiDiff.php',
+       'DiffOp_Add' => 'includes/diff/DairikiDiff.php',
+       'DiffOp_Change' => 'includes/diff/DairikiDiff.php',
+       'DiffOp_Copy' => 'includes/diff/DairikiDiff.php',
+       'DiffOp_Delete' => 'includes/diff/DairikiDiff.php',
+       'HWLDF_WordAccumulator' => 'includes/diff/DairikiDiff.php',
+       'ArrayDiffFormatter' => 'includes/diff/ArrayDiffFormatter.php',
        'Diff' => 'includes/diff/DairikiDiff.php',
        'DifferenceEngine' => 'includes/diff/DifferenceEngine.php',
-       'DiffFormatter' => 'includes/diff/DairikiDiff.php',
+       'DiffFormatter' => 'includes/diff/DiffFormatter.php',
        'MappedDiff' => 'includes/diff/DairikiDiff.php',
        'RangeDifference' => 'includes/diff/WikiDiff3.php',
-       'TableDiffFormatter' => 'includes/diff/DairikiDiff.php',
-       'UnifiedDiffFormatter' => 'includes/diff/DairikiDiff.php',
+       'TableDiffFormatter' => 'includes/diff/TableDiffFormatter.php',
+       'UnifiedDiffFormatter' => 'includes/diff/UnifiedDiffFormatter.php',
        'WikiDiff3' => 'includes/diff/WikiDiff3.php',
        'WordLevelDiff' => 'includes/diff/DairikiDiff.php',
 
index 1e7ce13..f25545d 100644 (file)
@@ -217,15 +217,6 @@ class SkinTemplate extends Skin {
         * @param $out OutputPage
         */
        function outputPage( OutputPage $out = null ) {
-               global $wgContLang;
-               global $wgScript, $wgStylePath;
-               global $wgMimeType, $wgJsMimeType;
-               global $wgXhtmlNamespaces, $wgHtml5Version;
-               global $wgDisableCounters, $wgSitename, $wgLogo;
-               global $wgMaxCredits, $wgShowCreditsIfMax;
-               global $wgPageShowWatchingUsers;
-               global $wgArticlePath, $wgScriptPath, $wgServer;
-
                wfProfileIn( __METHOD__ );
                Profiler::instance()->setTemplated( true );
 
@@ -237,14 +228,41 @@ class SkinTemplate extends Skin {
                }
 
                $out = $this->getOutput();
-               $request = $this->getRequest();
                $user = $this->getUser();
-               $title = $this->getTitle();
 
                wfProfileIn( __METHOD__ . '-init' );
                $this->initPage( $out );
                wfProfileOut( __METHOD__ . '-init' );
+               $tpl = $this->prepareQuickTemplate( $out );
+               // execute template
+               wfProfileIn( __METHOD__ . '-execute' );
+               $res = $tpl->execute();
+               wfProfileOut( __METHOD__ . '-execute' );
+
+               // result may be an error
+               $this->printOrError( $res );
 
+               if ( $oldContext ) {
+                       $this->setContext( $oldContext );
+               }
+       }
+
+       /**
+        * initialize various variables and generate the template
+        *
+        * @since 1.23
+        * @param $out OutputPage
+        * @return QuickTemplate the template to be executed by outputPage
+        */
+       protected function prepareQuickTemplate( OutputPage $out = null ) {
+               global $wgContLang, $wgScript, $wgStylePath,
+                       $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
+                       $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
+                       $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
+                       $wgScriptPath, $wgServer;
+
+               $title = $this->getTitle();
+               $request = $this->getRequest();
                $tpl = $this->setupTemplateForOutput();
 
                wfProfileIn( __METHOD__ . '-stuff-head' );
@@ -523,18 +541,8 @@ class SkinTemplate extends Skin {
                $tpl->set( 'dataAfterContent', $this->afterContentHook() );
                wfProfileOut( __METHOD__ . '-stuff5' );
 
-               // execute template
-               wfProfileIn( __METHOD__ . '-execute' );
-               $res = $tpl->execute();
-               wfProfileOut( __METHOD__ . '-execute' );
-
-               // result may be an error
-               $this->printOrError( $res );
-
-               if ( $oldContext ) {
-                       $this->setContext( $oldContext );
-               }
                wfProfileOut( __METHOD__ );
+               return $tpl;
        }
 
        /**
index ce6ecda..6be044c 100644 (file)
@@ -818,7 +818,7 @@ abstract class ApiBase extends ContextSource {
         * @param string $watchlist Valid values: 'watch', 'unwatch', 'preferences', 'nochange'
         * @param $titleObj Title the page under consideration
         * @param string $userOption The user option to consider when $watchlist=preferences.
-        *      If not set will magically default to either watchdefault or watchcreations
+        *      If not set will use watchdefault always and watchcreations if $titleObj doesn't exist.
         * @return bool
         */
        protected function getWatchlistValue( $watchlist, $titleObj, $userOption = null ) {
@@ -837,10 +837,10 @@ abstract class ApiBase extends ContextSource {
                                if ( $userWatching ) {
                                        return true;
                                }
-                               # If no user option was passed, use watchdefault or watchcreations
+                               # If no user option was passed, use watchdefault and watchcreations
                                if ( is_null( $userOption ) ) {
-                                       $userOption = $titleObj->exists()
-                                                       ? 'watchdefault' : 'watchcreations';
+                                       return $this->getUser()->getBoolOption( 'watchdefault' ) ||
+                                               $this->getUser()->getBoolOption( 'watchcreations' ) && !$titleObj->exists();
                                }
                                # Watch the article based on the user preference
                                return $this->getUser()->getBoolOption( $userOption );
index 7830c8b..428eef3 100644 (file)
@@ -98,7 +98,7 @@ class ApiProtect extends ApiBase {
                $cascade = $params['cascade'];
 
                $watch = $params['watch'] ? 'watch' : $params['watchlist'];
-               $this->setWatch( $watch, $titleObj );
+               $this->setWatch( $watch, $titleObj, 'watchdefault' );
 
                $status = $pageObj->doUpdateRestrictions( $protections, $expiryarray, $cascade, $params['reason'], $this->getUser() );
 
index ac9e85a..ebd3fc0 100644 (file)
@@ -361,7 +361,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        if ( $row['iw_local'] == '1' ) {
                                $val['local'] = '';
                        }
-                       // $val['trans'] = intval( $row['iw_trans'] ); // should this be exposed?
+                       if ( $row['iw_trans'] == '1' ) {
+                               $val['trans'] = '';
+                       }
                        if ( isset( $langNames[$prefix] ) ) {
                                $val['language'] = $langNames[$prefix];
                        }
index 467eccf..5839edc 100644 (file)
@@ -587,7 +587,19 @@ class ApiUpload extends ApiBase {
 
                /** @var $file File */
                $file = $this->mUpload->getLocalFile();
-               $watch = $this->getWatchlistValue( $this->mParams['watchlist'], $file->getTitle() );
+
+               // For preferences mode, we want to watch if 'watchdefault' is set or
+               // if the *file* doesn't exist and 'watchcreations' is set. But
+               // getWatchlistValue()'s automatic handling checks if the *title*
+               // exists or not, so we need to check both prefs manually.
+               $watch = $this->getWatchlistValue(
+                       $this->mParams['watchlist'], $file->getTitle(), 'watchdefault'
+               );
+               if ( !$watch && $this->mParams['watchlist'] == 'preferences' && !$file->exists() ) {
+                       $watch = $this->getWatchlistValue(
+                               $this->mParams['watchlist'], $file->getTitle(), 'watchcreations'
+                       );
+               }
 
                // Deprecated parameters
                if ( $this->mParams['watch'] ) {
diff --git a/includes/diff/ArrayDiffFormatter.php b/includes/diff/ArrayDiffFormatter.php
new file mode 100644 (file)
index 0000000..7da6905
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Portions taken from phpwiki-1.3.3.
+ *
+ * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
+ * You may copy this code freely under the conditions of the GPL.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup DifferenceEngine
+ */
+
+/**
+ * A pseudo-formatter that just passes along the Diff::$edits array
+ * @ingroup DifferenceEngine
+ */
+class ArrayDiffFormatter extends DiffFormatter {
+
+       /**
+        * @param $diff
+        * @return array
+        */
+       public 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' => isset( $edit->closing[$i] ) ? $edit->closing[$i] : null,
+                                                       'oldline' => $oldline++,
+                                                       'newline' => $newline++,
+                                               );
+                                       }
+                                       break;
+                               case 'copy':
+                                       $oldline += count( $edit->orig );
+                                       $newline += count( $edit->orig );
+                       }
+               }
+               return $retval;
+       }
+}
index 298d724..53e80c4 100644 (file)
  * @private
  * @ingroup DifferenceEngine
  */
-class _DiffOp {
-       var $type;
-       var $orig;
-       var $closing;
+abstract class DiffOp {
+       public $type;
+       public $orig;
+       public $closing;
 
-       function reverse() {
-               trigger_error( 'pure virtual', E_USER_ERROR );
-       }
+       public abstract function reverse();
 
        /**
         * @return int
@@ -59,8 +57,8 @@ class _DiffOp {
  * @private
  * @ingroup DifferenceEngine
  */
-class _DiffOp_Copy extends _DiffOp {
-       var $type = 'copy';
+class DiffOp_Copy extends DiffOp {
+       public $type = 'copy';
 
        function __construct( $orig, $closing = false ) {
                if ( !is_array( $closing ) ) {
@@ -71,10 +69,10 @@ class _DiffOp_Copy extends _DiffOp {
        }
 
        /**
-        * @return _DiffOp_Copy
+        * @return DiffOp_Copy
         */
        function reverse() {
-               return new _DiffOp_Copy( $this->closing, $this->orig );
+               return new DiffOp_Copy( $this->closing, $this->orig );
        }
 }
 
@@ -83,8 +81,8 @@ class _DiffOp_Copy extends _DiffOp {
  * @private
  * @ingroup DifferenceEngine
  */
-class _DiffOp_Delete extends _DiffOp {
-       var $type = 'delete';
+class DiffOp_Delete extends DiffOp {
+       public $type = 'delete';
 
        function __construct( $lines ) {
                $this->orig = $lines;
@@ -92,10 +90,10 @@ class _DiffOp_Delete extends _DiffOp {
        }
 
        /**
-        * @return _DiffOp_Add
+        * @return DiffOp_Add
         */
        function reverse() {
-               return new _DiffOp_Add( $this->orig );
+               return new DiffOp_Add( $this->orig );
        }
 }
 
@@ -104,8 +102,8 @@ class _DiffOp_Delete extends _DiffOp {
  * @private
  * @ingroup DifferenceEngine
  */
-class _DiffOp_Add extends _DiffOp {
-       var $type = 'add';
+class DiffOp_Add extends DiffOp {
+       public $type = 'add';
 
        function __construct( $lines ) {
                $this->closing = $lines;
@@ -113,10 +111,10 @@ class _DiffOp_Add extends _DiffOp {
        }
 
        /**
-        * @return _DiffOp_Delete
+        * @return DiffOp_Delete
         */
        function reverse() {
-               return new _DiffOp_Delete( $this->closing );
+               return new DiffOp_Delete( $this->closing );
        }
 }
 
@@ -125,8 +123,8 @@ class _DiffOp_Add extends _DiffOp {
  * @private
  * @ingroup DifferenceEngine
  */
-class _DiffOp_Change extends _DiffOp {
-       var $type = 'change';
+class DiffOp_Change extends DiffOp {
+       public $type = 'change';
 
        function __construct( $orig, $closing ) {
                $this->orig = $orig;
@@ -134,10 +132,10 @@ class _DiffOp_Change extends _DiffOp {
        }
 
        /**
-        * @return _DiffOp_Change
+        * @return DiffOp_Change
         */
        function reverse() {
-               return new _DiffOp_Change( $this->closing, $this->orig );
+               return new DiffOp_Change( $this->closing, $this->orig );
        }
 }
 
@@ -165,7 +163,7 @@ class _DiffOp_Change extends _DiffOp {
  * @private
  * @ingroup DifferenceEngine
  */
-class _DiffEngine {
+class DiffEngine {
 
        const MAX_XREF_LENGTH = 10000;
 
@@ -187,11 +185,11 @@ class _DiffEngine {
                wfProfileIn( __METHOD__ );
 
                // Diff and store locally
-               $this->diff_local( $from_lines, $to_lines );
+               $this->diffLocal( $from_lines, $to_lines );
 
                // Merge edits when possible
-               $this->_shift_boundaries( $from_lines, $this->xchanged, $this->ychanged );
-               $this->_shift_boundaries( $to_lines, $this->ychanged, $this->xchanged );
+               $this->shiftBoundaries( $from_lines, $this->xchanged, $this->ychanged );
+               $this->shiftBoundaries( $to_lines, $this->ychanged, $this->xchanged );
 
                // Compute the edit operations.
                $n_from = count( $from_lines );
@@ -211,7 +209,7 @@ class _DiffEngine {
                                ++$yi;
                        }
                        if ( $copy ) {
-                               $edits[] = new _DiffOp_Copy( $copy );
+                               $edits[] = new DiffOp_Copy( $copy );
                        }
 
                        // Find deletes & adds.
@@ -226,11 +224,11 @@ class _DiffEngine {
                        }
 
                        if ( $delete && $add ) {
-                               $edits[] = new _DiffOp_Change( $delete, $add );
+                               $edits[] = new DiffOp_Change( $delete, $add );
                        } elseif ( $delete ) {
-                               $edits[] = new _DiffOp_Delete( $delete );
+                               $edits[] = new DiffOp_Delete( $delete );
                        } elseif ( $add ) {
-                               $edits[] = new _DiffOp_Add( $add );
+                               $edits[] = new DiffOp_Add( $add );
                        }
                }
                wfProfileOut( __METHOD__ );
@@ -241,7 +239,7 @@ class _DiffEngine {
         * @param $from_lines
         * @param $to_lines
         */
-       function diff_local( $from_lines, $to_lines ) {
+       private function diffLocal( $from_lines, $to_lines ) {
                global $wgExternalDiffEngine;
                wfProfileIn( __METHOD__ );
 
@@ -282,21 +280,21 @@ class _DiffEngine {
 
                        // Ignore lines which do not exist in both files.
                        for ( $xi = $skip; $xi < $n_from - $endskip; $xi++ ) {
-                               $xhash[$this->_line_hash( $from_lines[$xi] )] = 1;
+                               $xhash[$this->lineHash( $from_lines[$xi] )] = 1;
                        }
 
                        for ( $yi = $skip; $yi < $n_to - $endskip; $yi++ ) {
                                $line = $to_lines[$yi];
-                               if ( ( $this->ychanged[$yi] = empty( $xhash[$this->_line_hash( $line )] ) ) ) {
+                               if ( ( $this->ychanged[$yi] = empty( $xhash[$this->lineHash( $line )] ) ) ) {
                                        continue;
                                }
-                               $yhash[$this->_line_hash( $line )] = 1;
+                               $yhash[$this->lineHash( $line )] = 1;
                                $this->yv[] = $line;
                                $this->yind[] = $yi;
                        }
                        for ( $xi = $skip; $xi < $n_from - $endskip; $xi++ ) {
                                $line = $from_lines[$xi];
-                               if ( ( $this->xchanged[$xi] = empty( $yhash[$this->_line_hash( $line )] ) ) ) {
+                               if ( ( $this->xchanged[$xi] = empty( $yhash[$this->lineHash( $line )] ) ) ) {
                                        continue;
                                }
                                $this->xv[] = $line;
@@ -304,7 +302,7 @@ class _DiffEngine {
                        }
 
                        // Find the LCS.
-                       $this->_compareseq( 0, count( $this->xv ), 0, count( $this->yv ) );
+                       $this->compareSeq( 0, count( $this->xv ), 0, count( $this->yv ) );
                }
                wfProfileOut( __METHOD__ );
        }
@@ -314,7 +312,7 @@ class _DiffEngine {
         * @param $line string
         * @return string
         */
-       function _line_hash( $line ) {
+       private function lineHash( $line ) {
                if ( strlen( $line ) > self::MAX_XREF_LENGTH ) {
                        return md5( $line );
                } else {
@@ -345,7 +343,7 @@ class _DiffEngine {
         * @param $nchunks
         * @return array
         */
-       function _diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
+       private function diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
                $flip = false;
 
                if ( $xlim - $xoff > $ylim - $yoff ) {
@@ -389,7 +387,7 @@ class _DiffEngine {
                                reset( $matches );
                                while ( list( , $y ) = each( $matches ) ) {
                                        if ( empty( $this->in_seq[$y] ) ) {
-                                               $k = $this->_lcs_pos( $y );
+                                               $k = $this->lcsPos( $y );
                                                assert( '$k > 0' );
                                                $ymids[$k] = $ymids[$k -1];
                                                break;
@@ -404,7 +402,7 @@ class _DiffEngine {
                                                $this->seq[$k] = $y;
                                                $this->in_seq[$y] = 1;
                                        } elseif ( empty( $this->in_seq[$y] ) ) {
-                                               $k = $this->_lcs_pos( $y );
+                                               $k = $this->lcsPos( $y );
                                                assert( '$k > 0' );
                                                $ymids[$k] = $ymids[$k -1];
                                        }
@@ -428,7 +426,7 @@ class _DiffEngine {
         * @param $ypos
         * @return int
         */
-       function _lcs_pos( $ypos ) {
+       private function lcsPos( $ypos ) {
                $end = $this->lcs;
                if ( $end == 0 || $ypos > $this->seq[$end] ) {
                        $this->seq[++$this->lcs] = $ypos;
@@ -470,7 +468,7 @@ class _DiffEngine {
         * @param $yoff
         * @param $ylim
         */
-       function _compareseq( $xoff, $xlim, $yoff, $ylim ) {
+       private function compareSeq( $xoff, $xlim, $yoff, $ylim ) {
                // Slide down the bottom initial diagonal.
                while ( $xoff < $xlim && $yoff < $ylim && $this->xv[$xoff] == $this->yv[$yoff] ) {
                        ++$xoff;
@@ -491,7 +489,7 @@ class _DiffEngine {
                        // $nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5);
                        // $nchunks = max(2,min(8,(int)$nchunks));
                        $nchunks = min( 7, $xlim - $xoff, $ylim - $yoff ) + 1;
-                       list( $lcs, $seps ) = $this->_diag( $xoff, $xlim, $yoff, $ylim, $nchunks );
+                       list( $lcs, $seps ) = $this->diag( $xoff, $xlim, $yoff, $ylim, $nchunks );
                }
 
                if ( $lcs == 0 ) {
@@ -508,7 +506,7 @@ class _DiffEngine {
                        reset( $seps );
                        $pt1 = $seps[0];
                        while ( $pt2 = next( $seps ) ) {
-                               $this->_compareseq( $pt1[0], $pt2[0], $pt1[1], $pt2[1] );
+                               $this->compareSeq( $pt1[0], $pt2[0], $pt1[1], $pt2[1] );
                                $pt1 = $pt2;
                        }
                }
@@ -527,7 +525,7 @@ class _DiffEngine {
         *
         * This is extracted verbatim from analyze.c (GNU diffutils-2.7).
         */
-       function _shift_boundaries( $lines, &$changed, $other_changed ) {
+       private function shiftBoundaries( $lines, &$changed, $other_changed ) {
                wfProfileIn( __METHOD__ );
                $i = 0;
                $j = 0;
@@ -654,7 +652,7 @@ class _DiffEngine {
  * @ingroup DifferenceEngine
  */
 class Diff {
-       var $edits;
+       public $edits;
 
        /**
         * Constructor.
@@ -665,9 +663,9 @@ class Diff {
         * @param $to_lines array An array of strings.
         */
        function __construct( $from_lines, $to_lines ) {
-               $eng = new _DiffEngine;
+               $eng = new DiffEngine;
                $this->edits = $eng->diff( $from_lines, $to_lines );
-               // $this->_check($from_lines, $to_lines);
+               // $this->check($from_lines, $to_lines);
        }
 
        /**
@@ -683,6 +681,7 @@ class Diff {
        function reverse() {
                $rev = $this;
                $rev->edits = array();
+               /** @var DiffOp $edit */
                foreach ( $this->edits as $edit ) {
                        $rev->edits[] = $edit->reverse();
                }
@@ -765,7 +764,7 @@ class Diff {
         * @param $from_lines
         * @param $to_lines
         */
-       function _check( $from_lines, $to_lines ) {
+       private function check( $from_lines, $to_lines ) {
                wfProfileIn( __METHOD__ );
                if ( serialize( $from_lines ) != serialize( $this->orig() ) ) {
                        trigger_error( "Reconstructed original doesn't match", E_USER_ERROR );
@@ -852,363 +851,61 @@ class MappedDiff extends Diff {
        }
 }
 
-/**
- * A class to format Diffs
- *
- * This class formats the diff in classic diff format.
- * It is intended that this class be customized via inheritance,
- * to obtain fancier outputs.
- * @todo document
- * @private
- * @ingroup DifferenceEngine
- */
-class DiffFormatter {
-       /**
-        * Number of leading context "lines" to preserve.
-        *
-        * This should be left at zero for this class, but subclasses
-        * may want to set this to other values.
-        */
-       var $leading_context_lines = 0;
-
-       /**
-        * Number of trailing context "lines" to preserve.
-        *
-        * This should be left at zero for this class, but subclasses
-        * may want to set this to other values.
-        */
-       var $trailing_context_lines = 0;
-
-       /**
-        * Format a diff.
-        *
-        * @param $diff Diff A Diff object.
-        * @return string The formatted output.
-        */
-       function format( $diff ) {
-               wfProfileIn( __METHOD__ );
-
-               $xi = $yi = 1;
-               $block = false;
-               $context = array();
-
-               $nlead = $this->leading_context_lines;
-               $ntrail = $this->trailing_context_lines;
-
-               $this->_start_diff();
-
-               foreach ( $diff->edits as $edit ) {
-                       if ( $edit->type == 'copy' ) {
-                               if ( is_array( $block ) ) {
-                                       if ( count( $edit->orig ) <= $nlead + $ntrail ) {
-                                               $block[] = $edit;
-                                       } else {
-                                               if ( $ntrail ) {
-                                                       $context = array_slice( $edit->orig, 0, $ntrail );
-                                                       $block[] = new _DiffOp_Copy( $context );
-                                               }
-                                               $this->_block( $x0, $ntrail + $xi - $x0,
-                                                       $y0, $ntrail + $yi - $y0,
-                                                       $block );
-                                               $block = false;
-                                       }
-                               }
-                               $context = $edit->orig;
-                       } else {
-                               if ( !is_array( $block ) ) {
-                                       $context = array_slice( $context, count( $context ) - $nlead );
-                                       $x0 = $xi - count( $context );
-                                       $y0 = $yi - count( $context );
-                                       $block = array();
-                                       if ( $context ) {
-                                               $block[] = new _DiffOp_Copy( $context );
-                                       }
-                               }
-                               $block[] = $edit;
-                       }
-
-                       if ( $edit->orig ) {
-                               $xi += count( $edit->orig );
-                       }
-                       if ( $edit->closing ) {
-                               $yi += count( $edit->closing );
-                       }
-               }
-
-               if ( is_array( $block ) ) {
-                       $this->_block( $x0, $xi - $x0,
-                               $y0, $yi - $y0,
-                               $block );
-               }
-
-               $end = $this->_end_diff();
-               wfProfileOut( __METHOD__ );
-               return $end;
-       }
-
-       /**
-        * @param $xbeg
-        * @param $xlen
-        * @param $ybeg
-        * @param $ylen
-        * @param $edits
-        */
-       function _block( $xbeg, $xlen, $ybeg, $ylen, &$edits ) {
-               wfProfileIn( __METHOD__ );
-               $this->_start_block( $this->_block_header( $xbeg, $xlen, $ybeg, $ylen ) );
-               foreach ( $edits as $edit ) {
-                       if ( $edit->type == 'copy' ) {
-                               $this->_context( $edit->orig );
-                       } elseif ( $edit->type == 'add' ) {
-                               $this->_added( $edit->closing );
-                       } elseif ( $edit->type == 'delete' ) {
-                               $this->_deleted( $edit->orig );
-                       } elseif ( $edit->type == 'change' ) {
-                               $this->_changed( $edit->orig, $edit->closing );
-                       } else {
-                               trigger_error( 'Unknown edit type', E_USER_ERROR );
-                       }
-               }
-               $this->_end_block();
-               wfProfileOut( __METHOD__ );
-       }
-
-       function _start_diff() {
-               ob_start();
-       }
-
-       /**
-        * @return string
-        */
-       function _end_diff() {
-               $val = ob_get_contents();
-               ob_end_clean();
-               return $val;
-       }
-
-       /**
-        * @param $xbeg
-        * @param $xlen
-        * @param $ybeg
-        * @param $ylen
-        * @return string
-        */
-       function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
-               if ( $xlen > 1 ) {
-                       $xbeg .= ',' . ( $xbeg + $xlen - 1 );
-               }
-               if ( $ylen > 1 ) {
-                       $ybeg .= ',' . ( $ybeg + $ylen - 1 );
-               }
-
-               return $xbeg . ( $xlen ? ( $ylen ? 'c' : 'd' ) : 'a' ) . $ybeg;
-       }
-
-       function _start_block( $header ) {
-               echo $header . "\n";
-       }
-
-       function _end_block() {
-       }
-
-       /**
-        * @param $lines
-        * @param $prefix string
-        */
-       function _lines( $lines, $prefix = ' ' ) {
-               foreach ( $lines as $line ) {
-                       echo "$prefix $line\n";
-               }
-       }
-
-       /**
-        * @param $lines
-        */
-       function _context( $lines ) {
-               $this->_lines( $lines );
-       }
-
-       /**
-        * @param $lines
-        */
-       function _added( $lines ) {
-               $this->_lines( $lines, '>' );
-       }
-
-       /**
-        * @param $lines
-        */
-       function _deleted( $lines ) {
-               $this->_lines( $lines, '<' );
-       }
-
-       /**
-        * @param $orig
-        * @param $closing
-        */
-       function _changed( $orig, $closing ) {
-               $this->_deleted( $orig );
-               echo "---\n";
-               $this->_added( $closing );
-       }
-}
-
-/**
- * A formatter that outputs unified diffs
- * @ingroup DifferenceEngine
- */
-class UnifiedDiffFormatter extends DiffFormatter {
-       var $leading_context_lines = 2;
-       var $trailing_context_lines = 2;
-
-       /**
-        * @param $lines
-        */
-       function _added( $lines ) {
-               $this->_lines( $lines, '+' );
-       }
-
-       /**
-        * @param $lines
-        */
-       function _deleted( $lines ) {
-               $this->_lines( $lines, '-' );
-       }
-
-       /**
-        * @param $orig
-        * @param $closing
-        */
-       function _changed( $orig, $closing ) {
-               $this->_deleted( $orig );
-               $this->_added( $closing );
-       }
-
-       /**
-        * @param $xbeg
-        * @param $xlen
-        * @param $ybeg
-        * @param $ylen
-        * @return string
-        */
-       function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
-               return "@@ -$xbeg,$xlen +$ybeg,$ylen @@";
-       }
-}
-
-/**
- * A pseudo-formatter that just passes along the Diff::$edits array
- * @ingroup DifferenceEngine
- */
-class ArrayDiffFormatter extends DiffFormatter {
-
-       /**
-        * @param $diff
-        * @return array
-        */
-       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' => isset( $edit->closing[$i] ) ? $edit->closing[$i] : null,
-                                                       '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
  */
 
-define( 'NBSP', '&#160;' ); // iso-8859-x non-breaking space.
-
 /**
  * @todo document
  * @private
  * @ingroup DifferenceEngine
  */
-class _HWLDF_WordAccumulator {
-       function __construct() {
-               $this->_lines = array();
-               $this->_line = '';
-               $this->_group = '';
-               $this->_tag = '';
-       }
+class HWLDF_WordAccumulator {
+       private $lines = array();
+       private $line = '';
+       private $group = '';
+       private $tag = '';
 
        /**
         * @param $new_tag
         */
-       function _flushGroup( $new_tag ) {
-               if ( $this->_group !== '' ) {
-                       if ( $this->_tag == 'ins' ) {
-                               $this->_line .= '<ins class="diffchange diffchange-inline">' .
-                                               htmlspecialchars( $this->_group ) . '</ins>';
-                       } elseif ( $this->_tag == 'del' ) {
-                               $this->_line .= '<del class="diffchange diffchange-inline">' .
-                                               htmlspecialchars( $this->_group ) . '</del>';
+       private function flushGroup( $new_tag ) {
+               if ( $this->group !== '' ) {
+                       if ( $this->tag == 'ins' ) {
+                               $this->line .= '<ins class="diffchange diffchange-inline">' .
+                                               htmlspecialchars( $this->group ) . '</ins>';
+                       } elseif ( $this->tag == 'del' ) {
+                               $this->line .= '<del class="diffchange diffchange-inline">' .
+                                               htmlspecialchars( $this->group ) . '</del>';
                        } else {
-                               $this->_line .= htmlspecialchars( $this->_group );
+                               $this->line .= htmlspecialchars( $this->group );
                        }
                }
-               $this->_group = '';
-               $this->_tag = $new_tag;
+               $this->group = '';
+               $this->tag = $new_tag;
        }
 
        /**
         * @param $new_tag
         */
-       function _flushLine( $new_tag ) {
-               $this->_flushGroup( $new_tag );
-               if ( $this->_line != '' ) {
-                       array_push( $this->_lines, $this->_line );
+       private function flushLine( $new_tag ) {
+               $this->flushGroup( $new_tag );
+               if ( $this->line != '' ) {
+                       array_push( $this->lines, $this->line );
                } else {
                        # make empty lines visible by inserting an NBSP
-                       array_push( $this->_lines, NBSP );
+                       array_push( $this->lines, '&#160;' );
                }
-               $this->_line = '';
+               $this->line = '';
        }
 
        /**
         * @param $words
         * @param $tag string
         */
-       function addWords( $words, $tag = '' ) {
-               if ( $tag != $this->_tag ) {
-                       $this->_flushGroup( $tag );
+       public function addWords( $words, $tag = '' ) {
+               if ( $tag != $this->tag ) {
+                       $this->flushGroup( $tag );
                }
 
                foreach ( $words as $word ) {
@@ -1217,20 +914,20 @@ class _HWLDF_WordAccumulator {
                                continue;
                        }
                        if ( $word[0] == "\n" ) {
-                               $this->_flushLine( $tag );
+                               $this->flushLine( $tag );
                                $word = substr( $word, 1 );
                        }
                        assert( '!strstr( $word, "\n" )' );
-                       $this->_group .= $word;
+                       $this->group .= $word;
                }
        }
 
        /**
         * @return array
         */
-       function getLines() {
-               $this->_flushLine( '~done' );
-               return $this->_lines;
+       public function getLines() {
+               $this->flushLine( '~done' );
+               return $this->lines;
        }
 }
 
@@ -1249,8 +946,8 @@ class WordLevelDiff extends MappedDiff {
        function __construct( $orig_lines, $closing_lines ) {
                wfProfileIn( __METHOD__ );
 
-               list( $orig_words, $orig_stripped ) = $this->_split( $orig_lines );
-               list( $closing_words, $closing_stripped ) = $this->_split( $closing_lines );
+               list( $orig_words, $orig_stripped ) = $this->split( $orig_lines );
+               list( $closing_words, $closing_stripped ) = $this->split( $closing_lines );
 
                parent::__construct( $orig_words, $closing_words,
                $orig_stripped, $closing_stripped );
@@ -1261,7 +958,7 @@ class WordLevelDiff extends MappedDiff {
         * @param $lines
         * @return array
         */
-       function _split( $lines ) {
+       private function split( $lines ) {
                wfProfileIn( __METHOD__ );
 
                $words = array();
@@ -1300,9 +997,9 @@ class WordLevelDiff extends MappedDiff {
        /**
         * @return array
         */
-       function orig() {
+       public function orig() {
                wfProfileIn( __METHOD__ );
-               $orig = new _HWLDF_WordAccumulator;
+               $orig = new HWLDF_WordAccumulator;
 
                foreach ( $this->edits as $edit ) {
                        if ( $edit->type == 'copy' ) {
@@ -1319,9 +1016,9 @@ class WordLevelDiff extends MappedDiff {
        /**
         * @return array
         */
-       function closing() {
+       public function closing() {
                wfProfileIn( __METHOD__ );
-               $closing = new _HWLDF_WordAccumulator;
+               $closing = new HWLDF_WordAccumulator;
 
                foreach ( $this->edits as $edit ) {
                        if ( $edit->type == 'copy' ) {
@@ -1335,161 +1032,3 @@ class WordLevelDiff extends MappedDiff {
                return $lines;
        }
 }
-
-/**
- * Wikipedia Table style diff formatter.
- * @todo document
- * @private
- * @ingroup DifferenceEngine
- */
-class TableDiffFormatter extends DiffFormatter {
-       function __construct() {
-               $this->leading_context_lines = 2;
-               $this->trailing_context_lines = 2;
-       }
-
-       /**
-        * @static
-        * @param $msg
-        * @return mixed
-        */
-       public static function escapeWhiteSpace( $msg ) {
-               $msg = preg_replace( '/^ /m', '&#160; ', $msg );
-               $msg = preg_replace( '/ $/m', ' &#160;', $msg );
-               $msg = preg_replace( '/  /', '&#160; ', $msg );
-               return $msg;
-       }
-
-       /**
-        * @param $xbeg
-        * @param $xlen
-        * @param $ybeg
-        * @param $ylen
-        * @return string
-        */
-       function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
-               $r = '<tr><td colspan="2" class="diff-lineno"><!--LINE ' . $xbeg . "--></td>\n" .
-                       '<td colspan="2" class="diff-lineno"><!--LINE ' . $ybeg . "--></td></tr>\n";
-               return $r;
-       }
-
-       /**
-        * @param $header
-        */
-       function _start_block( $header ) {
-               echo $header;
-       }
-
-       function _end_block() {
-       }
-
-       function _lines( $lines, $prefix = ' ', $color = 'white' ) {
-       }
-
-       /**
-        * HTML-escape parameter before calling this
-        * @param $line
-        * @return string
-        */
-       function addedLine( $line ) {
-               return $this->wrapLine( '+', 'diff-addedline', $line );
-       }
-
-       /**
-        * HTML-escape parameter before calling this
-        * @param $line
-        * @return string
-        */
-       function deletedLine( $line ) {
-               return $this->wrapLine( '−', 'diff-deletedline', $line );
-       }
-
-       /**
-        * HTML-escape parameter before calling this
-        * @param $line
-        * @return string
-        */
-       function contextLine( $line ) {
-               return $this->wrapLine( '&#160;', 'diff-context', $line );
-       }
-
-       /**
-        * @param $marker
-        * @param $class
-        * @param $line
-        * @return string
-        */
-       private function wrapLine( $marker, $class, $line ) {
-               if ( $line !== '' ) {
-                       // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
-                       $line = Xml::tags( 'div', null, $this->escapeWhiteSpace( $line ) );
-               }
-               return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
-       }
-
-       /**
-        * @return string
-        */
-       function emptyLine() {
-               return '<td colspan="2">&#160;</td>';
-       }
-
-       /**
-        * @param $lines array
-        */
-       function _added( $lines ) {
-               foreach ( $lines as $line ) {
-                       echo '<tr>' . $this->emptyLine() .
-                       $this->addedLine( '<ins class="diffchange">' .
-                       htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n";
-               }
-       }
-
-       /**
-        * @param $lines
-        */
-       function _deleted( $lines ) {
-               foreach ( $lines as $line ) {
-                       echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
-                       htmlspecialchars( $line ) . '</del>' ) .
-                       $this->emptyLine() . "</tr>\n";
-               }
-       }
-
-       /**
-        * @param $lines
-        */
-       function _context( $lines ) {
-               foreach ( $lines as $line ) {
-                       echo '<tr>' .
-                       $this->contextLine( htmlspecialchars( $line ) ) .
-                       $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n";
-               }
-       }
-
-       /**
-        * @param $orig
-        * @param $closing
-        */
-       function _changed( $orig, $closing ) {
-               wfProfileIn( __METHOD__ );
-
-               $diff = new WordLevelDiff( $orig, $closing );
-               $del = $diff->orig();
-               $add = $diff->closing();
-
-               # Notice that WordLevelDiff returns HTML-escaped output.
-               # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
-
-               while ( $line = array_shift( $del ) ) {
-                       $aline = array_shift( $add );
-                       echo '<tr>' . $this->deletedLine( $line ) .
-                       $this->addedLine( $aline ) . "</tr>\n";
-               }
-               foreach ( $add as $line ) {     # If any leftovers
-                       echo '<tr>' . $this->emptyLine() .
-                       $this->addedLine( $line ) . "</tr>\n";
-               }
-               wfProfileOut( __METHOD__ );
-       }
-}
diff --git a/includes/diff/DiffFormatter.php b/includes/diff/DiffFormatter.php
new file mode 100644 (file)
index 0000000..78ac77f
--- /dev/null
@@ -0,0 +1,225 @@
+<?php
+/**
+ * Base for diff rendering classes. Portions taken from phpwiki-1.3.3.
+ *
+ * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
+ * You may copy this code freely under the conditions of the GPL.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup DifferenceEngine
+ */
+
+/**
+ * Base class for diff formatters
+ *
+ * This class formats the diff in classic diff format.
+ * It is intended that this class be customized via inheritance,
+ * to obtain fancier outputs.
+ * @todo document
+ * @ingroup DifferenceEngine
+ */
+abstract class DiffFormatter {
+       /**
+        * Number of leading context "lines" to preserve.
+        *
+        * This should be left at zero for this class, but subclasses
+        * may want to set this to other values.
+        */
+       protected $leadingContextLines = 0;
+
+       /**
+        * Number of trailing context "lines" to preserve.
+        *
+        * This should be left at zero for this class, but subclasses
+        * may want to set this to other values.
+        */
+       protected $trailingContextLines = 0;
+
+       /**
+        * Format a diff.
+        *
+        * @param $diff Diff A Diff object.
+        * @return string The formatted output.
+        */
+       public function format( $diff ) {
+               wfProfileIn( __METHOD__ );
+
+               $xi = $yi = 1;
+               $block = false;
+               $context = array();
+
+               $nlead = $this->leadingContextLines;
+               $ntrail = $this->trailingContextLines;
+
+               $this->startDiff();
+
+               foreach ( $diff->edits as $edit ) {
+                       if ( $edit->type == 'copy' ) {
+                               if ( is_array( $block ) ) {
+                                       if ( count( $edit->orig ) <= $nlead + $ntrail ) {
+                                               $block[] = $edit;
+                                       } else {
+                                               if ( $ntrail ) {
+                                                       $context = array_slice( $edit->orig, 0, $ntrail );
+                                                       $block[] = new DiffOp_Copy( $context );
+                                               }
+                                               $this->block( $x0, $ntrail + $xi - $x0,
+                                                       $y0, $ntrail + $yi - $y0,
+                                                       $block );
+                                               $block = false;
+                                       }
+                               }
+                               $context = $edit->orig;
+                       } else {
+                               if ( !is_array( $block ) ) {
+                                       $context = array_slice( $context, count( $context ) - $nlead );
+                                       $x0 = $xi - count( $context );
+                                       $y0 = $yi - count( $context );
+                                       $block = array();
+                                       if ( $context ) {
+                                               $block[] = new DiffOp_Copy( $context );
+                                       }
+                               }
+                               $block[] = $edit;
+                       }
+
+                       if ( $edit->orig ) {
+                               $xi += count( $edit->orig );
+                       }
+                       if ( $edit->closing ) {
+                               $yi += count( $edit->closing );
+                       }
+               }
+
+               if ( is_array( $block ) ) {
+                       $this->block( $x0, $xi - $x0,
+                               $y0, $yi - $y0,
+                               $block );
+               }
+
+               $end = $this->endDiff();
+               wfProfileOut( __METHOD__ );
+               return $end;
+       }
+
+       /**
+        * @param $xbeg
+        * @param $xlen
+        * @param $ybeg
+        * @param $ylen
+        * @param $edits
+        */
+       protected function block( $xbeg, $xlen, $ybeg, $ylen, &$edits ) {
+               wfProfileIn( __METHOD__ );
+               $this->startBlock( $this->blockHeader( $xbeg, $xlen, $ybeg, $ylen ) );
+               foreach ( $edits as $edit ) {
+                       if ( $edit->type == 'copy' ) {
+                               $this->context( $edit->orig );
+                       } elseif ( $edit->type == 'add' ) {
+                               $this->added( $edit->closing );
+                       } elseif ( $edit->type == 'delete' ) {
+                               $this->deleted( $edit->orig );
+                       } elseif ( $edit->type == 'change' ) {
+                               $this->changed( $edit->orig, $edit->closing );
+                       } else {
+                               throw new MWException( "Unknown edit type: {$edit->type}" );
+                       }
+               }
+               $this->endBlock();
+               wfProfileOut( __METHOD__ );
+       }
+
+       protected function startDiff() {
+               ob_start();
+       }
+
+       /**
+        * @return string
+        */
+       protected function endDiff() {
+               $val = ob_get_contents();
+               ob_end_clean();
+               return $val;
+       }
+
+       /**
+        * @param $xbeg
+        * @param $xlen
+        * @param $ybeg
+        * @param $ylen
+        * @return string
+        */
+       protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
+               if ( $xlen > 1 ) {
+                       $xbeg .= ',' . ( $xbeg + $xlen - 1 );
+               }
+               if ( $ylen > 1 ) {
+                       $ybeg .= ',' . ( $ybeg + $ylen - 1 );
+               }
+
+               return $xbeg . ( $xlen ? ( $ylen ? 'c' : 'd' ) : 'a' ) . $ybeg;
+       }
+
+       protected function startBlock( $header ) {
+               echo $header . "\n";
+       }
+
+       protected function endBlock() {
+       }
+
+       /**
+        * @param $lines
+        * @param $prefix string
+        */
+       protected function lines( $lines, $prefix = ' ' ) {
+               foreach ( $lines as $line ) {
+                       echo "$prefix $line\n";
+               }
+       }
+
+       /**
+        * @param $lines
+        */
+       protected function context( $lines ) {
+               $this->lines( $lines );
+       }
+
+       /**
+        * @param $lines
+        */
+       protected function added( $lines ) {
+               $this->lines( $lines, '>' );
+       }
+
+       /**
+        * @param $lines
+        */
+       protected function deleted( $lines ) {
+               $this->lines( $lines, '<' );
+       }
+
+       /**
+        * @param $orig
+        * @param $closing
+        */
+       protected function changed( $orig, $closing ) {
+               $this->deleted( $orig );
+               echo "---\n";
+               $this->added( $closing );
+       }
+}
index 39f8a47..28f8889 100644 (file)
  * @ingroup DifferenceEngine
  */
 
-/**
- * Constant to indicate diff cache compatibility.
- * Bump this when changing the diff formatting in a way that
- * fixes important bugs or such to force cached diff views to
- * clear.
- */
-define( 'MW_DIFF_VERSION', '1.11a' );
-
 /**
  * @todo document
  * @ingroup DifferenceEngine
  */
 class DifferenceEngine extends ContextSource {
-       public $mOldid;
-       public $mNewid;
-       private $mOldTags;
-       private $mNewTags;
+       /**
+        * Constant to indicate diff cache compatibility.
+        * Bump this when changing the diff formatting in a way that
+        * fixes important bugs or such to force cached diff views to
+        * clear.
+        */
+       const CACHE_VERSION ='1.11a';
 
+       /**#@+
+        * @private
+        */
+       public $oldId;
+       public $newId;
+       private $oldTags;
+       private $newTags;
        /**
         * @var Content
         */
-       public $mOldContent;
-       public $mNewContent;
-       protected $mDiffLang;
+       public $oldContent;
+       /**
+        * @var Content
+        */
+       public $newContent;
+       protected $diffLang;
 
        /**
         * @var Title
         */
-       public $mOldPage;
-       public $mNewPage;
+       public $oldPage;
+       /**
+        * @var Title
+        */
+       public $newPage;
 
        /**
         * @var Revision
         */
-       public $mOldRev;
-       public $mNewRev;
-       private $mRevisionsIdsLoaded = false; // Have the revisions IDs been loaded
-       public $mRevisionsLoaded = false; // Have the revisions been loaded
-       public $mTextLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2?
-       public $mCacheHit = false; // Was the diff fetched from cache?
+       public $oldRev;
+       /**
+        * @var Revision
+        */
+       public $newRev;
+       private $revisionsIdsLoaded = false; // Have the revisions IDs been loaded
+       public $revisionsLoaded = false; // Have the revisions been loaded
+       public $textLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2?
+       public $cacheHit = false; // Was the diff fetched from cache?
 
        /**
         * Set this to true to add debug info to the HTML output.
@@ -71,19 +82,20 @@ class DifferenceEngine extends ContextSource {
 
        // If true, line X is not displayed when X is 1, for example to increase
        // readability and conserve space with many small diffs.
-       protected $mReducedLineNumbers = false;
+       protected $reducedLineNumbers = false;
 
        // Link to action=markpatrolled
-       protected $mMarkPatrolledLink = null;
+       protected $markPatrolledLink = null;
 
        protected $unhide = false; # show rev_deleted content if allowed
+       private $refreshCache;
        /**#@-*/
 
        /**
         * Constructor
         * @param $context IContextSource context to use, anything else will be ignored
         * @param $old Integer old ID we want to show and diff with.
-        * @param $new String|int either 'prev' or 'next'. Default: 0.
+        * @param $new String|int either revision ID or 'prev' or 'next'. Default: 0.
         * @param $rcid Integer Deprecated, no longer used!
         * @param $refreshCache boolean If set, refreshes the diff cache
         * @param $unhide boolean If set, allow viewing deleted revs
@@ -97,9 +109,9 @@ class DifferenceEngine extends ContextSource {
 
                wfDebug( "DifferenceEngine old '$old' new '$new' rcid '$rcid'\n" );
 
-               $this->mOldid = $old;
-               $this->mNewid = $new;
-               $this->mRefreshCache = $refreshCache;
+               $this->oldId = $old;
+               $this->newId = $new;
+               $this->refreshCache = $refreshCache;
                $this->unhide = $unhide;
        }
 
@@ -107,25 +119,25 @@ class DifferenceEngine extends ContextSource {
         * @param $value bool
         */
        function setReducedLineNumbers( $value = true ) {
-               $this->mReducedLineNumbers = $value;
+               $this->reducedLineNumbers = $value;
        }
 
        /**
         * @return Language
         */
        function getDiffLang() {
-               if ( $this->mDiffLang === null ) {
+               if ( $this->diffLang === null ) {
                        # Default language in which the diff text is written.
-                       $this->mDiffLang = $this->getTitle()->getPageLanguage();
+                       $this->diffLang = $this->getTitle()->getPageLanguage();
                }
-               return $this->mDiffLang;
+               return $this->diffLang;
        }
 
        /**
         * @return bool
         */
        function wasCacheHit() {
-               return $this->mCacheHit;
+               return $this->cacheHit;
        }
 
        /**
@@ -133,7 +145,7 @@ class DifferenceEngine extends ContextSource {
         */
        function getOldid() {
                $this->loadRevisionIds();
-               return $this->mOldid;
+               return $this->oldId;
        }
 
        /**
@@ -141,7 +153,7 @@ class DifferenceEngine extends ContextSource {
         */
        function getNewid() {
                $this->loadRevisionIds();
-               return $this->mNewid;
+               return $this->newId;
        }
 
        /**
@@ -188,15 +200,15 @@ class DifferenceEngine extends ContextSource {
                $out = $this->getOutput();
 
                $missing = array();
-               if ( $this->mOldRev === null ||
-                       ( $this->mOldRev && $this->mOldContent === null )
+               if ( $this->oldRev === null ||
+                       ( $this->oldRev && $this->oldContent === null )
                ) {
-                       $missing[] = $this->deletedIdMarker( $this->mOldid );
+                       $missing[] = $this->deletedIdMarker( $this->oldId );
                }
-               if ( $this->mNewRev === null ||
-                       ( $this->mNewRev && $this->mNewContent === null )
+               if ( $this->newRev === null ||
+                       ( $this->newRev && $this->newContent === null )
                ) {
-                       $missing[] = $this->deletedIdMarker( $this->mNewid );
+                       $missing[] = $this->deletedIdMarker( $this->newId );
                }
 
                $out->setPageTitle( $this->msg( 'errorpagetitle' ) );
@@ -219,10 +231,10 @@ class DifferenceEngine extends ContextSource {
                }
 
                $user = $this->getUser();
-               $permErrors = $this->mNewPage->getUserPermissionsErrors( 'read', $user );
-               if ( $this->mOldPage ) { # mOldPage might not be set, see below.
+               $permErrors = $this->newPage->getUserPermissionsErrors( 'read', $user );
+               if ( $this->oldPage ) { # oldPage might not be set, see below.
                        $permErrors = wfMergeErrorArrays( $permErrors,
-                               $this->mOldPage->getUserPermissionsErrors( 'read', $user ) );
+                               $this->oldPage->getUserPermissionsErrors( 'read', $user ) );
                }
                if ( count( $permErrors ) ) {
                        wfProfileOut( __METHOD__ );
@@ -230,7 +242,6 @@ class DifferenceEngine extends ContextSource {
                }
 
                $rollback = '';
-               $undoLink = '';
 
                $query = array();
                # Carry over 'diffonly' param via navigation links
@@ -244,47 +255,47 @@ class DifferenceEngine extends ContextSource {
 
                # Check if one of the revisions is deleted/suppressed
                $deleted = $suppressed = false;
-               $allowed = $this->mNewRev->userCan( Revision::DELETED_TEXT, $user );
+               $allowed = $this->newRev->userCan( Revision::DELETED_TEXT, $user );
 
                $revisionTools = array();
 
-               # mOldRev is false if the difference engine is called with a "vague" query for
+               # oldRev is false if the difference engine is called with a "vague" query for
                # a diff between a version V and its previous version V' AND the version V
                # is the first version of that article. In that case, V' does not exist.
-               if ( $this->mOldRev === false ) {
-                       $out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
+               if ( $this->oldRev === false ) {
+                       $out->setPageTitle( $this->msg( 'difference-title', $this->newPage->getPrefixedText() ) );
                        $samePage = true;
                        $oldHeader = '';
                } else {
-                       wfRunHooks( 'DiffViewHeader', array( $this, $this->mOldRev, $this->mNewRev ) );
+                       wfRunHooks( 'DiffViewHeader', array( $this, $this->oldRev, $this->newRev ) );
 
-                       if ( $this->mNewPage->equals( $this->mOldPage ) ) {
-                               $out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
+                       if ( $this->newPage->equals( $this->oldPage ) ) {
+                               $out->setPageTitle( $this->msg( 'difference-title', $this->newPage->getPrefixedText() ) );
                                $samePage = true;
                        } else {
                                $out->setPageTitle( $this->msg( 'difference-title-multipage',
-                                       $this->mOldPage->getPrefixedText(), $this->mNewPage->getPrefixedText() ) );
+                                       $this->oldPage->getPrefixedText(), $this->newPage->getPrefixedText() ) );
                                $out->addSubtitle( $this->msg( 'difference-multipage' ) );
                                $samePage = false;
                        }
 
-                       if ( $samePage && $this->mNewPage->quickUserCan( 'edit', $user ) ) {
-                               if ( $this->mNewRev->isCurrent() && $this->mNewPage->userCan( 'rollback', $user ) ) {
-                                       $rollbackLink = Linker::generateRollback( $this->mNewRev, $this->getContext() );
+                       if ( $samePage && $this->newPage->quickUserCan( 'edit', $user ) ) {
+                               if ( $this->newRev->isCurrent() && $this->newPage->userCan( 'rollback', $user ) ) {
+                                       $rollbackLink = Linker::generateRollback( $this->newRev, $this->getContext() );
                                        if ( $rollbackLink ) {
                                                $out->preventClickjacking();
                                                $rollback = '&#160;&#160;&#160;' . $rollbackLink;
                                        }
                                }
 
-                               if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) &&
-                                       !$this->mNewRev->isDeleted( Revision::DELETED_TEXT )
+                               if ( !$this->oldRev->isDeleted( Revision::DELETED_TEXT ) &&
+                                       !$this->newRev->isDeleted( Revision::DELETED_TEXT )
                                ) {
                                        $undoLink = Html::element( 'a', array(
-                                                       'href' => $this->mNewPage->getLocalURL( array(
+                                                       'href' => $this->newPage->getLocalURL( array(
                                                                'action' => 'edit',
-                                                               'undoafter' => $this->mOldid,
-                                                               'undo' => $this->mNewid ) ),
+                                                               'undoafter' => $this->oldId,
+                                                               'undo' => $this->newId ) ),
                                                        'title' => Linker::titleAttrib( 'undo' )
                                                ),
                                                $this->msg( 'editundo' )->text()
@@ -294,92 +305,92 @@ class DifferenceEngine extends ContextSource {
                        }
 
                        # Make "previous revision link"
-                       if ( $samePage && $this->mOldRev->getPrevious() ) {
+                       if ( $samePage && $this->oldRev->getPrevious() ) {
                                $prevlink = Linker::linkKnown(
-                                       $this->mOldPage,
+                                       $this->oldPage,
                                        $this->msg( 'previousdiff' )->escaped(),
                                        array( 'id' => 'differences-prevlink' ),
-                                       array( 'diff' => 'prev', 'oldid' => $this->mOldid ) + $query
+                                       array( 'diff' => 'prev', 'oldid' => $this->oldId ) + $query
                                );
                        } else {
                                $prevlink = '&#160;';
                        }
 
-                       if ( $this->mOldRev->isMinor() ) {
+                       if ( $this->oldRev->isMinor() ) {
                                $oldminor = ChangesList::flag( 'minor' );
                        } else {
                                $oldminor = '';
                        }
 
-                       $ldel = $this->revisionDeleteLink( $this->mOldRev );
-                       $oldRevisionHeader = $this->getRevisionHeader( $this->mOldRev, 'complete' );
-                       $oldChangeTags = ChangeTags::formatSummaryRow( $this->mOldTags, 'diff' );
+                       $ldel = $this->revisionDeleteLink( $this->oldRev );
+                       $oldRevisionHeader = $this->getRevisionHeader( $this->oldRev, 'complete' );
+                       $oldChangeTags = ChangeTags::formatSummaryRow( $this->oldTags, 'diff' );
 
                        $oldHeader = '<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader . '</strong></div>' .
                                '<div id="mw-diff-otitle2">' .
-                                       Linker::revUserTools( $this->mOldRev, !$this->unhide ) . '</div>' .
+                                       Linker::revUserTools( $this->oldRev, !$this->unhide ) . '</div>' .
                                '<div id="mw-diff-otitle3">' . $oldminor .
-                                       Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
+                                       Linker::revComment( $this->oldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
                                '<div id="mw-diff-otitle5">' . $oldChangeTags[0] . '</div>' .
                                '<div id="mw-diff-otitle4">' . $prevlink . '</div>';
 
-                       if ( $this->mOldRev->isDeleted( Revision::DELETED_TEXT ) ) {
+                       if ( $this->oldRev->isDeleted( Revision::DELETED_TEXT ) ) {
                                $deleted = true; // old revisions text is hidden
-                               if ( $this->mOldRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
+                               if ( $this->oldRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
                                        $suppressed = true; // also suppressed
                                }
                        }
 
                        # Check if this user can see the revisions
-                       if ( !$this->mOldRev->userCan( Revision::DELETED_TEXT, $user ) ) {
+                       if ( !$this->oldRev->userCan( Revision::DELETED_TEXT, $user ) ) {
                                $allowed = false;
                        }
                }
 
                # Make "next revision link"
                # Skip next link on the top revision
-               if ( $samePage && !$this->mNewRev->isCurrent() ) {
+               if ( $samePage && !$this->newRev->isCurrent() ) {
                        $nextlink = Linker::linkKnown(
-                               $this->mNewPage,
+                               $this->newPage,
                                $this->msg( 'nextdiff' )->escaped(),
                                array( 'id' => 'differences-nextlink' ),
-                               array( 'diff' => 'next', 'oldid' => $this->mNewid ) + $query
+                               array( 'diff' => 'next', 'oldid' => $this->newId ) + $query
                        );
                } else {
                        $nextlink = '&#160;';
                }
 
-               if ( $this->mNewRev->isMinor() ) {
+               if ( $this->newRev->isMinor() ) {
                        $newminor = ChangesList::flag( 'minor' );
                } else {
                        $newminor = '';
                }
 
                # Handle RevisionDelete links...
-               $rdel = $this->revisionDeleteLink( $this->mNewRev );
+               $rdel = $this->revisionDeleteLink( $this->newRev );
 
                # Allow extensions to define their own revision tools
-               wfRunHooks( 'DiffRevisionTools', array( $this->mNewRev, &$revisionTools ) );
+               wfRunHooks( 'DiffRevisionTools', array( $this->newRev, &$revisionTools ) );
                $formattedRevisionTools = array();
                // Put each one in parentheses (poor man's button)
                foreach ( $revisionTools as $tool ) {
                        $formattedRevisionTools[] = $this->msg( 'parentheses' )->rawParams( $tool )->escaped();
                }
-               $newRevisionHeader = $this->getRevisionHeader( $this->mNewRev, 'complete' ) .
+               $newRevisionHeader = $this->getRevisionHeader( $this->newRev, 'complete' ) .
                        ' ' . implode( ' ', $formattedRevisionTools );
-               $newChangeTags = ChangeTags::formatSummaryRow( $this->mNewTags, 'diff' );
+               $newChangeTags = ChangeTags::formatSummaryRow( $this->newTags, 'diff' );
 
                $newHeader = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' .
-                       '<div id="mw-diff-ntitle2">' . Linker::revUserTools( $this->mNewRev, !$this->unhide ) .
+                       '<div id="mw-diff-ntitle2">' . Linker::revUserTools( $this->newRev, !$this->unhide ) .
                                " $rollback</div>" .
                        '<div id="mw-diff-ntitle3">' . $newminor .
-                               Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
+                               Linker::revComment( $this->newRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
                        '<div id="mw-diff-ntitle5">' . $newChangeTags[0] . '</div>' .
                        '<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
 
-               if ( $this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
+               if ( $this->newRev->isDeleted( Revision::DELETED_TEXT ) ) {
                        $deleted = true; // new revisions text is hidden
-                       if ( $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
+                       if ( $this->newRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
                                $suppressed = true; // also suppressed
                        }
                }
@@ -435,22 +446,22 @@ class DifferenceEngine extends ContextSource {
                global $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
                $user = $this->getUser();
 
-               if ( $this->mMarkPatrolledLink === null ) {
+               if ( $this->markPatrolledLink === null ) {
                        // Prepare a change patrol link, if applicable
                        if (
                                // Is patrolling enabled and the user allowed to?
-                               $wgUseRCPatrol && $this->mNewPage->quickUserCan( 'patrol', $user ) &&
+                               $wgUseRCPatrol && $this->newPage->quickUserCan( 'patrol', $user ) &&
                                // Only do this if the revision isn't more than 6 hours older
                                // than the Max RC age (6h because the RC might not be cleaned out regularly)
-                               RecentChange::isInRCLifespan( $this->mNewRev->getTimestamp(), 21600 )
+                               RecentChange::isInRCLifespan( $this->newRev->getTimestamp(), 21600 )
                        ) {
                                // Look for an unpatrolled change corresponding to this diff
 
                                $db = wfGetDB( DB_SLAVE );
                                $change = RecentChange::newFromConds(
                                        array(
-                                               'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ),
-                                               'rc_this_oldid' => $this->mNewid,
+                                               'rc_timestamp' => $db->timestamp( $this->newRev->getTimestamp() ),
+                                               'rc_this_oldid' => $this->newId,
                                                'rc_patrolled' => 0
                                        ),
                                        __METHOD__,
@@ -474,8 +485,8 @@ class DifferenceEngine extends ContextSource {
                                        }
 
                                        $token = $user->getEditToken( $rcid );
-                                       $this->mMarkPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
-                                               $this->mNewPage,
+                                       $this->markPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
+                                               $this->newPage,
                                                $this->msg( 'markaspatrolleddiff' )->escaped(),
                                                array(),
                                                array(
@@ -485,14 +496,14 @@ class DifferenceEngine extends ContextSource {
                                                )
                                        ) . ']</span>';
                                } else {
-                                       $this->mMarkPatrolledLink = '';
+                                       $this->markPatrolledLink = '';
                                }
                        } else {
-                               $this->mMarkPatrolledLink = '';
+                               $this->markPatrolledLink = '';
                        }
                }
 
-               return $this->mMarkPatrolledLink;
+               return $this->markPatrolledLink;
        }
 
        /**
@@ -513,7 +524,7 @@ class DifferenceEngine extends ContextSource {
        function renderNewRevision() {
                wfProfileIn( __METHOD__ );
                $out = $this->getOutput();
-               $revHeader = $this->getRevisionHeader( $this->mNewRev );
+               $revHeader = $this->getRevisionHeader( $this->newRev );
                # Add "current version as of X" title
                $out->addHTML( "<hr class='diff-hr' />
                <h2 class='diff-currentversion-title'>{$revHeader}</h2>\n" );
@@ -521,47 +532,47 @@ class DifferenceEngine extends ContextSource {
                # @codingStandardsIgnoreStart Ignoring long lines.
                if ( wfRunHooks( 'ArticleContentOnDiff', array( $this, $out ) ) ) {
                        $this->loadNewText();
-                       $out->setRevisionId( $this->mNewid );
-                       $out->setRevisionTimestamp( $this->mNewRev->getTimestamp() );
+                       $out->setRevisionId( $this->newId );
+                       $out->setRevisionTimestamp( $this->newRev->getTimestamp() );
                        $out->setArticleFlag( true );
 
                        // NOTE: only needed for B/C: custom rendering of JS/CSS via hook
-                       if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) {
+                       if ( $this->newPage->isCssJsSubpage() || $this->newPage->isCssOrJsPage() ) {
                                // Stolen from Article::view --AG 2007-10-11
                                // Give hooks a chance to customise the output
                                // @todo standardize this crap into one function
-                               if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+                               if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->newContent, $this->newPage, $out ) ) ) {
                                        // NOTE: deprecated hook, B/C only
                                        // use the content object's own rendering
-                                       $cnt = $this->mNewRev->getContent();
-                                       $po = $cnt ? $cnt->getParserOutput( $this->mNewRev->getTitle(), $this->mNewRev->getId() ) : null;
+                                       $cnt = $this->newRev->getContent();
+                                       $po = $cnt ? $cnt->getParserOutput( $this->newRev->getTitle(), $this->newRev->getId() ) : null;
                                        $txt = $po ? $po->getText() : '';
                                        $out->addHTML( $txt );
                                }
-                       } elseif ( !wfRunHooks( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+                       } elseif ( !wfRunHooks( 'ArticleContentViewCustom', array( $this->newContent, $this->newPage, $out ) ) ) {
                                // Handled by extension
-                       } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+                       } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', array( $this->newContent, $this->newPage, $out ) ) ) {
                                // NOTE: deprecated hook, B/C only
                                // Handled by extension
                        } else {
                                // Normal page
-                               if ( $this->getTitle()->equals( $this->mNewPage ) ) {
+                               if ( $this->getTitle()->equals( $this->newPage ) ) {
                                        // If the Title stored in the context is the same as the one
                                        // of the new revision, we can use its associated WikiPage
                                        // object.
                                        $wikiPage = $this->getWikiPage();
                                } else {
                                        // Otherwise we need to create our own WikiPage object
-                                       $wikiPage = WikiPage::factory( $this->mNewPage );
+                                       $wikiPage = WikiPage::factory( $this->newPage );
                                }
 
-                               $parserOutput = $this->getParserOutput( $wikiPage, $this->mNewRev );
+                               $parserOutput = $this->getParserOutput( $wikiPage, $this->newRev );
 
                                # Also try to load it as a redirect
-                               $rt = $this->mNewContent ? $this->mNewContent->getRedirectTarget() : null;
+                               $rt = $this->newContent ? $this->newContent->getRedirectTarget() : null;
 
                                if ( $rt ) {
-                                       $article = Article::newFromTitle( $this->mNewPage, $this->getContext() );
+                                       $article = Article::newFromTitle( $this->newPage, $this->getContext() );
                                        $out->addHTML( $article->viewRedirect( $rt ) );
 
                                        # WikiPage::getParserOutput() should not return false, but just in case
@@ -599,7 +610,8 @@ class DifferenceEngine extends ContextSource {
         *
         * @param string|bool $otitle Header for old text or false
         * @param string|bool $ntitle Header for new text or false
-        * @param string $notice
+        * @param string $notice HTML between diff header and body
+        *
         * @return bool
         */
        function showDiff( $otitle, $ntitle, $notice = '' ) {
@@ -654,36 +666,36 @@ class DifferenceEngine extends ContextSource {
        public function getDiffBody() {
                global $wgMemc;
                wfProfileIn( __METHOD__ );
-               $this->mCacheHit = true;
+               $this->cacheHit = true;
                // Check if the diff should be hidden from this user
                if ( !$this->loadRevisionData() ) {
                        wfProfileOut( __METHOD__ );
                        return false;
-               } elseif ( $this->mOldRev &&
-                       !$this->mOldRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
+               } elseif ( $this->oldRev &&
+                       !$this->oldRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
                ) {
                        wfProfileOut( __METHOD__ );
                        return false;
-               } elseif ( $this->mNewRev &&
-                       !$this->mNewRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
+               } elseif ( $this->newRev &&
+                       !$this->newRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
                ) {
                        wfProfileOut( __METHOD__ );
                        return false;
                }
                // Short-circuit
-               if ( $this->mOldRev === false || ( $this->mOldRev && $this->mNewRev
-                       && $this->mOldRev->getID() == $this->mNewRev->getID() ) )
+               if ( $this->oldRev === false || ( $this->oldRev && $this->newRev
+                       && $this->oldRev->getID() == $this->newRev->getID() ) )
                {
                        wfProfileOut( __METHOD__ );
                        return '';
                }
                // Cacheable?
                $key = false;
-               if ( $this->mOldid && $this->mNewid ) {
+               if ( $this->oldId && $this->newId ) {
                        $key = $this->getDiffBodyCacheKey();
 
                        // Try cache
-                       if ( !$this->mRefreshCache ) {
+                       if ( !$this->refreshCache ) {
                                $difftext = $wgMemc->get( $key );
                                if ( $difftext ) {
                                        wfIncrStats( 'diff_cache_hit' );
@@ -694,7 +706,7 @@ class DifferenceEngine extends ContextSource {
                                }
                        } // don't try to load but save the result
                }
-               $this->mCacheHit = false;
+               $this->cacheHit = false;
 
                // Loadtext is permission safe, this just clears out the diff
                if ( !$this->loadText() ) {
@@ -702,7 +714,7 @@ class DifferenceEngine extends ContextSource {
                        return false;
                }
 
-               $difftext = $this->generateContentDiffBody( $this->mOldContent, $this->mNewContent );
+               $difftext = $this->generateContentDiffBody( $this->oldContent, $this->newContent );
 
                // Save to cache for 7 days
                if ( !wfRunHooks( 'AbortDiffCache', array( &$this ) ) ) {
@@ -729,12 +741,12 @@ class DifferenceEngine extends ContextSource {
         * @throws MWException
         */
        protected function getDiffBodyCacheKey() {
-               if ( !$this->mOldid || !$this->mNewid ) {
-                       throw new MWException( 'mOldid and mNewid must be set to get diff cache key.' );
+               if ( !$this->oldId || !$this->newId ) {
+                       throw new MWException( 'oldId and newId must be set to get diff cache key.' );
                }
 
-               return wfMemcKey( 'diff', 'version', MW_DIFF_VERSION,
-                       'oldid', $this->mOldid, 'newid', $this->mNewid );
+               return wfMemcKey( 'diff', 'version', self::CACHE_VERSION,
+                       'oldid', $this->oldId, 'newid', $this->newId );
        }
 
        /**
@@ -867,6 +879,9 @@ class DifferenceEngine extends ContextSource {
        /**
         * Generate a debug comment indicating diff generating time,
         * server node, and generator backend.
+        *
+        * @param String $generator: What diff engine was used
+        *
         * @return string
         */
        protected function debug( $generator = "internal" ) {
@@ -879,16 +894,20 @@ class DifferenceEngine extends ContextSource {
                        $data[] = wfHostname();
                }
                $data[] = wfTimestamp( TS_DB );
-               return "<!-- diff generator: " .
-               implode( " ",
-               array_map(
+               return "<!-- diff generator: "
+                       . implode( " ",
+                               array_map(
                                        "htmlspecialchars",
-               $data ) ) .
-                       " -->\n";
+                               $data )
+                       )
+                       . " -->\n";
        }
 
        /**
         * Replace line numbers with the text in the user's language
+        *
+        * @param String $text
+        *
         * @return mixed
         */
        function localiseLineNumbers( $text ) {
@@ -897,7 +916,7 @@ class DifferenceEngine extends ContextSource {
        }
 
        function localiseLineNumbersCb( $matches ) {
-               if ( $matches[1] === '1' && $this->mReducedLineNumbers ) {
+               if ( $matches[1] === '1' && $this->reducedLineNumbers ) {
                        return '';
                }
                return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped();
@@ -908,25 +927,25 @@ class DifferenceEngine extends ContextSource {
         * @return string
         */
        function getMultiNotice() {
-               if ( !is_object( $this->mOldRev ) || !is_object( $this->mNewRev ) ) {
+               if ( !is_object( $this->oldRev ) || !is_object( $this->newRev ) ) {
                        return '';
-               } elseif ( !$this->mOldPage->equals( $this->mNewPage ) ) {
+               } elseif ( !$this->oldPage->equals( $this->newPage ) ) {
                        // Comparing two different pages? Count would be meaningless.
                        return '';
                }
 
-               if ( $this->mOldRev->getTimestamp() > $this->mNewRev->getTimestamp() ) {
-                       $oldRev = $this->mNewRev; // flip
-                       $newRev = $this->mOldRev; // flip
+               if ( $this->oldRev->getTimestamp() > $this->newRev->getTimestamp() ) {
+                       $oldRev = $this->newRev; // flip
+                       $newRev = $this->oldRev; // flip
                } else { // normal case
-                       $oldRev = $this->mOldRev;
-                       $newRev = $this->mNewRev;
+                       $oldRev = $this->oldRev;
+                       $newRev = $this->newRev;
                }
 
-               $nEdits = $this->mNewPage->countRevisionsBetween( $oldRev, $newRev );
+               $nEdits = $this->newPage->countRevisionsBetween( $oldRev, $newRev );
                if ( $nEdits > 0 ) {
                        $limit = 100; // use diff-multi-manyusers if too many users
-                       $numUsers = $this->mNewPage->countAuthorsBetween( $oldRev, $newRev, $limit );
+                       $numUsers = $this->newPage->countAuthorsBetween( $oldRev, $newRev, $limit );
                        return self::intermediateEditsMsg( $nEdits, $numUsers, $limit );
                }
                return ''; // nothing
@@ -1008,6 +1027,12 @@ class DifferenceEngine extends ContextSource {
        /**
         * Add the header to a diff body
         *
+        * @param String $diff: Diff body
+        * @param String $otitle: Old revision header
+        * @param String $ntitle: New revision header
+        * @param String $multi: Notice telling user that there are intermediate revisions between the ones being compared
+        * @param String $notice: Other notices, e.g. that user is viewing deleted content
+        *
         * @return string
         */
        function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
@@ -1073,11 +1098,11 @@ class DifferenceEngine extends ContextSource {
         * @since 1.21
         */
        function setContent( Content $oldContent, Content $newContent ) {
-               $this->mOldContent = $oldContent;
-               $this->mNewContent = $newContent;
+               $this->oldContent = $oldContent;
+               $this->newContent = $newContent;
 
-               $this->mTextLoaded = 2;
-               $this->mRevisionsLoaded = true;
+               $this->textLoaded = 2;
+               $this->revisionsLoaded = true;
        }
 
        /**
@@ -1086,7 +1111,7 @@ class DifferenceEngine extends ContextSource {
         * @since 1.19
         */
        function setTextLanguage( $lang ) {
-               $this->mDiffLang = wfGetLangObj( $lang );
+               $this->diffLang = wfGetLangObj( $lang );
        }
 
        /**
@@ -1120,23 +1145,23 @@ class DifferenceEngine extends ContextSource {
         * Load revision IDs
         */
        private function loadRevisionIds() {
-               if ( $this->mRevisionsIdsLoaded ) {
+               if ( $this->revisionsIdsLoaded ) {
                        return;
                }
 
-               $this->mRevisionsIdsLoaded = true;
+               $this->revisionsIdsLoaded = true;
 
-               $old = $this->mOldid;
-               $new = $this->mNewid;
+               $old = $this->oldId;
+               $new = $this->newId;
 
-               list( $this->mOldid, $this->mNewid ) = self::mapDiffPrevNext( $old, $new );
-               if ( $new === 'next' && $this->mNewid === false ) {
+               list( $this->oldId, $this->newId ) = self::mapDiffPrevNext( $old, $new );
+               if ( $new === 'next' && $this->newId === false ) {
                        # if no result, NewId points to the newest old revision. The only newer
                        # revision is cur, which is "0".
-                       $this->mNewid = 0;
+                       $this->newId = 0;
                }
 
-               wfRunHooks( 'NewDifferenceEngine', array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new ) );
+               wfRunHooks( 'NewDifferenceEngine', array( $this->getTitle(), &$this->oldId, &$this->newId, $old, $new ) );
        }
 
        /**
@@ -1152,74 +1177,74 @@ class DifferenceEngine extends ContextSource {
         * @return bool
         */
        function loadRevisionData() {
-               if ( $this->mRevisionsLoaded ) {
+               if ( $this->revisionsLoaded ) {
                        return true;
                }
 
                // Whether it succeeds or fails, we don't want to try again
-               $this->mRevisionsLoaded = true;
+               $this->revisionsLoaded = true;
 
                $this->loadRevisionIds();
 
                // Load the new revision object
-               if ( $this->mNewid ) {
-                       $this->mNewRev = Revision::newFromId( $this->mNewid );
+               if ( $this->newId ) {
+                       $this->newRev = Revision::newFromId( $this->newId );
                } else {
-                       $this->mNewRev = Revision::newFromTitle(
+                       $this->newRev = Revision::newFromTitle(
                                $this->getTitle(),
                                false,
                                Revision::READ_NORMAL
                        );
                }
 
-               if ( !$this->mNewRev instanceof Revision ) {
+               if ( !$this->newRev instanceof Revision ) {
                        return false;
                }
 
                // Update the new revision ID in case it was 0 (makes life easier doing UI stuff)
-               $this->mNewid = $this->mNewRev->getId();
-               $this->mNewPage = $this->mNewRev->getTitle();
+               $this->newId = $this->newRev->getId();
+               $this->newPage = $this->newRev->getTitle();
 
                // Load the old revision object
-               $this->mOldRev = false;
-               if ( $this->mOldid ) {
-                       $this->mOldRev = Revision::newFromId( $this->mOldid );
-               } elseif ( $this->mOldid === 0 ) {
-                       $rev = $this->mNewRev->getPrevious();
+               $this->oldRev = false;
+               if ( $this->oldId ) {
+                       $this->oldRev = Revision::newFromId( $this->oldId );
+               } elseif ( $this->oldId === 0 ) {
+                       $rev = $this->newRev->getPrevious();
                        if ( $rev ) {
-                               $this->mOldid = $rev->getId();
-                               $this->mOldRev = $rev;
+                               $this->oldId = $rev->getId();
+                               $this->oldRev = $rev;
                        } else {
                                // No previous revision; mark to show as first-version only.
-                               $this->mOldid = false;
-                               $this->mOldRev = false;
+                               $this->oldId = false;
+                               $this->oldRev = false;
                        }
-               } /* elseif ( $this->mOldid === false ) leave mOldRev false; */
+               } /* elseif ( $this->oldId === false ) leave oldRev false; */
 
-               if ( is_null( $this->mOldRev ) ) {
+               if ( is_null( $this->oldRev ) ) {
                        return false;
                }
 
-               if ( $this->mOldRev ) {
-                       $this->mOldPage = $this->mOldRev->getTitle();
+               if ( $this->oldRev ) {
+                       $this->oldPage = $this->oldRev->getTitle();
                }
 
                // Load tags information for both revisions
                $dbr = wfGetDB( DB_SLAVE );
-               if ( $this->mOldid !== false ) {
-                       $this->mOldTags = $dbr->selectField(
+               if ( $this->oldId !== false ) {
+                       $this->oldTags = $dbr->selectField(
                                'tag_summary',
                                'ts_tags',
-                               array( 'ts_rev_id' => $this->mOldid ),
+                               array( 'ts_rev_id' => $this->oldId ),
                                __METHOD__
                        );
                } else {
-                       $this->mOldTags = false;
+                       $this->oldTags = false;
                }
-               $this->mNewTags = $dbr->selectField(
+               $this->newTags = $dbr->selectField(
                        'tag_summary',
                        'ts_tags',
-                       array( 'ts_rev_id' => $this->mNewid ),
+                       array( 'ts_rev_id' => $this->newId ),
                        __METHOD__
                );
 
@@ -1232,27 +1257,27 @@ class DifferenceEngine extends ContextSource {
         * @return bool
         */
        function loadText() {
-               if ( $this->mTextLoaded == 2 ) {
+               if ( $this->textLoaded == 2 ) {
                        return true;
                }
 
                // Whether it succeeds or fails, we don't want to try again
-               $this->mTextLoaded = 2;
+               $this->textLoaded = 2;
 
                if ( !$this->loadRevisionData() ) {
                        return false;
                }
 
-               if ( $this->mOldRev ) {
-                       $this->mOldContent = $this->mOldRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
-                       if ( $this->mOldContent === null ) {
+               if ( $this->oldRev ) {
+                       $this->oldContent = $this->oldRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
+                       if ( $this->oldContent === null ) {
                                return false;
                        }
                }
 
-               if ( $this->mNewRev ) {
-                       $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
-                       if ( $this->mNewContent === null ) {
+               if ( $this->newRev ) {
+                       $this->newContent = $this->newRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
+                       if ( $this->newContent === null ) {
                                return false;
                        }
                }
@@ -1266,17 +1291,17 @@ class DifferenceEngine extends ContextSource {
         * @return bool
         */
        function loadNewText() {
-               if ( $this->mTextLoaded >= 1 ) {
+               if ( $this->textLoaded >= 1 ) {
                        return true;
                }
 
-               $this->mTextLoaded = 1;
+               $this->textLoaded = 1;
 
                if ( !$this->loadRevisionData() ) {
                        return false;
                }
 
-               $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
+               $this->newContent = $this->newRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
 
                return true;
        }
diff --git a/includes/diff/TableDiffFormatter.php b/includes/diff/TableDiffFormatter.php
new file mode 100644 (file)
index 0000000..0ce17df
--- /dev/null
@@ -0,0 +1,183 @@
+<?php
+/**
+ * Portions taken from phpwiki-1.3.3.
+ *
+ * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
+ * You may copy this code freely under the conditions of the GPL.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup DifferenceEngine
+ */
+
+/**
+ * MediaWiki default table style diff formatter
+ * @todo document
+ * @private
+ * @ingroup DifferenceEngine
+ */
+class TableDiffFormatter extends DiffFormatter {
+       function __construct() {
+               $this->leadingContextLines = 2;
+               $this->trailingContextLines = 2;
+       }
+
+       /**
+        * @static
+        * @param $msg
+        * @return mixed
+        */
+       public static function escapeWhiteSpace( $msg ) {
+               $msg = preg_replace( '/^ /m', '&#160; ', $msg );
+               $msg = preg_replace( '/ $/m', ' &#160;', $msg );
+               $msg = preg_replace( '/  /', '&#160; ', $msg );
+               return $msg;
+       }
+
+       /**
+        * @param $xbeg
+        * @param $xlen
+        * @param $ybeg
+        * @param $ylen
+        * @return string
+        */
+       protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
+               $r = '<tr><td colspan="2" class="diff-lineno"><!--LINE ' . $xbeg . "--></td>\n" .
+                       '<td colspan="2" class="diff-lineno"><!--LINE ' . $ybeg . "--></td></tr>\n";
+               return $r;
+       }
+
+       /**
+        * @param $header
+        */
+       protected function startBlock( $header ) {
+               echo $header;
+       }
+
+       protected function endBlock() {
+       }
+
+       protected function lines( $lines, $prefix = ' ', $color = 'white' ) {
+       }
+
+       /**
+        * HTML-escape parameter before calling this
+        * @param $line
+        * @return string
+        */
+       protected function addedLine( $line ) {
+               return $this->wrapLine( '+', 'diff-addedline', $line );
+       }
+
+       /**
+        * HTML-escape parameter before calling this
+        * @param $line
+        * @return string
+        */
+       protected function deletedLine( $line ) {
+               return $this->wrapLine( '−', 'diff-deletedline', $line );
+       }
+
+       /**
+        * HTML-escape parameter before calling this
+        * @param $line
+        * @return string
+        */
+       protected function contextLine( $line ) {
+               return $this->wrapLine( '&#160;', 'diff-context', $line );
+       }
+
+       /**
+        * @param $marker
+        * @param $class
+        * @param $line
+        * @return string
+        */
+       protected function wrapLine( $marker, $class, $line ) {
+               if ( $line !== '' ) {
+                       // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
+                       $line = Xml::tags( 'div', null, $this->escapeWhiteSpace( $line ) );
+               }
+               return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
+       }
+
+       /**
+        * @return string
+        */
+       protected function emptyLine() {
+               return '<td colspan="2">&#160;</td>';
+       }
+
+       /**
+        * @param $lines array
+        */
+       protected function added( $lines ) {
+               foreach ( $lines as $line ) {
+                       echo '<tr>' . $this->emptyLine() .
+                               $this->addedLine( '<ins class="diffchange">' .
+                                       htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n";
+               }
+       }
+
+       /**
+        * @param $lines
+        */
+       protected function deleted( $lines ) {
+               foreach ( $lines as $line ) {
+                       echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
+                                       htmlspecialchars( $line ) . '</del>' ) .
+                               $this->emptyLine() . "</tr>\n";
+               }
+       }
+
+       /**
+        * @param $lines
+        */
+       protected function context( $lines ) {
+               foreach ( $lines as $line ) {
+                       echo '<tr>' .
+                               $this->contextLine( htmlspecialchars( $line ) ) .
+                               $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n";
+               }
+       }
+
+       /**
+        * @param $orig
+        * @param $closing
+        */
+       protected function changed( $orig, $closing ) {
+               wfProfileIn( __METHOD__ );
+
+               $diff = new WordLevelDiff( $orig, $closing );
+               $del = $diff->orig();
+               $add = $diff->closing();
+
+               # Notice that WordLevelDiff returns HTML-escaped output.
+               # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
+
+               while ( $line = array_shift( $del ) ) {
+                       $aline = array_shift( $add );
+                       echo '<tr>' . $this->deletedLine( $line ) .
+                               $this->addedLine( $aline ) . "</tr>\n";
+               }
+               foreach ( $add as $line ) {     # If any leftovers
+                       echo '<tr>' . $this->emptyLine() .
+                               $this->addedLine( $line ) . "</tr>\n";
+               }
+               wfProfileOut( __METHOD__ );
+       }
+}
diff --git a/includes/diff/UnifiedDiffFormatter.php b/includes/diff/UnifiedDiffFormatter.php
new file mode 100644 (file)
index 0000000..d489538
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Portions taken from phpwiki-1.3.3.
+ *
+ * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
+ * You may copy this code freely under the conditions of the GPL.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup DifferenceEngine
+ */
+
+/**
+ * A formatter that outputs unified diffs
+ * @ingroup DifferenceEngine
+ */
+class UnifiedDiffFormatter extends DiffFormatter {
+       protected $leadingContextLines = 2;
+       protected $trailingContextLines = 2;
+
+       /**
+        * @param $lines
+        */
+       protected function added( $lines ) {
+               $this->lines( $lines, '+' );
+       }
+
+       /**
+        * @param $lines
+        */
+       protected function deleted( $lines ) {
+               $this->lines( $lines, '-' );
+       }
+
+       /**
+        * @param $orig
+        * @param $closing
+        */
+       protected function changed( $orig, $closing ) {
+               $this->deleted( $orig );
+               $this->added( $closing );
+       }
+
+       /**
+        * @param $xbeg
+        * @param $xlen
+        * @param $ybeg
+        * @param $ylen
+        * @return string
+        */
+       protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
+               return "@@ -$xbeg,$xlen +$ybeg,$ylen @@";
+       }
+}
index ec2e2c0..1787d66 100644 (file)
@@ -1706,7 +1706,7 @@ class SwiftFileBackendFileList extends SwiftFileBackendList {
                $relPath = substr( $path, $this->suffixStart );
                if ( is_array( $stat ) ) {
                        $storageDir = rtrim( $this->params['dir'], '/' );
-                       $this->backend->loadListingStatInternal( "$storageDir/$path", $stat );
+                       $this->backend->loadListingStatInternal( "$storageDir/$relPath", $stat );
                }
                return $relPath;
        }
index 8c8de8e..dd32656 100644 (file)
@@ -88,7 +88,9 @@ class SpecialSearch extends SpecialPage {
                $this->outputHeader();
                $out = $this->getOutput();
                $out->allowClickjacking();
-               $out->addModuleStyles( 'mediawiki.special' );
+               $out->addModuleStyles( array(
+                       'mediawiki.special', 'mediawiki.special.search', 'mediawiki.ui'
+               ) );
 
                // Strip underscores from title parameter; most of the time we'll want
                // text form here. But don't strip underscores from actual text params!
@@ -1093,10 +1095,14 @@ class SpecialSearch extends SpecialPage {
                $out .= Html::input( 'search', $term, 'search', array(
                        'id' => $this->profile === 'advanced' ? 'powerSearchText' : 'searchText',
                        'size' => '50',
-                       'autofocus'
+                       'autofocus',
+                       'class' => 'mw-ui-input',
                ) ) . "\n";
                $out .= Html::hidden( 'fulltext', 'Search' ) . "\n";
-               $out .= Xml::submitButton( $this->msg( 'searchbutton' )->text() ) . "\n";
+               $out .= Xml::submitButton(
+                       $this->msg( 'searchbutton' )->text(),
+                       array( 'class' => array( 'mw-ui-button', 'mw-ui-primary' ) )
+               ) . "\n";
                return $out . $this->didYouMeanHtml;
        }
 
index b79aaa9..0700c49 100644 (file)
@@ -60,7 +60,7 @@ class SpecialUpload extends SpecialPage {
 
        /** User input variables from the root section **/
        public $mIgnoreWarning;
-       public $mWatchThis;
+       public $mWatchthis;
        public $mCopyrightStatus;
        public $mCopyrightSource;
 
@@ -75,8 +75,6 @@ class SpecialUpload extends SpecialPage {
        public $uploadFormTextTop;
        public $uploadFormTextAfterSummary;
 
-       public $mWatchthis;
-
        /**
         * Initialize instance variables from request and create an Upload handler
         */
@@ -517,11 +515,17 @@ class SpecialUpload extends SpecialPage {
                        return true;
                }
 
+               $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
+               if ( $desiredTitleObj instanceof Title && $this->getUser()->isWatched( $desiredTitleObj ) ) {
+                       // Already watched, don't change that
+                       return true;
+               }
+
                $local = wfLocalFile( $this->mDesiredDestName );
                if ( $local && $local->exists() ) {
                        // We're uploading a new version of an existing file.
                        // No creation, so don't watch it if we're not already.
-                       return $this->getUser()->isWatched( $local->getTitle() );
+                       return false;
                } else {
                        // New page should get watched if that's our option.
                        return $this->getUser()->getOption( 'watchcreations' );
@@ -1011,7 +1015,7 @@ class UploadForm extends HTMLForm {
                                        'id' => 'wpWatchthis',
                                        'label-message' => 'watchthisupload',
                                        'section' => 'options',
-                                       'default' => $user->getOption( 'watchcreations' ),
+                                       'default' => $this->mWatch,
                                )
                        );
                }
index 336b05b..62c33a2 100644 (file)
@@ -60,15 +60,21 @@ class SpecialWatchlist extends SpecialPage {
                // Add feed links
                $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
                if ( $wlToken ) {
-                       $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
-                                                               'wlowner' => $user->getName(), 'wltoken' => $wlToken ) );
+                       $this->addFeedLinks( array(
+                               'action' => 'feedwatchlist',
+                               'allrev' => 1,
+                               'wlowner' => $user->getName(),
+                               'wltoken' => $wlToken,
+                       ) );
                }
 
                $this->setHeaders();
                $this->outputHeader();
 
-               $output->addSubtitle( $this->msg( 'watchlistfor2', $user->getName()
-                       )->rawParams( SpecialEditWatchlist::buildTools( null ) ) );
+               $output->addSubtitle(
+                       $this->msg( 'watchlistfor2', $user->getName() )
+                               ->rawParams( SpecialEditWatchlist::buildTools( null ) )
+               );
 
                $request = $this->getRequest();
 
@@ -205,10 +211,6 @@ class SpecialWatchlist extends SpecialPage {
                        $nonRevisionTypes = array( RC_LOG );
                        wfRunHooks( 'SpecialWatchlistGetNonRevisionTypes', array( &$nonRevisionTypes ) );
                        if ( $nonRevisionTypes ) {
-                               if ( count( $nonRevisionTypes ) === 1 ) {
-                                       // if only one use an equality instead of IN condition
-                                       $nonRevisionTypes = reset( $nonRevisionTypes );
-                               }
                                $conds[] = $dbr->makeList(
                                        array(
                                                'rc_this_oldid=page_latest',
index 3dc94c8..64078b4 100644 (file)
@@ -276,7 +276,7 @@ class BackupDumper {
                }
 
                $this->lb = wfGetLBFactory()->newMainLB();
-               $db = $this->lb->getConnection( DB_SLAVE, 'backup' );
+               $db = $this->lb->getConnection( DB_SLAVE, 'dump' );
 
                // Discourage the server from disconnecting us if it takes a long time
                // to read out the big ol' batch query.
index c515c6f..8fdb958 100644 (file)
@@ -126,7 +126,7 @@ class TextPassDumper extends BackupDumper {
 
                // 2. The Connection, through the load balancer.
                try {
-                       $this->db = $this->lb->getConnection( DB_SLAVE, 'backup' );
+                       $this->db = $this->lb->getConnection( DB_SLAVE, 'dump' );
                } catch ( Exception $e ) {
                        throw new MWException( __METHOD__ . " rotating DB failed to obtain new database (" . $e->getMessage() . ")" );
                }
index 914e47e..7e6e8e6 100644 (file)
@@ -12,3 +12,9 @@
 .searchresult {
        display: inline !ie;
 }
+
+/** Add some extra padding keep browser's "clear field"
+ UI from rubbing up against the side of the field */
+input[type="search"] {
+       padding-right: 0.5em;
+}