From 389f46dfbeb3336d671d0abdbc93d5dd09a6f09a Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 7 May 2009 16:00:29 +0000 Subject: [PATCH] (bug 16925) Diffs no longer silently fail when $wgExternalDiffEngine is set to 'wikidiff' or 'wikidiff2' but extension is not installed. Should now gracefully fall back to the PHP diff. --- RELEASE-NOTES | 2 ++ includes/diff/DifferenceEngine.php | 44 ++++++++++++++++++------------ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e1494d33c0..6c989416f4 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -111,6 +111,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 18677) Give proper error message when viewing &action=protect without sufficient rights * (bug 6802) profileinfo.php now also work on other database servers than MySQL +* (bug 16925) Diffs no longer fail when $wgExternalDiffEngine is set to 'wikidiff' + or 'wikidiff2' but extension is not installed == API changes in 1.16 == diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index d3f59acc34..a9a88a912d 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -617,6 +617,24 @@ CONTROL; return $difftext; } + /** + * Make sure the proper modules are loaded before we try to + * make the diff + */ + private function initDiffEngines() { + global $wgExternalDiffEngine; + if ( $wgExternalDiffEngine == 'wikidiff' && !function_exists( 'wikidiff_do_diff' ) { + wfProfileIn( __METHOD__ . '-php_wikidiff.so' ); + @dl( 'php_wikidiff.so' ); + wfProfileOut( __METHOD__ . '-php_wikidiff.so' ); + } + else if ( $wgExternalDiffEngine == 'wikidiff2' && !function_exists( 'wikidiff2_do_diff' ) ) { + wfProfileIn( __METHOD__ . '-php_wikidiff2.so' ); + @dl( 'php_wikidiff2.so' ); + wfProfileOut( __METHOD__ . '-php_wikidiff2.so' ); + } + } + /** * Generate a diff, no caching * $otext and $ntext must be already segmented @@ -627,33 +645,25 @@ CONTROL; $otext = str_replace( "\r\n", "\n", $otext ); $ntext = str_replace( "\r\n", "\n", $ntext ); - if ( $wgExternalDiffEngine == 'wikidiff' ) { + $this->initDiffEngines(); + + if ( $wgExternalDiffEngine == 'wikidiff' && function_exists( 'wikidiff_do_diff' ) ) { # For historical reasons, external diff engine expects # input text to be HTML-escaped already $otext = htmlspecialchars ( $wgContLang->segmentForDiff( $otext ) ); $ntext = htmlspecialchars ( $wgContLang->segmentForDiff( $ntext ) ); - if( !function_exists( 'wikidiff_do_diff' ) ) { - dl('php_wikidiff.so'); - } return $wgContLang->unsegementForDiff( wikidiff_do_diff( $otext, $ntext, 2 ) ) . $this->debug( 'wikidiff1' ); } - if ( $wgExternalDiffEngine == 'wikidiff2' ) { + if ( $wgExternalDiffEngine == 'wikidiff2' && function_exists( 'wikidiff2_do_diff' ) ) { # Better external diff engine, the 2 may some day be dropped # This one does the escaping and segmenting itself - if ( !function_exists( 'wikidiff2_do_diff' ) ) { - wfProfileIn( __METHOD__ . "-dl" ); - @dl('php_wikidiff2.so'); - wfProfileOut( __METHOD__ . "-dl" ); - } - if ( function_exists( 'wikidiff2_do_diff' ) ) { - wfProfileIn( 'wikidiff2_do_diff' ); - $text = wikidiff2_do_diff( $otext, $ntext, 2 ); - $text .= $this->debug( 'wikidiff2' ); - wfProfileOut( 'wikidiff2_do_diff' ); - return $text; - } + wfProfileIn( 'wikidiff2_do_diff' ); + $text = wikidiff2_do_diff( $otext, $ntext, 2 ); + $text .= $this->debug( 'wikidiff2' ); + wfProfileOut( 'wikidiff2_do_diff' ); + return $text; } if ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) { # Diff via the shell -- 2.20.1