Merge "Add id field to watchlist db table"
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index 99eefc0..44e6a24 100644 (file)
@@ -573,7 +573,7 @@ class DifferenceEngine extends ContextSource {
                <h2 class='diff-currentversion-title'>{$revHeader}</h2>\n" );
                # Page content may be handled by a hooked call instead...
                # @codingStandardsIgnoreStart Ignoring long lines.
-               if ( Hooks::run( 'ArticleContentOnDiff', array( $this, $out ) ) ) {
+               if ( Hooks::run( 'ArticleContentOnDiff', [ $this, $out ] ) ) {
                        $this->loadNewText();
                        $out->setRevisionId( $this->mNewid );
                        $out->setRevisionTimestamp( $this->mNewRev->getTimestamp() );
@@ -584,7 +584,7 @@ class DifferenceEngine extends ContextSource {
                                // This needs to be synchronised with Article::showCssOrJsPage(), which sucks
                                // Give hooks a chance to customise the output
                                // @todo standardize this crap into one function
-                               if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+                               if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
                                        // NOTE: deprecated hook, B/C only
                                        // use the content object's own rendering
                                        $cnt = $this->mNewRev->getContent();
@@ -593,9 +593,9 @@ class DifferenceEngine extends ContextSource {
                                                $out->addParserOutputContent( $po );
                                        }
                                }
-                       } elseif ( !Hooks::run( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+                       } elseif ( !Hooks::run( 'ArticleContentViewCustom', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
                                // Handled by extension
-                       } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+                       } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', [ $this->mNewContent, $this->mNewPage, $out ] ) ) {
                                // NOTE: deprecated hook, B/C only
                                // Handled by extension
                        } else {
@@ -842,30 +842,44 @@ class DifferenceEngine extends ContextSource {
         * @return bool|string
         */
        public function generateTextDiffBody( $otext, $ntext ) {
+               $time = microtime( true );
+
+               $result = $this->textDiff( $otext, $ntext );
+
+               $time = microtime( true ) - $time;
+               $this->getStats()->timing( 'diff_time', $time * 1000 );
+
+               return $result;
+       }
+
+       /**
+        * Generates diff, to be wrapped internally in a logging/instrumentation
+        *
+        * @param string $otext Old text, must be already segmented
+        * @param string $ntext New text, must be already segmented
+        * @return bool|string
+        */
+       protected function textDiff( $otext, $ntext ) {
                global $wgExternalDiffEngine, $wgContLang;
 
                $otext = str_replace( "\r\n", "\n", $otext );
                $ntext = str_replace( "\r\n", "\n", $ntext );
 
-               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 ) );
-
-                       return $wgContLang->unsegmentForDiff( wikidiff_do_diff( $otext, $ntext, 2 ) ) .
-                       $this->debug( 'wikidiff1' );
+               if ( $wgExternalDiffEngine == 'wikidiff' ) {
+                       wfDeprecated( 'wikidiff support', '1.27' );
+                       $wgExternalDiffEngine = false;
                }
 
-               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
-                       $text = wikidiff2_do_diff( $otext, $ntext, 2 );
-                       $text .= $this->debug( 'wikidiff2' );
+               if ( $wgExternalDiffEngine == 'wikidiff2' ) {
+                       if ( function_exists( 'wikidiff2_do_diff' ) ) {
+                               # 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 );
+                               $text .= $this->debug( 'wikidiff2' );
 
-                       return $text;
-               }
-               if ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
+                               return $text;
+                       }
+               } elseif ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
                        # Diff via the shell
                        $tmpDir = wfTempDir();
                        $tempName1 = tempnam( $tmpDir, 'diff_' );