Add missing PHPDoc block to DifferenceEngine::getParserOutput
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index fb12c1e..e76bffc 100644 (file)
@@ -634,7 +634,10 @@ class DifferenceEngine extends ContextSource {
                                        if ( Hooks::run( 'DifferenceEngineRenderRevisionAddParserOutput',
                                                [ $this, $out, $parserOutput, $wikiPage ] )
                                        ) {
-                                               $out->addParserOutput( $parserOutput );
+                                               $out->addParserOutput( $parserOutput, [
+                                                       'enableSectionEditLinks' => $this->mNewRev->isCurrent()
+                                                               && $this->mNewRev->getTitle()->quickUserCan( 'edit', $this->getUser() ),
+                                               ] );
                                        }
                                }
                        }
@@ -647,6 +650,12 @@ class DifferenceEngine extends ContextSource {
                }
        }
 
+       /**
+        * @param WikiPage $page
+        * @param Revision $rev
+        *
+        * @return ParserOutput|bool False if the revision was not found
+        */
        protected function getParserOutput( WikiPage $page, Revision $rev ) {
                $parserOptions = $page->makeParserOptions( $this->getContext() );
 
@@ -765,7 +774,7 @@ class DifferenceEngine extends ContextSource {
                                $difftext = $cache->get( $key );
                                if ( $difftext ) {
                                        wfIncrStats( 'diff_cache.hit' );
-                                       $difftext = $this->localiseLineNumbers( $difftext );
+                                       $difftext = $this->localiseDiff( $difftext );
                                        $difftext .= "\n<!-- diff cache key $key -->\n";
 
                                        return $difftext;
@@ -793,9 +802,9 @@ class DifferenceEngine extends ContextSource {
                } else {
                        wfIncrStats( 'diff_cache.uncacheable' );
                }
-               // Replace line numbers with the text in the user's language
+               // localise line numbers and title attribute text
                if ( $difftext !== false ) {
-                       $difftext = $this->localiseLineNumbers( $difftext );
+                       $difftext = $this->localiseDiff( $difftext );
                }
 
                return $difftext;
@@ -1080,6 +1089,22 @@ class DifferenceEngine extends ContextSource {
                        " -->\n";
        }
 
+       /**
+        * Localise diff output
+        *
+        * @param string $text
+        * @return string
+        */
+       private function localiseDiff( $text ) {
+               $text = $this->localiseLineNumbers( $text );
+               if ( $this->getEngine() === 'wikidiff2' &&
+                       version_compare( phpversion( 'wikidiff2' ), '1.5.1', '>=' )
+               ) {
+                       $text = $this->addLocalisedTitleTooltips( $text );
+               }
+               return $text;
+       }
+
        /**
         * Replace line numbers with the text in the user's language
         *
@@ -1103,6 +1128,31 @@ class DifferenceEngine extends ContextSource {
                return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped();
        }
 
+       /**
+        * Add title attributes for tooltips on moved paragraph indicators
+        *
+        * @param string $text
+        * @return string
+        */
+       private function addLocalisedTitleTooltips( $text ) {
+               return preg_replace_callback(
+                       '/class="mw-diff-movedpara-(left|right)"/',
+                       [ $this, 'addLocalisedTitleTooltipsCb' ],
+                       $text
+               );
+       }
+
+       /**
+        * @param array $matches
+        * @return string
+        */
+       private function addLocalisedTitleTooltipsCb( array $matches ) {
+               $key = $matches[1] === 'right' ?
+                       'diff-paragraph-moved-toold' :
+                       'diff-paragraph-moved-tonew';
+               return $matches[0] . ' title="' . $this->msg( $key )->escaped() . '"';
+       }
+
        /**
         * If there are revisions between the ones being compared, return a note saying so.
         *