r102522 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102521‎ | r102522 | r102523 >
Date:15:44, 9 November 2011
Author:reedy
Status:ok
Tags:
Comment:
REL1_18 MFT r99369
Modified paths:
  • /branches/REL1_18/phase3 (modified) (history)
  • /branches/REL1_18/phase3/includes (modified) (history)
  • /branches/REL1_18/phase3/includes/SkinTemplate.php (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/includes/SkinTemplate.php
@@ -1682,43 +1682,73 @@
16831683 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
16841684 * is present it will be used to generate a tooltip and accesskey for the link.
16851685 * 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.
16861696 */
1687 - function makeLink( $key, $item ) {
 1697+ function makeLink( $key, $item, $options = array() ) {
16881698 if ( isset( $item['text'] ) ) {
16891699 $text = $item['text'];
16901700 } else {
16911701 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
16921702 }
16931703
1694 - if ( !isset( $item['href'] ) ) {
1695 - return htmlspecialchars( $text );
1696 - }
 1704+ $html = htmlspecialchars( $text );
16971705
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 );
17021710 }
 1711+ while ( count( $wrapper ) > 0 ) {
 1712+ $element = array_pop( $wrapper );
 1713+ $html = Html::rawElement( $element['tag'], isset( $element['attributes'] ) ? $element['attributes'] : null, $html );
 1714+ }
17031715 }
17041716
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+ }
17131740 }
1714 - } else {
1715 - $attrs = array_merge(
1716 - $attrs,
1717 - Linker::tooltipAndAccesskeyAttribs( $item['single-id'] )
1718 - );
17191741 }
 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 );
17201750 }
17211751
1722 - return Html::element( 'a', $attrs, $text );
 1752+ return $html;
17231753 }
17241754
17251755 /**
@@ -1739,19 +1769,19 @@
17401770 * (however the link will still support a tooltip and accesskey from it)
17411771 * If you need an id or class on a single link you should include a "links"
17421772 * array with just one link item inside of it.
 1773+ * $options is also passed on to makeLink calls
17431774 */
17441775 function makeListItem( $key, $item, $options = array() ) {
17451776 if ( isset( $item['links'] ) ) {
17461777 $html = '';
17471778 foreach ( $item['links'] as $linkKey => $link ) {
1748 - $html .= $this->makeLink( $linkKey, $link );
 1779+ $html .= $this->makeLink( $linkKey, $link, $options );
17491780 }
17501781 } 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] );
17561786 }
17571787 if ( isset( $item['id'] ) ) {
17581788 // The id goes on the <li> not on the <a> for single links
@@ -1759,7 +1789,7 @@
17601790 // generating tooltips and accesskeys.
17611791 $link['single-id'] = $item['id'];
17621792 }
1763 - $html = $this->makeLink( $key, $link );
 1793+ $html = $this->makeLink( $key, $link, $options );
17641794 }
17651795
17661796 $attrs = array();
Property changes on: branches/REL1_18/phase3/includes
___________________________________________________________________
Modified: svn:mergeinfo
17671797 Merged /trunk/phase3/includes:r99369
Property changes on: branches/REL1_18/phase3
___________________________________________________________________
Modified: svn:mergeinfo
17681798 Merged /trunk/phase3:r99369

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99369Fix up makeLinkItem and makeLink:...dantman19:39, 9 October 2011

Status & tagging log