r79055 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79054‎ | r79055 | r79056 >
Date:12:23, 27 December 2010
Author:dantman
Status:resolved (Comments)
Tags:
Comment:
Commit getPersonalTools to allow personal bar generation to be simplified.
Modified paths:
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/skins/Modern.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)
  • /trunk/phase3/skins/Vector.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/Vector.php
@@ -401,17 +401,6 @@
402402 $this->data['view_urls'] = $nav['views'];
403403 $this->data['action_urls'] = $nav['actions'];
404404 $this->data['variant_urls'] = $nav['variants'];
405 - // Build additional attributes for personal_urls
406 - foreach ( $this->data['personal_urls'] as $key => $item) {
407 - $this->data['personal_urls'][$key]['attributes'] =
408 - ' id="' . Sanitizer::escapeId( "pt-$key" ) . '"';
409 - if ( isset( $item['active'] ) && $item['active'] ) {
410 - $this->data['personal_urls'][$key]['attributes'] .=
411 - ' class="active"';
412 - }
413 - $this->data['personal_urls'][$key]['key'] =
414 - $this->skin->tooltipAndAccesskey('pt-'.$key);
415 - }
416405
417406 // Reverse horizontally rendered navigation elements
418407 if ( $wgLang->isRTL() ) {
@@ -687,9 +676,10 @@
688677 <div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
689678 <h5><?php $this->msg('personaltools') ?></h5>
690679 <ul<?php $this->html('userlangattributes') ?>>
691 - <?php foreach($this->data['personal_urls'] as $item): ?>
692 - <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>
693 - <?php endforeach; ?>
 680+<?php foreach($this->getPersonalTools() as $key => $item) { ?>
 681+ <?php echo $this->makeListItem($key, $item); ?>
 682+
 683+<?php } ?>
694684 </ul>
695685 </div>
696686 <?php
Index: trunk/phase3/skins/MonoBook.php
@@ -129,14 +129,10 @@
130130 <h5><?php $this->msg('personaltools') ?></h5>
131131 <div class="pBody">
132132 <ul<?php $this->html('userlangattributes') ?>>
133 -<?php foreach($this->data['personal_urls'] as $key => $item) { ?>
134 - <li id="<?php echo Sanitizer::escapeId( "pt-$key" ) ?>"<?php
135 - if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php
136 - echo htmlspecialchars($item['href']) ?>"<?php echo $skin->tooltipAndAccesskey('pt-'.$key) ?><?php
137 - if(!empty($item['class'])) { ?> class="<?php
138 - echo htmlspecialchars($item['class']) ?>"<?php } ?>><?php
139 - echo htmlspecialchars($item['text']) ?></a></li>
140 -<?php } ?>
 133+<?php foreach($this->getPersonalTools() as $key => $item) { ?>
 134+ <?php echo $this->makeListItem($key, $item); ?>
 135+
 136+<?php } ?>
141137 </ul>
142138 </div>
143139 </div>
Index: trunk/phase3/skins/Modern.php
@@ -154,14 +154,10 @@
155155 <h5><?php $this->msg('personaltools') ?></h5>
156156 <div class="pBody">
157157 <ul>
158 -<?php foreach($this->data['personal_urls'] as $key => $item) { ?>
159 - <li id="<?php echo Sanitizer::escapeId( "pt-$key" ) ?>"<?php
160 - if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php
161 - echo htmlspecialchars($item['href']) ?>"<?php echo $skin->tooltipAndAccesskey('pt-'.$key) ?><?php
162 - if(!empty($item['class'])) { ?> class="<?php
163 - echo htmlspecialchars($item['class']) ?>"<?php } ?>><?php
164 - echo htmlspecialchars($item['text']) ?></a></li>
165 -<?php } ?>
 158+<?php foreach($this->getPersonalTools() as $key => $item) { ?>
 159+ <?php echo $this->makeListItem($key, $item); ?>
 160+
 161+<?php } ?>
166162 </ul>
167163 </div>
168164 </div>
Index: trunk/phase3/includes/SkinTemplate.php
@@ -1290,6 +1290,33 @@
12911291 }
12921292
12931293 /**
 1294+ * Create an array of personal tools items from the data in the quicktemplate
 1295+ * stored by SkinTemplate.
 1296+ * The resulting array is built acording to a format intended to be passed
 1297+ * through makeListItem to generate the html.
 1298+ * This is in reality the same list as already stored in personal_urls
 1299+ * however it is reformatted so that you can just pass the individual items
 1300+ * to makeListItem instead of hardcoding the element creation boilerplate.
 1301+ */
 1302+ function getPersonalTools() {
 1303+ $personal_tools = array();
 1304+ foreach( $this->data['personal_urls'] as $key => $ptool ) {
 1305+ # The class on a personal_urls item is meant to go on the <a> instead
 1306+ # of the <li> so we have to use a single item "links" array instead
 1307+ # of using most of the personal_url's keys directly
 1308+ $personal_tools[$key] = array();
 1309+ $personal_tools[$key]["links"][] = array();
 1310+ $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
 1311+ $personal_tools[$key]["active"] = $ptool["active"];
 1312+ foreach ( array("href", "class", "text") as $k ) {
 1313+ if ( isset($ptool[$k]) )
 1314+ $personal_tools[$key]["links"][0][$k] = $ptool[$k];
 1315+ }
 1316+ }
 1317+ return $personal_tools;
 1318+ }
 1319+
 1320+ /**
12941321 * Makes a link, usually used by makeListItem to generate a link for an item
12951322 * in a list used in navigation lists, portlets, portals, sidebars, etc...
12961323 *
@@ -1380,7 +1407,7 @@
13811408 // generating tooltips and accesskeys.
13821409 $link['single-id'] = $item['id'];
13831410 }
1384 - $html = $this->makeLink( $key, $link );
 1411+ $html = $this->makeLink( $key, $link );
13851412 }
13861413
13871414 $attrs = array();
@@ -1390,6 +1417,9 @@
13911418 }
13921419 }
13931420 if ( isset( $item['active'] ) && $item['active'] ) {
 1421+ if ( !isset( $attrs['class'] ) ) {
 1422+ $attrs['class'] = '';
 1423+ }
13941424 $attrs['class'] .= ' active';
13951425 $attrs['class'] = trim( $attrs['class'] );
13961426 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r79243Followup r79055 c12495 fix undefined index notice.dantman10:03, 30 December 2010

Comments

#Comment by Catrope (talk | contribs)   09:58, 30 December 2010

Notice: Undefined index: active in /home/catrope/mediawiki/trunk/phase3/includes/SkinTemplate.php on line 1310

#Comment by Dantman (talk | contribs)   10:06, 30 December 2010

Should be fixed in r79243

Status & tagging log