From f2a1ec41d38eab44617fe9eec9eaef8dd929f849 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Wed, 13 Aug 2008 15:11:36 +0000 Subject: [PATCH] Fix regression from r37834: accesskey tooltip hint should be given for the minor edit and watch labels on the edit page. This code could still use refactoring, but that's a separate issue. :) I relied on the fact that $n is usable to catch back-references in JavaScript replacement text -- this seems to work in latest-ish versions of Firefox, Konqueror, and Opera, so I'm assuming it works everywhere. ;) As usual, the Web gives tons of dodgy-looking cookbooks with no useful info whenever I try to search for anything JavaScript-related. Since I'm backporting this to 1.13 as a regression fix, this fix causes no change from 1.12 or 1.13 and so I'm not putting it in the release notes. --- includes/EditPage.php | 4 ++-- includes/Linker.php | 28 ++++++++++++++++++++-------- skins/common/wikibits.js | 7 +++---- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 3e67d06a79..41a2e6d7a0 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1994,7 +1994,7 @@ END ); $checkboxes['minor'] = Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) . - " "; + " "; } $watchLabel = wfMsgExt('watchthis', array('parseinline')); @@ -2007,7 +2007,7 @@ END ); $checkboxes['watch'] = Xml::check( 'wpWatchthis', $checked['watch'], $attribs ) . - " "; + " "; } return $checkboxes; } diff --git a/includes/Linker.php b/includes/Linker.php index cafd4bc2b0..6ddf33125a 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1667,9 +1667,9 @@ class Linker { $attribs['accesskey'] = $accesskey; } - $out = Xml::expandAttributes( $attribs ); + $ret = Xml::expandAttributes( $attribs ); wfProfileOut( __METHOD__ ); - return $out; + return $ret; } /** @@ -1678,20 +1678,32 @@ class Linker { * isn't always, because sometimes the accesskey needs to go on a different * element than the id, for reverse-compatibility, etc.) * - * @param string $name Id of the element, minus prefixes. + * @param string $name Id of the element, minus prefixes. + * @param mixed $options null or the string 'withaccess' to add an access- + * key hint * @return string title attribute, ready to drop in an element * (e.g., ' title="This does something"'). */ - public function tooltip( $name ) { + public function tooltip( $name, $options = null ) { wfProfileIn( __METHOD__ ); + $attribs = array(); + $tooltip = wfMsg( "tooltip-$name" ); - if ( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) { - wfProfileOut( __METHOD__ ); - return ' title="'.htmlspecialchars( $tooltip ).'"'; + if( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) { + $attribs['title'] = $tooltip; + } + + if( isset( $attribs['title'] ) && $options == 'withaccess' ) { + $accesskey = wfMsg( "accesskey-$name" ); + if( $accesskey && $accesskey != '-' && + !wfEmptyMsg( "accesskey-$name", $accesskey ) ) { + $attribs['title'] .= " [$accesskey]"; + } } + $ret = Xml::expandAttributes( $attribs ); wfProfileOut( __METHOD__ ); - return ''; + return $ret; } } diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index 678492b4a3..59f15cef64 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -215,7 +215,7 @@ if (is_opera) { } else if (is_ff2) { tooltipAccessKeyPrefix = 'alt-shift-'; } -var tooltipAccessKeyRegexp = /\[(ctrl-)?(alt-)?(shift-)?(esc-)?.\]$/; +var tooltipAccessKeyRegexp = /\[(ctrl-)?(alt-)?(shift-)?(esc-)?(.)\]$/; /** * Add the appropriate prefix to the accesskey shown in the tooltip. @@ -240,10 +240,9 @@ function updateTooltipAccessKeys( nodeList ) { for ( var i = 0; i < nodeList.length; i++ ) { var element = nodeList[i]; var tip = element.getAttribute("title"); - var key = element.getAttribute("accesskey"); - if ( key && tooltipAccessKeyRegexp.exec(tip) ) { + if ( tip && tooltipAccessKeyRegexp.exec(tip) ) { tip = tip.replace(tooltipAccessKeyRegexp, - "["+tooltipAccessKeyPrefix+key+"]"); + "["+tooltipAccessKeyPrefix+"$5]"); element.setAttribute("title", tip ); } } -- 2.20.1