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
This commit is contained in:
parent
b87a4fba8a
commit
76e64c3afe
3 changed files with 44 additions and 4 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 ) {
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue