From: Tobias Gritschacher Date: Thu, 8 Jun 2017 14:59:21 +0000 (+0200) Subject: Introduce config var for moved-paragraph-detection threshold X-Git-Tag: 1.31.0-rc.0~2688^2 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=76e64c3afe7cb24cf99ea489babc68813986882f;p=lhc%2Fweb%2Fwiklou.git Introduce config var for moved-paragraph-detection threshold This introduces a configuration variable for the bailout threshold for the moved-paragraph-detection in wikidiff2. This allows to rollout a new version of wikidiff2 that supports detecting changes in moved paragraphs without changing behaviour of all wikis in production as the default value of the setting (0) will leave the new feature disabled. Compatibility with older versions of wikidiff2 is retained by checking for the version number of wikidiff2 and calling the method without the 4th parameter if the version is < 0.3.0. Bug: T166571 Change-Id: Ic01054354a4fbba410e58c9873edcbde797f883d --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 5b7ca3ecc9..6a277090ca 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -8281,6 +8281,20 @@ $wgUpdateRowsPerQuery = 100; */ $wgExternalDiffEngine = false; +/** + * wikidiff2 supports detection of changes in moved paragraphs. + * This setting controls the maximum number of paragraphs to compare before it bails out. + * Supported values: + * * 0: detection of moved paragraphs is disabled + * * int > 0: maximum number of paragraphs to compare + * Note: number of paragraph comparisons is in O(n^2). + * This setting is only effective if the wikidiff2 PHP/HHVM module is used as diffengine. + * See $wgExternalDiffEngine. + * + * @since 1.30 + */ +$wgWikiDiff2MovedParagraphDetectionCutoff = 0; + /** * Disable redirects to special pages and interwiki redirects, which use a 302 * and have no "redirected from" link. diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index b0ab24488f..525ea2d1e1 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -908,10 +908,35 @@ class DifferenceEngine extends ContextSource { $wgExternalDiffEngine = false; } + // 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' ) && $wgExternalDiffEngine === false ) { - # Better external diff engine, the 2 may some day be dropped - # This one does the escaping and segmenting itself - $text = wikidiff2_do_diff( $otext, $ntext, 2 ); + $wikidiff2Version = phpversion( 'wikidiff2' ); + if ( + $wikidiff2Version !== false && + version_compare( $wikidiff2Version, '0.3.0', '>=' ) + ) { + $text = wikidiff2_do_diff( + $otext, + $ntext, + 2, + $this->getConfig()->get( 'WikiDiff2MovedParagraphDetectionCutoff' ) + ); + } else { + // Don't pass the 4th parameter for compatibility with older versions of wikidiff2 + $text = wikidiff2_do_diff( + $otext, + $ntext, + 2 + ); + + // Log a warning in case the configuration value is set to not silently ignore it + if ( $this->getConfig()->get( 'WikiDiff2MovedParagraphDetectionCutoff' ) > 0 ) { + wfLogWarning( '$wgWikiDiff2MovedParagraphDetectionCutoff is set but has no + effect since the used version of WikiDiff2 does not support it.' ); + } + } + $text .= $this->debug( 'wikidiff2' ); return $text; diff --git a/tests/phan/stubs/wikidiff.php b/tests/phan/stubs/wikidiff.php index 9bd5d8d26e..1015b0b9ba 100644 --- a/tests/phan/stubs/wikidiff.php +++ b/tests/phan/stubs/wikidiff.php @@ -22,7 +22,8 @@ * @param string $text1 * @param string $text2 * @param int $numContextLines + * @param int $movedParagraphDetectionCutoff * @return string */ -function wikidiff2_do_diff( $text1, $text2, $numContextLines ) { +function wikidiff2_do_diff( $text1, $text2, $numContextLines, $movedParagraphDetectionCutoff = 0 ) { }