X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fdiff%2FDifferenceEngine.php;h=03f72122d04cfef7f7c01f60b687bb2667f9abd4;hp=fb12c1ea64ac907d81707ca9ae9201ccc2d9c5c3;hb=f7b1b48c4e2c92baad49951b73bc08e67ca32b85;hpb=23ebfcddc47ffb648154398147ad1b7bc7c20761 diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index fb12c1ea64..03f72122d0 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -765,7 +765,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\n"; return $difftext; @@ -793,9 +793,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 +1080,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 +1119,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|old)"/', + [ $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. *