From e7c0da1dc1b10cafc31f1a14cd2200f4221c8cff Mon Sep 17 00:00:00 2001 From: Bene Date: Tue, 4 Feb 2014 08:21:45 +0100 Subject: [PATCH] Add title to list item of language link The key itemtitle can be used to set the title of the actual list item element. This is useful for article badges as it is already done by the js hack to add a title for the icon. Bug: 60717 Change-Id: Ic05c7535d7a35d9ee523373e1e3620e72887459d --- includes/SkinTemplate.php | 10 ++++-- tests/phpunit/includes/SkinTemplateTest.php | 38 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/includes/SkinTemplateTest.php diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 35183ce252..e3e79e1d7a 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -1838,7 +1838,7 @@ abstract class BaseTemplate extends QuickTemplate { * * @param $key string, usually a key from the list you are generating this link from. * @param $item array, of list item data containing some of a specific set of keys. - * The "id" and "class" keys will be used as attributes for the list item, + * The "id", "class" and "itemtitle" keys will be used as attributes for the list item, * if "active" contains a value of true a "active" class will also be appended to class. * * @param $options array @@ -1855,7 +1855,8 @@ abstract class BaseTemplate extends QuickTemplate { * list item directly so they will not be passed to makeLink * (however the link will still support a tooltip and accesskey from it) * If you need an id or class on a single link you should include a "links" - * array with just one link item inside of it. + * array with just one link item inside of it. If you want to add a title + * to the list item itself, you can set "itemtitle" to the value. * $options is also passed on to makeLink calls * * @return string @@ -1869,7 +1870,7 @@ abstract class BaseTemplate extends QuickTemplate { } else { $link = $item; // These keys are used by makeListItem and shouldn't be passed on to the link - foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) { + foreach ( array( 'id', 'class', 'active', 'tag', 'itemtitle' ) as $k ) { unset( $link[$k] ); } if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) { @@ -1894,6 +1895,9 @@ abstract class BaseTemplate extends QuickTemplate { $attrs['class'] .= ' active'; $attrs['class'] = trim( $attrs['class'] ); } + if ( isset( $item['itemtitle'] ) ) { + $attrs['title'] = $item['itemtitle']; + } return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html ); } diff --git a/tests/phpunit/includes/SkinTemplateTest.php b/tests/phpunit/includes/SkinTemplateTest.php new file mode 100644 index 0000000000..8f54714908 --- /dev/null +++ b/tests/phpunit/includes/SkinTemplateTest.php @@ -0,0 +1,38 @@ + + */ + +class SkinTemplateTest extends MediaWikiTestCase { + + /** + * @dataProvider makeListItemProvider + */ + public function testMakeListItem( $expected, $key, $item, $options, $message ) { + $template = $this->getMockForAbstractClass( 'BaseTemplate' ); + + $this->assertEquals( + $expected, + $template->makeListItem( $key, $item, $options ), + $message + ); + } + + public function makeListItemProvider() { + return array( + array( + '
  • text
  • ', + '', + array( 'class' => 'class', 'itemtitle' => 'itemtitle', 'href' => 'url', 'title' => 'title', 'text' => 'text' ), + array(), + 'Test makteListItem with normal values' + ) + ); + } +} -- 2.20.1