From 2658e07fb913070c3fecc98b3d1a07fea4b74401 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Wed, 13 Aug 2008 14:52:40 +0000 Subject: [PATCH] Cleanup some of my old code a bit. These should still be replaced with nicer functions altogether, though, as Brion would have it. --- includes/Linker.php | 45 +++++++++++++++++++++++++-------------------- includes/Xml.php | 2 +- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 023b64142c..cafd4bc2b0 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1647,25 +1647,28 @@ class Linker { * @return string title and accesskey attributes, ready to drop in an * element (e.g., ' title="This does something [x]" accesskey="x"'). */ - public function tooltipAndAccesskey($name) { - $fname="Linker::tooltipAndAccesskey"; - wfProfileIn($fname); - $out = ''; + public function tooltipAndAccesskey( $name ) { + wfProfileIn( __METHOD__ ); + $attribs = array(); - $tooltip = wfMsg('tooltip-'.$name); - if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') { + $tooltip = wfMsg( "tooltip-$name" ); + if( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) { // Compatibility: formerly some tooltips had [alt-.] hardcoded $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip ); - $out .= ' title="'.htmlspecialchars($tooltip); + $attribs['title'] = $tooltip; } - $accesskey = wfMsg('accesskey-'.$name); - if ($accesskey && $accesskey != '-' && !wfEmptyMsg('accesskey-'.$name, $accesskey)) { - if ($out) $out .= " [$accesskey]\" accesskey=\"$accesskey\""; - else $out .= " title=\"[$accesskey]\" accesskey=\"$accesskey\""; - } elseif ($out) { - $out .= '"'; + + $accesskey = wfMsg( "accesskey-$name" ); + if( $accesskey && $accesskey != '-' && + !wfEmptyMsg( "accesskey-$name", $accesskey ) ) { + if( isset( $attribs['title'] ) ) { + $attribs['title'] .= " [$accesskey]"; + } + $attribs['accesskey'] = $accesskey; } - wfProfileOut($fname); + + $out = Xml::expandAttributes( $attribs ); + wfProfileOut( __METHOD__ ); return $out; } @@ -1679,14 +1682,16 @@ class Linker { * @return string title attribute, ready to drop in an element * (e.g., ' title="This does something"'). */ - public function tooltip($name) { - $out = ''; + public function tooltip( $name ) { + wfProfileIn( __METHOD__ ); - $tooltip = wfMsg('tooltip-'.$name); - if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') { - $out = ' title="'.htmlspecialchars($tooltip).'"'; + $tooltip = wfMsg( "tooltip-$name" ); + if ( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) { + wfProfileOut( __METHOD__ ); + return ' title="'.htmlspecialchars( $tooltip ).'"'; } - return $out; + wfProfileOut( __METHOD__ ); + return ''; } } diff --git a/includes/Xml.php b/includes/Xml.php index a36e2819ec..1551878518 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -41,7 +41,7 @@ class Xml { * Return null if no attributes given. * @param $attribs Array of attributes for an XML element */ - private static function expandAttributes( $attribs ) { + public static function expandAttributes( $attribs ) { $out = ''; if( is_null( $attribs ) ) { return null; -- 2.20.1