Implement $wgFooterIcons to replace copyrightico and poweredbyico with a flexible...
authorDaniel Friesen <dantman@users.mediawiki.org>
Sat, 4 Dec 2010 20:55:23 +0000 (20:55 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Sat, 4 Dec 2010 20:55:23 +0000 (20:55 +0000)
Implementations for MonoBook, Vector, and Modern. Modern implementation uses text instead of icons as desired.

includes/DefaultSettings.php
includes/Setup.php
includes/SkinTemplate.php
skins/Modern.php
skins/MonoBook.php
skins/Vector.php

index 7ab734b..0dc2d9f 100644 (file)
@@ -2262,6 +2262,25 @@ $wgDisableOutputCompression = false;
  */
 $wgExperimentalHtmlIds = true;
 
+/**
+ * Abstract list of footer icons for skins in place of old copyrightico and poweredbyico code
+ * You can add new icons to the built in copyright or poweredby, or you can create
+ * a new block. Though note that you may need to add some custom css to get good styling
+ * of new blocks in monobook. vector and modern should work without any special css.
+ */
+$wgFooterIcons = array(
+       "copyright" => array(
+               "copyright" => array(), // placeholder for the built in copyright icon
+       ),
+       "poweredby" => array(
+               "mediawiki" => array(
+                       "src" => null, // Defaults to "$wgStylePath/common/images/poweredby_mediawiki_88x31.png"
+                       "url" => "http://www.mediawiki.org/",
+                       "alt" => "Powered by MediaWiki",
+               )
+       ),
+);
+
 /**
  * Search form behavior for Vector skin only
  * true = use an icon search button
index d78aade..b937c0e 100644 (file)
@@ -63,6 +63,28 @@ if( isset( $wgFileStore['deleted']['directory'] ) ) {
        $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
 }
 
+if( isset($wgFooterIcons["copyright"]) &&
+  isset($wgFooterIcons["copyright"]["copyright"]) &&
+  $wgFooterIcons["copyright"]["copyright"] === array() ) {
+       if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
+               $wgFooterIcons["copyright"]["copyright"] = $wgCopyrightIcon;
+       } elseif ( $wgRightsIcon || $wgRightsText ) {
+               $wgFooterIcons["copyright"]["copyright"] = array(
+                       "url" => $wgRightsUrl,
+                       "src" => $wgRightsIcon,
+                       "alt" => $wgRightsText,
+               );
+       } else {
+               unset($wgFooterIcons["copyright"]["copyright"]);
+       }
+}
+
+if( isset($wgFooterIcons["poweredby"]) &&
+  isset($wgFooterIcons["poweredby"]["mediawiki"]) &&
+  $wgFooterIcons["poweredby"]["mediawiki"]["src"] === null ) {
+       $wgFooterIcons["poweredby"]["mediawiki"]["src"] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
+}
+
 /**
  * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
  * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
index 5a78f90..a722971 100644 (file)
@@ -425,6 +425,21 @@ class SkinTemplate extends Skin {
                                'disclaimer',
                        ),
                ) );
+               
+               global $wgFooterIcons;
+               $tpl->set( 'footericons', $wgFooterIcons );
+               foreach ( $tpl->data["footericons"] as $footerIconsKey => &$footerIconsBlock ) {
+                       if ( count($footerIconsBlock) > 0 ) {
+                               foreach ( $footerIconsBlock as &$footerIcon ) {
+                                       if ( isset($footerIcon["src"]) ) {
+                                               if ( !isset($footerIcon["width"]) ) $footerIcon["width"] = 88;
+                                               if ( !isset($footerIcon["height"]) ) $footerIcon["height"] = 31;
+                                       }
+                               }
+                       } else {
+                               unset($tpl->data["footericons"][$footerIconsKey]);
+                       }
+               }
 
                if ( $wgDebugComments ) {
                        $tpl->setRef( 'debug', $out->mDebugtext );
index c5bddc6..086f8bf 100644 (file)
@@ -21,17 +21,6 @@ class SkinModern extends SkinTemplate {
        var $skinname = 'modern', $stylename = 'modern',
                $template = 'ModernTemplate', $useHeadElement = true;
 
-       /*
-        * We don't like the default getPoweredBy, the icon clashes with the
-        * skin L&F.
-        */
-       function getPoweredBy() {
-               global $wgVersion;
-               $text = "<div class='mw_poweredby'>Powered by MediaWiki $wgVersion</div>";
-               wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
-               return $text;
-       }
-
        function setupSkinUserCss( OutputPage $out ){
                // Do not call parent::setupSkinUserCss(), we have our own print style
                $out->addStyle( 'common/shared.css', 'screen' );
@@ -63,6 +52,18 @@ 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' );
 ?>
 
@@ -182,10 +183,6 @@ class ModernTemplate extends MonoBookTemplate {
        <div id="footer"<?php $this->html('userlangattributes') ?>>
                        <ul id="f-list">
 <?php
-               $footerlinks = array(
-                       'lastmod', 'viewcount', 'numberofwatchingusers', 'credits', 'copyright',
-                       'privacy', 'about', 'disclaimer', 'tagline',
-               );
                foreach( $footerlinks as $aLink ) {
                        if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
 ?>                             <li id="<?php echo$aLink?>"><?php $this->html($aLink) ?></li>
@@ -193,7 +190,25 @@ class ModernTemplate extends MonoBookTemplate {
                }
 ?>
                        </ul>
-               <?php echo $this->html("poweredbyico"); ?>
+<?php
+               foreach ( $footericons as $blockName => $footerIcons ) { ?>
+                       <div id="mw_<?php echo htmlspecialchars($blockName); ?>">
+<?php
+                       foreach ( $footerIcons as $icon ) { 
+                               if ( is_string($icon) ) {
+                                       $html = $icon;
+                               } else {
+                                       $html = htmlspecialchars($icon["alt"]);
+                                       if ( $icon["url"] ) {
+                                               $html = Html::element( 'a', array( "href" => $icon["url"] ), $html );
+                                       }
+                               }
+                               echo "                          $html\n";
+                       } ?>
+                       </div>
+<?php
+               }
+?>
        </div>
 
        <?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?>
index 663279a..e3e2e9a 100644 (file)
@@ -74,6 +74,22 @@ class MonoBookTemplate extends QuickTemplate {
                $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
+               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]);
+                       }
+               }
 
                $this->html( 'headelement' );
 ?><div id="globalWrapper">
@@ -171,12 +187,26 @@ class MonoBookTemplate extends QuickTemplate {
 </div><!-- end of the left (by default at least) column -->
 <div class="visualClear"></div>
 <div id="footer"<?php $this->html('userlangattributes') ?>>
-<?php
-if($this->data['poweredbyico']) { ?>
-       <div id="f-poweredbyico"><?php $this->html('poweredbyico') ?></div>
-<?php }
-if($this->data['copyrightico']) { ?>
-       <div id="f-copyrightico"><?php $this->html('copyrightico') ?></div>
+<?php foreach ( $footericons as $blockName => $footerIcons ) { ?>
+       <div id="f-<?php echo htmlspecialchars($blockName); ?>ico">
+<?php  foreach ( $footerIcons as $icon ) { 
+                       if ( is_string($icon) ) {
+                               $html = $icon;
+                       } else {
+                               $url = $icon["url"];
+                               unset($icon["url"]);
+                               if ( isset($icon["src"]) ) {
+                                       $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
+                               } else {
+                                       $html = htmlspecialchars($icon["alt"]);
+                               }
+                               if ( $url ) {
+                                       $html = Html::rawElement( 'a', array( "href" => $url ), $html );
+                               }
+                       }
+                       echo "          $html\n";
+               } ?>
+       </div>
 <?php }
 
                // Generate additional footer links
index b57432e..057f205 100644 (file)
@@ -413,13 +413,7 @@ class VectorTemplate extends QuickTemplate {
 
                // Generate additional footer links
                $footerlinks = $this->data["footerlinks"];
-               // footerlinks doesn't include icons for now, so we'll just append the default
-               $footerlinks["icons"] = array( 'poweredbyico', 'copyrightico', );
                
-               $footerlinksClasses = array(
-                       'icons' => array( 'noprint' )
-               );
-
                // Reduce footer links down to only those which are being used
                $validFooterLinks = array();
                foreach( $footerlinks as $category => $links ) {
@@ -430,6 +424,24 @@ class VectorTemplate extends QuickTemplate {
                                }
                        }
                }
+               
+               // 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'] =
@@ -523,7 +535,7 @@ class VectorTemplate extends QuickTemplate {
                <div id="footer"<?php $this->html('userlangattributes') ?>>
                        <?php foreach( $validFooterLinks as $category => $links ): ?>
                                <?php if ( count( $links ) > 0 ): ?>
-                               <ul id="footer-<?php echo $category ?>"<?php if (isset($footerlinksClasses[$category])) echo ' class="' . implode(" ", $footerlinksClasses[$category]) . '"'; ?>>
+                               <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>
@@ -532,6 +544,31 @@ class VectorTemplate extends QuickTemplate {
                                </ul>
                                <?php endif; ?>
                        <?php endforeach; ?>
+<?php                  if ( count( $footericons ) > 0 ): ?>
+                               <ul id="footer-icons">
+<?php                  foreach ( $footericons as $blockName => $footerIcons ): ?>
+                                       <li id="footer-<?php echo htmlspecialchars($blockName); ?>ico" class="noprint">
+<?php                                  foreach ( $footerIcons as $icon ):
+                                                       if ( is_string($icon) ) {
+                                                               $html = $icon;
+                                                       } else {
+                                                               $url = $icon["url"];
+                                                               unset($icon["url"]);
+                                                               if ( isset($icon["src"]) ) {
+                                                                       $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
+                                                               } else {
+                                                                       $html = htmlspecialchars($icon["alt"]);
+                                                               }
+                                                               if ( $url ) {
+                                                                       $html = Html::rawElement( 'a', array( "href" => $url ), $html );
+                                                               }
+                                                       }
+                                                       echo "                                          $html\n";
+                                               endforeach; ?>
+                                       </li>
+<?php                  endforeach; ?>
+                               </ul>
+                       <?php endif; ?>
                        <div style="clear:both"></div>
                </div>
                <!-- /footer -->