Index: branches/REL1_18/phase3/includes/SkinTemplate.php |
— | — | @@ -1682,43 +1682,73 @@ |
1683 | 1683 | * If an "id" or "single-id" (if you don't want the actual id to be output on the link) |
1684 | 1684 | * is present it will be used to generate a tooltip and accesskey for the link. |
1685 | 1685 | * If you don't want an accesskey, set $item['tooltiponly'] = true; |
| 1686 | + * $options can be used to affect the output of a link: |
| 1687 | + * You can use a text-wrapper key to specify a list of elements to wrap the |
| 1688 | + * text of a link in. This should be an array of arrays containing a 'tag' and |
| 1689 | + * optionally an 'attributes' key. If you only have one element you don't need |
| 1690 | + * to wrap it in another array. eg: To use <a><span>...</span></a> in all links |
| 1691 | + * use array( 'text-wrapper' => array( 'tag' => 'span' ) ) for your options. |
| 1692 | + * A link-class key can be used to specify additional classes to apply to all links. |
| 1693 | + * A link-fallback can be used to specify a tag to use instead of <a> if there is |
| 1694 | + * no link. eg: If you specify 'link-fallback' => 'span' than any non-link will |
| 1695 | + * output a <span> instead of just text. |
1686 | 1696 | */ |
1687 | | - function makeLink( $key, $item ) { |
| 1697 | + function makeLink( $key, $item, $options = array() ) { |
1688 | 1698 | if ( isset( $item['text'] ) ) { |
1689 | 1699 | $text = $item['text']; |
1690 | 1700 | } else { |
1691 | 1701 | $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key ); |
1692 | 1702 | } |
1693 | 1703 | |
1694 | | - if ( !isset( $item['href'] ) ) { |
1695 | | - return htmlspecialchars( $text ); |
1696 | | - } |
| 1704 | + $html = htmlspecialchars( $text ); |
1697 | 1705 | |
1698 | | - $attrs = array(); |
1699 | | - foreach ( array( 'href', 'id', 'class', 'rel', 'type', 'target') as $attr ) { |
1700 | | - if ( isset( $item[$attr] ) ) { |
1701 | | - $attrs[$attr] = $item[$attr]; |
| 1706 | + if ( isset( $options['text-wrapper'] ) ) { |
| 1707 | + $wrapper = $options['text-wrapper']; |
| 1708 | + if ( isset( $wrapper['tag'] ) ) { |
| 1709 | + $wrapper = array( $wrapper ); |
1702 | 1710 | } |
| 1711 | + while ( count( $wrapper ) > 0 ) { |
| 1712 | + $element = array_pop( $wrapper ); |
| 1713 | + $html = Html::rawElement( $element['tag'], isset( $element['attributes'] ) ? $element['attributes'] : null, $html ); |
| 1714 | + } |
1703 | 1715 | } |
1704 | 1716 | |
1705 | | - if ( isset( $item['id'] ) ) { |
1706 | | - $item['single-id'] = $item['id']; |
1707 | | - } |
1708 | | - if ( isset( $item['single-id'] ) ) { |
1709 | | - if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) { |
1710 | | - $attrs['title'] = $this->skin->titleAttrib( $item['single-id'] ); |
1711 | | - if ( $attrs['title'] === false ) { |
1712 | | - unset( $attrs['title'] ); |
| 1717 | + if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) { |
| 1718 | + $attrs = $item; |
| 1719 | + foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) { |
| 1720 | + unset( $attrs[$k] ); |
| 1721 | + } |
| 1722 | + |
| 1723 | + if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) { |
| 1724 | + $item['single-id'] = $item['id']; |
| 1725 | + } |
| 1726 | + if ( isset( $item['single-id'] ) ) { |
| 1727 | + if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) { |
| 1728 | + $title = Linker::titleAttrib( $item['single-id'] ); |
| 1729 | + if ( $title !== false ) { |
| 1730 | + $attrs['title'] = $title; |
| 1731 | + } |
| 1732 | + } else { |
| 1733 | + $tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'] ); |
| 1734 | + if ( isset( $tip['title'] ) && $tip['title'] !== false ) { |
| 1735 | + $attrs['title'] = $tip['title']; |
| 1736 | + } |
| 1737 | + if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) { |
| 1738 | + $attrs['accesskey'] = $tip['accesskey']; |
| 1739 | + } |
1713 | 1740 | } |
1714 | | - } else { |
1715 | | - $attrs = array_merge( |
1716 | | - $attrs, |
1717 | | - Linker::tooltipAndAccesskeyAttribs( $item['single-id'] ) |
1718 | | - ); |
1719 | 1741 | } |
| 1742 | + if ( isset( $options['link-class'] ) ) { |
| 1743 | + if ( isset( $attrs['class'] ) ) { |
| 1744 | + $attrs['class'] .= " {$options['link-class']}"; |
| 1745 | + } else { |
| 1746 | + $attrs['class'] = $options['link-class']; |
| 1747 | + } |
| 1748 | + } |
| 1749 | + $html = Html::rawElement( isset( $attrs['href'] ) ? 'a' : $options['link-fallback'], $attrs, $html ); |
1720 | 1750 | } |
1721 | 1751 | |
1722 | | - return Html::element( 'a', $attrs, $text ); |
| 1752 | + return $html; |
1723 | 1753 | } |
1724 | 1754 | |
1725 | 1755 | /** |
— | — | @@ -1739,19 +1769,19 @@ |
1740 | 1770 | * (however the link will still support a tooltip and accesskey from it) |
1741 | 1771 | * If you need an id or class on a single link you should include a "links" |
1742 | 1772 | * array with just one link item inside of it. |
| 1773 | + * $options is also passed on to makeLink calls |
1743 | 1774 | */ |
1744 | 1775 | function makeListItem( $key, $item, $options = array() ) { |
1745 | 1776 | if ( isset( $item['links'] ) ) { |
1746 | 1777 | $html = ''; |
1747 | 1778 | foreach ( $item['links'] as $linkKey => $link ) { |
1748 | | - $html .= $this->makeLink( $linkKey, $link ); |
| 1779 | + $html .= $this->makeLink( $linkKey, $link, $options ); |
1749 | 1780 | } |
1750 | 1781 | } else { |
1751 | | - $link = array(); |
1752 | | - foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly', 'target' ) as $k ) { |
1753 | | - if ( isset( $item[$k] ) ) { |
1754 | | - $link[$k] = $item[$k]; |
1755 | | - } |
| 1782 | + $link = $item; |
| 1783 | + // These keys are used by makeListItem and shouldn't be passed on to the link |
| 1784 | + foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) { |
| 1785 | + unset( $link[$k] ); |
1756 | 1786 | } |
1757 | 1787 | if ( isset( $item['id'] ) ) { |
1758 | 1788 | // The id goes on the <li> not on the <a> for single links |
— | — | @@ -1759,7 +1789,7 @@ |
1760 | 1790 | // generating tooltips and accesskeys. |
1761 | 1791 | $link['single-id'] = $item['id']; |
1762 | 1792 | } |
1763 | | - $html = $this->makeLink( $key, $link ); |
| 1793 | + $html = $this->makeLink( $key, $link, $options ); |
1764 | 1794 | } |
1765 | 1795 | |
1766 | 1796 | $attrs = array(); |
Property changes on: branches/REL1_18/phase3/includes |
___________________________________________________________________ |
Modified: svn:mergeinfo |
1767 | 1797 | Merged /trunk/phase3/includes:r99369 |
Property changes on: branches/REL1_18/phase3 |
___________________________________________________________________ |
Modified: svn:mergeinfo |
1768 | 1798 | Merged /trunk/phase3:r99369 |