Update formatting for includes/diff
authorSiebrand Mazeland <s.mazeland@xs4all.nl>
Wed, 20 Nov 2013 19:11:57 +0000 (20:11 +0100)
committerSiebrand Mazeland <s.mazeland@xs4all.nl>
Wed, 20 Nov 2013 19:11:57 +0000 (20:11 +0100)
Change-Id: Id032a32ca6ebea3daf5313a05602c5e98603d983

includes/diff/ArrayDiffFormatter.php
includes/diff/DairikiDiff.php
includes/diff/DiffFormatter.php
includes/diff/DifferenceEngine.php
includes/diff/TableDiffFormatter.php
includes/diff/UnifiedDiffFormatter.php
includes/diff/WikiDiff3.php

index 7da6905..331ce7d 100644 (file)
@@ -29,7 +29,6 @@
  * @ingroup DifferenceEngine
  */
 class ArrayDiffFormatter extends DiffFormatter {
-
        /**
         * @param $diff
         * @return array
@@ -74,6 +73,7 @@ class ArrayDiffFormatter extends DiffFormatter {
                                        $newline += count( $edit->orig );
                        }
                }
+
                return $retval;
        }
 }
index 53e80c4..bb0cb5f 100644 (file)
@@ -144,14 +144,14 @@ class DiffOp_Change extends DiffOp {
  *
  * The algorithm used here is mostly lifted from the perl module
  * Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
- *      http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
+ *     http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
  *
  * More ideas are taken from:
- *      http://www.ics.uci.edu/~eppstein/161/960229.html
+ *     http://www.ics.uci.edu/~eppstein/161/960229.html
  *
  * Some ideas are (and a bit of code) are from from analyze.c, from GNU
  * diffutils-2.7, which can be found at:
- *      ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
+ *     ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
  *
  * closingly, some ideas (subdivision by NCHUNKS > 2, and some optimizations)
  * are my own.
@@ -164,7 +164,6 @@ class DiffOp_Change extends DiffOp {
  * @ingroup DifferenceEngine
  */
 class DiffEngine {
-
        const MAX_XREF_LENGTH = 10000;
 
        protected $xchanged, $ychanged;
@@ -204,7 +203,8 @@ class DiffEngine {
                        // Skip matching "snake".
                        $copy = array();
                        while ( $xi < $n_from && $yi < $n_to
-                       && !$this->xchanged[$xi] && !$this->ychanged[$yi] ) {
+                               && !$this->xchanged[$xi] && !$this->ychanged[$yi]
+                       ) {
                                $copy[] = $from_lines[$xi++];
                                ++$yi;
                        }
@@ -232,6 +232,7 @@ class DiffEngine {
                        }
                }
                wfProfileOut( __METHOD__ );
+
                return $edits;
        }
 
@@ -373,11 +374,11 @@ class DiffEngine {
                for ( $chunk = 0; $chunk < $nchunks; $chunk++ ) {
                        if ( $chunk > 0 ) {
                                for ( $i = 0; $i <= $this->lcs; $i++ ) {
-                                       $ymids[$i][$chunk -1] = $this->seq[$i];
+                                       $ymids[$i][$chunk - 1] = $this->seq[$i];
                                }
                        }
 
-                       $x1 = $xoff + (int)( ( $numer + ( $xlim -$xoff ) * $chunk ) / $nchunks );
+                       $x1 = $xoff + (int)( ( $numer + ( $xlim - $xoff ) * $chunk ) / $nchunks );
                        for ( ; $x < $x1; $x++ ) {
                                $line = $flip ? $this->yv[$x] : $this->xv[$x];
                                if ( empty( $ymatches[$line] ) ) {
@@ -389,12 +390,12 @@ class DiffEngine {
                                        if ( empty( $this->in_seq[$y] ) ) {
                                                $k = $this->lcsPos( $y );
                                                assert( '$k > 0' );
-                                               $ymids[$k] = $ymids[$k -1];
+                                               $ymids[$k] = $ymids[$k - 1];
                                                break;
                                        }
                                }
                                while ( list( , $y ) = each( $matches ) ) {
-                                       if ( $y > $this->seq[$k -1] ) {
+                                       if ( $y > $this->seq[$k - 1] ) {
                                                assert( '$y < $this->seq[$k]' );
                                                // Optimization: this is a common case:
                                                //      next match is just replacing previous match.
@@ -404,7 +405,7 @@ class DiffEngine {
                                        } elseif ( empty( $this->in_seq[$y] ) ) {
                                                $k = $this->lcsPos( $y );
                                                assert( '$k > 0' );
-                                               $ymids[$k] = $ymids[$k -1];
+                                               $ymids[$k] = $ymids[$k - 1];
                                        }
                                }
                        }
@@ -431,6 +432,7 @@ class DiffEngine {
                if ( $end == 0 || $ypos > $this->seq[$end] ) {
                        $this->seq[++$this->lcs] = $ypos;
                        $this->in_seq[$ypos] = 1;
+
                        return $this->lcs;
                }
 
@@ -449,6 +451,7 @@ class DiffEngine {
                $this->in_seq[$this->seq[$end]] = false;
                $this->seq[$end] = $ypos;
                $this->in_seq[$ypos] = 1;
+
                return $end;
        }
 
@@ -477,7 +480,8 @@ class DiffEngine {
 
                // Slide up the top initial diagonal.
                while ( $xlim > $xoff && $ylim > $yoff
-               && $this->xv[$xlim - 1] == $this->yv[$ylim - 1] ) {
+                       && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]
+               ) {
                        --$xlim;
                        --$ylim;
                }
@@ -550,7 +554,7 @@ class DiffEngine {
                                $j++;
                        }
 
-                       while ( $i < $len && ! $changed[$i] ) {
+                       while ( $i < $len && !$changed[$i] ) {
                                assert( '$j < $other_len && ! $other_changed[$j]' );
                                $i++;
                                $j++;
@@ -659,7 +663,7 @@ class Diff {
         * Computes diff between sequences of strings.
         *
         * @param $from_lines array An array of strings.
-        *                (Typically these are lines from a file.)
+        *   Typically these are lines from a file.
         * @param $to_lines array An array of strings.
         */
        function __construct( $from_lines, $to_lines ) {
@@ -673,10 +677,10 @@ class Diff {
         *
         * SYNOPSIS:
         *
-        *      $diff = new Diff($lines1, $lines2);
-        *      $rev = $diff->reverse();
+        *    $diff = new Diff($lines1, $lines2);
+        *    $rev = $diff->reverse();
         * @return Object A Diff object representing the inverse of the
-        *                                original diff.
+        *   original diff.
         */
        function reverse() {
                $rev = $this;
@@ -685,6 +689,7 @@ class Diff {
                foreach ( $this->edits as $edit ) {
                        $rev->edits[] = $edit->reverse();
                }
+
                return $rev;
        }
 
@@ -699,6 +704,7 @@ class Diff {
                                return false;
                        }
                }
+
                return true;
        }
 
@@ -716,6 +722,7 @@ class Diff {
                                $lcs += count( $edit->orig );
                        }
                }
+
                return $lcs;
        }
 
@@ -735,6 +742,7 @@ class Diff {
                                array_splice( $lines, count( $lines ), 0, $edit->orig );
                        }
                }
+
                return $lines;
        }
 
@@ -754,6 +762,7 @@ class Diff {
                                array_splice( $lines, count( $lines ), 0, $edit->closing );
                        }
                }
+
                return $lines;
        }
 
@@ -811,18 +820,18 @@ class MappedDiff extends Diff {
         * changes in white-space.
         *
         * @param $from_lines array An array of strings.
-        *      (Typically these are lines from a file.)
+        *   Typically these are lines from a file.
         *
         * @param $to_lines array An array of strings.
         *
         * @param $mapped_from_lines array This array should
-        *      have the same size number of elements as $from_lines.
-        *      The elements in $mapped_from_lines and
-        *      $mapped_to_lines are what is actually compared
-        *      when computing the diff.
+        *   have the same size number of elements as $from_lines.
+        *   The elements in $mapped_from_lines and
+        *   $mapped_to_lines are what is actually compared
+        *   when computing the diff.
         *
         * @param $mapped_to_lines array This array should
-        *      have the same number of elements as $to_lines.
+        *   have the same number of elements as $to_lines.
         */
        function __construct( $from_lines, $to_lines,
                $mapped_from_lines, $mapped_to_lines ) {
@@ -873,10 +882,10 @@ class HWLDF_WordAccumulator {
                if ( $this->group !== '' ) {
                        if ( $this->tag == 'ins' ) {
                                $this->line .= '<ins class="diffchange diffchange-inline">' .
-                                               htmlspecialchars( $this->group ) . '</ins>';
+                                       htmlspecialchars( $this->group ) . '</ins>';
                        } elseif ( $this->tag == 'del' ) {
                                $this->line .= '<del class="diffchange diffchange-inline">' .
-                                               htmlspecialchars( $this->group ) . '</del>';
+                                       htmlspecialchars( $this->group ) . '</del>';
                        } else {
                                $this->line .= htmlspecialchars( $this->group );
                        }
@@ -927,6 +936,7 @@ class HWLDF_WordAccumulator {
         */
        public function getLines() {
                $this->flushLine( '~done' );
+
                return $this->lines;
        }
 }
@@ -950,7 +960,7 @@ class WordLevelDiff extends MappedDiff {
                list( $closing_words, $closing_stripped ) = $this->split( $closing_lines );
 
                parent::__construct( $orig_words, $closing_words,
-               $orig_stripped, $closing_stripped );
+                       $orig_stripped, $closing_stripped );
                wfProfileOut( __METHOD__ );
        }
 
@@ -979,8 +989,8 @@ class WordLevelDiff extends MappedDiff {
                        } else {
                                $m = array();
                                if ( preg_match_all( '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
-                                       $line, $m ) )
-                               {
+                                       $line, $m )
+                               {
                                        foreach ( $m[0] as $word ) {
                                                $words[] = $word;
                                        }
@@ -991,6 +1001,7 @@ class WordLevelDiff extends MappedDiff {
                        }
                }
                wfProfileOut( __METHOD__ );
+
                return array( $words, $stripped );
        }
 
@@ -1010,6 +1021,7 @@ class WordLevelDiff extends MappedDiff {
                }
                $lines = $orig->getLines();
                wfProfileOut( __METHOD__ );
+
                return $lines;
        }
 
@@ -1029,6 +1041,7 @@ class WordLevelDiff extends MappedDiff {
                }
                $lines = $closing->getLines();
                wfProfileOut( __METHOD__ );
+
                return $lines;
        }
 }
index 78ac77f..428e97d 100644 (file)
  * @ingroup DifferenceEngine
  */
 abstract class DiffFormatter {
-       /**
-        * Number of leading context "lines" to preserve.
+       /** @var int 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.
+       /** @var int 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.
@@ -114,6 +112,7 @@ abstract class DiffFormatter {
 
                $end = $this->endDiff();
                wfProfileOut( __METHOD__ );
+
                return $end;
        }
 
@@ -154,6 +153,7 @@ abstract class DiffFormatter {
        protected function endDiff() {
                $val = ob_get_contents();
                ob_end_clean();
+
                return $val;
        }
 
index cf78ce0..91e74c9 100644 (file)
@@ -34,33 +34,47 @@ define( 'MW_DIFF_VERSION', '1.11a' );
  * @ingroup DifferenceEngine
  */
 class DifferenceEngine extends ContextSource {
+       /** @var int */
        public $mOldid;
+
+       /** @var int */
        public $mNewid;
+
        private $mOldTags;
        private $mNewTags;
 
-       /**
-        * @var Content
-        */
+       /** @var Content */
        public $mOldContent;
+
+       /** @var Content */
        public $mNewContent;
+
+       /** @var Language */
        protected $mDiffLang;
 
-       /**
-        * @var Title
-        */
+       /** @var  Title */
        public $mOldPage;
+
+       /** @var  Title */
        public $mNewPage;
 
-       /**
-        * @var Revision
-        */
+       /** @var Revision */
        public $mOldRev;
+
+       /** @var  Revision */
        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?
+
+       /** @var bool Have the revisions IDs been loaded */
+       private $mRevisionsIdsLoaded = false;
+
+       /** @var bool Have the revisions been loaded */
+       public $mRevisionsLoaded = false;
+
+       /** @var int How many text blobs have been loaded, 0, 1 or 2? */
+       public $mTextLoaded = 0;
+
+       /** @var bool Was the diff fetched from cache? */
+       public $mCacheHit = false;
 
        /**
         * Set this to true to add debug info to the HTML output.
@@ -69,14 +83,16 @@ class DifferenceEngine extends ContextSource {
         */
        public $enableDebugComment = false;
 
-       // If true, line X is not displayed when X is 1, for example to increase
-       // readability and conserve space with many small diffs.
+       /** @var bool  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;
 
-       // Link to action=markpatrolled
+       /** @var string Link to action=markpatrolled  */
        protected $mMarkPatrolledLink = null;
 
-       protected $unhide = false; # show rev_deleted content if allowed
+       /** @var bool Show rev_deleted content if allowed */
+       protected $unhide = false;
        /**#@-*/
 
        /**
@@ -118,6 +134,7 @@ class DifferenceEngine extends ContextSource {
                        # Default language in which the diff text is written.
                        $this->mDiffLang = $this->getTitle()->getPageLanguage();
                }
+
                return $this->mDiffLang;
        }
 
@@ -133,6 +150,7 @@ class DifferenceEngine extends ContextSource {
         */
        function getOldid() {
                $this->loadRevisionIds();
+
                return $this->mOldid;
        }
 
@@ -141,6 +159,7 @@ class DifferenceEngine extends ContextSource {
         */
        function getNewid() {
                $this->loadRevisionIds();
+
                return $this->mNewid;
        }
 
@@ -160,12 +179,14 @@ class DifferenceEngine extends ContextSource {
                        if ( $row ) {
                                $rev = Revision::newFromArchiveRow( $row );
                                $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
+
                                return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( array(
                                        'target' => $title->getPrefixedText(),
                                        'timestamp' => $rev->getTimestamp()
-                               ));
+                               ) );
                        }
                }
+
                return false;
        }
 
@@ -215,6 +236,7 @@ class DifferenceEngine extends ContextSource {
                if ( !$this->loadRevisionData() ) {
                        $this->showMissingRevision();
                        wfProfileOut( __METHOD__ );
+
                        return;
                }
 
@@ -283,7 +305,8 @@ class DifferenceEngine extends ContextSource {
                                                        'href' => $this->mNewPage->getLocalURL( array(
                                                                'action' => 'edit',
                                                                'undoafter' => $this->mOldid,
-                                                               'undo' => $this->mNewid ) ),
+                                                               'undo' => $this->mNewid
+                                                       ) ),
                                                        'title' => Linker::titleAttrib( 'undo' )
                                                ),
                                                $this->msg( 'editundo' )->text()
@@ -316,9 +339,9 @@ class DifferenceEngine extends ContextSource {
 
                        $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->mOldRev, !$this->unhide ) . '</div>' .
                                '<div id="mw-diff-otitle3">' . $oldminor .
-                                       Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
+                               Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
                                '<div id="mw-diff-otitle5">' . $oldChangeTags[0] . '</div>' .
                                '<div id="mw-diff-otitle4">' . $prevlink . '</div>';
 
@@ -370,9 +393,9 @@ class DifferenceEngine extends ContextSource {
 
                $newHeader = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' .
                        '<div id="mw-diff-ntitle2">' . Linker::revUserTools( $this->mNewRev, !$this->unhide ) .
-                               " $rollback</div>" .
+                       " $rollback</div>" .
                        '<div id="mw-diff-ntitle3">' . $newminor .
-                               Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
+                       Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
                        '<div id="mw-diff-ntitle5">' . $newChangeTags[0] . '</div>' .
                        '<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
 
@@ -503,6 +526,7 @@ class DifferenceEngine extends ContextSource {
                if ( $link !== '' ) {
                        $link = '&#160;&#160;&#160;' . $link . ' ';
                }
+
                return $link;
        }
 
@@ -589,6 +613,7 @@ class DifferenceEngine extends ContextSource {
                }
 
                $parserOutput = $page->getParserOutput( $parserOptions, $rev->getId() );
+
                return $parserOutput;
        }
 
@@ -606,10 +631,12 @@ class DifferenceEngine extends ContextSource {
                $diff = $this->getDiff( $otitle, $ntitle, $notice );
                if ( $diff === false ) {
                        $this->showMissingRevision();
+
                        return false;
                } else {
                        $this->showDiffStyle();
                        $this->getOutput()->addHTML( $diff );
+
                        return true;
                }
        }
@@ -658,23 +685,27 @@ class DifferenceEngine extends ContextSource {
                // 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() )
                ) {
                        wfProfileOut( __METHOD__ );
+
                        return false;
                } elseif ( $this->mNewRev &&
                        !$this->mNewRev->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() ) )
-               {
+                       && $this->mOldRev->getID() == $this->mNewRev->getID() )
+               {
                        wfProfileOut( __METHOD__ );
+
                        return '';
                }
                // Cacheable?
@@ -690,6 +721,7 @@ class DifferenceEngine extends ContextSource {
                                        $difftext = $this->localiseLineNumbers( $difftext );
                                        $difftext .= "\n<!-- diff cache key $key -->\n";
                                        wfProfileOut( __METHOD__ );
+
                                        return $difftext;
                                }
                        } // don't try to load but save the result
@@ -699,6 +731,7 @@ class DifferenceEngine extends ContextSource {
                // Loadtext is permission safe, this just clears out the diff
                if ( !$this->loadText() ) {
                        wfProfileOut( __METHOD__ );
+
                        return false;
                }
 
@@ -718,6 +751,7 @@ class DifferenceEngine extends ContextSource {
                        $difftext = $this->localiseLineNumbers( $difftext );
                }
                wfProfileOut( __METHOD__ );
+
                return $difftext;
        }
 
@@ -757,8 +791,8 @@ class DifferenceEngine extends ContextSource {
         */
        function generateContentDiffBody( Content $old, Content $new ) {
                if ( !( $old instanceof TextContent ) ) {
-                       throw new MWException( "Diff not implemented for " . get_class( $old ) . "; "
-                                       . "override generateContentDiffBody to fix this." );
+                       throw new MWException( "Diff not implemented for " . get_class( $old ) . "; " .
+                               "override generateContentDiffBody to fix this." );
                }
 
                if ( !( $new instanceof TextContent ) ) {
@@ -806,9 +840,10 @@ class DifferenceEngine extends ContextSource {
                if ( $wgExternalDiffEngine == 'wikidiff' && function_exists( 'wikidiff_do_diff' ) ) {
                        # For historical reasons, external diff engine expects
                        # input text to be HTML-escaped already
-                       $otext = htmlspecialchars ( $wgContLang->segmentForDiff( $otext ) );
-                       $ntext = htmlspecialchars ( $wgContLang->segmentForDiff( $ntext ) );
+                       $otext = htmlspecialchars( $wgContLang->segmentForDiff( $otext ) );
+                       $ntext = htmlspecialchars( $wgContLang->segmentForDiff( $ntext ) );
                        wfProfileOut( __METHOD__ );
+
                        return $wgContLang->unsegmentForDiff( wikidiff_do_diff( $otext, $ntext, 2 ) ) .
                        $this->debug( 'wikidiff1' );
                }
@@ -821,6 +856,7 @@ class DifferenceEngine extends ContextSource {
                        $text .= $this->debug( 'wikidiff2' );
                        wfProfileOut( 'wikidiff2_do_diff' );
                        wfProfileOut( __METHOD__ );
+
                        return $text;
                }
                if ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
@@ -832,11 +868,13 @@ class DifferenceEngine extends ContextSource {
                        $tempFile1 = fopen( $tempName1, "w" );
                        if ( !$tempFile1 ) {
                                wfProfileOut( __METHOD__ );
+
                                return false;
                        }
                        $tempFile2 = fopen( $tempName2, "w" );
                        if ( !$tempFile2 ) {
                                wfProfileOut( __METHOD__ );
+
                                return false;
                        }
                        fwrite( $tempFile1, $otext );
@@ -851,6 +889,7 @@ class DifferenceEngine extends ContextSource {
                        unlink( $tempName1 );
                        unlink( $tempName2 );
                        wfProfileOut( __METHOD__ );
+
                        return $difftext;
                }
 
@@ -860,7 +899,8 @@ class DifferenceEngine extends ContextSource {
                $diffs = new Diff( $ota, $nta );
                $formatter = new TableDiffFormatter();
                $difftext = $wgContLang->unsegmentForDiff( $formatter->format( $diffs ) ) .
-               wfProfileOut( __METHOD__ );
+                       wfProfileOut( __METHOD__ );
+
                return $difftext;
        }
 
@@ -868,7 +908,7 @@ 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
+        * @param String $generator : What diff engine was used
         *
         * @return string
         */
@@ -882,13 +922,10 @@ class DifferenceEngine extends ContextSource {
                        $data[] = wfHostname();
                }
                $data[] = wfTimestamp( TS_DB );
-               return "<!-- diff generator: "
-                       . implode( " ",
-                               array_map(
-                                       "htmlspecialchars",
-                               $data )
-                       )
-                       . " -->\n";
+
+               return "<!-- diff generator: " .
+                       implode( " ",   array_map( "htmlspecialchars", $data ) ) .
+                       " -->\n";
        }
 
        /**
@@ -899,14 +936,18 @@ class DifferenceEngine extends ContextSource {
         * @return mixed
         */
        function localiseLineNumbers( $text ) {
-               return preg_replace_callback( '/<!--LINE (\d+)-->/',
-               array( &$this, 'localiseLineNumbersCb' ), $text );
+               return preg_replace_callback(
+                       '/<!--LINE (\d+)-->/',
+                       array( &$this, 'localiseLineNumbersCb' ),
+                       $text
+               );
        }
 
        function localiseLineNumbersCb( $matches ) {
                if ( $matches[1] === '1' && $this->mReducedLineNumbers ) {
                        return '';
                }
+
                return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped();
        }
 
@@ -934,8 +975,10 @@ class DifferenceEngine extends ContextSource {
                if ( $nEdits > 0 ) {
                        $limit = 100; // use diff-multi-manyusers if too many users
                        $numUsers = $this->mNewPage->countAuthorsBetween( $oldRev, $newRev, $limit );
+
                        return self::intermediateEditsMsg( $nEdits, $numUsers, $limit );
                }
+
                return ''; // nothing
        }
 
@@ -953,6 +996,7 @@ class DifferenceEngine extends ContextSource {
                } else {
                        $msg = 'diff-multi';
                }
+
                return wfMessage( $msg )->numParams( $numEdits, $numUsers )->parse();
        }
 
@@ -1015,11 +1059,11 @@ 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
+        * @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
         */
index 0ce17df..5f28627 100644 (file)
@@ -45,6 +45,7 @@ class TableDiffFormatter extends DiffFormatter {
                $msg = preg_replace( '/^ /m', '&#160; ', $msg );
                $msg = preg_replace( '/ $/m', ' &#160;', $msg );
                $msg = preg_replace( '/  /', '&#160; ', $msg );
+
                return $msg;
        }
 
@@ -58,6 +59,7 @@ class TableDiffFormatter extends DiffFormatter {
        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;
        }
 
@@ -112,6 +114,7 @@ class TableDiffFormatter extends DiffFormatter {
                        // 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>";
        }
 
@@ -174,7 +177,7 @@ class TableDiffFormatter extends DiffFormatter {
                        echo '<tr>' . $this->deletedLine( $line ) .
                                $this->addedLine( $aline ) . "</tr>\n";
                }
-               foreach ( $add as $line ) {     # If any leftovers
+               foreach ( $add as $line ) { # If any leftovers
                        echo '<tr>' . $this->emptyLine() .
                                $this->addedLine( $line ) . "</tr>\n";
                }
index d489538..0a86ccc 100644 (file)
  * @ingroup DifferenceEngine
  */
 class UnifiedDiffFormatter extends DiffFormatter {
+       /** @var int */
        protected $leadingContextLines = 2;
+
+       /** @var int */
        protected $trailingContextLines = 2;
 
        /**
index ea6f6e5..7c019b0 100644 (file)
@@ -138,8 +138,9 @@ class WikiDiff3 {
                         */
                        $max = min( $this->m, $this->n );
                        for ( $forwardBound = 0; $forwardBound < $max
-                                       && $this->from[$forwardBound] === $this->to[$forwardBound];
-                                       ++$forwardBound ) {
+                               && $this->from[$forwardBound] === $this->to[$forwardBound];
+                               ++$forwardBound
+                       ) {
                                $this->removed[$forwardBound] = $this->added[$forwardBound] = false;
                        }
 
@@ -147,7 +148,8 @@ class WikiDiff3 {
                        $backBoundL2 = $this->n - 1;
 
                        while ( $backBoundL1 >= $forwardBound && $backBoundL2 >= $forwardBound
-                                       && $this->from[$backBoundL1] === $this->to[$backBoundL2] ) {
+                               && $this->from[$backBoundL1] === $this->to[$backBoundL2]
+                       ) {
                                $this->removed[$backBoundL1--] = $this->added[$backBoundL2--] = false;
                        }
 
@@ -156,8 +158,14 @@ class WikiDiff3 {
                        $snake = array( 0, 0, 0 );
 
                        $this->length = $forwardBound + $this->m - $backBoundL1 - 1
-                               + $this->lcs_rec( $forwardBound, $backBoundL1,
-                               $forwardBound, $backBoundL2, $V, $snake );
+                               + $this->lcs_rec(
+                                       $forwardBound,
+                                       $backBoundL1,
+                                       $forwardBound,
+                                       $backBoundL2,
+                                       $V,
+                                       $snake
+                       );
                }
 
                $this->m = $m;
@@ -189,8 +197,9 @@ class WikiDiff3 {
                while ( $xi < $this->m || $yi < $this->n ) {
                        // Matching "snake".
                        while ( $xi < $this->m && $yi < $this->n
-                                       && !$this->removed[$xi]
-                                       && !$this->added[$yi] ) {
+                               && !$this->removed[$xi]
+                               && !$this->added[$yi]
+                       ) {
                                ++$xi;
                                ++$yi;
                        }
@@ -206,10 +215,10 @@ class WikiDiff3 {
                        }
 
                        if ( $xi > $xstart || $yi > $ystart ) {
-                               $ranges[] = new RangeDifference( $xstart, $xi,
-                                                               $ystart, $yi );
+                               $ranges[] = new RangeDifference( $xstart, $xi, $ystart, $yi );
                        }
                }
+
                return $ranges;
        }
 
@@ -220,7 +229,7 @@ class WikiDiff3 {
                }
 
                $d = $this->find_middle_snake( $bottoml1, $topl1, $bottoml2,
-                                                       $topl2, $V, $snake );
+                       $topl2, $V, $snake );
 
                // need to store these so we don't lose them when they're
                // overwritten by the recursion
@@ -236,9 +245,9 @@ class WikiDiff3 {
                if ( $d > 1 ) {
                        return $len
                        + $this->lcs_rec( $bottoml1, $startx - 1, $bottoml2,
-                                                       $starty - 1, $V, $snake )
+                               $starty - 1, $V, $snake )
                        + $this->lcs_rec( $startx + $len, $topl1, $starty + $len,
-                                                       $topl2, $V, $snake );
+                               $topl2, $V, $snake );
                } elseif ( $d == 1 ) {
                        /*
                         * In this case the sequences differ by exactly 1 line. We have
@@ -250,8 +259,10 @@ class WikiDiff3 {
                                $this->removed[$bottoml1 + $i] =
                                        $this->added[$bottoml2 + $i] = false;
                        }
+
                        return $max + $len;
                }
+
                return $len;
        }
 
@@ -263,8 +274,8 @@ class WikiDiff3 {
                $snake0 = &$snake[0];
                $snake1 = &$snake[1];
                $snake2 = &$snake[2];
-               $bottoml1_min_1 = $bottoml1 -1;
-               $bottoml2_min_1 = $bottoml2 -1;
+               $bottoml1_min_1 = $bottoml1 - 1;
+               $bottoml2_min_1 = $bottoml2 - 1;
                $N = $topl1 - $bottoml1_min_1;
                $M = $topl2 - $bottoml2_min_1;
                $delta = $N - $M;
@@ -307,7 +318,8 @@ class WikiDiff3 {
                                // compute forward furthest reaching paths
                                for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
                                        if ( $k == -$d || ( $k < $d
-                                                       && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] ) ) {
+                                                       && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
+                                       ) {
                                                $x = $V0[$limit_plus_1 + $k];
                                        } else {
                                                $x = $V0[$limit_min_1 + $k] + 1;
@@ -320,12 +332,13 @@ class WikiDiff3 {
                                                ++$absx;
                                                ++$absy;
                                        }
-                                       $x = $absx -$bottoml1;
+                                       $x = $absx - $bottoml1;
 
-                                       $snake2 = $absx -$snake0;
+                                       $snake2 = $absx - $snake0;
                                        $V0[$limit + $k] = $x;
                                        if ( $k >= $delta - $d + 1 && $k <= $delta + $d - 1
-                                                       && $x >= $V1[$limit + $k - $delta] ) {
+                                               && $x >= $V1[$limit + $k - $delta]
+                                       ) {
                                                return 2 * $d - 1;
                                        }
 
@@ -345,7 +358,8 @@ class WikiDiff3 {
                                // compute backward furthest reaching paths
                                for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
                                        if ( $k == $d
-                                       || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] ) ) {
+                                               || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
+                                       ) {
                                                $x = $V1[$limit_min_1 + $k];
                                        } else {
                                                $x = $V1[$limit_plus_1 + $k] - 1;
@@ -355,7 +369,8 @@ class WikiDiff3 {
 
                                        $snake2 = 0;
                                        while ( $x > 0 && $y > 0
-                                       && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1] ) {
+                                               && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1]
+                                       ) {
                                                --$x;
                                                --$y;
                                                ++$snake2;
@@ -380,7 +395,8 @@ class WikiDiff3 {
                                // compute forward furthest reaching paths
                                for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
                                        if ( $k == -$d
-                                       || ( $k < $d && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] ) ) {
+                                               || ( $k < $d && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
+                                       ) {
                                                $x = $V0[$limit_plus_1 + $k];
                                        } else {
                                                $x = $V0[$limit_min_1 + $k] + 1;
@@ -393,14 +409,14 @@ class WikiDiff3 {
                                                ++$absx;
                                                ++$absy;
                                        }
-                                       $x = $absx -$bottoml1;
-                                       $snake2 = $absx -$snake0;
+                                       $x = $absx - $bottoml1;
+                                       $snake2 = $absx - $snake0;
                                        $V0[$limit + $k] = $x;
 
                                        // check to see if we can cut down the diagonal range
                                        if ( $x >= $N && $end_forward > $k - 1 ) {
                                                $end_forward = $k - 1;
-                                       } elseif ( $absy -$bottoml2 >= $M ) {
+                                       } elseif ( $absy - $bottoml2 >= $M ) {
                                                $start_forward = $k + 1;
                                                $value_to_add_forward = 0;
                                        }
@@ -413,7 +429,8 @@ class WikiDiff3 {
                                // compute backward furthest reaching paths
                                for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
                                        if ( $k == $d
-                                       || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] ) ) {
+                                               || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
+                                       ) {
                                                $x = $V1[$limit_min_1 + $k];
                                        } else {
                                                $x = $V1[$limit_plus_1 + $k] - 1;
@@ -423,7 +440,8 @@ class WikiDiff3 {
 
                                        $snake2 = 0;
                                        while ( $x > 0 && $y > 0
-                                                       && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1] ) {
+                                               && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1]
+                                       ) {
                                                --$x;
                                                --$y;
                                                ++$snake2;
@@ -431,9 +449,11 @@ class WikiDiff3 {
                                        $V1[$limit + $k] = $x;
 
                                        if ( $k >= -$delta - $d && $k <= $d - $delta
-                                                       && $x <= $V0[$limit + $k + $delta] ) {
+                                               && $x <= $V0[$limit + $k + $delta]
+                                       ) {
                                                $snake0 = $bottoml1 + $x;
                                                $snake1 = $bottoml2 + $y;
+
                                                return 2 * $d;
                                        }
 
@@ -460,6 +480,7 @@ class WikiDiff3 {
                $snake2 = 0;
                wfDebug( "Computing the LCS is too expensive. Using a heuristic.\n" );
                $this->heuristicUsed = true;
+
                return 5; /*
                * HACK: since we didn't really finish the LCS computation
                * we don't really know the length of the SES. We don't do
@@ -554,11 +575,11 @@ class WikiDiff3 {
        public function getLcsLength() {
                if ( $this->heuristicUsed && !$this->lcsLengthCorrectedForHeuristic ) {
                        $this->lcsLengthCorrectedForHeuristic = true;
-                       $this->length = $this->m -array_sum( $this->added );
+                       $this->length = $this->m - array_sum( $this->added );
                }
+
                return $this->length;
        }
-
 }
 
 /**
@@ -568,13 +589,22 @@ class WikiDiff3 {
  * @ingroup DifferenceEngine
  */
 class RangeDifference {
-
+       /** @var int */
        public $leftstart;
+
+       /** @var int */
        public $leftend;
+
+       /** @var int */
        public $leftlength;
 
+       /** @var int */
        public $rightstart;
+
+       /** @var int */
        public $rightend;
+
+       /** @var int */
        public $rightlength;
 
        function __construct( $leftstart, $leftend, $rightstart, $rightend ) {