* (bug 419, 1764) Using a custom syntax for the sidebar and supporting multiple
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Tue, 24 May 2005 20:06:52 +0000 (20:06 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Tue, 24 May 2005 20:06:52 +0000 (20:06 +0000)
  sidebars through the MediaWiki namespace.

includes/SkinTemplate.php
languages/Language.php
skins/MonoBook.php

index 8c62be4..eae160d 100644 (file)
@@ -383,7 +383,7 @@ class SkinTemplate extends Skin {
                } else {
                        $tpl->set( 'body_onload', false );
                }
-               $tpl->set( 'navigation_urls', $this->getNavigationLinks() );
+               $tpl->set( 'sidebar', $this->buildSidebar() );
                $tpl->set( 'nav_urls', $this->buildNavUrls() );
 
                // execute template
@@ -704,15 +704,37 @@ class SkinTemplate extends Skin {
                return $content_actions;
        }
        
-       function getNavigationLinks() {
-               global $wgOut;
-               $fname = 'SkinTemplate::getNavigationLinks';
+       /**
+        * Build an array that represents the sidebar(s), the navigation bar among them
+        *
+        * @return array
+        * @access private
+        */ 
+       function buildSidebar() {
+               $fname = 'SkinTemplate::buildSidebar';
                wfProfileIn( $fname );
                
-               $parsed = $wgOut->parse( wfMsgForContent( 'navbar' ) );
+               $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
+               foreach ($lines as $line) {
+                       if (strpos($line, '*') !== 0)
+                               continue;
+                       if (strpos($line, '**') !== 0) {
+                               $line = trim($line, '* ');
+                               $heading = $line;
+                       } else {
+                               if (strpos($line, '|') !== false) { // sanity check
+                                       $line = explode( '|' , trim($line, '* '), 2 );
+                                       $bar[$heading][] = array(
+                                               'text' => wfMsg( $line[1] ),
+                                               'href' => $this->makeInternalOrExternalUrl( wfMsgForContent( $line[0] ) ),
+                                               'id' => 'n-' . $line[1],
+                                       );
+                               } else { continue; }
+                       }
+               }
                
                wfProfileOut( $fname );
-               return $parsed;
+               return $bar;
        }
 
        /**
index 59ec85e..107d7b8 100644 (file)
@@ -254,14 +254,22 @@ global $wgRightsText;
 
 # The navigation toolbar, int: is used here to make sure that the appropriate
 # messages are automatically pulled from the user-selected language file.
-'navbar' =>'
-* [[{{msg:mainpage}}|{{int:mainpage}}]]
-* [[{{msg:portal-url}}|{{int:portal}}]]
-* [[{{msg:currentevents-url}}|{{int:currentevents}}]]
-* [[{{msg:recentchanges-url}}|{{int:recentchanges}}]]
-* [[{{msg:randompage-url}}|{{int:randompage}}]]
-* [[{{msg:helppage}}|{{int:help}}]]
-* [[{{msg:sitesupport-url}}|{{int:sitesupport}}]]',
+
+'sidebar' => "
+This is the markup that's parsed when the sidebar(s) are generated, lines that
+do not begin with * or ** are automatically discarded.
+
+Only put [a-z-] in the level one headings since it will be used as an XHMTL id.
+
+* navigation
+** mainpage|mainpage
+** portal-url|portal
+** currentevents-url|currentevents
+** recentchanges-url|recentchanges
+** randompage-url|randompage
+** helppage|help
+** sitesupport-url|sitesupport
+",
 
 # User preference toggles
 'tog-underline' => 'Underline links',
index b021999..66eee2e 100644 (file)
@@ -107,7 +107,7 @@ class MonoBookTemplate extends QuickTemplate {
          <h5><?php $this->msg('personaltools') ?></h5>
          <div class="pBody">
            <ul>
-           <?php foreach($this->data['personal_urls'] as $key => $item) {
+           <?php foreach($this->data['personal_urls'] as $bar => $item) {
               ?><li id="pt-<?php echo htmlspecialchars($key) ?>"><a href="<?php
               echo htmlspecialchars($item['href']) ?>"<?php
               if(!empty($item['class'])) { ?> class="<?php
@@ -123,12 +123,20 @@ class MonoBookTemplate extends QuickTemplate {
            title="<?php $this->msg('mainpage') ?>"></a>
        </div>
        <script type="<?php $this->text('jsmimetype') ?>"> if (window.isMSIE55) fixalpha(); </script>
-       <div class="portlet" id="p-nav">
-         <h5><?php $this->msg('navigation') ?></h5>
-         <div class="pBody">
-           <?php echo $this->data['navigation_urls']; ?>
+       <?php foreach ($this->data['sidebar'] as $bar => $cont) { ?>
+       <div class='portlet' id='p-<?php echo htmlspecialchars($bat) ?>'>
+         <h5><?php $this->msg( $bar ) ?></h5>
+         <div class='pBody'>
+           <ul>
+           <?php foreach($cont as $key => $val) { ?>
+             <li id="<?php echo htmlspecialchars($val['href'])
+                ?>"><a href="<?php echo htmlspecialchars($val['href']) ?>"><?php
+                echo htmlspecialchars($val['text'])?></a></li><?php
+             } ?>
+           </ul>
          </div>
        </div>
+       <?php } ?>
        <div id="p-search" class="portlet">
          <h5><label for="searchInput"><?php $this->msg('search') ?></label></h5>
          <div class="pBody">