Commit getFooterLinks and getFooterIcons helpers to abstract the common code used...
authorDaniel Friesen <dantman@users.mediawiki.org>
Tue, 7 Dec 2010 19:45:09 +0000 (19:45 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Tue, 7 Dec 2010 19:45:09 +0000 (19:45 +0000)
includes/SkinTemplate.php
skins/Modern.php
skins/MonoBook.php
skins/Vector.php

index 7617194..7c4fcd0 100644 (file)
@@ -1394,5 +1394,78 @@ abstract class BaseTemplate extends QuickTemplate {
                }
        }
        
+       /**
+        * Returns an array of footerlinks trimmed down to only those footer links that
+        * are valid.
+        * If you pass "flat" as an option then the returned array will be a flat array
+        * of footer icons instead of a key/value array of footerlinks arrays broken
+        * up into categories.
+        */
+       function getFooterLinks($option = null) {
+               $footerlinks = $this->data["footerlinks"];
+               
+               // Reduce footer links down to only those which are being used
+               $validFooterLinks = array();
+               foreach( $footerlinks as $category => $links ) {
+                       $validFooterLinks[$category] = array();
+                       foreach( $links as $link ) {
+                               if( isset( $this->data[$link] ) && $this->data[$link] ) {
+                                       $validFooterLinks[$category][] = $link;
+                               }
+                       }
+                       if ( count( $validFooterLinks[$category] ) <= 0 ) {
+                               unset($validFooterLinks[$category]);
+                       }
+               }
+               
+               if ( $option == "flat" ) {
+                       // fold footerlinks into a single array using a bit of trickery
+                       $validFooterLinks = call_user_func_array('array_merge', array_values($validFooterLinks));
+               }
+               
+               return $validFooterLinks;
+       }
+       
+       /**
+        * Returns an array of footer icons filtered down by options relevant to how
+        * the skin wishes to display them.
+        * If you pass "icononly" as the option all footer icons which do not have an
+        * image icon set will be filtered out.
+        * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
+        * in the list of footer icons. This is mostly useful for skins which only
+        * display the text from footericons instead of the images and don't want a
+        * duplicate copyright statement because footerlinks already rendered one.
+        */
+       function getFooterIcons($option = null) {
+               // Generate additional footer icons
+               $footericons = $this->data["footericons"];
+               
+               if ( $option == "icononly" ) {
+                       // Unset any icons which don't have an image
+                       foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
+                               foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
+                                       if ( !is_string($footerIcon) && !isset($footerIcon["src"]) ) {
+                                               unset($footerIconsBlock[$footerIconKey]);
+                                       }
+                               }
+                       }
+                       // Redo removal of any empty blocks
+                       foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
+                               if ( count($footerIconsBlock) <= 0 ) {
+                                       unset($footericons[$footerIconsKey]);
+                               }
+                       }
+               } else if ( $option == "nocopyright" ) {
+                       $footericons = $this->data["footericons"];
+                       unset($footericons["copyright"]["copyright"]);
+                       if ( count($footericons["copyright"]) <= 0 ) {
+                               unset($footericons["copyright"]);
+                       }
+               }
+               
+               return $footericons;
+       }
+       
+       
 }
 
