r9177 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r9176 | r9177 (on ViewVC) | r9178 >
Date:20:06, 24 May 2005
Author:avar
Status:new
Tags:
Comment:* (bug 419, 1764) Using a custom syntax for the sidebar and supporting multiple
sidebars through the MediaWiki namespace.
Modified paths:

Diff [purge]

Index: trunk/phase3/skins/MonoBook.php
===================================================================
--- trunk/phase3/skins/MonoBook.php	(revision 9176)
+++ trunk/phase3/skins/MonoBook.php	(revision 9177)
@@ -107,7 +107,7 @@
 	  <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 @@
 	    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">
Index: trunk/phase3/includes/SkinTemplate.php
===================================================================
--- trunk/phase3/includes/SkinTemplate.php	(revision 9176)
+++ trunk/phase3/includes/SkinTemplate.php	(revision 9177)
@@ -383,7 +383,7 @@
 		} 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 @@
 		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: trunk/phase3/languages/Language.php
===================================================================
--- trunk/phase3/languages/Language.php	(revision 9176)
+++ trunk/phase3/languages/Language.php	(revision 9177)
@@ -254,15 +254,23 @@
 
 # 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',
 'tog-highlightbroken' => 'Format broken links <a href="" class="new">like this</a> (alternative: like this<a href="" class="internal">?</a>).',
Views
Toolbox