Provide personal tools getter
authorpetarpetkovic <ppetkovic@wikimedia.org>
Mon, 6 Nov 2017 19:03:12 +0000 (20:03 +0100)
committerpetarpetkovic <ppetkovic@wikimedia.org>
Wed, 13 Dec 2017 11:42:55 +0000 (12:42 +0100)
- Add public function to get user's personal tools.
- Add new level of abstraction to the creation on personal tools list items,
by enabling user to provide list of personal tools.

Change-Id: I549376af6f7380dbadfb5f3f7f7171bbe64cccd7

includes/skins/SkinTemplate.php

index 532ee51..badd7a2 100644 (file)
@@ -524,15 +524,48 @@ class SkinTemplate extends Skin {
         * @return string
         */
        public function getPersonalToolsList() {
+               return $this->makePersonalToolsList();
+       }
+
+       /**
+        * Get the HTML for the personal tools list
+        *
+        * @since 1.31
+        *
+        * @param array $personalTools
+        * @param array $options
+        * @return string
+        */
+       public function makePersonalToolsList( $personalTools = null, $options = [] ) {
                $tpl = $this->setupTemplateForOutput();
                $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
                $html = '';
-               foreach ( $tpl->getPersonalTools() as $key => $item ) {
-                       $html .= $tpl->makeListItem( $key, $item );
+
+               if ( $personalTools === null ) {
+                       $personalTools = $tpl->getPersonalTools();
+               }
+
+               foreach ( $personalTools as $key => $item ) {
+                       $html .= $tpl->makeListItem( $key, $item, $options );
                }
+
                return $html;
        }
 
+       /**
+        * Get personal tools for the user
+        *
+        * @since 1.31
+        *
+        * @return array Array of personal tools
+        */
+       public function getStructuredPersonalTools() {
+               $tpl = $this->setupTemplateForOutput();
+               $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
+
+               return $tpl->getPersonalTools();
+       }
+
        /**
         * Format language name for use in sidebar interlanguage links list.
         * By default it is capitalized.