From 7f4e1895931f02023be07e2967ab1c48a16a667e Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 9 Feb 2006 13:04:20 +0000 Subject: [PATCH] Added support for wikidiff2 and similar external diff engines. --- RELEASE-NOTES | 3 +- includes/DefaultSettings.php | 4 +-- includes/DifferenceEngine.php | 52 +++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a24f097f94..ff954204f4 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 36070185e0..1841eba487 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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; diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 5a4954a696..392ce597e6 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -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\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; } -- 2.20.1