MediaWiki/archive/customizing/new navbox

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to: navigation, search

add a new navigation box to MediaWiki

Overview

"Navigation Box" refers to either of the two sets of links in the control bar -- displayed at left under the wiki logo in MonoBook, possibly elsewhere with other skins. Normally there are three: "navigation", "search", and "toolbox". These can easily be modified extensively, but I wanted to add another one for links back to the "main site" (of which the wiki was just a part). Unfortunately, it looks like this has to be done separately for each skin (I guess the thinking is that a given skin might want to give each box special treatment, though it would be nice if there were a way to set up default handling for all boxes). Looking just at MonoBook.php, this code produces the box normally labeled "navigation":

<h5>
 <?php $this->msg('navigation') ?>
<div class="pBody">
 <ul>
  <?php
   foreach($this->data['navigation_urls'] as $navlink) { ?>
    <li id="<?php echo htmlspecialchars($navlink['id']) ?>">
     <a href="<?php echo htmlspecialchars($navlink['href']) ?>"><?php echo htmlspecialchars($navlink['text']) ?></a>
    </li>
   <?php }
  ?>

Immediately after that, I added the following:

<!-- 2005-06-16 Woozle customizations -->
<h5>
 <?php $this->msg('backlinks') ?>
<div class="pBody">
 <ul>
  <?php foreach($this->data['backlink_urls'] as $navlink) { ?>
   <li id="<?php echo
    htmlspecialchars($navlink['id']) ?>">
    <a href="<?php echo htmlspecialchars($navlink['href']) ?>"><?php echo htmlspecialchars($navlink['text']) ?></a>
   </li>
  <?php } ?>
<!-- end custom code -->

Reloading the page after this change produced no immediate results, but some time later a cache must have expired and some error messages appeared under the "navigation" box. After that, I defined MediaWiki:backlinks to contain "vbz links", and a box labeled "vbz links" faithfully appeared (with an error message in it). Next, I added the following code to LocalSettings.php (near the end, just before the "?>"):

## 2005-06-16 Woozle customizations: define "backlinks" and "backlink_urls" for custom skin code:
$wgMainsiteLinks = array (
 array( 'text'=>'sitelink1','href'=>'sitelink1-url' ),
 array( 'text'=>'sitelink2','href'=>'sitelink2-url' ),
 array( 'text'=>'sitelink3','href'=>'sitelink3-url' ),
 array( 'text'=>'sitelink4','href'=>'sitelink4-url' ),
 array( 'text'=>'sitelink5','href'=>'sitelink5-url' ),
 array( 'text'=>'sitelink6','href'=>'sitelink6-url' ),
 array( 'text'=>'sitelink7','href'=>'sitelink7-url' ),
 array( 'text'=>'sitelink8','href'=>'sitelink8-url' ),
 array( 'text'=>'sitelink9','href'=>'sitelink9-url' ),
);
## end Woozle customization

(Note: I discovered by accident that either "_url" or "-url" will work as a prefix, but they're not equivalent; if you change the value and the control bar doesn't appear to change, make sure you're not confusing them with each other.) Then I modified SkinTemplate.php (the top and bottom lines were there already):

$tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
$tpl->set( 'mainsite_urls', $this->buildMainsiteUrls() ); // # 2005-06-16 Woozle customization
$tpl->set( 'nav_urls', $this->buildNavUrls() );

...and finally MonoBook.php (inserted area as indicated by comments):

<h5>
 <?php $this->msg('navigation')?>
<div class="pBody">
 <ul><?php foreach($this->data['navigation_urls'] as $navlink) { ?>
  <li id="<?php echo htmlspecialchars($navlink['id']) ?>">
   <a href="<?php echo htmlspecialchars($navlink['href'])?>"><?php echo htmlspecialchars($navlink['text']) ?></a>
  </li>

<?php } ?>

<!-- 2005-06-16 Woozle customizations -->
<h5>
 <?php $this->msg('backlinks') ?>
<div class="pBody">
 <ul> <?php foreach($this->data['mainsite_urls'] as $navlink) { ?>
  <li id="<?php echo htmlspecialchars($navlink['id']) ?>">
   <a href="<?php echo htmlspecialchars($navlink['href']) ?>"><?php echo htmlspecialchars($navlink['text']) ?></a>
  </li>

<?php } ?>

I think that's all the code mods I made. Once those are done, all that's left is to modify MediaWiki:Sitelink1, MediaWiki:Sitelink1-url, and so on. To make a line disappear (without removing it from the custom code), set the displayed text to "-".