Index: trunk/phase3/includes/SkinTemplate.php |
— | — | @@ -1643,43 +1643,73 @@ |
1644 | 1644 | * If an "id" or "single-id" (if you don't want the actual id to be output on the link) |
1645 | 1645 | * is present it will be used to generate a tooltip and accesskey for the link. |
1646 | 1646 | * If you don't want an accesskey, set $item['tooltiponly'] = true; |
| 1647 | + * $options can be used to affect the output of a link: |
| 1648 | + * You can use a text-wrapper key to specify a list of elements to wrap the |
| 1649 | + * text of a link in. This should be an array of arrays containing a 'tag' and |
| 1650 | + * optionally an 'attributes' key. If you only have one element you don't need |
| 1651 | + * to wrap it in another array. eg: To use <a><span>...</span></a> in all links |
| 1652 | + * use array( 'text-wrapper' => array( 'tag' => 'span' ) ) for your options. |
| 1653 | + * A link-class key can be used to specify additional classes to apply to all links. |
| 1654 | + * A link-fallback can be used to specify a tag to use instead of <a> if there is |
| 1655 | + * no link. eg: If you specify 'link-fallback' => 'span' than any non-link will |
| 1656 | + * output a <span> instead of just text. |
1647 | 1657 | */ |
1648 | | - function makeLink( $key, $item ) { |
| 1658 | + function makeLink( $key, $item, $options = array() ) { |
1649 | 1659 | if ( isset( $item['text'] ) ) { |
1650 | 1660 | $text = $item['text']; |
1651 | 1661 | } else { |
1652 | 1662 | $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key ); |
1653 | 1663 | } |
1654 | 1664 | |
1655 | | - if ( !isset( $item['href'] ) ) { |
1656 | | - return htmlspecialchars( $text ); |
1657 | | - } |
| 1665 | + $html = htmlspecialchars( $text ); |
1658 | 1666 | |
1659 | | - $attrs = array(); |
1660 | | - foreach ( array( 'href', 'id', 'class', 'rel', 'type', 'target') as $attr ) { |
1661 | | - if ( isset( $item[$attr] ) ) { |
1662 | | - $attrs[$attr] = $item[$attr]; |
| 1667 | + if ( isset( $options['text-wrapper'] ) ) { |
| 1668 | + $wrapper = $options['text-wrapper']; |
| 1669 | + if ( isset( $wrapper['tag'] ) ) { |
| 1670 | + $wrapper = array( $wrapper ); |
1663 | 1671 | } |
| 1672 | + while ( count( $wrapper ) > 0 ) { |
| 1673 | + $element = array_pop( $wrapper ); |
| 1674 | + $html = Html::rawElement( $element['tag'], isset( $element['attributes'] ) ? $element['attributes'] : null, $html ); |
| 1675 | + } |
1664 | 1676 | } |
1665 | 1677 | |
1666 | | - if ( isset( $item['id'] ) ) { |
1667 | | - $item['single-id'] = $item['id']; |
1668 | | - } |
1669 | | - if ( isset( $item['single-id'] ) ) { |
1670 | | - if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) { |
1671 | | - $attrs['title'] = Linker::titleAttrib( $item['single-id'] ); |
1672 | | - if ( $attrs['title'] === false ) { |
1673 | | - unset( $attrs['title'] ); |
| 1678 | + if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) { |
| 1679 | + $attrs = $item; |
| 1680 | + foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) { |
| 1681 | + unset( $attrs[$k] ); |
| 1682 | + } |
| 1683 | + |
| 1684 | + if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) { |
| 1685 | + $item['single-id'] = $item['id']; |
| 1686 | + } |
| 1687 | + if ( isset( $item['single-id'] ) ) { |
| 1688 | + if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) { |
| 1689 | + $title = Linker::titleAttrib( $item['single-id'] ); |
| 1690 | + if ( $title !== false ) { |
| 1691 | + $attrs['title'] = $title; |
| 1692 | + } |
| 1693 | + } else { |
| 1694 | + $tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'] ); |
| 1695 | + if ( isset( $tip['title'] ) && $tip['title'] !== false ) { |
| 1696 | + $attrs['title'] = $tip['title']; |
| 1697 | + } |
| 1698 | + if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) { |
| 1699 | + $attrs['accesskey'] = $tip['accesskey']; |
| 1700 | + } |
1674 | 1701 | } |
1675 | | - } else { |
1676 | | - $attrs = array_merge( |
1677 | | - $attrs, |
1678 | | - Linker::tooltipAndAccesskeyAttribs( $item['single-id'] ) |
1679 | | - ); |
1680 | 1702 | } |
| 1703 | + if ( isset( $options['link-class'] ) ) { |
| 1704 | + if ( isset( $attrs['class'] ) ) { |
| 1705 | + $attrs['class'] .= " {$options['link-class']}"; |
| 1706 | + } else { |
| 1707 | + $attrs['class'] = $options['link-class']; |
| 1708 | + } |
| 1709 | + } |
| 1710 | + $html = Html::rawElement( isset( $attrs['href'] ) ? 'a' : $options['link-fallback'], $attrs, $html ); |
1681 | 1711 | } |
1682 | 1712 | |
1683 | | - return Html::element( 'a', $attrs, $text ); |
| 1713 | + return $html; |
1684 | 1714 | } |
1685 | 1715 | |
1686 | 1716 | /** |
— | — | @@ -1700,19 +1730,19 @@ |
1701 | 1731 | * (however the link will still support a tooltip and accesskey from it) |
1702 | 1732 | * If you need an id or class on a single link you should include a "links" |
1703 | 1733 | * array with just one link item inside of it. |
| 1734 | + * $options is also passed on to makeLink calls |
1704 | 1735 | */ |
1705 | 1736 | function makeListItem( $key, $item, $options = array() ) { |
1706 | 1737 | if ( isset( $item['links'] ) ) { |
1707 | 1738 | $html = ''; |
1708 | 1739 | foreach ( $item['links'] as $linkKey => $link ) { |
1709 | | - $html .= $this->makeLink( $linkKey, $link ); |
| 1740 | + $html .= $this->makeLink( $linkKey, $link, $options ); |
1710 | 1741 | } |
1711 | 1742 | } else { |
1712 | | - $link = array(); |
1713 | | - foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly', 'target' ) as $k ) { |
1714 | | - if ( isset( $item[$k] ) ) { |
1715 | | - $link[$k] = $item[$k]; |
1716 | | - } |
| 1743 | + $link = $item; |
| 1744 | + // These keys are used by makeListItem and shouldn't be passed on to the link |
| 1745 | + foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) { |
| 1746 | + unset( $link[$k] ); |
1717 | 1747 | } |
1718 | 1748 | if ( isset( $item['id'] ) ) { |
1719 | 1749 | // The id goes on the <li> not on the <a> for single links |
— | — | @@ -1720,7 +1750,7 @@ |
1721 | 1751 | // generating tooltips and accesskeys. |
1722 | 1752 | $link['single-id'] = $item['id']; |
1723 | 1753 | } |
1724 | | - $html = $this->makeLink( $key, $link ); |
| 1754 | + $html = $this->makeLink( $key, $link, $options ); |
1725 | 1755 | } |
1726 | 1756 | |
1727 | 1757 | $attrs = array(); |