Allow parameters to be passed into skin tooltip messages

You can now pass parameters to toolbox links' tooltips,
by setting 'tooltip-params' key in a $nav_urls item of
SkinTemplate::buildNavUrls.

This functionality is used to add GENDER support to two
tooltip messages.

Bug: T123365
Change-Id: I45577d54bd78ba1e2ba10fb8f04367244495bfea
This commit is contained in:
victorbarbu 2016-01-12 15:45:30 +02:00 committed by TTO
parent 5a93e6b00b
commit 6ea30d631d
5 changed files with 31 additions and 19 deletions

View file

@ -2150,13 +2150,13 @@ class Linker {
* @param string $name Id of the element, minus prefixes.
* @param string|null $options Null or the string 'withaccess' to add an access-
* key hint
* @param array $msgParams Parameters to pass to the message
*
* @return string Contents of the title attribute (which you must HTML-
* escape), or false for no title attribute
*/
public static function titleAttrib( $name, $options = null ) {
$message = wfMessage( "tooltip-$name" );
public static function titleAttrib( $name, $options = null, array $msgParams = array() ) {
$message = wfMessage( "tooltip-$name", $msgParams );
if ( !$message->exists() ) {
$tooltip = false;
} else {
@ -2306,15 +2306,18 @@ class Linker {
/**
* Returns the attributes for the tooltip and access key.
*
* @param string $name
* @param array $msgParams Params for constructing the message
*
* @return array
*/
public static function tooltipAndAccesskeyAttribs( $name ) {
public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = array() ) {
# @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
# no attribute" instead of "output '' as value for attribute", this
# would be three lines.
$attribs = array(
'title' => self::titleAttrib( $name, 'withaccess' ),
'title' => self::titleAttrib( $name, 'withaccess', $msgParams ),
'accesskey' => self::accesskey( $name )
);
if ( $attribs['title'] === false ) {

View file

@ -358,21 +358,28 @@ abstract class BaseTemplate extends QuickTemplate {
if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
$attrs = $item;
foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary',
'tooltip-params' ) as $k ) {
unset( $attrs[$k] );
}
if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
$item['single-id'] = $item['id'];
}
$tooltipParams = array();
if ( isset( $item['tooltip-params'] ) ) {
$tooltipParams = $item['tooltip-params'];
}
if ( isset( $item['single-id'] ) ) {
if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
$title = Linker::titleAttrib( $item['single-id'] );
$title = Linker::titleAttrib( $item['single-id'], null, $tooltipParams );
if ( $title !== false ) {
$attrs['title'] = $title;
}
} else {
$tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'] );
$tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'], $tooltipParams );
if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
$attrs['title'] = $tip['title'];
}

View file

@ -1246,7 +1246,8 @@ class SkinTemplate extends Skin {
$nav_urls['contributions'] = array(
'text' => $this->msg( 'contributions', $rootUser )->text(),
'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser ),
'tooltip-params' => array( $rootUser ),
);
$nav_urls['log'] = array(
@ -1262,7 +1263,8 @@ class SkinTemplate extends Skin {
if ( $this->showEmailUser( $user ) ) {
$nav_urls['emailuser'] = array(
'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser ),
'tooltip-params' => array( $rootUser ),
);
}

View file

@ -2558,13 +2558,13 @@
"accesskey-import": "s",
"accesskey-watchlistedit-normal-submit": "s",
"accesskey-watchlistedit-raw-submit": "s",
"tooltip-pt-userpage": "Your user page",
"tooltip-pt-userpage": "{{GENDER:|Your user}} page",
"tooltip-pt-anonuserpage": "The user page for the IP address you are editing as",
"tooltip-pt-mytalk": "Your talk page",
"tooltip-pt-mytalk": "{{GENDER:|Your}} talk page",
"tooltip-pt-anontalk": "Discussion about edits from this IP address",
"tooltip-pt-preferences": "Your preferences",
"tooltip-pt-preferences": "{{GENDER:|Your}} preferences",
"tooltip-pt-watchlist": "A list of pages you are monitoring for changes",
"tooltip-pt-mycontris": "A list of your contributions",
"tooltip-pt-mycontris": "A list of {{GENDER:|your}} contributions",
"tooltip-pt-anoncontribs": "A list of edits made from this IP address",
"tooltip-pt-login": "You are encouraged to log in; however, it is not mandatory",
"tooltip-pt-logout": "Log out",
@ -2596,8 +2596,8 @@
"tooltip-t-recentchangeslinked": "Recent changes in pages linked from this page",
"tooltip-feed-rss": "RSS feed for this page",
"tooltip-feed-atom": "Atom feed for this page",
"tooltip-t-contributions": "A list of contributions by this user",
"tooltip-t-emailuser": "Send an email to this user",
"tooltip-t-contributions": "A list of contributions by {{GENDER:$1|this user}}",
"tooltip-t-emailuser": "Send an email to {{GENDER:$1|this user}}",
"tooltip-t-info": "More information about this page",
"tooltip-t-upload": "Upload files",
"tooltip-t-specialpages": "A list of all special pages",

View file

@ -2771,8 +2771,8 @@
"tooltip-t-recentchangeslinked": "Used as tooltip for the link {{msg-mw|Recentchangeslinked}}.\n\nSee also:\n* {{msg-mw|Recentchangeslinked}}\n* {{msg-mw|Accesskey-t-recentchangeslinked}}\n* {{msg-mw|Tooltip-t-recentchangeslinked}}",
"tooltip-feed-rss": "Used as tooltip for RSS feed link.\n\nSee also:\n* {{msg-mw|Feed-rss}}\n* {{msg-mw|Accesskey-feed-rss}}\n* {{msg-mw|Tooltip-feed-rss}}",
"tooltip-feed-atom": "Used as tooltip for Atom feed link.\n\nSee also:\n* {{msg-mw|Feed-atom}}\n* {{msg-mw|Accesskey-feed-atom}}\n* {{msg-mw|Tooltip-feed-atom}}",
"tooltip-t-contributions": "Tooltip shown when hovering over {{msg-mw|Contributions}} in the toolbox.\n\nSee also:\n* {{msg-mw|Contributions}}\n* {{msg-mw|Accesskey-t-contributions}}\n* {{msg-mw|Tooltip-t-contributions}}",
"tooltip-t-emailuser": "Tooltip shown when hovering over the {{msg-mw|Emailuser}} link in the toolbox (sidebar, below).\n\nSee also:\n* {{msg-mw|Emailuser}}\n* {{msg-mw|Accesskey-t-emailuser}}\n* {{msg-mw|Tooltip-t-emailuser}}",
"tooltip-t-contributions": "Tooltip shown when hovering over {{msg-mw|Contributions}} in the toolbox.\n\nParameters:\n* $1 - Name of the user\n\nSee also:\n* {{msg-mw|Contributions}}\n* {{msg-mw|Accesskey-t-contributions}}\n* {{msg-mw|Tooltip-t-contributions}}",
"tooltip-t-emailuser": "Tooltip shown when hovering over the {{msg-mw|Emailuser}} link in the toolbox (sidebar, below).\n\nParameters:\n* $1 - Name of the user\n\nSee also:\n* {{msg-mw|Emailuser}}\n* {{msg-mw|Accesskey-t-emailuser}}\n* {{msg-mw|Tooltip-t-emailuser}}",
"tooltip-t-info": "Tooltip shown when hovering over the {{msg-mw|pageinfo-toolboxlink}} link in the toolbox (sidebar, below).",
"tooltip-t-upload": "Tooltip shown when hovering over the link to upload files shown in the side bar menu on all pages.\n\nSee also:\n* {{msg-mw|Upload}}\n* {{msg-mw|Accesskey-t-upload}}\n* {{msg-mw|Tooltip-t-upload}}\n{{Identical|Upload file}}",
"tooltip-t-specialpages": "The tooltip when hovering over the link {{msg-mw|Specialpages}} going to a list of all special pages available in the wiki.\n\nSee also:\n* {{msg-mw|Specialpages}}\n* {{msg-mw|Accesskey-t-specialpages}}\n* {{msg-mw|Tooltip-t-specialpages}}",