Add title to list item of language link
authorBene <benestar.wikimedia@googlemail.com>
Tue, 4 Feb 2014 07:21:45 +0000 (08:21 +0100)
committerBene <benestar.wikimedia@googlemail.com>
Mon, 3 Mar 2014 19:06:36 +0000 (20:06 +0100)
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
tests/phpunit/includes/SkinTemplateTest.php [new file with mode: 0644]

index 35183ce..e3e79e1 100644 (file)
@@ -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 (file)
index 0000000..8f54714
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * @covers SkinTemplate
+ *
+ * @group Output
+ *
+ * @licence GNU GPL v2+
+ * @author Bene* < benestar.wikimedia@gmail.com >
+ */
+
+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(
+                               '<li class="class" title="itemtitle"><a href="url" title="title">text</a></li>',
+                               '',
+                               array( 'class' => 'class', 'itemtitle' => 'itemtitle', 'href' => 'url', 'title' => 'title', 'text' => 'text' ),
+                               array(),
+                               'Test makteListItem with normal values'
+                       )
+               );
+       }
+}