From f7b1b48c4e2c92baad49951b73bc08e67ca32b85 Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Tue, 7 Nov 2017 12:44:53 +0100 Subject: [PATCH] Add localised tooltips for moved paragraph indicators Bug: T166882 Change-Id: I71600acc19319f7b5781b42dc88cd5e8c65c29a0 --- includes/diff/DifferenceEngine.php | 47 ++++++++++++++++++++++++++++-- languages/i18n/en.json | 2 ++ languages/i18n/qqq.json | 2 ++ 3 files changed, 48 insertions(+), 3 deletions(-) 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. * diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 021a115f39..52ac44703c 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -943,6 +943,8 @@ "diff-multi-sameuser": "({{PLURAL:$1|One intermediate revision|$1 intermediate revisions}} by the same user not shown)", "diff-multi-otherusers": "({{PLURAL:$1|One intermediate revision|$1 intermediate revisions}} by {{PLURAL:$2|one other user|$2 users}} not shown)", "diff-multi-manyusers": "({{PLURAL:$1|One intermediate revision|$1 intermediate revisions}} by more than $2 {{PLURAL:$2|user|users}} not shown)", + "diff-paragraph-moved-tonew": "Paragraph was moved. Click to jump to new location.", + "diff-paragraph-moved-toold": "Paragraph was moved. Click to jump to old location.", "difference-missing-revision": "{{PLURAL:$2|One revision|$2 revisions}} of this difference ($1) {{PLURAL:$2|was|were}} not found.\n\nThis is usually caused by following an outdated diff link to a page that has been deleted.\nDetails can be found in the [{{fullurl:{{#Special:Log}}/delete|page={{FULLPAGENAMEE}}}} deletion log].", "search-summary": "", "searchresults": "Search results", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index a1e65c011a..e5d4984441 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1137,6 +1137,8 @@ "diff-multi-sameuser": "This message appears in the revision history of a page when comparing two versions which aren't consecutive, and the intermediate revisions were all created by the same user as the new revision.\n\nParameters:\n* $1 - the number of revisions\n{{Related|Diff-multi}}", "diff-multi-otherusers": "This message appears in the revision history of a page when comparing two versions which aren't consecutive, and at least one of the intermediate revisions was created by a user other than the user who created the new revision.\n\nParameters:\n* $1 - the number of revisions\n* $2 - the number of distinct other users who made those revisions\n{{Related|Diff-multi}}", "diff-multi-manyusers": "This message appears in the revision history of a page when comparing two versions which aren't consecutive, and the intermediate revisions have been edited by more than 100 users.\n\nParameters:\n* $1 - the number of revisions, will always be 101 or more\n* $2 - the number of users that were found, which was limited at 100\n{{Related|Diff-multi}}", + "diff-paragraph-moved-tonew": "Explaining title tag for the indicating symbols when a paragraph was moved hinting to the new location in the Diff view.", + "diff-paragraph-moved-toold": "Explaining title tag for the indicating symbols when a paragraph was moved hinting to the old location in the Diff view.", "difference-missing-revision": "Text displayed when the requested revision does not exist using a diff link.\n\nExample: [{{canonicalurl:Project:News|diff=426850&oldid=99999999}} Diff with invalid revision#]\n\nParameters:\n* $1 - the list of missing revisions IDs\n* $2 - the number of items in $1 (one or two)", "search-summary": "{{doc-specialpagesummary|search}}", "searchresults": "This is the title of the page that contains the results of a search.\n\n{{Identical|Search results}}", -- 2.20.1