Cleanup some of my old code a bit. These should still be replaced with nicer functio...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 13 Aug 2008 14:52:40 +0000 (14:52 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 13 Aug 2008 14:52:40 +0000 (14:52 +0000)
includes/Linker.php
includes/Xml.php

index 023b641..cafd4bc 100644 (file)
@@ -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 '';
        }
 }
index a36e281..1551878 100644 (file)
@@ -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;