r78003 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78002‎ | r78003 | r78004 >
Date:19:45, 7 December 2010
Author:dantman
Status:ok
Tags:
Comment:
Commit getFooterLinks and getFooterIcons helpers to abstract the common code used to trim footerlinks down to only valid items, flatten it if needed, trim non-image icons out of footericons, and remove the copyright icon if needed.
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
@@ -411,37 +411,6 @@
412412 $this->skin->tooltipAndAccesskey('pt-'.$key);
413413 }
414414
415 - // Generate additional footer links
416 - $footerlinks = $this->data["footerlinks"];
417 -
418 - // Reduce footer links down to only those which are being used
419 - $validFooterLinks = array();
420 - foreach( $footerlinks as $category => $links ) {
421 - $validFooterLinks[$category] = array();
422 - foreach( $links as $link ) {
423 - if( isset( $this->data[$link] ) && $this->data[$link] ) {
424 - $validFooterLinks[$category][] = $link;
425 - }
426 - }
427 - }
428 -
429 - // Generate additional footer icons
430 - $footericons = $this->data["footericons"];
431 - // Unset any icons which don't have an image
432 - foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
433 - foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
434 - if ( !is_string($footerIcon) && !isset($footerIcon["src"]) ) {
435 - unset($footerIconsBlock[$footerIconKey]);
436 - }
437 - }
438 - }
439 - // Redo removal of any empty blocks
440 - foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
441 - if ( count($footerIconsBlock) <= 0 ) {
442 - unset($footericons[$footerIconsKey]);
443 - }
444 - }
445 -
446415 // Reverse horizontally rendered navigation elements
447416 if ( $wgLang->isRTL() ) {
448417 $this->data['view_urls'] =
@@ -533,18 +502,15 @@
534503 <!-- /panel -->
535504 <!-- footer -->
536505 <div id="footer"<?php $this->html('userlangattributes') ?>>
537 - <?php foreach( $validFooterLinks as $category => $links ): ?>
538 - <?php if ( count( $links ) > 0 ): ?>
 506+ <?php foreach( $this->getFooterLinks() as $category => $links ): ?>
539507 <ul id="footer-<?php echo $category ?>">
540508 <?php foreach( $links as $link ): ?>
541 - <?php if( isset( $this->data[$link] ) && $this->data[$link] ): ?>
542509 <li id="footer-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
543 - <?php endif; ?>
544510 <?php endforeach; ?>
545511 </ul>
546 - <?php endif; ?>
547512 <?php endforeach; ?>
548 -<?php if ( count( $footericons ) > 0 ): ?>
 513+ <?php $footericons = $this->getFooterIcons("icononly");
 514+ if ( count( $footericons ) > 0 ): ?>
549515 <ul id="footer-icons" class="noprint">
550516 <?php foreach ( $footericons as $blockName => $footerIcons ): ?>
551517 <li id="footer-<?php echo htmlspecialchars($blockName); ?>ico">
Index: trunk/phase3/skins/MonoBook.php
@@ -70,10 +70,6 @@
7171 // Suppress warnings to prevent notices about missing indexes in $this->data
7272 wfSuppressWarnings();
7373
74 - // Generate additional footer links
75 - $footerlinks = $this->data["footerlinks"];
76 - // fold footerlinks into a single array using a bit of trickery
77 - $footerlinks = call_user_func_array('array_merge', array_values($footerlinks));
7874 // Generate additional footer icons
7975 $footericons = $this->data["footericons"];
8076 // Unset any icons which don't have an image
@@ -198,19 +194,14 @@
199195 <?php }
200196
201197 // Generate additional footer links
202 - $validFooterLinks = array();
203 - foreach( $footerlinks as $aLink ) {
204 - if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
205 - $validFooterLinks[] = $aLink;
206 - }
207 - }
 198+ $validFooterLinks = $this->getFooterLinks("flat");