index 752d0de..71ededc 100644 (file)
@@ -52,18 +52,6 @@ class ModernTemplate extends MonoBookTemplate {
                // Suppress warnings to prevent notices about missing indexes in $this->data
                wfSuppressWarnings();
 
-               // Generate additional footer links
-               $footerlinks = $this->data["footerlinks"];
-               // fold footerlinks into a single array using a bit of trickery
-               $footerlinks = call_user_func_array('array_merge', array_values($footerlinks));
-               // Generate additional footer icons
-               $footericons = $this->data["footericons"];
-               // Unset copyright.copyright since we don't need the icon and already output a copyright from footerlinks
-               unset($footericons["copyright"]["copyright"]);
-               if ( count($footericons["copyright"]) <= 0 ) {
-                       unset($footericons["copyright"]);
-               }
-
                $this->html( 'headelement' );
 ?>
 
@@ -183,7 +171,7 @@ class ModernTemplate extends MonoBookTemplate {
        <div id="footer"<?php $this->html('userlangattributes') ?>>
                        <ul id="f-list">
 <?php
-               foreach( $footerlinks as $aLink ) {
+               foreach( $this->getFooterLinks("flat") as $aLink ) {
                        if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
 ?>                             <li id="<?php echo$aLink?>"><?php $this->html($aLink) ?></li>
 <?php          }
@@ -191,7 +179,7 @@ class ModernTemplate extends MonoBookTemplate {
 ?>
                        </ul>
 <?php
-               foreach ( $footericons as $blockName => $footerIcons ) { ?>
+               foreach ( $this->getFooterIcons("nocopyright") as $blockName => $footerIcons ) { ?>
                        <div id="mw_<?php echo htmlspecialchars($blockName); ?>">
 <?php
                        foreach ( $footerIcons as $icon ) { ?>
index ad50090..7fb7344 100644 (file)
@@ -70,10 +70,6 @@ class MonoBookTemplate extends BaseTemplate {
                // Suppress warnings to prevent notices about missing indexes in $this->data
                wfSuppressWarnings();
 
-               // Generate additional footer links
-               $footerlinks = $this->data["footerlinks"];
-               // fold footerlinks into a single array using a bit of trickery
-               $footerlinks = call_user_func_array('array_merge', array_values($footerlinks));
                // Generate additional footer icons
                $footericons = $this->data["footericons"];
                // Unset any icons which don't have an image
@@ -198,19 +194,14 @@ class MonoBookTemplate extends BaseTemplate {
 <?php }
 
                // Generate additional footer links
-               $validFooterLinks = array();
-               foreach( $footerlinks as $aLink ) {
-                       if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
-                               $validFooterLinks[] = $aLink;
-                       }
-               }
+               $validFooterLinks = $this->getFooterLinks("flat");
                if ( count( $validFooterLinks ) > 0 ) {
 ?>     <ul id="f-list">
 <?php
-                       foreach( $validFooterLinks as $aLink ) {
-                               if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
-?>             <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
-<?php                  }
+                       foreach( $validFooterLinks as $aLink ) { ?>
+               <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
+
+<?php
                        }
 ?>
        </ul>
index 7250842..1f3c56a 100644 (file)
@@ -411,37 +411,6 @@ class VectorTemplate extends BaseTemplate {
                                $this->skin->tooltipAndAccesskey('pt-'.$key);
                }
 
-               // Generate additional footer links
-               $footerlinks = $this->data["footerlinks"];
-               
-               // Reduce footer links down to only those which are being used
-               $validFooterLinks = array();
-               foreach( $footerlinks as $category => $links ) {
-                       $validFooterLinks[$category] = array();
-                       foreach( $links as $link ) {
-                               if( isset( $this->data[$link] ) && $this->data[$link] ) {
-                                       $validFooterLinks[$category][] = $link;
-                               }
-                       }
-               }
-               
-               // Generate additional footer icons
-               $footericons = $this->data["footericons"];
-               // Unset any icons which don't have an image
-               foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
-                       foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
-                               if ( !is_string($footerIcon) && !isset($footerIcon["src"]) ) {
-                                       unset($footerIconsBlock[$footerIconKey]);
-                               }
-                       }
-               }
-               // Redo removal of any empty blocks
-               foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
-                       if ( count($footerIconsBlock) <= 0 ) {
-                               unset($footericons[$footerIconsKey]);
-                       }
-               }
-               
                // Reverse horizontally rendered navigation elements
                if ( $wgLang->isRTL() ) {
                        $this->data['view_urls'] =
@@ -533,18 +502,15 @@ class VectorTemplate extends BaseTemplate {
                <!-- /panel -->
                <!-- footer -->
                <div id="footer"<?php $this->html('userlangattributes') ?>>
-                       <?php foreach( $validFooterLinks as $category => $links ): ?>
-                               <?php if ( count( $links ) > 0 ): ?>
+                       <?php foreach( $this->getFooterLinks() as $category => $links ): ?>
                                <ul id="footer-<?php echo $category ?>">
                                        <?php foreach( $links as $link ): ?>
-                                               <?php if( isset( $this->data[$link] ) && $this->data[$link] ): ?>
                                                <li id="footer-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
-                                               <?php endif; ?>
                                        <?php endforeach; ?>
                                </ul>
-                               <?php endif; ?>
                        <?php endforeach; ?>
-<?php                  if ( count( $footericons ) > 0 ): ?>
+                       <?php $footericons = $this->getFooterIcons("icononly");
+                       if ( count( $footericons ) > 0 ): ?>
                                <ul id="footer-icons" class="noprint">
 <?php                  foreach ( $footericons as $blockName => $footerIcons ): ?>
                                        <li id="footer-<?php echo htmlspecialchars($blockName); ?>ico">