Index: trunk/phase3/includes/Linker.php |
— | — | @@ -1698,38 +1698,37 @@ |
1699 | 1699 | } |
1700 | 1700 | |
1701 | 1701 | /** |
1702 | | - * Given the id of an interface element, constructs the appropriate title |
1703 | | - * and accesskey attributes from the system messages. (Note, this is usu- |
1704 | | - * ally the id but isn't always, because sometimes the accesskey needs to |
1705 | | - * go on a different element than the id, for reverse-compatibility, etc.) |
1706 | | - * |
1707 | | - * @param string $name Id of the element, minus prefixes. |
1708 | | - * @return string title and accesskey attributes, ready to drop in an |
1709 | | - * element (e.g., ' title="This does something [x]" accesskey="x"'). |
| 1702 | + * @deprecated Returns raw bits of HTML, use titleAttrib() and accesskey() |
1710 | 1703 | */ |
1711 | 1704 | public function tooltipAndAccesskey( $name ) { |
1712 | | - wfProfileIn( __METHOD__ ); |
1713 | | - $attribs = array(); |
1714 | | - |
1715 | | - $tooltip = wfMsg( "tooltip-$name" ); |
1716 | | - if( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) { |
1717 | | - // Compatibility: formerly some tooltips had [alt-.] hardcoded |
1718 | | - $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip ); |
1719 | | - $attribs['title'] = $tooltip; |
| 1705 | + # FIXME: If Sanitizer::expandAttributes() treated "false" as "output |
| 1706 | + # no attribute" instead of "output '' as value for attribute", this |
| 1707 | + # would be three lines. |
| 1708 | + $attribs = array( |
| 1709 | + 'title' => $this->titleAttrib( $name, 'withaccess' ), |
| 1710 | + 'accesskey' => $this->accesskey( $name ) |
| 1711 | + ); |
| 1712 | + if ( $attribs['title'] === false ) { |
| 1713 | + unset( $attribs['title'] ); |
1720 | 1714 | } |
| 1715 | + if ( $attribs['accesskey'] === false ) { |
| 1716 | + unset( $attribs['accesskey'] ); |
| 1717 | + } |
| 1718 | + return Xml::expandAttributes( $attribs ); |
| 1719 | + } |
1721 | 1720 | |
1722 | | - $accesskey = wfMsg( "accesskey-$name" ); |
1723 | | - if( $accesskey != '' && $accesskey != '-' && |
1724 | | - !wfEmptyMsg( "accesskey-$name", $accesskey ) ) { |
1725 | | - if( isset( $attribs['title'] ) ) { |
1726 | | - $attribs['title'] .= " [$accesskey]"; |
1727 | | - } |
1728 | | - $attribs['accesskey'] = $accesskey; |
| 1721 | + /** @deprecated Returns raw bits of HTML, use titleAttrib() */ |
| 1722 | + public function tooltip( $name, $options = null ) { |
| 1723 | + # FIXME: If Sanitizer::expandAttributes() treated "false" as "output |
| 1724 | + # no attribute" instead of "output '' as value for attribute", this |
| 1725 | + # would be two lines. |
| 1726 | + $tooltip = $this->titleAttrib( $name, $options ); |
| 1727 | + if ( $tooltip === false ) { |
| 1728 | + return ''; |
1729 | 1729 | } |
1730 | | - |
1731 | | - $ret = Xml::expandAttributes( $attribs ); |
1732 | | - wfProfileOut( __METHOD__ ); |
1733 | | - return $ret; |
| 1730 | + return Xml::expandAttributes( array( |
| 1731 | + 'title' => $this->titleAttrib( $name, $options ) |
| 1732 | + ) ); |
1734 | 1733 | } |
1735 | 1734 | |
1736 | 1735 | /** |
— | — | @@ -1741,29 +1740,57 @@ |
1742 | 1741 | * @param string $name Id of the element, minus prefixes. |
1743 | 1742 | * @param mixed $options null or the string 'withaccess' to add an access- |
1744 | 1743 | * key hint |
1745 | | - * @return string title attribute, ready to drop in an element |
1746 | | - * (e.g., ' title="This does something"'). |
| 1744 | + * @return string Contents of the title attribute (which you must HTML- |
| 1745 | + * escape), or false for no title attribute |
1747 | 1746 | */ |
1748 | | - public function tooltip( $name, $options = null ) { |
| 1747 | + public function titleAttrib( $name, $options = null ) { |
1749 | 1748 | wfProfileIn( __METHOD__ ); |
1750 | 1749 | |
1751 | | - $attribs = array(); |
| 1750 | + $tooltip = wfMsg( "tooltip-$name" ); |
| 1751 | + # Compatibility: formerly some tooltips had [alt-.] hardcoded |
| 1752 | + $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip ); |
1752 | 1753 | |
1753 | | - $tooltip = wfMsg( "tooltip-$name" ); |
1754 | | - if( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) { |
1755 | | - $attribs['title'] = $tooltip; |
| 1754 | + # Message equal to '-' means suppress it. |
| 1755 | + if ( wfEmptyMsg( "tooltip-$name", $tooltip ) || $tooltip == '-' ) { |
| 1756 | + $tooltip = false; |
1756 | 1757 | } |
1757 | 1758 | |
1758 | | - if( isset( $attribs['title'] ) && $options == 'withaccess' ) { |
1759 | | - $accesskey = wfMsg( "accesskey-$name" ); |
1760 | | - if( $accesskey != '' && $accesskey != '-' && |
1761 | | - !wfEmptyMsg( "accesskey-$name", $accesskey ) ) { |
1762 | | - $attribs['title'] .= " [$accesskey]"; |
| 1759 | + if ( $options == 'withaccess' ) { |
| 1760 | + $accesskey = $this->accesskey( $name ); |
| 1761 | + if( $accesskey !== false ) { |
| 1762 | + if ( $tooltip === false || $tooltip === '' ) { |
| 1763 | + $tooltip = "[$accesskey]"; |
| 1764 | + } else { |
| 1765 | + $tooltip .= " [$accesskey]"; |
| 1766 | + } |
1763 | 1767 | } |
1764 | 1768 | } |
1765 | 1769 | |
1766 | | - $ret = Xml::expandAttributes( $attribs ); |
1767 | 1770 | wfProfileOut( __METHOD__ ); |
1768 | | - return $ret; |
| 1771 | + return $tooltip; |
1769 | 1772 | } |
| 1773 | + |
| 1774 | + /** |
| 1775 | + * Given the id of an interface element, constructs the appropriate |
| 1776 | + * accesskey attribute from the system messages. (Note, this is usually |
| 1777 | + * the id but isn't always, because sometimes the accesskey needs to go on |
| 1778 | + * a different element than the id, for reverse-compatibility, etc.) |
| 1779 | + * |
| 1780 | + * @param string $name Id of the element, minus prefixes. |
| 1781 | + * @return string Contents of the accesskey attribute (which you must HTML- |
| 1782 | + * escape), or false for no accesskey attribute |
| 1783 | + */ |
| 1784 | + public function accesskey( $name ) { |
| 1785 | + $accesskey = wfMsg( "accesskey-$name" ); |
| 1786 | + |
| 1787 | + # FIXME: Per standard MW behavior, a value of '-' means to suppress the |
| 1788 | + # attribute, but this is broken for accesskey: that might be a useful |
| 1789 | + # value. |
| 1790 | + if( $accesskey != '' |
| 1791 | + && $accesskey != '-' |
| 1792 | + && !wfEmptyMsg( "accesskey-$name", $accesskey ) ) { |
| 1793 | + return $accesskey; |
| 1794 | + } |
| 1795 | + return false; |
| 1796 | + } |
1770 | 1797 | } |