Stylize. No differences when using: svn diff -x -wu
authorAntoine Musso <hashar@users.mediawiki.org>
Sat, 27 Nov 2010 19:01:51 +0000 (19:01 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sat, 27 Nov 2010 19:01:51 +0000 (19:01 +0000)
includes/diff/DifferenceEngine.php
includes/diff/WikiDiff.php
includes/diff/WikiDiff3.php

index d2370d7..f18d655 100644 (file)
@@ -5,7 +5,7 @@
  * @file
  * @ingroup DifferenceEngine
  */
+
 /**
  * Constant to indicate diff cache compatibility.
  * Bump this when changing the diff formatting in a way that
@@ -64,17 +64,17 @@ class DifferenceEngine {
                        global $wgTitle;
                        $this->mTitle = $wgTitle;
                }
-               wfDebug("DifferenceEngine old '$old' new '$new' rcid '$rcid'\n");
+               wfDebug( "DifferenceEngine old '$old' new '$new' rcid '$rcid'\n" );
 
                if ( 'prev' === $new ) {
                        # Show diff between revision $old and the previous one.
                        # Get previous one from DB.
-                       $this->mNewid = intval($old);
+                       $this->mNewid = intval( $old );
                        $this->mOldid = $this->mTitle->getPreviousRevisionID( $this->mNewid );
                } elseif ( 'next' === $new ) {
                        # Show diff between revision $old and the next one.
                        # Get next one from DB.
-                       $this->mOldid = intval($old);
+                       $this->mOldid = intval( $old );
                        $this->mNewid = $this->mTitle->getNextRevisionID( $this->mOldid );
                        if ( false === $this->mNewid ) {
                                # if no result, NewId points to the newest old revision. The only newer
@@ -82,11 +82,11 @@ class DifferenceEngine {
                                $this->mNewid = 0;
                        }
                } else {
-                       $this->mOldid = intval($old);
-                       $this->mNewid = intval($new);
-                       wfRunHooks( 'NewDifferenceEngine', array(&$titleObj, &$this->mOldid, &$this->mNewid, $old, $new) ); 
+                       $this->mOldid = intval( $old );
+                       $this->mNewid = intval( $new );
+                       wfRunHooks( 'NewDifferenceEngine', array( &$titleObj, &$this->mOldid, &$this->mNewid, $old, $new ) );
                }
-               $this->mRcidMarkPatrolled = intval($rcid);  # force it to be an integer
+               $this->mRcidMarkPatrolled = intval( $rcid );  # force it to be an integer
                $this->mRefreshCache = $refreshCache;
                $this->unhide = $unhide;
        }
@@ -98,15 +98,15 @@ class DifferenceEngine {
        function getTitle() {
                return $this->mTitle;
        }
-       
+
        function wasCacheHit() {
                return $this->mCacheHit;
        }
-       
+
        function getOldid() {
                return $this->mOldid;
        }
-       
+
        function getNewid() {
                return $this->mNewid;
        }
@@ -119,20 +119,20 @@ class DifferenceEngine {
                # If external diffs are enabled both globally and for the user,
                # we'll use the application/x-external-editor interface to call
                # an external diff tool like kompare, kdiff3, etc.
-               if($wgUseExternalEditor && $wgUser->getOption('externaldiff')) {
-                       global $wgInputEncoding,$wgServer,$wgScript,$wgLang;
+               if ( $wgUseExternalEditor && $wgUser->getOption( 'externaldiff' ) ) {
+                       global $wgInputEncoding, $wgServer, $wgScript, $wgLang;
                        $wgOut->disable();
-                       header ( "Content-type: application/x-external-editor; charset=".$wgInputEncoding );
-                       $url1=$this->mTitle->getFullURL( array(
+                       header ( "Content-type: application/x-external-editor; charset=" . $wgInputEncoding );
+                       $url1 = $this->mTitle->getFullURL( array(
                                'action' => 'raw',
                                'oldid' => $this->mOldid
                        ) );
-                       $url2=$this->mTitle->getFullURL( array(
+                       $url2 = $this->mTitle->getFullURL( array(
                                'action' => 'raw',
                                'oldid' => $this->mNewid
                        ) );
-                       $special=$wgLang->getNsText(NS_SPECIAL);
-                       $control=<<<CONTROL
+                       $special = $wgLang->getNsText( NS_SPECIAL );
+                       $control = <<<CONTROL
                        [Process]
                        Type=Diff text
                        Engine=MediaWiki
@@ -147,7 +147,7 @@ class DifferenceEngine {
                        Extension=wiki
                        URL=$url2
 CONTROL;
-                       echo($control);
+                       echo( $control );
                        return;
                }
 
@@ -181,7 +181,7 @@ CONTROL;
 
                $oldTitle = $this->mOldPage->getPrefixedText();
                $newTitle = $this->mNewPage->getPrefixedText();
-               if( $oldTitle == $newTitle ) {
+               if ( $oldTitle == $newTitle ) {
                        $wgOut->setPageTitle( $newTitle );
                } else {
                        $wgOut->setPageTitle( $oldTitle . ', ' . $newTitle );
@@ -212,13 +212,13 @@ CONTROL;
                }
 
                // Prepare a change patrol link, if applicable
-               if( $wgUseRCPatrol && $this->mTitle->userCan('patrol') ) {
+               if ( $wgUseRCPatrol && $this->mTitle->userCan( 'patrol' ) ) {
                        // If we've been given an explicit change identifier, use it; saves time
-                       if( $this->mRcidMarkPatrolled ) {
+                       if ( $this->mRcidMarkPatrolled ) {
                                $rcid = $this->mRcidMarkPatrolled;
                                $rc = RecentChange::newFromId( $rcid );
                                // Already patrolled?
-                               $rcid = is_object($rc) && !$rc->getAttribute('rc_patrolled') ? $rcid : 0;
+                               $rcid = is_object( $rc ) && !$rc->getAttribute( 'rc_patrolled' ) ? $rcid : 0;
                        } else {
                                // Look for an unpatrolled change corresponding to this diff
                                $db = wfGetDB( DB_SLAVE );
@@ -233,7 +233,7 @@ CONTROL;
                                        ),
                                        __METHOD__
                                );
-                               if( $change instanceof RecentChange ) {
+                               if ( $change instanceof RecentChange ) {
                                        $rcid = $change->mAttribs['rc_id'];
                                        $this->mRcidMarkPatrolled = $rcid;
                                } else {
@@ -242,10 +242,10 @@ CONTROL;
                                }
                        }
                        // Build the link
-                       if( $rcid ) {
+                       if ( $rcid ) {
                                $token = $wgUser->editToken( $rcid );
                                $patrol = ' <span class="patrollink">[' . $sk->link(
-                                       $this->mTitle, 
+                                       $this->mTitle,
                                        wfMsgHtml( 'markaspatrolleddiff' ),
                                        array(),
                                        array(
@@ -266,7 +266,7 @@ CONTROL;
                }
 
                # Carry over 'diffonly' param via navigation links
-               if( $diffOnly != $wgUser->getBoolOption('diffonly') ) {
+               if ( $diffOnly != $wgUser->getBoolOption( 'diffonly' ) ) {
                        $query['diffonly'] = $diffOnly;
                }
 
@@ -274,10 +274,10 @@ CONTROL;
                $query['diff'] = 'prev';
                $query['oldid'] = $this->mOldid;
                # Cascade unhide param in links for easy deletion browsing
-               if( $this->unhide ) {
+               if ( $this->unhide ) {
                        $query['unhide'] = 1;
                }
-               if( !$this->mOldRev->getPrevious() ) {
+               if ( !$this->mOldRev->getPrevious() ) {
                        $prevlink = '&#160;';
                } else {
                        $prevlink = $sk->link(
@@ -298,7 +298,7 @@ CONTROL;
                $query['diff'] = 'next';
                $query['oldid'] = $this->mNewid;
                # Skip next link on the top revision
-               if( $this->mNewRev->isCurrent() ) {
+               if ( $this->mNewRev->isCurrent() ) {
                        $nextlink = '&#160;';
                } else {
                        $nextlink = $sk->link(
@@ -318,10 +318,10 @@ CONTROL;
                $oldminor = '';
                $newminor = '';
 
-               if( $this->mOldRev->isMinor() ) {
+               if ( $this->mOldRev->isMinor() ) {
                        $oldminor = ChangesList::flag( 'minor' );
                }
-               if( $this->mNewRev->isMinor() ) {
+               if ( $this->mNewRev->isMinor() ) {
                        $newminor = ChangesList::flag( 'minor' );
                }
 
@@ -329,41 +329,41 @@ CONTROL;
                $ldel = $this->revisionDeleteLink( $this->mOldRev );
                $rdel = $this->revisionDeleteLink( $this->mNewRev );
 
-               $oldHeader = '<div id="mw-diff-otitle1"><strong>'.$this->mOldtitle.'</strong></div>' .
+               $oldHeader = '<div id="mw-diff-otitle1"><strong>' . $this->mOldtitle . '</strong></div>' .
                        '<div id="mw-diff-otitle2">' .
-                               $sk->revUserTools( $this->mOldRev, !$this->unhide ).'</div>' .
+                               $sk->revUserTools( $this->mOldRev, !$this->unhide ) . '</div>' .
                        '<div id="mw-diff-otitle3">' . $oldminor .
-                               $sk->revComment( $this->mOldRev, !$diffOnly, !$this->unhide ).$ldel.'</div>' .
-                       '<div id="mw-diff-otitle4">' . $prevlink .'</div>';
-               $newHeader = '<div id="mw-diff-ntitle1"><strong>'.$this->mNewtitle.'</strong></div>' .
+                               $sk->revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
+                       '<div id="mw-diff-otitle4">' . $prevlink . '</div>';
+               $newHeader = '<div id="mw-diff-ntitle1"><strong>' . $this->mNewtitle . '</strong></div>' .
                        '<div id="mw-diff-ntitle2">' . $sk->revUserTools( $this->mNewRev, !$this->unhide ) .
                                " $rollback</div>" .
                        '<div id="mw-diff-ntitle3">' . $newminor .
-                               $sk->revComment( $this->mNewRev, !$diffOnly, !$this->unhide ).$rdel.'</div>' .
+                               $sk->revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
                        '<div id="mw-diff-ntitle4">' . $nextlink . $patrol . '</div>';
 
                # Check if this user can see the revisions
-               $allowed = $this->mOldRev->userCan(Revision::DELETED_TEXT)
-                       && $this->mNewRev->userCan(Revision::DELETED_TEXT);
+               $allowed = $this->mOldRev->userCan( Revision::DELETED_TEXT )
+                       && $this->mNewRev->userCan( Revision::DELETED_TEXT );
                # Check if one of the revisions is deleted/suppressed
                $deleted = $suppressed = false;
-               if( $this->mOldRev->isDeleted(Revision::DELETED_TEXT) ) {
+               if ( $this->mOldRev->isDeleted( Revision::DELETED_TEXT ) ) {
                        $deleted = true; // old revisions text is hidden
-                       if( $this->mOldRev->isDeleted(Revision::DELETED_RESTRICTED) )
+                       if ( $this->mOldRev->isDeleted( Revision::DELETED_RESTRICTED ) )
                                $suppressed = true; // also suppressed
                }
-               if( $this->mNewRev->isDeleted(Revision::DELETED_TEXT) ) {
+               if ( $this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
                        $deleted = true; // new revisions text is hidden
-                       if( $this->mNewRev->isDeleted(Revision::DELETED_RESTRICTED) )
+                       if ( $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) )
                                $suppressed = true; // also suppressed
                }
                # If the diff cannot be shown due to a deleted revision, then output
                # the diff header and links to unhide (if available)...
-               if( $deleted && (!$this->unhide || !$allowed) ) {
+               if ( $deleted && ( !$this->unhide || !$allowed ) ) {
                        $this->showDiffStyle();
                        $multi = $this->getMultiNotice();
                        $wgOut->addHTML( $this->addHeader( '', $oldHeader, $newHeader, $multi ) );
-                       if( !$allowed ) {
+                       if ( !$allowed ) {
                                $msg = $suppressed ? 'rev-suppressed-no-diff' : 'rev-deleted-no-diff';
                                # Give explanation for why revision is not visible
                                $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
@@ -382,18 +382,18 @@ CONTROL;
                } else {
                        # Add deletion notice if the user is viewing deleted content
                        $notice = '';
-                       if( $deleted ) {
+                       if ( $deleted ) {
                                $msg = $suppressed ? 'rev-suppressed-diff-view' : 'rev-deleted-diff-view';
-                               $notice = "<div class='mw-warning plainlinks'>\n".wfMsgExt($msg,'parseinline')."</div>\n";
+                               $notice = "<div class='mw-warning plainlinks'>\n" . wfMsgExt( $msg, 'parseinline' ) . "</div>\n";
                        }
                        $this->showDiff( $oldHeader, $newHeader, $notice );
-                       if( !$diffOnly ) {
+                       if ( !$diffOnly ) {
                                $this->renderNewRevision();
                        }
                }
                wfProfileOut( __METHOD__ );
        }
-       
+
        protected function revisionDeleteLink( $rev ) {
                global $wgUser;
                $link = '';
@@ -401,9 +401,9 @@ CONTROL;
                // Show del/undel link if:
                // (a) the user can delete revisions, or
                // (b) the user can view deleted revision *and* this one is deleted
-               if( $canHide || ($rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' )) ) {
+               if ( $canHide || ( $rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
                        $sk = $wgUser->getSkin();
-                       if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
+                       if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
                                $link = $sk->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
                        } else {
                                $query = array(
@@ -428,27 +428,27 @@ CONTROL;
 
                $wgOut->addHTML( "<hr /><h2>{$this->mPagetitle}</h2>\n" );
                # Add deleted rev tag if needed
-               if( !$this->mNewRev->userCan(Revision::DELETED_TEXT) ) {
+               if ( !$this->mNewRev->userCan( Revision::DELETED_TEXT ) ) {
                        $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
-               } else if( $this->mNewRev->isDeleted(Revision::DELETED_TEXT) ) {
+               } else if ( $this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
                        $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
                }
 
                $pCache = true;
-               if( !$this->mNewRev->isCurrent() ) {
+               if ( !$this->mNewRev->isCurrent() ) {
                        $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection( false );
                        $pCache = false;
                }
 
                $this->loadNewText();
-               if( is_object( $this->mNewRev ) ) {
+               if ( is_object( $this->mNewRev ) ) {
                        $wgOut->setRevisionId( $this->mNewRev->getId() );
                }
 
-               if( $this->mTitle->isCssJsSubpage() || $this->mTitle->isCssOrJsPage() ) {
+               if ( $this->mTitle->isCssJsSubpage() || $this->mTitle->isCssOrJsPage() ) {
                        // Stolen from Article::view --AG 2007-10-11
                        // Give hooks a chance to customise the output
-                       if( wfRunHooks( 'ShowRawCssJs', array( $this->mNewtext, $this->mTitle, $wgOut ) ) ) {
+                       if ( wfRunHooks( 'ShowRawCssJs', array( $this->mNewtext, $this->mTitle, $wgOut ) ) ) {
                                // Wrap the whole lot in a <pre> and don't parse
                                $m = array();
                                preg_match( '!\.(css|js)$!u', $this->mTitle->getText(), $m );
@@ -456,26 +456,26 @@ CONTROL;
                                $wgOut->addHTML( htmlspecialchars( $this->mNewtext ) );
                                $wgOut->addHTML( "\n</pre>\n" );
                        }
-               } elseif( wfRunHooks( 'ArticleContentOnDiff', array( $this, $wgOut ) ) ) {
+               } elseif ( wfRunHooks( 'ArticleContentOnDiff', array( $this, $wgOut ) ) ) {
                        if ( $pCache ) {
                                $article = new Article( $this->mTitle, 0 );
                                $pOutput = ParserCache::singleton()->get( $article, $wgOut->parserOptions() );
-                               if( $pOutput ) {
+                               if ( $pOutput ) {
                                        $wgOut->addParserOutput( $pOutput );
                                } else {
                                        $article->doViewParse();
-                               } 
+                               }
                        } else {
                                $wgOut->addWikiTextTidy( $this->mNewtext );
                        }
                }
-       
-               if( is_object( $this->mNewRev ) && !$this->mNewRev->isCurrent() ) {
+
+               if ( is_object( $this->mNewRev ) && !$this->mNewRev->isCurrent() ) {
                        $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
                }
 
                # Add redundant patrol link on bottom...
-               if( $this->mRcidMarkPatrolled && $this->mTitle->quickUserCan('patrol') ) {
+               if ( $this->mRcidMarkPatrolled && $this->mTitle->quickUserCan( 'patrol' ) ) {
                        $sk = $wgUser->getSkin();
                        $token = $wgUser->editToken( $this->mRcidMarkPatrolled );
                        $wgOut->addHTML(
@@ -523,7 +523,7 @@ CONTROL;
                        $wgOut->loginToUse();
                        $wgOut->output();
                        wfProfileOut( __METHOD__ );
-                       throw new MWException("Permission Error: you do not have access to view this page");
+                       throw new MWException( "Permission Error: you do not have access to view this page" );
                }
 
                # Prepare the header box
@@ -531,7 +531,7 @@ CONTROL;
                $sk = $wgUser->getSkin();
 
                $next = $this->mTitle->getNextRevisionID( $this->mNewid );
-               if( !$next ) {
+               if ( !$next ) {
                        $nextlink = '';
                } else {
                        $nextlink = '<br />' . $sk->link(
@@ -659,7 +659,7 @@ CONTROL;
                        wfIncrStats( 'diff_uncacheable' );
                } elseif ( $key !== false && $difftext !== false ) {
                        wfIncrStats( 'diff_cache_miss' );
-                       $wgMemc->set( $key, $difftext, 7*86400 );
+                       $wgMemc->set( $key, $difftext, 7 * 86400 );
                } else {
                        wfIncrStats( 'diff_uncacheable' );
                }
@@ -768,13 +768,13 @@ CONTROL;
         * Generate a debug comment indicating diff generating time,
         * server node, and generator backend.
         */
-       protected function debug( $generator="internal" ) {
+       protected function debug( $generator = "internal" ) {
                global $wgShowHostnames;
                if ( !$this->enableDebugComment ) {
                        return '';
                }
                $data = array( $generator );
-               if( $wgShowHostnames ) {
+               if ( $wgShowHostnames ) {
                        $data[] = wfHostname();
                }
                $data[] = wfTimestamp( TS_DB );
@@ -820,11 +820,11 @@ CONTROL;
                }
 
                $nEdits = $this->mTitle->countRevisionsBetween( $oldid, $newid );
-               if ( $nEdits> 0 ) {
+               if ( $nEdits > 0 ) {
                        $limit = 100;
                        // We use ($limit + 1) so we can detect if there are > 100 authors
                        // in a given revision range. In that case, diff-multi-manyusers is used.
-                       $numUsers = $this->mTitle->countAuthorsBetween( $oldid, $newid, $limit+1 );
+                       $numUsers = $this->mTitle->countAuthorsBetween( $oldid, $newid, $limit + 1 );
                        return self::intermediateEditsMsg( $nEdits, $numUsers, $limit );
                }
                return ''; // nothing
@@ -836,7 +836,7 @@ CONTROL;
         * @param $numUsers int
         * @param $limit int
         * @return string
-        */     
+        */
        public static function intermediateEditsMsg( $numEdits, $numUsers, $limit ) {
                global $wgLang;
                if ( $numUsers > $limit ) {
@@ -854,7 +854,7 @@ CONTROL;
         */
        static function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
                $header = "<table class='diff'>";
-               if( $diff ) { // Safari/Chrome show broken output if cols not used
+               if ( $diff ) { // Safari/Chrome show broken output if cols not used
                        $header .= "
                        <col class='diff-marker' />
                        <col class='diff-content' />
@@ -915,7 +915,7 @@ CONTROL;
                $this->mNewRev = $this->mNewid
                        ? Revision::newFromId( $this->mNewid )
                        : Revision::newFromTitle( $this->mTitle );
-               if( !$this->mNewRev instanceof Revision )
+               if ( !$this->mNewRev instanceof Revision )
                        return false;
 
                // Update the new revision ID in case it was 0 (makes life easier doing UI stuff)
@@ -929,7 +929,7 @@ CONTROL;
                $dateofrev = $wgLang->date( $this->mNewRev->getTimestamp(), true );
                $timeofrev = $wgLang->time( $this->mNewRev->getTimestamp(), true );
                $this->mNewPage = $this->mNewRev->getTitle();
-               if( $this->mNewRev->isCurrent() ) {
+               if ( $this->mNewRev->isCurrent() ) {
                        $newLink = $this->mNewPage->escapeLocalUrl( array(
                                'oldid' => $this->mNewid
                        ) );
@@ -963,19 +963,19 @@ CONTROL;
                        $this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a>";
                        $this->mNewtitle .= " (<a href='$newEdit'>" . wfMsgHtml( $editable ? 'editold' : 'viewsourceold' ) . "</a>)";
                }
-               if( !$this->mNewRev->userCan(Revision::DELETED_TEXT) ) {
+               if ( !$this->mNewRev->userCan( Revision::DELETED_TEXT ) ) {
                        $this->mNewtitle = "<span class='history-deleted'>{$this->mPagetitle}</span>";
-               } else if ( $this->mNewRev->isDeleted(Revision::DELETED_TEXT) ) {
+               } else if ( $this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
                        $this->mNewtitle = "<span class='history-deleted'>{$this->mNewtitle}</span>";
                }
 
                // Load the old revision object
                $this->mOldRev = false;
-               if( $this->mOldid ) {
+               if ( $this->mOldid ) {
                        $this->mOldRev = Revision::newFromId( $this->mOldid );
                } elseif ( $this->mOldid === 0 ) {
                        $rev = $this->mNewRev->getPrevious();
-                       if( $rev ) {
+                       if ( $rev ) {
                                $this->mOldid = $rev->getId();
                                $this->mOldRev = $rev;
                        } else {
@@ -983,9 +983,9 @@ CONTROL;
                                $this->mOldid = false;
                                $this->mOldRev = false;
                        }
-               }/* elseif ( $this->mOldid === false ) leave mOldRev false; */
+               } /* elseif ( $this->mOldid === false ) leave mOldRev false; */
 
-               if( is_null( $this->mOldRev ) ) {
+               if ( is_null( $this->mOldRev ) ) {
                        return false;
                }
 
@@ -1014,13 +1014,13 @@ CONTROL;
                        ) );
                        $htmlLink = htmlspecialchars( wfMsg( 'editundo' ) );
                        $htmlTitle = $wgUser->getSkin()->titleAttrib( 'undo' );
-                       if( $editable && !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) && !$this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
+                       if ( $editable && !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) && !$this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
                                $this->mNewtitle .= " (<a href='$newUndo' $htmlTitle>" . $htmlLink . "</a>)";
                        }
 
-                       if( !$this->mOldRev->userCan( Revision::DELETED_TEXT ) ) {
+                       if ( !$this->mOldRev->userCan( Revision::DELETED_TEXT ) ) {
                                $this->mOldtitle = '<span class="history-deleted">' . $this->mOldPagetitle . '</span>';
-                       } else if( $this->mOldRev->isDeleted( Revision::DELETED_TEXT ) ) {
+                       } else if ( $this->mOldRev->isDeleted( Revision::DELETED_TEXT ) ) {
                                $this->mOldtitle = '<span class="history-deleted">' . $this->mOldtitle . '</span>';
                        }
                }
index 4760550..84f02c7 100644 (file)
@@ -21,15 +21,15 @@ class _DiffOp {
        var $closing;
 
        function reverse() {
-               trigger_error('pure virtual', E_USER_ERROR);
+               trigger_error( 'pure virtual', E_USER_ERROR );
        }
 
        function norig() {
-               return $this->orig ? sizeof($this->orig) : 0;
+               return $this->orig ? sizeof( $this->orig ) : 0;
        }
 
        function nclosing() {
-               return $this->closing ? sizeof($this->closing) : 0;
+               return $this->closing ? sizeof( $this->closing ) : 0;
        }
 }
 
@@ -41,15 +41,15 @@ class _DiffOp {
 class _DiffOp_Copy extends _DiffOp {
        var $type = 'copy';
 
-       function __construct ($orig, $closing = false) {
-               if (!is_array($closing))
+       function __construct ( $orig, $closing = false ) {
+               if ( !is_array( $closing ) )
                $closing = $orig;
                $this->orig = $orig;
                $this->closing = $closing;
        }
 
        function reverse() {
-               return new _DiffOp_Copy($this->closing, $this->orig);
+               return new _DiffOp_Copy( $this->closing, $this->orig );
        }
 }
 
@@ -61,13 +61,13 @@ class _DiffOp_Copy extends _DiffOp {
 class _DiffOp_Delete extends _DiffOp {
        var $type = 'delete';
 
-       function __construct ($lines) {
+       function __construct ( $lines ) {
                $this->orig = $lines;
                $this->closing = false;
        }
 
        function reverse() {
-               return new _DiffOp_Add($this->orig);
+               return new _DiffOp_Add( $this->orig );
        }
 }
 
@@ -79,13 +79,13 @@ class _DiffOp_Delete extends _DiffOp {
 class _DiffOp_Add extends _DiffOp {
        var $type = 'add';
 
-       function __construct ($lines) {
+       function __construct ( $lines ) {
                $this->closing = $lines;
                $this->orig = false;
        }
 
        function reverse() {
-               return new _DiffOp_Delete($this->closing);
+               return new _DiffOp_Delete( $this->closing );
        }
 }
 
@@ -97,13 +97,13 @@ class _DiffOp_Add extends _DiffOp {
 class _DiffOp_Change extends _DiffOp {
        var $type = 'change';
 
-       function __construct ($orig, $closing) {
+       function __construct ( $orig, $closing ) {
                $this->orig = $orig;
                $this->closing = $closing;
        }
 
        function reverse() {
-               return new _DiffOp_Change($this->closing, $this->orig);
+               return new _DiffOp_Change( $this->closing, $this->orig );
        }
 }
 
@@ -135,115 +135,115 @@ class _DiffEngine {
 
        const MAX_XREF_LENGTH =  10000;
 
-       function diff ($from_lines, $to_lines){
+       function diff ( $from_lines, $to_lines ) {
                wfProfileIn( __METHOD__ );
 
                // Diff and store locally
-               $this->diff_local($from_lines, $to_lines);
+               $this->diff_local( $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->_shift_boundaries( $from_lines, $this->xchanged, $this->ychanged );
+               $this->_shift_boundaries( $to_lines, $this->ychanged, $this->xchanged );
 
                // Compute the edit operations.
-               $n_from = sizeof($from_lines);
-               $n_to = sizeof($to_lines);
+               $n_from = sizeof( $from_lines );
+               $n_to = sizeof( $to_lines );
 
                $edits = array();
                $xi = $yi = 0;
-               while ($xi < $n_from || $yi < $n_to) {
-                       assert($yi < $n_to || $this->xchanged[$xi]);
-                       assert($xi < $n_from || $this->ychanged[$yi]);
+               while ( $xi < $n_from || $yi < $n_to ) {
+                       assert( $yi < $n_to || $this->xchanged[$xi] );
+                       assert( $xi < $n_from || $this->ychanged[$yi] );
 
                        // 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;
                        }
-                       if ($copy)
-                       $edits[] = new _DiffOp_Copy($copy);
+                       if ( $copy )
+                       $edits[] = new _DiffOp_Copy( $copy );
 
                        // Find deletes & adds.
                        $delete = array();
-                       while ($xi < $n_from && $this->xchanged[$xi])
+                       while ( $xi < $n_from && $this->xchanged[$xi] )
                        $delete[] = $from_lines[$xi++];
 
                        $add = array();
-                       while ($yi < $n_to && $this->ychanged[$yi])
+                       while ( $yi < $n_to && $this->ychanged[$yi] )
                        $add[] = $to_lines[$yi++];
 
-                       if ($delete && $add)
-                       $edits[] = new _DiffOp_Change($delete, $add);
-                       elseif ($delete)
-                       $edits[] = new _DiffOp_Delete($delete);
-                       elseif ($add)
-                       $edits[] = new _DiffOp_Add($add);
+                       if ( $delete && $add )
+                       $edits[] = new _DiffOp_Change( $delete, $add );
+                       elseif ( $delete )
+                       $edits[] = new _DiffOp_Delete( $delete );
+                       elseif ( $add )
+                       $edits[] = new _DiffOp_Add( $add );
                }
                wfProfileOut( __METHOD__ );
                return $edits;
        }
 
-       function diff_local ($from_lines, $to_lines) {
+       function diff_local ( $from_lines, $to_lines ) {
                global $wgExternalDiffEngine;
-               wfProfileIn( __METHOD__);
+               wfProfileIn( __METHOD__ );
 
-               if($wgExternalDiffEngine == 'wikidiff3'){
+               if ( $wgExternalDiffEngine == 'wikidiff3' ) {
                        // wikidiff3
                        $wikidiff3 = new WikiDiff3();
-                       $wikidiff3->diff($from_lines, $to_lines);
+                       $wikidiff3->diff( $from_lines, $to_lines );
                        $this->xchanged = $wikidiff3->removed;
                        $this->ychanged = $wikidiff3->added;
-                       unset($wikidiff3);
-               }else{
+                       unset( $wikidiff3 );
+               } else {
                        // old diff
-                       $n_from = sizeof($from_lines);
-                       $n_to = sizeof($to_lines);
+                       $n_from = sizeof( $from_lines );
+                       $n_to = sizeof( $to_lines );
                        $this->xchanged = $this->ychanged = array();
                        $this->xv = $this->yv = array();
                        $this->xind = $this->yind = array();
-                       unset($this->seq);
-                       unset($this->in_seq);
-                       unset($this->lcs);
+                       unset( $this->seq );
+                       unset( $this->in_seq );
+                       unset( $this->lcs );
 
                        // Skip leading common lines.
-                       for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) {
-                               if ($from_lines[$skip] !== $to_lines[$skip])
+                       for ( $skip = 0; $skip < $n_from && $skip < $n_to; $skip++ ) {
+                               if ( $from_lines[$skip] !== $to_lines[$skip] )
                                break;
                                $this->xchanged[$skip] = $this->ychanged[$skip] = false;
                        }
                        // Skip trailing common lines.
                        $xi = $n_from; $yi = $n_to;
-                       for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) {
-                               if ($from_lines[$xi] !== $to_lines[$yi])
+                       for ( $endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++ ) {
+                               if ( $from_lines[$xi] !== $to_lines[$yi] )
                                break;
                                $this->xchanged[$xi] = $this->ychanged[$yi] = false;
                        }
 
                        // 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;
+                       for ( $xi = $skip; $xi < $n_from - $endskip; $xi++ ) {
+                               $xhash[$this->_line_hash( $from_lines[$xi] )] = 1;
                        }
 
-                       for ($yi = $skip; $yi < $n_to - $endskip; $yi++) {
+                       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->_line_hash( $line )] ) ) )
                                continue;
-                               $yhash[$this->_line_hash($line)] = 1;
+                               $yhash[$this->_line_hash( $line )] = 1;
                                $this->yv[] = $line;
                                $this->yind[] = $yi;
                        }
-                       for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
+                       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->_line_hash( $line )] ) ) )
                                continue;
                                $this->xv[] = $line;
                                $this->xind[] = $xi;
                        }
 
                        // Find the LCS.
-                       $this->_compareseq(0, sizeof($this->xv), 0, sizeof($this->yv));
+                       $this->_compareseq( 0, sizeof( $this->xv ), 0, sizeof( $this->yv ) );
                }
                wfProfileOut( __METHOD__ );
        }
@@ -275,99 +275,99 @@ class _DiffEngine {
         * match.  The caller must trim matching lines from the beginning and end
         * of the portions it is going to specify.
         */
-       function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) {
+       function _diag ( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
                $flip = false;
 
-               if ($xlim - $xoff > $ylim - $yoff) {
+               if ( $xlim - $xoff > $ylim - $yoff ) {
                        // Things seems faster (I'm not sure I understand why)
                        // when the shortest sequence in X.
                        $flip = true;
-                       list ($xoff, $xlim, $yoff, $ylim)
-                       = array( $yoff, $ylim, $xoff, $xlim);
+                       list ( $xoff, $xlim, $yoff, $ylim )
+                       = array( $yoff, $ylim, $xoff, $xlim );
                }
 
-               if ($flip)
-               for ($i = $ylim - 1; $i >= $yoff; $i--)
+               if ( $flip )
+               for ( $i = $ylim - 1; $i >= $yoff; $i-- )
                $ymatches[$this->xv[$i]][] = $i;
                else
-               for ($i = $ylim - 1; $i >= $yoff; $i--)
+               for ( $i = $ylim - 1; $i >= $yoff; $i-- )
                $ymatches[$this->yv[$i]][] = $i;
 
                $this->lcs = 0;
-               $this->seq[0]= $yoff - 1;
+               $this->seq[0] = $yoff - 1;
                $this->in_seq = array();
                $ymids[0] = array();
 
                $numer = $xlim - $xoff + $nchunks - 1;
                $x = $xoff;
-               for ($chunk = 0; $chunk < $nchunks; $chunk++) {
-                       if ($chunk > 0)
-                       for ($i = 0; $i <= $this->lcs; $i++)
-                       $ymids[$i][$chunk-1] = $this->seq[$i];
+               for ( $chunk = 0; $chunk < $nchunks; $chunk++ ) {
+                       if ( $chunk > 0 )
+                       for ( $i = 0; $i <= $this->lcs; $i++ )
+                       $ymids[$i][$chunk -1] = $this->seq[$i];
 
-                       $x1 = $xoff + (int)(($numer + ($xlim-$xoff)*$chunk) / $nchunks);
-                       for ( ; $x < $x1; $x++) {
+                       $x1 = $xoff + (int)( ( $numer + ( $xlim -$xoff ) * $chunk ) / $nchunks );
+                       for ( ; $x < $x1; $x++ ) {
                                $line = $flip ? $this->yv[$x] : $this->xv[$x];
-                               if (empty($ymatches[$line])) {
+                               if ( empty( $ymatches[$line] ) ) {
                                        continue;
                                }
                                $matches = $ymatches[$line];
-                               reset($matches);
+                               reset( $matches );
                                while ( list( , $y ) = each( $matches ) ) {
                                        if ( empty( $this->in_seq[$y] ) ) {
                                                $k = $this->_lcs_pos( $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]) {
-                                               assert($y < $this->seq[$k]);
+                               while ( list ( , $y ) = each( $matches ) ) {
+                                       if ( $y > $this->seq[$k -1] ) {
+                                               assert( $y < $this->seq[$k] );
                                                // Optimization: this is a common case:
                                                //      next match is just replacing previous match.
                                                $this->in_seq[$this->seq[$k]] = false;
                                                $this->seq[$k] = $y;
                                                $this->in_seq[$y] = 1;
-                                       } else if (empty($this->in_seq[$y])) {
-                                               $k = $this->_lcs_pos($y);
-                                               assert($k > 0);
-                                               $ymids[$k] = $ymids[$k-1];
+                                       } else if ( empty( $this->in_seq[$y] ) ) {
+                                               $k = $this->_lcs_pos( $y );
+                                               assert( $k > 0 );
+                                               $ymids[$k] = $ymids[$k -1];
                                        }
                                }
                        }
                }
 
-               $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
+               $seps[] = $flip ? array( $yoff, $xoff ) : array( $xoff, $yoff );
                $ymid = $ymids[$this->lcs];
-               for ($n = 0; $n < $nchunks - 1; $n++) {
-                       $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks);
+               for ( $n = 0; $n < $nchunks - 1; $n++ ) {
+                       $x1 = $xoff + (int)( ( $numer + ( $xlim - $xoff ) * $n ) / $nchunks );
                        $y1 = $ymid[$n] + 1;
-                       $seps[] = $flip ? array($y1, $x1) : array($x1, $y1);
+                       $seps[] = $flip ? array( $y1, $x1 ) : array( $x1, $y1 );
                }
-               $seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim);
+               $seps[] = $flip ? array( $ylim, $xlim ) : array( $xlim, $ylim );
 
-               return array($this->lcs, $seps);
+               return array( $this->lcs, $seps );
        }
 
-       function _lcs_pos ($ypos) {
+       function _lcs_pos ( $ypos ) {
                $end = $this->lcs;
-               if ($end == 0 || $ypos > $this->seq[$end]) {
+               if ( $end == 0 || $ypos > $this->seq[$end] ) {
                        $this->seq[++$this->lcs] = $ypos;
                        $this->in_seq[$ypos] = 1;
                        return $this->lcs;
                }
 
                $beg = 1;
-               while ($beg < $end) {
-                       $mid = (int)(($beg + $end) / 2);
+               while ( $beg < $end ) {
+                       $mid = (int)( ( $beg + $end ) / 2 );
                        if ( $ypos > $this->seq[$mid] )
                        $beg = $mid + 1;
                        else
                        $end = $mid;
                }
 
-               assert($ypos != $this->seq[$end]);
+               assert( $ypos != $this->seq[$end] );
 
                $this->in_seq[$this->seq[$end]] = false;
                $this->seq[$end] = $ypos;
@@ -386,45 +386,45 @@ class _DiffEngine {
         * Note that XLIM, YLIM are exclusive bounds.
         * All line numbers are origin-0 and discarded lines are not counted.
         */
-       function _compareseq ($xoff, $xlim, $yoff, $ylim) {
+       function _compareseq ( $xoff, $xlim, $yoff, $ylim ) {
                // Slide down the bottom initial diagonal.
-               while ($xoff < $xlim && $yoff < $ylim
-               && $this->xv[$xoff] == $this->yv[$yoff]) {
+               while ( $xoff < $xlim && $yoff < $ylim
+               && $this->xv[$xoff] == $this->yv[$yoff] ) {
                        ++$xoff;
                        ++$yoff;
                }
 
                // Slide up the top initial diagonal.
-               while ($xlim > $xoff && $ylim > $yoff
-               && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) {
+               while ( $xlim > $xoff && $ylim > $yoff
+               && $this->xv[$xlim - 1] == $this->yv[$ylim - 1] ) {
                        --$xlim;
                        --$ylim;
                }
 
-               if ($xoff == $xlim || $yoff == $ylim)
+               if ( $xoff == $xlim || $yoff == $ylim )
                $lcs = 0;
                else {
                        // This is ad hoc but seems to work well.
-                       //$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);
+                       // $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 );
                }
 
-               if ($lcs == 0) {
+               if ( $lcs == 0 ) {
                        // X and Y sequences have no common subsequence:
                        // mark all changed.
-                       while ($yoff < $ylim)
+                       while ( $yoff < $ylim )
                        $this->ychanged[$this->yind[$yoff++]] = 1;
-                       while ($xoff < $xlim)
+                       while ( $xoff < $xlim )
                        $this->xchanged[$this->xind[$xoff++]] = 1;
                } else {
                        // Use the partitions to split this problem into subproblems.
-                       reset($seps);
+                       reset( $seps );
                        $pt1 = $seps[0];
-                       while ($pt2 = next($seps)) {
-                               $this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]);
+                       while ( $pt2 = next( $seps ) ) {
+                               $this->_compareseq ( $pt1[0], $pt2[0], $pt1[1], $pt2[1] );
                                $pt1 = $pt2;
                        }
                }
@@ -442,16 +442,16 @@ class _DiffEngine {
         *
         * This is extracted verbatim from analyze.c (GNU diffutils-2.7).
         */
-       function _shift_boundaries ($lines, &$changed, $other_changed) {
+       function _shift_boundaries ( $lines, &$changed, $other_changed ) {
                wfProfileIn( __METHOD__ );
                $i = 0;
                $j = 0;
 
-               assert('sizeof($lines) == sizeof($changed)');
-               $len = sizeof($lines);
-               $other_len = sizeof($other_changed);
+               assert( 'sizeof($lines) == sizeof($changed)' );
+               $len = sizeof( $lines );
+               $other_len = sizeof( $other_changed );
 
-               while (1) {
+               while ( 1 ) {
                        /*
                         * Scan forwards to find beginning of another run of changes.
                         * Also keep track of the corresponding point in the other file.
@@ -463,23 +463,23 @@ class _DiffEngine {
                         * Furthermore, $j is always kept so that $j == $other_len or
                         * $other_changed[$j] == false.
                         */
-                       while ($j < $other_len && $other_changed[$j])
+                       while ( $j < $other_len && $other_changed[$j] )
                        $j++;
 
-                       while ($i < $len && ! $changed[$i]) {
-                               assert('$j < $other_len && ! $other_changed[$j]');
+                       while ( $i < $len && ! $changed[$i] ) {
+                               assert( '$j < $other_len && ! $other_changed[$j]' );
                                $i++; $j++;
-                               while ($j < $other_len && $other_changed[$j])
+                               while ( $j < $other_len && $other_changed[$j] )
                                $j++;
                        }
 
-                       if ($i == $len)
+                       if ( $i == $len )
                        break;
 
                        $start = $i;
 
                        // Find the end of this run of changes.
-                       while (++$i < $len && $changed[$i])
+                       while ( ++$i < $len && $changed[$i] )
                        continue;
 
                        do {
@@ -494,15 +494,15 @@ class _DiffEngine {
                                 * previous unchanged line matches the last changed one.
                                 * This merges with previous changed regions.
                                 */
-                               while ($start > 0 && $lines[$start - 1] == $lines[$i - 1]) {
+                               while ( $start > 0 && $lines[$start - 1] == $lines[$i - 1] ) {
                                        $changed[--$start] = 1;
                                        $changed[--$i] = false;
-                                       while ($start > 0 && $changed[$start - 1])
+                                       while ( $start > 0 && $changed[$start - 1] )
                                        $start--;
-                                       assert('$j > 0');
-                                       while ($other_changed[--$j])
+                                       assert( '$j > 0' );
+                                       while ( $other_changed[--$j] )
                                        continue;
-                                       assert('$j >= 0 && !$other_changed[$j]');
+                                       assert( '$j >= 0 && !$other_changed[$j]' );
                                }
 
                                /*
@@ -519,33 +519,33 @@ class _DiffEngine {
                                 * Do this second, so that if there are no merges,
                                 * the changed region is moved forward as far as possible.
                                 */
-                               while ($i < $len && $lines[$start] == $lines[$i]) {
+                               while ( $i < $len && $lines[$start] == $lines[$i] ) {
                                        $changed[$start++] = false;
                                        $changed[$i++] = 1;
-                                       while ($i < $len && $changed[$i])
+                                       while ( $i < $len && $changed[$i] )
                                        $i++;
 
-                                       assert('$j < $other_len && ! $other_changed[$j]');
+                                       assert( '$j < $other_len && ! $other_changed[$j]' );
                                        $j++;
-                                       if ($j < $other_len && $other_changed[$j]) {
+                                       if ( $j < $other_len && $other_changed[$j] ) {
                                                $corresponding = $i;
-                                               while ($j < $other_len && $other_changed[$j])
+                                               while ( $j < $other_len && $other_changed[$j] )
                                                $j++;
                                        }
                                }
-                       } while ($runlength != $i - $start);
+                       } while ( $runlength != $i - $start );
 
                        /*
                         * If possible, move the fully-merged run of changes
                         * back to a corresponding run in the other file.
                         */
-                       while ($corresponding < $i) {
+                       while ( $corresponding < $i ) {
                                $changed[--$start] = 1;
                                $changed[--$i] = 0;
-                               assert('$j > 0');
-                               while ($other_changed[--$j])
+                               assert( '$j > 0' );
+                               while ( $other_changed[--$j] )
                                continue;
-                               assert('$j >= 0 && !$other_changed[$j]');
+                               assert( '$j >= 0 && !$other_changed[$j]' );
                        }
                }
                wfProfileOut( __METHOD__ );
@@ -570,10 +570,10 @@ class Diff
         *                (Typically these are lines from a file.)
         * @param $to_lines array An array of strings.
         */
-       function __construct($from_lines, $to_lines) {
+       function __construct( $from_lines, $to_lines ) {
                $eng = new _DiffEngine;
-               $this->edits = $eng->diff($from_lines, $to_lines);
-               //$this->_check($from_lines, $to_lines);
+               $this->edits = $eng->diff( $from_lines, $to_lines );
+               // $this->_check($from_lines, $to_lines);
        }
 
        /**
@@ -589,7 +589,7 @@ class Diff
        function reverse () {
                $rev = $this;
                $rev->edits = array();
-               foreach ($this->edits as $edit) {
+               foreach ( $this->edits as $edit ) {
                        $rev->edits[] = $edit->reverse();
                }
                return $rev;
@@ -601,8 +601,8 @@ class Diff
         * @return bool True iff two sequences were identical.
         */
        function isEmpty () {
-               foreach ($this->edits as $edit) {
-                       if ($edit->type != 'copy')
+               foreach ( $this->edits as $edit ) {
+                       if ( $edit->type != 'copy' )
                        return false;
                }
                return true;
@@ -617,9 +617,9 @@ class Diff
         */
        function lcs () {
                $lcs = 0;
-               foreach ($this->edits as $edit) {
-                       if ($edit->type == 'copy')
-                       $lcs += sizeof($edit->orig);
+               foreach ( $this->edits as $edit ) {
+                       if ( $edit->type == 'copy' )
+                       $lcs += sizeof( $edit->orig );
                }
                return $lcs;
        }
@@ -635,9 +635,9 @@ class Diff
        function orig() {
                $lines = array();
 
-               foreach ($this->edits as $edit) {
-                       if ($edit->orig)
-                       array_splice($lines, sizeof($lines), 0, $edit->orig);
+               foreach ( $this->edits as $edit ) {
+                       if ( $edit->orig )
+                       array_splice( $lines, sizeof( $lines ), 0, $edit->orig );
                }
                return $lines;
        }
@@ -653,9 +653,9 @@ class Diff
        function closing() {
                $lines = array();
 
-               foreach ($this->edits as $edit) {
-                       if ($edit->closing)
-                       array_splice($lines, sizeof($lines), 0, $edit->closing);
+               foreach ( $this->edits as $edit ) {
+                       if ( $edit->closing )
+                       array_splice( $lines, sizeof( $lines ), 0, $edit->closing );
                }
                return $lines;
        }
@@ -665,29 +665,29 @@ class Diff
         *
         * This is here only for debugging purposes.
         */
-       function _check ($from_lines, $to_lines) {
+       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);
-               if (serialize($to_lines) != serialize($this->closing()))
-               trigger_error("Reconstructed closing doesn't match", E_USER_ERROR);
+               if ( serialize( $from_lines ) != serialize( $this->orig() ) )
+               trigger_error( "Reconstructed original doesn't match", E_USER_ERROR );
+               if ( serialize( $to_lines ) != serialize( $this->closing() ) )
+               trigger_error( "Reconstructed closing doesn't match", E_USER_ERROR );
 
                $rev = $this->reverse();
-               if (serialize($to_lines) != serialize($rev->orig()))
-               trigger_error("Reversed original doesn't match", E_USER_ERROR);
-               if (serialize($from_lines) != serialize($rev->closing()))
-               trigger_error("Reversed closing doesn't match", E_USER_ERROR);
+               if ( serialize( $to_lines ) != serialize( $rev->orig() ) )
+               trigger_error( "Reversed original doesn't match", E_USER_ERROR );
+               if ( serialize( $from_lines ) != serialize( $rev->closing() ) )
+               trigger_error( "Reversed closing doesn't match", E_USER_ERROR );
 
 
                $prevtype = 'none';
-               foreach ($this->edits as $edit) {
+               foreach ( $this->edits as $edit ) {
                        if ( $prevtype == $edit->type )
-                       trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
+                       trigger_error( "Edit sequence is non-optimal", E_USER_ERROR );
                        $prevtype = $edit->type;
                }
 
                $lcs = $this->lcs();
-               trigger_error('Diff okay: LCS = '.$lcs, E_USER_NOTICE);
+               trigger_error( 'Diff okay: LCS = ' . $lcs, E_USER_NOTICE );
                wfProfileOut( __METHOD__ );
        }
 }
@@ -722,27 +722,27 @@ class MappedDiff extends Diff
         * @param $mapped_to_lines array This array should
         *      have the same number of elements as $to_lines.
         */
-       function __construct($from_lines, $to_lines,
-       $mapped_from_lines, $mapped_to_lines) {
+       function __construct( $from_lines, $to_lines,
+       $mapped_from_lines, $mapped_to_lines ) {
                wfProfileIn( __METHOD__ );
 
-               assert(sizeof($from_lines) == sizeof($mapped_from_lines));
-               assert(sizeof($to_lines) == sizeof($mapped_to_lines));
+               assert( sizeof( $from_lines ) == sizeof( $mapped_from_lines ) );
+               assert( sizeof( $to_lines ) == sizeof( $mapped_to_lines ) );
 
-               parent::__construct($mapped_from_lines, $mapped_to_lines);
+               parent::__construct( $mapped_from_lines, $mapped_to_lines );
 
                $xi = $yi = 0;
-               for ($i = 0; $i < sizeof($this->edits); $i++) {
+               for ( $i = 0; $i < sizeof( $this->edits ); $i++ ) {
                        $orig = &$this->edits[$i]->orig;
-                       if (is_array($orig)) {
-                               $orig = array_slice($from_lines, $xi, sizeof($orig));
-                               $xi += sizeof($orig);
+                       if ( is_array( $orig ) ) {
+                               $orig = array_slice( $from_lines, $xi, sizeof( $orig ) );
+                               $xi += sizeof( $orig );
                        }
 
                        $closing = &$this->edits[$i]->closing;
-                       if (is_array($closing)) {
-                               $closing = array_slice($to_lines, $yi, sizeof($closing));
-                               $yi += sizeof($closing);
+                       if ( is_array( $closing ) ) {
+                               $closing = array_slice( $to_lines, $yi, sizeof( $closing ) );
+                               $yi += sizeof( $closing );
                        }
                }
                wfProfileOut( __METHOD__ );
@@ -782,7 +782,7 @@ class DiffFormatter {
         * @param $diff object A Diff object.
         * @return string The formatted output.
         */
-       function format($diff) {
+       function format( $diff ) {
                wfProfileIn( __METHOD__ );
 
                $xi = $yi = 1;
@@ -794,67 +794,67 @@ class DiffFormatter {
 
                $this->_start_diff();
 
-               foreach ($diff->edits as $edit) {
-                       if ($edit->type == 'copy') {
-                               if (is_array($block)) {
-                                       if (sizeof($edit->orig) <= $nlead + $ntrail) {
+               foreach ( $diff->edits as $edit ) {
+                       if ( $edit->type == 'copy' ) {
+                               if ( is_array( $block ) ) {
+                                       if ( sizeof( $edit->orig ) <= $nlead + $ntrail ) {
                                                $block[] = $edit;
                                        }
-                                       else{
-                                               if ($ntrail) {
-                                                       $context = array_slice($edit->orig, 0, $ntrail);
-                                                       $block[] = new _DiffOp_Copy($context);
+                                       else {
+                                               if ( $ntrail ) {
+                                                       $context = array_slice( $edit->orig, 0, $ntrail );
+                                                       $block[] = new _DiffOp_Copy( $context );
                                                }
-                                               $this->_block($x0, $ntrail + $xi - $x0,
+                                               $this->_block( $x0, $ntrail + $xi - $x0,
                                                $y0, $ntrail + $yi - $y0,
-                                               $block);
+                                               $block );
                                                $block = false;
                                        }
                                }
                                $context = $edit->orig;
                        }
                        else {
-                               if (! is_array($block)) {
-                                       $context = array_slice($context, sizeof($context) - $nlead);
-                                       $x0 = $xi - sizeof($context);
-                                       $y0 = $yi - sizeof($context);
+                               if ( ! is_array( $block ) ) {
+                                       $context = array_slice( $context, sizeof( $context ) - $nlead );
+                                       $x0 = $xi - sizeof( $context );
+                                       $y0 = $yi - sizeof( $context );
                                        $block = array();
-                                       if ($context)
-                                       $block[] = new _DiffOp_Copy($context);
+                                       if ( $context )
+                                       $block[] = new _DiffOp_Copy( $context );
                                }
                                $block[] = $edit;
                        }
 
-                       if ($edit->orig)
-                       $xi += sizeof($edit->orig);
-                       if ($edit->closing)
-                       $yi += sizeof($edit->closing);
+                       if ( $edit->orig )
+                       $xi += sizeof( $edit->orig );
+                       if ( $edit->closing )
+                       $yi += sizeof( $edit->closing );
                }
 
-               if (is_array($block))
-               $this->_block($x0, $xi - $x0,
+               if ( is_array( $block ) )
+               $this->_block( $x0, $xi - $x0,
                $y0, $yi - $y0,
-               $block);
+               $block );
 
                $end = $this->_end_diff();
                wfProfileOut( __METHOD__ );
                return $end;
        }
 
-       function _block($xbeg, $xlen, $ybeg, $ylen, &$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);
+               $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);
+                       trigger_error( 'Unknown edit type', E_USER_ERROR );
                }
                $this->_end_block();
                wfProfileOut( __METHOD__ );
@@ -870,42 +870,42 @@ class DiffFormatter {
                return $val;
        }
 
-       function _block_header($xbeg, $xlen, $ybeg, $ylen) {
-               if ($xlen > 1)
-               $xbeg .= "," . ($xbeg + $xlen - 1);
-               if ($ylen > 1)
-               $ybeg .= "," . ($ybeg + $ylen - 1);
+       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;
+               return $xbeg . ( $xlen ? ( $ylen ? 'c' : 'd' ) : 'a' ) . $ybeg;
        }
 
-       function _start_block($header) {
+       function _start_block( $header ) {
                echo $header . "\n";
        }
 
        function _end_block() {
        }
 
-       function _lines($lines, $prefix = ' ') {
-               foreach ($lines as $line)
+       function _lines( $lines, $prefix = ' ' ) {
+               foreach ( $lines as $line )
                echo "$prefix $line\n";
        }
 
-       function _context($lines) {
-               $this->_lines($lines);
+       function _context( $lines ) {
+               $this->_lines( $lines );
        }
 
-       function _added($lines) {
-               $this->_lines($lines, '>');
+       function _added( $lines ) {
+               $this->_lines( $lines, '>' );
        }
-       function _deleted($lines) {
-               $this->_lines($lines, '<');
+       function _deleted( $lines ) {
+               $this->_lines( $lines, '<' );
        }
 
-       function _changed($orig, $closing) {
-               $this->_deleted($orig);
+       function _changed( $orig, $closing ) {
+               $this->_deleted( $orig );
                echo "---\n";
-               $this->_added($closing);
+               $this->_added( $closing );
        }
 }
 
@@ -918,17 +918,17 @@ class UnifiedDiffFormatter extends DiffFormatter {
        var $leading_context_lines = 2;
        var $trailing_context_lines = 2;
 
-       function _added($lines) {
-               $this->_lines($lines, '+');
+       function _added( $lines ) {
+               $this->_lines( $lines, '+' );
        }
-       function _deleted($lines) {
-               $this->_lines($lines, '-');
+       function _deleted( $lines ) {
+               $this->_lines( $lines, '-' );
        }
-       function _changed($orig, $closing) {
-               $this->_deleted($orig);
-               $this->_added($closing);
+       function _changed( $orig, $closing ) {
+               $this->_deleted( $orig );
+               $this->_added( $closing );
        }
-       function _block_header($xbeg, $xlen, $ybeg, $ylen) {
+       function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
                return "@@ -$xbeg,$xlen +$ybeg,$ylen @@";
        }
 }
@@ -938,23 +938,23 @@ class UnifiedDiffFormatter extends DiffFormatter {
  * @ingroup DifferenceEngine
  */
 class ArrayDiffFormatter extends DiffFormatter {
-       function format($diff) {
+       function format( $diff ) {
                $oldline = 1;
                $newline = 1;
                $retval = array();
-               foreach($diff->edits as $edit)
-               switch($edit->type) {
+               foreach ( $diff->edits as $edit )
+               switch( $edit->type ) {
                        case 'add':
-                               foreach($edit->closing as $l) {
+                               foreach ( $edit->closing as $l ) {
                                        $retval[] = array(
                                                        'action' => 'add',
-                                                       'new'=> $l,
+                                                       'new' => $l,
                                                        'newline' => $newline++
                                        );
                                }
                                break;
                        case 'delete':
-                               foreach($edit->orig as $l) {
+                               foreach ( $edit->orig as $l ) {
                                        $retval[] = array(
                                                        'action' => 'delete',
                                                        'old' => $l,
@@ -963,7 +963,7 @@ class ArrayDiffFormatter extends DiffFormatter {
                                }
                                break;
                        case 'change':
-                               foreach($edit->orig as $i => $l) {
+                               foreach ( $edit->orig as $i => $l ) {
                                        $retval[] = array(
                                                        'action' => 'change',
                                                        'old' => $l,
@@ -974,8 +974,8 @@ class ArrayDiffFormatter extends DiffFormatter {
                                }
                                break;
                        case 'copy':
-                               $oldline += count($edit->orig);
-                               $newline += count($edit->orig);
+                               $oldline += count( $edit->orig );
+                               $newline += count( $edit->orig );
                }
                return $retval;
        }
@@ -986,7 +986,7 @@ class ArrayDiffFormatter extends DiffFormatter {
  *
  */
 
-define('NBSP', '&#160;'); // iso-8859-x non-breaking space.
+define( 'NBSP', '&#160;' ); // iso-8859-x non-breaking space.
 
 /**
  * @todo document
@@ -1001,12 +1001,12 @@ class _HWLDF_WordAccumulator {
                $this->_tag = '';
        }
 
-       function _flushGroup ($new_tag) {
-               if ($this->_group !== '') {
-                       if ($this->_tag == 'ins')
+       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')
+                       elseif ( $this->_tag == 'del' )
                        $this->_line .= '<del class="diffchange diffchange-inline">' .
                        htmlspecialchars ( $this->_group ) . '</del>';
                        else
@@ -1016,9 +1016,9 @@ class _HWLDF_WordAccumulator {
                $this->_tag = $new_tag;
        }
 
-       function _flushLine ($new_tag) {
-               $this->_flushGroup($new_tag);
-               if ($this->_line != '')
+       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
@@ -1026,26 +1026,26 @@ class _HWLDF_WordAccumulator {
                $this->_line = '';
        }
 
-       function addWords ($words, $tag = '') {
-               if ($tag != $this->_tag)
-               $this->_flushGroup($tag);
+       function addWords ( $words, $tag = '' ) {
+               if ( $tag != $this->_tag )
+               $this->_flushGroup( $tag );
 
-               foreach ($words as $word) {
+               foreach ( $words as $word ) {
                        // new-line should only come as first char of word.
-                       if ($word == '')
+                       if ( $word == '' )
                        continue;
-                       if ($word[0] == "\n") {
-                               $this->_flushLine($tag);
-                               $word = substr($word, 1);
+                       if ( $word[0] == "\n" ) {
+                               $this->_flushLine( $tag );
+                               $word = substr( $word, 1 );
                        }
-                       assert(!strstr($word, "\n"));
+                       assert( !strstr( $word, "\n" ) );
                        $this->_group .= $word;
                }
        }
 
        function getLines() {
-               $this->_flushLine('~done');
-               return preg_replace( '/\n/m', '', $this->_lines);
+               $this->_flushLine( '~done' );
+               return preg_replace( '/\n/m', '', $this->_lines );
        }
 }
 
@@ -1057,18 +1057,18 @@ class _HWLDF_WordAccumulator {
 class WordLevelDiff extends MappedDiff {
        const MAX_LINE_LENGTH = 10000;
 
-       function __construct ($orig_lines, $closing_lines) {
+       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);
+               parent::__construct( $orig_words, $closing_words,
+               $orig_stripped, $closing_stripped );
                wfProfileOut( __METHOD__ );
        }
 
-       function _split($lines) {
+       function _split( $lines ) {
                wfProfileIn( __METHOD__ );
 
                $words = array();
@@ -1088,8 +1088,8 @@ class WordLevelDiff extends MappedDiff {
                                $stripped[] = $line;
                        } else {
                                $m = array();
-                               if (preg_match_all('/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
-                               $line, $m))
+                               if ( preg_match_all( '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
+                               $line, $m ) )
                                {
                                        $words = array_merge( $words, $m[0] );
                                        $stripped = array_merge( $stripped, $m[1] );
@@ -1097,18 +1097,18 @@ class WordLevelDiff extends MappedDiff {
                        }
                }
                wfProfileOut( __METHOD__ );
-               return array($words, $stripped);
+               return array( $words, $stripped );
        }
 
        function orig () {
                wfProfileIn( __METHOD__ );
                $orig = new _HWLDF_WordAccumulator;
 
-               foreach ($this->edits as $edit) {
-                       if ($edit->type == 'copy')
-                       $orig->addWords($edit->orig);
-                       elseif ($edit->orig)
-                       $orig->addWords($edit->orig, 'del');
+               foreach ( $this->edits as $edit ) {
+                       if ( $edit->type == 'copy' )
+                       $orig->addWords( $edit->orig );
+                       elseif ( $edit->orig )
+                       $orig->addWords( $edit->orig, 'del' );
                }
                $lines = $orig->getLines();
                wfProfileOut( __METHOD__ );
@@ -1119,11 +1119,11 @@ class WordLevelDiff extends MappedDiff {
                wfProfileIn( __METHOD__ );
                $closing = new _HWLDF_WordAccumulator;
 
-               foreach ($this->edits as $edit) {
-                       if ($edit->type == 'copy')
-                       $closing->addWords($edit->closing);
-                       elseif ($edit->closing)
-                       $closing->addWords($edit->closing, 'ins');
+               foreach ( $this->edits as $edit ) {
+                       if ( $edit->type == 'copy' )
+                       $closing->addWords( $edit->closing );
+                       elseif ( $edit->closing )
+                       $closing->addWords( $edit->closing, 'ins' );
                }
                $lines = $closing->getLines();
                wfProfileOut( __METHOD__ );
@@ -1151,8 +1151,8 @@ class TableDiffFormatter extends DiffFormatter {
        }
 
        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";
+               $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;
        }
 
@@ -1163,7 +1163,7 @@ class TableDiffFormatter extends DiffFormatter {
        function _end_block() {
        }
 
-       function _lines( $lines, $prefix=' ', $color='white' ) {
+       function _lines( $lines, $prefix = ' ', $color = 'white' ) {
        }
 
        # HTML-escape parameter before calling this
@@ -1182,7 +1182,7 @@ class TableDiffFormatter extends DiffFormatter {
        }
 
        private function wrapLine( $marker, $class, $line ) {
-               if( $line !== '' ) {
+               if ( $line !== '' ) {
                        // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
                        $line = Xml::tags( 'div', null, $this->escapeWhiteSpace( $line ) );
                }
@@ -1194,15 +1194,15 @@ class TableDiffFormatter extends DiffFormatter {
        }
 
        function _added( $lines ) {
-               foreach ($lines as $line) {
+               foreach ( $lines as $line ) {
                        echo '<tr>' . $this->emptyLine() .
                        $this->addedLine( '<ins class="diffchange">' .
                        htmlspecialchars ( $line ) . '</ins>' ) . "</tr>\n";
                }
        }
 
-       function _deleted($lines) {
-               foreach ($lines as $line) {
+       function _deleted( $lines ) {
+               foreach ( $lines as $line ) {
                        echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
                        htmlspecialchars ( $line ) . '</del>' ) .
                        $this->emptyLine() . "</tr>\n";
@@ -1210,7 +1210,7 @@ class TableDiffFormatter extends DiffFormatter {
        }
 
        function _context( $lines ) {
-               foreach ($lines as $line) {
+               foreach ( $lines as $line ) {
                        echo '<tr>' .
                        $this->contextLine( htmlspecialchars ( $line ) ) .
                        $this->contextLine( htmlspecialchars ( $line ) ) . "</tr>\n";
@@ -1232,7 +1232,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 b66958a..8def296 100644 (file)
@@ -38,7 +38,7 @@
  */
 class WikiDiff3 {
 
-       //Input variables
+       // Input variables
        private $from;
        private $to;
        private $m;
@@ -47,117 +47,117 @@ class WikiDiff3 {
        private $tooLong;
        private $powLimit;
 
-       //State variables
+       // State variables
        private $maxDifferences;
        private $lcsLengthCorrectedForHeuristic = false;
 
-       //Output variables
+       // Output variables
        public $length;
        public $removed;
        public $added;
        public $heuristicUsed;
 
-       function __construct($tooLong = 2000000, $powLimit = 1.45){
+       function __construct( $tooLong = 2000000, $powLimit = 1.45 ) {
                $this->tooLong = $tooLong;
                $this->powLimit = $powLimit;
        }
 
-       public function diff(/*array*/ $from, /*array*/ $to){
-               //remember initial lengths
-               $m = sizeof($from);
-               $n = count($to);
+       public function diff( /*array*/ $from, /*array*/ $to ) {
+               // remember initial lengths
+               $m = sizeof( $from );
+               $n = count( $to );
 
                $this->heuristicUsed = false;
 
-               //output
-               $removed = $m > 0 ? array_fill(0, $m, true) : array();
-               $added = $n > 0 ? array_fill(0, $n, true) : array();
+               // output
+               $removed = $m > 0 ? array_fill( 0, $m, true ) : array();
+               $added = $n > 0 ? array_fill( 0, $n, true ) : array();
 
-               //reduce the complexity for the next step (intentionally done twice)
-               //remove common tokens at the start
+               // reduce the complexity for the next step (intentionally done twice)
+               // remove common tokens at the start
                $i = 0;
-               while($i < $m && $i < $n && $from[$i] === $to[$i]) {
+               while ( $i < $m && $i < $n && $from[$i] === $to[$i] ) {
                        $removed[$i] = $added[$i] = false;
-                       unset($from[$i], $to[$i]);
+                       unset( $from[$i], $to[$i] );
                        ++$i;
                }
 
-               //remove common tokens at the end
+               // remove common tokens at the end
                $j = 1;
-               while($i + $j <= $m && $i + $j <= $n && $from[$m - $j] === $to[$n - $j]) {
+               while ( $i + $j <= $m && $i + $j <= $n && $from[$m - $j] === $to[$n - $j] ) {
                        $removed[$m - $j] = $added[$n - $j] = false;
-                       unset($from[$m - $j], $to[$n - $j]);
+                       unset( $from[$m - $j], $to[$n - $j] );
                        ++$j;
                }
 
                $this->from = $newFromIndex = $this->to = $newToIndex = array();
 
-               //remove tokens not in both sequences
+               // remove tokens not in both sequences
                $shared = array();
-               foreach( $from as $key ) {
+               foreach ( $from as $key ) {
                        $shared[$key] = false;
                }
 
-               foreach($to as $index => &$el) {
-                       if(array_key_exists($el, $shared)) {
-                               //keep it
+               foreach ( $to as $index => &$el ) {
+                       if ( array_key_exists( $el, $shared ) ) {
+                               // keep it
                                $this->to[] = $el;
                                $shared[$el] = true;
                                $newToIndex[] = $index;
                        }
                }
-               foreach($from as $index => &$el) {
-                       if($shared[$el]) {
-                               //keep it
+               foreach ( $from as $index => &$el ) {
+                       if ( $shared[$el] ) {
+                               // keep it
                                $this->from[] = $el;
                                $newFromIndex[] = $index;
                        }
                }
 
-               unset($shared, $from, $to);
+               unset( $shared, $from, $to );
 
-               $this->m = count($this->from);
-               $this->n = count($this->to);
+               $this->m = count( $this->from );
+               $this->n = count( $this->to );
 
-               $this->removed = $this->m > 0 ? array_fill(0, $this->m, true) : array();
-               $this->added = $this->n > 0 ? array_fill(0, $this->n, true) : array();
+               $this->removed = $this->m > 0 ? array_fill( 0, $this->m, true ) : array();
+               $this->added = $this->n > 0 ? array_fill( 0, $this->n, true ) : array();
 
-               if ($this->m == 0 || $this->n == 0) {
+               if ( $this->m == 0 || $this->n == 0 ) {
                        $this->length = 0;
                } else {
-                       $this->maxDifferences = ceil(($this->m + $this->n) / 2.0);
-                       if ($this->m * $this->n > $this->tooLong) {
+                       $this->maxDifferences = ceil( ( $this->m + $this->n ) / 2.0 );
+                       if ( $this->m * $this->n > $this->tooLong ) {
                                // limit complexity to D^POW_LIMIT for long sequences
-                               $this->maxDifferences = floor(pow($this->maxDifferences, $this->powLimit - 1.0));
-                               wfDebug("Limiting max number of differences to $this->maxDifferences\n");
+                               $this->maxDifferences = floor( pow( $this->maxDifferences, $this->powLimit - 1.0 ) );
+                               wfDebug( "Limiting max number of differences to $this->maxDifferences\n" );
                        }
 
                        /*
                         * The common prefixes and suffixes are always part of some LCS, include
                         * them now to reduce our search space
                         */
-                       $max = min($this->m, $this->n);
-                       for ($forwardBound = 0; $forwardBound < $max
+                       $max = min( $this->m, $this->n );
+                       for ( $forwardBound = 0; $forwardBound < $max
                                        && $this->from[$forwardBound] === $this->to[$forwardBound];
-                                       ++$forwardBound) {
+                                       ++$forwardBound ) {
                                $this->removed[$forwardBound] = $this->added[$forwardBound] = false;
                        }
 
                        $backBoundL1 = $this->m - 1;
                        $backBoundL2 = $this->n - 1;
 
-                       while ($backBoundL1 >= $forwardBound && $backBoundL2 >= $forwardBound
-                                       && $this->from[$backBoundL1] === $this->to[$backBoundL2]) {
+                       while ( $backBoundL1 >= $forwardBound && $backBoundL2 >= $forwardBound
+                                       && $this->from[$backBoundL1] === $this->to[$backBoundL2] ) {
                                $this->removed[$backBoundL1--] = $this->added[$backBoundL2--] = false;
                        }
 
-                       $temp = array_fill(0, $this->m + $this->n + 1, 0);
-                       $V = array($temp, $temp);
-                       $snake = array(0, 0, 0);
+                       $temp = array_fill( 0, $this->m + $this->n + 1, 0 );
+                       $V = array( $temp, $temp );
+                       $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;
@@ -165,13 +165,13 @@ class WikiDiff3 {
 
                $this->length += $i + $j - 1;
 
-               foreach($this->removed as $key => &$removed_elem) {
-                       if(!$removed_elem) {
+               foreach ( $this->removed as $key => &$removed_elem ) {
+                       if ( !$removed_elem ) {
                                $removed[$newFromIndex[$key]] = false;
                        }
                }
-               foreach($this->added as $key => &$added_elem) {
-                       if(!$added_elem) {
+               foreach ( $this->added as $key => &$added_elem ) {
+                       if ( !$added_elem ) {
                                $added[$newToIndex[$key]] = false;
                        }
                }
@@ -179,48 +179,48 @@ class WikiDiff3 {
                $this->added = $added;
        }
 
-       function diff_range($from_lines, $to_lines) {
+       function diff_range( $from_lines, $to_lines ) {
                // Diff and store locally
-               $this->diff($from_lines, $to_lines);
-               unset($from_lines, $to_lines);
+               $this->diff( $from_lines, $to_lines );
+               unset( $from_lines, $to_lines );
 
                $ranges = array();
                $xi = $yi = 0;
-               while ($xi < $this->m || $yi < $this->n) {
+               while ( $xi < $this->m || $yi < $this->n ) {
                        // Matching "snake".
-                       while ($xi < $this->m && $yi < $this->n
+                       while ( $xi < $this->m && $yi < $this->n
                                        && !$this->removed[$xi]
-                                       && !$this->added[$yi]) {
+                                       && !$this->added[$yi] ) {
                                ++$xi;
                                ++$yi;
                        }
                        // Find deletes & adds.
                        $xstart = $xi;
-                       while ($xi < $this->m && $this->removed[$xi]) {
+                       while ( $xi < $this->m && $this->removed[$xi] ) {
                                ++$xi;
                        }
 
                        $ystart = $yi;
-                       while ($yi < $this->n && $this->added[$yi]) {
+                       while ( $yi < $this->n && $this->added[$yi] ) {
                                ++$yi;
                        }
 
-                       if ($xi > $xstart || $yi > $ystart) {
-                               $ranges[] = new RangeDifference($xstart, $xi,
-                                                               $ystart, $yi);
+                       if ( $xi > $xstart || $yi > $ystart ) {
+                               $ranges[] = new RangeDifference( $xstart, $xi,
+                                                               $ystart, $yi );
                        }
                }
                return $ranges;
        }
 
-       private function lcs_rec($bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake) {
+       private function lcs_rec( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
                // check that both sequences are non-empty
-               if ($bottoml1 > $topl1 || $bottoml2 > $topl2) {
+               if ( $bottoml1 > $topl1 || $bottoml2 > $topl2 ) {
                        return 0;
                }
 
-               $d = $this->find_middle_snake($bottoml1, $topl1, $bottoml2,
-                                                       $topl2, $V, $snake);
+               $d = $this->find_middle_snake( $bottoml1, $topl1, $bottoml2,
+                                                       $topl2, $V, $snake );
 
                // need to store these so we don't lose them when they're
                // overwritten by the recursion
@@ -229,24 +229,24 @@ class WikiDiff3 {
                $starty = $snake[1];
 
                // the middle snake is part of the LCS, store it
-               for ($i = 0; $i < $len; ++$i) {
+               for ( $i = 0; $i < $len; ++$i ) {
                        $this->removed[$startx + $i] = $this->added[$starty + $i] = false;
                }
 
-               if ($d > 1) {
+               if ( $d > 1 ) {
                        return $len
-                       + $this->lcs_rec($bottoml1, $startx - 1, $bottoml2,
-                                                       $starty - 1, $V, $snake)
-                       + $this->lcs_rec($startx + $len, $topl1, $starty + $len,
-                                                       $topl2, $V, $snake);
-               } else if ($d == 1) {
+                       + $this->lcs_rec( $bottoml1, $startx - 1, $bottoml2,
+                                                       $starty - 1, $V, $snake )
+                       + $this->lcs_rec( $startx + $len, $topl1, $starty + $len,
+                                                       $topl2, $V, $snake );
+               } else if ( $d == 1 ) {
                        /*
                         * In this case the sequences differ by exactly 1 line. We have
                         * already saved all the lines after the difference in the for loop
                         * above, now we need to save all the lines before the difference.
                         */
-                       $max = min($startx - $bottoml1, $starty - $bottoml2);
-                       for ($i = 0; $i < $max; ++$i) {
+                       $max = min( $startx - $bottoml1, $starty - $bottoml2 );
+                       for ( $i = 0; $i < $max; ++$i ) {
                                $this->removed[$bottoml1 + $i] =
                                        $this->added[$bottoml2 + $i] = false;
                        }
@@ -255,7 +255,7 @@ class WikiDiff3 {
                return $len;
        }
 
-       private function find_middle_snake($bottoml1, $topl1, $bottoml2,$topl2, &$V, &$snake) {
+       private function find_middle_snake( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
                $from = &$this->from;
                $to = &$this->to;
                $V0 = &$V[0];
@@ -263,24 +263,24 @@ 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;
-               $maxabsx = $N+$bottoml1;
-               $maxabsy = $M+$bottoml2;
-               $limit = min($this->maxDifferences, ceil(($N + $M ) / 2));
+               $maxabsx = $N + $bottoml1;
+               $maxabsy = $M + $bottoml2;
+               $limit = min( $this->maxDifferences, ceil( ( $N + $M ) / 2 ) );
 
-               //value_to_add_forward: a 0 or 1 that we add to the start
+               // value_to_add_forward: a 0 or 1 that we add to the start
                // offset to make it odd/even
-               if (($M & 1) == 1) {
+               if ( ( $M & 1 ) == 1 ) {
                        $value_to_add_forward = 1;
                } else {
                        $value_to_add_forward = 0;
                }
 
-               if (($N & 1) == 1) {
+               if ( ( $N & 1 ) == 1 ) {
                        $value_to_add_backward = 1;
                } else {
                        $value_to_add_backward = 0;
@@ -296,18 +296,18 @@ class WikiDiff3 {
 
                $V0[$limit_plus_1] = 0;
                $V1[$limit_min_1] = $N;
-               $limit = min($this->maxDifferences, ceil(($N + $M ) / 2));
+               $limit = min( $this->maxDifferences, ceil( ( $N + $M ) / 2 ) );
 
-               if (($delta & 1) == 1) {
-                       for ($d = 0; $d <= $limit; ++$d) {
-                               $start_diag = max($value_to_add_forward + $start_forward, -$d);
-                               $end_diag = min($end_forward, $d);
+               if ( ( $delta & 1 ) == 1 ) {
+                       for ( $d = 0; $d <= $limit; ++$d ) {
+                               $start_diag = max( $value_to_add_forward + $start_forward, -$d );
+                               $end_diag = min( $end_forward, $d );
                                $value_to_add_forward = 1 - $value_to_add_forward;
 
                                // 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])) {
+                               for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
+                                       if ( $k == -$d || ( $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;
@@ -316,36 +316,36 @@ class WikiDiff3 {
                                        $absx = $snake0 = $x + $bottoml1;
                                        $absy = $snake1 = $x - $k + $bottoml2;
 
-                                       while ($absx < $maxabsx && $absy < $maxabsy && $from[$absx] === $to[$absy]) {
+                                       while ( $absx < $maxabsx && $absy < $maxabsy && $from[$absx] === $to[$absy] ) {
                                                ++$absx;
                                                ++$absy;
                                        }
-                                       $x = $absx-$bottoml1;
+                                       $x = $absx -$bottoml1;
 
                                        $snake2 = $absx -$snake0;
                                        $V0[$limit + $k] = $x;
-                                       if ($k >= $delta - $d + 1 && $k <= $delta + $d - 1
-                                                       && $x >= $V1[$limit + $k - $delta]) {
+                                       if ( $k >= $delta - $d + 1 && $k <= $delta + $d - 1
+                                                       && $x >= $V1[$limit + $k - $delta] ) {
                                                return 2 * $d - 1;
                                        }
 
                                        // check to see if we can cut down the diagonal range
-                                       if ($x >= $N && $end_forward > $k - 1) {
+                                       if ( $x >= $N && $end_forward > $k - 1 ) {
                                                $end_forward = $k - 1;
-                                       } else if ($absy - $bottoml2 >= $M) {
+                                       } else if ( $absy - $bottoml2 >= $M ) {
                                                $start_forward = $k + 1;
                                                $value_to_add_forward = 0;
                                        }
                                }
 
-                               $start_diag = max($value_to_add_backward + $start_backward, -$d);
-                               $end_diag = min($end_backward, $d);
+                               $start_diag = max( $value_to_add_backward + $start_backward, -$d );
+                               $end_diag = min( $end_backward, $d );
                                $value_to_add_backward = 1 - $value_to_add_backward;
 
                                // 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])) {
+                               for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
+                                       if ( $k == $d
+                                       || ( $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;
@@ -354,8 +354,8 @@ class WikiDiff3 {
                                        $y = $x - $k - $delta;
 
                                        $snake2 = 0;
-                                       while ($x > 0 && $y > 0
-                                       && $from[$x +$bottoml1_min_1] === $to[$y + $bottoml2_min_1]) {
+                                       while ( $x > 0 && $y > 0
+                                       && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1] ) {
                                                --$x;
                                                --$y;
                                                ++$snake2;
@@ -363,24 +363,24 @@ class WikiDiff3 {
                                        $V1[$limit + $k] = $x;
 
                                        // check to see if we can cut down our diagonal range
-                                       if ($x <= 0) {
+                                       if ( $x <= 0 ) {
                                                $start_backward = $k + 1;
                                                $value_to_add_backward = 0;
-                                       } else if ($y <= 0 && $end_backward > $k - 1) {
+                                       } else if ( $y <= 0 && $end_backward > $k - 1 ) {
                                                $end_backward = $k - 1;
                                        }
                                }
                        }
                } else {
-                       for ($d = 0; $d <= $limit; ++$d) {
-                               $start_diag = max($value_to_add_forward + $start_forward, -$d);
-                               $end_diag = min($end_forward, $d);
+                       for ( $d = 0; $d <= $limit; ++$d ) {
+                               $start_diag = max( $value_to_add_forward + $start_forward, -$d );
+                               $end_diag = min( $end_forward, $d );
                                $value_to_add_forward = 1 - $value_to_add_forward;
 
                                // 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])) {
+                               for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
+                                       if ( $k == -$d
+                                       || ( $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;
@@ -389,31 +389,31 @@ class WikiDiff3 {
                                        $absx = $snake0 = $x + $bottoml1;
                                        $absy = $snake1 = $x - $k + $bottoml2;
 
-                                       while ($absx < $maxabsx && $absy < $maxabsy && $from[$absx] === $to[$absy]) {
+                                       while ( $absx < $maxabsx && $absy < $maxabsy && $from[$absx] === $to[$absy] ) {
                                                ++$absx;
                                                ++$absy;
                                        }
-                                       $x = $absx-$bottoml1;
+                                       $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) {
+                                       if ( $x >= $N && $end_forward > $k - 1 ) {
                                                $end_forward = $k - 1;
-                                       } else if ($absy-$bottoml2 >= $M) {
+                                       } else if ( $absy -$bottoml2 >= $M ) {
                                                $start_forward = $k + 1;
                                                $value_to_add_forward = 0;
                                        }
                                }
 
-                               $start_diag = max($value_to_add_backward + $start_backward, -$d);
-                               $end_diag = min($end_backward, $d);
+                               $start_diag = max( $value_to_add_backward + $start_backward, -$d );
+                               $end_diag = min( $end_backward, $d );
                                $value_to_add_backward = 1 - $value_to_add_backward;
 
                                // 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])) {
+                               for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
+                                       if ( $k == $d
+                                       || ( $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;
@@ -422,26 +422,26 @@ class WikiDiff3 {
                                        $y = $x - $k - $delta;
 
                                        $snake2 = 0;
-                                       while ($x > 0 && $y > 0
-                                                       && $from[$x +$bottoml1_min_1] === $to[$y + $bottoml2_min_1]) {
+                                       while ( $x > 0 && $y > 0
+                                                       && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1] ) {
                                                --$x;
                                                --$y;
                                                ++$snake2;
                                        }
                                        $V1[$limit + $k] = $x;
 
-                                       if ($k >= -$delta - $d && $k <= $d - $delta
-                                                       && $x <= $V0[$limit + $k + $delta]) {
+                                       if ( $k >= -$delta - $d && $k <= $d - $delta
+                                                       && $x <= $V0[$limit + $k + $delta] ) {
                                                $snake0 = $bottoml1 + $x;
                                                $snake1 = $bottoml2 + $y;
                                                return 2 * $d;
                                        }
 
                                        // check to see if we can cut down our diagonal range
-                                       if ($x <= 0) {
+                                       if ( $x <= 0 ) {
                                                $start_backward = $k + 1;
                                                $value_to_add_backward = 0;
-                                       } else if ($y <= 0 && $end_backward > $k - 1) {
+                                       } else if ( $y <= 0 && $end_backward > $k - 1 ) {
                                                $end_backward = $k - 1;
                                        }
                                }
@@ -453,12 +453,12 @@ class WikiDiff3 {
                 * there.
                 */
 
-               $most_progress = self::findMostProgress($M, $N, $limit, $V);
+               $most_progress = self::findMostProgress( $M, $N, $limit, $V );
 
                $snake0 = $bottoml1 + $most_progress[0];
                $snake1 = $bottoml2 + $most_progress[1];
                $snake2 = 0;
-               wfDebug("Computing the LCS is too expensive. Using a heuristic.\n");
+               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
@@ -469,48 +469,48 @@ class WikiDiff3 {
                */
        }
 
-       private static function findMostProgress($M, $N, $limit, $V) {
+       private static function findMostProgress( $M, $N, $limit, $V ) {
                $delta = $N - $M;
 
-               if (($M & 1) == ($limit & 1)) {
-                       $forward_start_diag = max(-$M, -$limit);
+               if ( ( $M & 1 ) == ( $limit & 1 ) ) {
+                       $forward_start_diag = max( -$M, -$limit );
                } else {
-                       $forward_start_diag = max(1 - $M, -$limit);
+                       $forward_start_diag = max( 1 - $M, -$limit );
                }
 
-               $forward_end_diag = min($N, $limit);
+               $forward_end_diag = min( $N, $limit );
 
-               if (($N & 1) == ($limit & 1)) {
-                       $backward_start_diag = max(-$N, -$limit);
+               if ( ( $N & 1 ) == ( $limit & 1 ) ) {
+                       $backward_start_diag = max( -$N, -$limit );
                } else {
-                       $backward_start_diag = max(1 - $N, -$limit);
+                       $backward_start_diag = max( 1 - $N, -$limit );
                }
 
-               $backward_end_diag = -min($M, $limit);
+               $backward_end_diag = -min( $M, $limit );
 
-               $temp = array(0, 0, 0);
+               $temp = array( 0, 0, 0 );
 
 
-               $max_progress = array_fill(0, ceil(max($forward_end_diag - $forward_start_diag,
-                               $backward_end_diag - $backward_start_diag) / 2), $temp);
+               $max_progress = array_fill( 0, ceil( max( $forward_end_diag - $forward_start_diag,
+                               $backward_end_diag - $backward_start_diag ) / 2 ), $temp );
                $num_progress = 0; // the 1st entry is current, it is initialized
                // with 0s
 
                // first search the forward diagonals
-               for ($k = $forward_start_diag; $k <= $forward_end_diag; $k += 2) {
+               for ( $k = $forward_start_diag; $k <= $forward_end_diag; $k += 2 ) {
                        $x = $V[0][$limit + $k];
                        $y = $x - $k;
-                       if ($x > $N || $y > $M) {
+                       if ( $x > $N || $y > $M ) {
                                continue;
                        }
 
                        $progress = $x + $y;
-                       if ($progress > $max_progress[0][2]) {
+                       if ( $progress > $max_progress[0][2] ) {
                                $num_progress = 0;
                                $max_progress[0][0] = $x;
                                $max_progress[0][1] = $y;
                                $max_progress[0][2] = $progress;
-                       } else if ($progress == $max_progress[0][2]) {
+                       } else if ( $progress == $max_progress[0][2] ) {
                                ++$num_progress;
                                $max_progress[$num_progress][0] = $x;
                                $max_progress[$num_progress][1] = $y;
@@ -523,21 +523,21 @@ class WikiDiff3 {
                // direction
 
                // now search the backward diagonals
-               for ($k = $backward_start_diag; $k <= $backward_end_diag; $k += 2) {
+               for ( $k = $backward_start_diag; $k <= $backward_end_diag; $k += 2 ) {
                        $x = $V[1][$limit + $k];
                        $y = $x - $k - $delta;
-                       if ($x < 0 || $y < 0) {
+                       if ( $x < 0 || $y < 0 ) {
                                continue;
                        }
 
                        $progress = $N - $x + $M - $y;
-                       if ($progress > $max_progress[0][2]) {
+                       if ( $progress > $max_progress[0][2] ) {
                                $num_progress = 0;
                                $max_progress_forward = false;
                                $max_progress[0][0] = $x;
                                $max_progress[0][1] = $y;
                                $max_progress[0][2] = $progress;
-                       } else if ($progress == $max_progress[0][2] && !$max_progress_forward) {
+                       } else if ( $progress == $max_progress[0][2] && !$max_progress_forward ) {
                                ++$num_progress;
                                $max_progress[$num_progress][0] = $x;
                                $max_progress[$num_progress][1] = $y;
@@ -546,13 +546,13 @@ class WikiDiff3 {
                }
 
                // return the middle diagonal with maximal progress.
-               return $max_progress[floor($num_progress / 2)];
+               return $max_progress[floor( $num_progress / 2 )];
        }
 
-       public function getLcsLength(){
-               if($this->heuristicUsed && !$this->lcsLengthCorrectedForHeuristic){
+       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;
        }
@@ -562,7 +562,7 @@ class WikiDiff3 {
 /**
  * Alternative representation of a set of changes, by the index
  * ranges that are changed.
- * 
+ *
  * @ingroup DifferenceEngine
  */
 class RangeDifference {
@@ -575,7 +575,7 @@ class RangeDifference {
        public $rightend;
        public $rightlength;
 
-       function __construct($leftstart, $leftend, $rightstart, $rightend){
+       function __construct( $leftstart, $leftend, $rightstart, $rightend ) {
                $this->leftstart = $leftstart;
                $this->leftend = $leftend;
                $this->leftlength = $leftend - $leftstart;