208199 if ( count( $validFooterLinks ) > 0 ) {
209200 ?> <ul id="f-list">
210201 <?php
211 - foreach( $validFooterLinks as $aLink ) {
212 - if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
213 -?> <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
214 -<?php }
 202+ foreach( $validFooterLinks as $aLink ) { ?>
 203+ <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
 204+
 205+<?php
215206 }
216207 ?>
217208 </ul>
Index: trunk/phase3/skins/Modern.php
@@ -52,18 +52,6 @@
5353 // Suppress warnings to prevent notices about missing indexes in $this->data
5454 wfSuppressWarnings();
5555
56 - // Generate additional footer links
57 - $footerlinks = $this->data["footerlinks"];
58 - // fold footerlinks into a single array using a bit of trickery
59 - $footerlinks = call_user_func_array('array_merge', array_values($footerlinks));
60 - // Generate additional footer icons
61 - $footericons = $this->data["footericons"];
62 - // Unset copyright.copyright since we don't need the icon and already output a copyright from footerlinks
63 - unset($footericons["copyright"]["copyright"]);
64 - if ( count($footericons["copyright"]) <= 0 ) {
65 - unset($footericons["copyright"]);
66 - }
67 -
6856 $this->html( 'headelement' );
6957 ?>
7058
@@ -183,7 +171,7 @@
184172 <div id="footer"<?php $this->html('userlangattributes') ?>>
185173 <ul id="f-list">
186174 <?php
187 - foreach( $footerlinks as $aLink ) {
 175+ foreach( $this->getFooterLinks("flat") as $aLink ) {
188176 if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
189177 ?> <li id="<?php echo$aLink?>"><?php $this->html($aLink) ?></li>
190178 <?php }
@@ -191,7 +179,7 @@
192180 ?>
193181 </ul>
194182 <?php
195 - foreach ( $footericons as $blockName => $footerIcons ) { ?>
 183+ foreach ( $this->getFooterIcons("nocopyright") as $blockName => $footerIcons ) { ?>
196184 <div id="mw_<?php echo htmlspecialchars($blockName); ?>">
197185 <?php
198186 foreach ( $footerIcons as $icon ) { ?>
Index: trunk/phase3/includes/SkinTemplate.php
@@ -1394,5 +1394,78 @@
13951395 }
13961396 }
13971397
 1398+ /**
 1399+ * Returns an array of footerlinks trimmed down to only those footer links that
 1400+ * are valid.
 1401+ * If you pass "flat" as an option then the returned array will be a flat array
 1402+ * of footer icons instead of a key/value array of footerlinks arrays broken
 1403+ * up into categories.
 1404+ */
 1405+ function getFooterLinks($option = null) {
 1406+ $footerlinks = $this->data["footerlinks"];
 1407+
 1408+ // Reduce footer links down to only those which are being used
 1409+ $validFooterLinks = array();
 1410+ foreach( $footerlinks as $category => $links ) {
 1411+ $validFooterLinks[$category] = array();
 1412+ foreach( $links as $link ) {
 1413+ if( isset( $this->data[$link] ) && $this->data[$link] ) {
 1414+ $validFooterLinks[$category][] = $link;
 1415+ }
 1416+ }
 1417+ if ( count( $validFooterLinks[$category] ) <= 0 ) {
 1418+ unset($validFooterLinks[$category]);
 1419+ }
 1420+ }
 1421+
 1422+ if ( $option == "flat" ) {
 1423+ // fold footerlinks into a single array using a bit of trickery
 1424+ $validFooterLinks = call_user_func_array('array_merge', array_values($validFooterLinks));
 1425+ }
 1426+
 1427+ return $validFooterLinks;
 1428+ }
 1429+
 1430+ /**
 1431+ * Returns an array of footer icons filtered down by options relevant to how
 1432+ * the skin wishes to display them.
 1433+ * If you pass "icononly" as the option all footer icons which do not have an
 1434+ * image icon set will be filtered out.
 1435+ * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
 1436+ * in the list of footer icons. This is mostly useful for skins which only
 1437+ * display the text from footericons instead of the images and don't want a
 1438+ * duplicate copyright statement because footerlinks already rendered one.
 1439+ */
 1440+ function getFooterIcons($option = null) {
 1441+ // Generate additional footer icons
 1442+ $footericons = $this->data["footericons"];
 1443+
 1444+ if ( $option == "icononly" ) {
 1445+ // Unset any icons which don't have an image
 1446+ foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
 1447+ foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
 1448+ if ( !is_string($footerIcon) && !isset($footerIcon["src"]) ) {
 1449+ unset($footerIconsBlock[$footerIconKey]);
 1450+ }
 1451+ }
 1452+ }
 1453+ // Redo removal of any empty blocks
 1454+ foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
 1455+ if ( count($footerIconsBlock) <= 0 ) {
 1456+ unset($footericons[$footerIconsKey]);
 1457+ }
 1458+ }
 1459+ } else if ( $option == "nocopyright" ) {
 1460+ $footericons = $this->data["footericons"];
 1461+ unset($footericons["copyright"]["copyright"]);
 1462+ if ( count($footericons["copyright"]) <= 0 ) {
 1463+ unset($footericons["copyright"]);
 1464+ }
 1465+ }
 1466+
 1467+ return $footericons;
 1468+ }
 1469+
 1470+
13981471 }
13991472

Follow-up revisions

RevisionCommit summaryAuthorDate
r78004Follow up r78003, forgot to make MonoBook use the footericons code.dantman19:58, 7 December 2010

Status & tagging log