Added support for wikidiff2 and similar external diff engines.
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 9 Feb 2006 13:04:20 +0000 (13:04 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 9 Feb 2006 13:04:20 +0000 (13:04 +0000)
RELEASE-NOTES
includes/DefaultSettings.php
includes/DifferenceEngine.php

index a24f097..ff95420 100644 (file)
@@ -232,6 +232,7 @@ i18n / Languages:
 * (bug 4267) Switch dv sd ug ks arc languages to RTL
 * Default main page content improved per bug 4690
 * (bug 4615) Update for Portuguese language (pt)
+* Separated MessagesSl.php as the other languages.
 
 Parser:
 * (bug 2522) {{CURRENTDAY2}} now shows the current day number with two digits
@@ -606,7 +607,7 @@ fully support the editing toolbar, but was found to be too confusing.
 * (bug 4147) Added cleanupWatchlist.php to clear out bogus watchlist entries
 * (partial bug 3456) Disable auto redirect to Main Page after account creation
 * (bug 4824) Separate out IE7 CSS compat hacks, fix for RTL pages
-* Separated MessagesSl.php as the other languages.
+* Added support for wikidiff2 and similar external diff engines.
 
 
 === Caveats ===
index 3607018..1841eba 100644 (file)
@@ -1474,8 +1474,8 @@ $wgAllowPageInfo = false;
 /** Maximum indent level of toc. */
 $wgMaxTocLevel = 999;
 
-/** Use external C++ diff engine (module wikidiff from the extensions package) */
-$wgUseExternalDiffEngine = false;
+/** Name of the external diff engine to use */
+$wgExternalDiffEngine = false;
 
 /** Use RC Patrolling to check for vandalism */
 $wgUseRCPatrol = true;
index 5a4954a..392ce59 100644 (file)
@@ -44,7 +44,7 @@ class DifferenceEngine {
                $this->mTitle = $titleObj;
                wfDebug("DifferenceEngine old '$old' new '$new' rcid '$rcid'\n");
 
-               if ( 'prev' == $new ) {
+               if ( 'prev' === $new ) {
                        # Show diff between revision $old and the previous one.
                        # Get previous one from DB.
                        #
@@ -52,7 +52,7 @@ class DifferenceEngine {
 
                        $this->mOldid = $this->mTitle->getPreviousRevisionID( $this->mNewid );
 
-               } elseif ( 'next' == $new ) {
+               } elseif ( 'next' === $new ) {
                        # Show diff between revision $old and the previous one.
                        # Get previous one from DB.
                        #
@@ -316,8 +316,10 @@ CONTROL;
         * Returns false on error
         */
        function getDiffBody() {
-               global $wgUseExternalDiffEngine, $wgContLang, $wgMemc, $wgDBname;
-
+               global $wgExternalDiffEngine, $wgContLang, $wgMemc, $wgDBname;
+               $fname = 'DifferenceEngine::getDiffBody';
+               wfProfileIn( $fname );
+               
                // Cacheable?
                $key = false;
                if ( $this->mOldid && $this->mNewid ) {
@@ -328,17 +330,19 @@ CONTROL;
                                wfIncrStats( 'diff_cache_hit' );
                                $difftext = $this->localiseLineNumbers( $difftext );
                                $difftext .= "\n<!-- diff cache key $key -->\n"; 
+                               wfProfileOut( $fname );
                                return $difftext;
                        }
                }
 
                if ( !$this->loadText() ) {
+                       wfProfileOut( $fname );
                        return false;
                }
 
                $otext = $wgContLang->segmentForDiff($this->mOldtext);
                $ntext = $wgContLang->segmentForDiff($this->mNewtext);
-               if ( $wgUseExternalDiffEngine ) {
+               if ( $wgExternalDiffEngine == 'wikidiff' ) {
                        # For historical reasons, external diff engine expects
                        # input text to be HTML-escaped already
                        $otext = str_replace( "\r\n", "\n", htmlspecialchars ( $otext ) );
@@ -347,6 +351,43 @@ CONTROL;
                                dl('php_wikidiff.so');
                        }
                        $difftext = wikidiff_do_diff( $otext, $ntext, 2 );
+               } elseif ( $wgExternalDiffEngine == 'wikidiff2' ) {
+                       # Better external diff engine, the 2 may some day be dropped
+                       # This one does the escaping itself
+                       $otext = str_replace( "\r\n", "\n", $otext );
+                       $ntext = str_replace( "\r\n", "\n", $ntext );                   
+                       if ( !function_exists( 'wikidiff2_do_diff' ) ) {
+                               dl('php_wikidiff2.so');
+                       }
+                       $difftext = wikidiff2_do_diff( $otext, $ntext, 2 );
+               } elseif ( $wgExternalDiffEngine !== false ) {
+                       # Diff via the shell
+                       global $wgTmpDirectory;
+                       $otext = str_replace( "\r\n", "\n", $otext );
+                       $ntext = str_replace( "\r\n", "\n", $ntext );
+                       $tempName1 = tempnam( $wgTmpDirectory, 'diff_' );
+                       $tempName2 = tempnam( $wgTmpDirectory, 'diff_' );
+
+                       $tempFile1 = fopen( $tempName1, "w" );
+                       if ( !$tempFile1 ) {
+                               wfProfileOut( $fname );
+                               return false;
+                       }
+                       $tempFile2 = fopen( $tempName2, "w" );
+                       if ( !$tempFile2 ) {
+                               wfProfileOut( $fname );
+                               return false;
+                       }
+                       fwrite( $tempFile1, $otext );
+                       fwrite( $tempFile2, $ntext );
+                       fclose( $tempFile1 );
+                       fclose( $tempFile2 );
+                       $cmd = wfEscapeShellArg( $wgExternalDiffEngine, $tempName1, $tempName2 );
+                       wfProfileIn( "$fname-shellexec" );
+                       $difftext = wfShellExec( $cmd );
+                       wfProfileOut( "$fname-shellexec" );
+                       unlink( $tempName1 );
+                       unlink( $tempName2 );
                } else {
                        $ota = explode( "\n", str_replace( "\r\n", "\n", $otext ) );
                        $nta = explode( "\n", str_replace( "\r\n", "\n", $ntext ) );
@@ -365,6 +406,7 @@ CONTROL;
                }
                // Replace line numbers with the text in the user's language
                $difftext = $this->localiseLineNumbers( $difftext );
+               wfProfileOut( $fname );
                return $difftext;
        }