Commit getPersonalTools to allow personal bar generation to be simplified.
authorDaniel Friesen <dantman@users.mediawiki.org>
Mon, 27 Dec 2010 12:23:06 +0000 (12:23 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Mon, 27 Dec 2010 12:23:06 +0000 (12:23 +0000)
includes/SkinTemplate.php
skins/Modern.php
skins/MonoBook.php
skins/Vector.php

index 0a18bb7..6ef1e62 100644 (file)
@@ -1289,6 +1289,33 @@ abstract class BaseTemplate extends QuickTemplate {
                return $toolbox;
        }
 
+       /**
+        * Create an array of personal tools items from the data in the quicktemplate
+        * stored by SkinTemplate.
+        * The resulting array is built acording to a format intended to be passed
+        * through makeListItem to generate the html.
+        * This is in reality the same list as already stored in personal_urls
+        * however it is reformatted so that you can just pass the individual items
+        * to makeListItem instead of hardcoding the element creation boilerplate.
+        */
+       function getPersonalTools() {
+               $personal_tools = array();
+               foreach( $this->data['personal_urls'] as $key => $ptool ) {
+                       # The class on a personal_urls item is meant to go on the <a> instead
+                       # of the <li> so we have to use a single item "links" array instead
+                       # of using most of the personal_url's keys directly
+                       $personal_tools[$key] = array();
+                       $personal_tools[$key]["links"][] = array();
+                       $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
+                       $personal_tools[$key]["active"] = $ptool["active"];
+                       foreach ( array("href", "class", "text") as $k ) {
+                               if ( isset($ptool[$k]) )
+                                       $personal_tools[$key]["links"][0][$k] = $ptool[$k];
+                       }
+               }
+               return $personal_tools;
+       }
+
        /**
         * Makes a link, usually used by makeListItem to generate a link for an item
         * in a list used in navigation lists, portlets, portals, sidebars, etc...
@@ -1380,7 +1407,7 @@ abstract class BaseTemplate extends QuickTemplate {
                                // generating tooltips and accesskeys.
                                $link['single-id'] = $item['id'];
                        }
-                       $html = $this->makeLink( $key, $link  );
+                       $html = $this->makeLink( $key, $link );
                }
 
                $attrs = array();
@@ -1390,6 +1417,9 @@ abstract class BaseTemplate extends QuickTemplate {
                        }
                }
                if ( isset( $item['active'] ) && $item['active'] ) {
+                       if ( !isset( $attrs['class'] ) ) {
+                               $attrs['class'] = '';
+                       }
                        $attrs['class'] .= ' active';
                        $attrs['class'] = trim( $attrs['class'] );
                }
index 71ededc..6cc4fc1 100644 (file)
@@ -154,14 +154,10 @@ class ModernTemplate extends MonoBookTemplate {
                <h5><?php $this->msg('personaltools') ?></h5>
                <div class="pBody">
                        <ul>
-<?php                  foreach($this->data['personal_urls'] as $key => $item) { ?>
-                               <li id="<?php echo Sanitizer::escapeId( "pt-$key" ) ?>"<?php
-                                       if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php
-                               echo htmlspecialchars($item['href']) ?>"<?php echo $skin->tooltipAndAccesskey('pt-'.$key) ?><?php
-                               if(!empty($item['class'])) { ?> class="<?php
-                               echo htmlspecialchars($item['class']) ?>"<?php } ?>><?php
-                               echo htmlspecialchars($item['text']) ?></a></li>
-<?php                  } ?>
+<?php          foreach($this->getPersonalTools() as $key => $item) { ?>
+                               <?php echo $this->makeListItem($key, $item); ?>
+
+<?php          } ?>
                        </ul>
                </div>
        </div>
index 9c7a0e1..ec13ed0 100644 (file)
@@ -129,14 +129,10 @@ class MonoBookTemplate extends BaseTemplate {
                <h5><?php $this->msg('personaltools') ?></h5>
                <div class="pBody">
                        <ul<?php $this->html('userlangattributes') ?>>
-<?php                  foreach($this->data['personal_urls'] as $key => $item) { ?>
-                               <li id="<?php echo Sanitizer::escapeId( "pt-$key" ) ?>"<?php
-                                       if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php
-                               echo htmlspecialchars($item['href']) ?>"<?php echo $skin->tooltipAndAccesskey('pt-'.$key) ?><?php
-                               if(!empty($item['class'])) { ?> class="<?php
-                               echo htmlspecialchars($item['class']) ?>"<?php } ?>><?php
-                               echo htmlspecialchars($item['text']) ?></a></li>
-<?php                  } ?>
+<?php          foreach($this->getPersonalTools() as $key => $item) { ?>
+                               <?php echo $this->makeListItem($key, $item); ?>
+
+<?php          } ?>
                        </ul>
                </div>
        </div>
index 8b4a92a..0ce3991 100644 (file)
@@ -401,17 +401,6 @@ class VectorTemplate extends BaseTemplate {
                $this->data['view_urls'] = $nav['views'];
                $this->data['action_urls'] = $nav['actions'];
                $this->data['variant_urls'] = $nav['variants'];
-               // Build additional attributes for personal_urls
-               foreach ( $this->data['personal_urls'] as $key => $item) {
-                       $this->data['personal_urls'][$key]['attributes'] =
-                               ' id="' . Sanitizer::escapeId( "pt-$key" ) . '"';
-                       if ( isset( $item['active'] ) && $item['active'] ) {
-                               $this->data['personal_urls'][$key]['attributes'] .=
-                                       ' class="active"';
-                       }
-                       $this->data['personal_urls'][$key]['key'] =
-                               $this->skin->tooltipAndAccesskey('pt-'.$key);
-               }
 
                // Reverse horizontally rendered navigation elements
                if ( $wgLang->isRTL() ) {
@@ -687,9 +676,10 @@ class VectorTemplate extends BaseTemplate {
 <div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
        <h5><?php $this->msg('personaltools') ?></h5>
        <ul<?php $this->html('userlangattributes') ?>>
-               <?php foreach($this->data['personal_urls'] as $item): ?>
-                       <li <?php echo $item['attributes'] ?>><a href="<?php echo htmlspecialchars($item['href']) ?>"<?php echo $item['key'] ?><?php if(!empty($item['class'])): ?> class="<?php echo htmlspecialchars($item['class']) ?>"<?php endif; ?>><?php echo htmlspecialchars($item['text']) ?></a></li>
-               <?php endforeach; ?>
+<?php                  foreach($this->getPersonalTools() as $key => $item) { ?>
+               <?php echo $this->makeListItem($key, $item); ?>
+
+<?php                  } ?>
        </ul>
 </div>
 <?php