Merge "Remove excess getExternalLB() argument"
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index 148e50c..95420d9 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup DifferenceEngine
  */
+use MediaWiki\MediaWikiServices;
 
 /** @deprecated use class constant instead */
 define( 'MW_DIFF_VERSION', '1.11a' );
@@ -376,6 +377,11 @@ class DifferenceEngine extends ContextSource {
                        }
                }
 
+               $out->addJsConfigVars( [
+                       'wgDiffOldId' => $this->mOldid,
+                       'wgDiffNewId' => $this->mNewid,
+               ] );
+
                # Make "next revision link"
                # Skip next link on the top revision
                if ( $samePage && !$this->mNewRev->isCurrent() ) {
@@ -846,13 +852,13 @@ class DifferenceEngine extends ContextSource {
         * @return bool|string
         */
        public function generateTextDiffBody( $otext, $ntext ) {
-               $diff = function() use ( $otext, $ntext ) {
+               $diff = function () use ( $otext, $ntext ) {
                        $time = microtime( true );
 
                        $result = $this->textDiff( $otext, $ntext );
 
                        $time = intval( ( microtime( true ) - $time ) * 1000 );
-                       $this->getStats()->timing( 'diff_time', $time );
+                       MediaWikiServices::getInstance()->getStatsdDataFactory()->timing( 'diff_time', $time );
                        // Log requests slower than 99th percentile
                        if ( $time > 100 && $this->mOldPage && $this->mNewPage ) {
                                wfDebugLog( 'diff',
@@ -866,7 +872,7 @@ class DifferenceEngine extends ContextSource {
                 * @param Status $status
                 * @throws FatalError
                 */
-               $error = function( $status ) {
+               $error = function ( $status ) {
                        throw new FatalError( $status->getWikiText() );
                };
 
@@ -907,10 +913,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;