MediaWiki/archive/customizing/new navbox: Difference between revisions

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
No edit summary
 
m Woozle moved page add a new navigation box to MediaWiki to MediaWiki/archive/customizing/new navbox without leaving a redirect: probably quite obsolete
 
(15 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Techniques]]:
=add a new navigation box to MediaWiki=
[[MediaWiki]]: [[MediaWikiDoc:Add a New Navigation Box|Add a New
==Overview==
Navigation Box]]
"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":
"Navigation Box" refers to either of the two sets of links in the
 
control bar -- displayed at left under the wiki logo in MonoBook,
<h5>
possibly elsewhere with other skins. Normally there are three:
  <?php $this->msg('navigation') ?>
"navigation", "search", and "toolbox". These can easily be modified
</h5>
extensively, but I wanted to add another one for links back to the
&lt;div class="pBody">
"main site" (of which the wiki was just a part).
  &lt;ul>
Unfortunately, it looks like this has to be done separately for each
  <?php
skin (I guess the thinking is that a given skin might want to give each
    foreach($this->data['navigation_urls'] as $navlink) { ?>
box special treatment, though it would be nice if there were a way to
    &lt;li id="<?php echo htmlspecialchars($navlink['id']) ?>">
set up default handling for all boxes). Looking just at MonoBook.php,
      &lt;a href="<?php echo htmlspecialchars($navlink['href']) ?>"><?php echo htmlspecialchars($navlink['text']) ?></a>
this code produces the box normally labeled "navigation":
    &lt;/li>
<pre> <h5><?php $this->msg('navigation')
    <?php }
?></h5> <div class="pBody"> <ul> <?php
  ?>
foreach($this->data['navigation_urls'] as $navlink) { ?> <li
  </ul>
id="<?php echo htmlspecialchars($navlink['id']) ?>"><a
</div>
href="<?php echo htmlspecialchars($navlink['href'])
?>"><?php echo htmlspecialchars($navlink['text'])
?></a></li><?php } ?> </ul> </div>
</pre>
Immediately after that, I added the following:
Immediately after that, I added the following:
<pre>
&lt;!-- 2005-06-16 Woozle customizations -->
<!-- 2005-06-16 Woozle customizations --> <h5><?php
&lt;h5>
$this->msg('backlinks') ?></h5> <div class="pBody">
  <?php $this->msg('backlinks') ?>
<ul> <?php foreach($this->data['backlink_urls'] as
</h5>
$navlink) { ?> <li id="<?php echo
&lt;div class="pBody">
htmlspecialchars($navlink['id']) ?>"><a href="<?php echo
  &lt;ul>
htmlspecialchars($navlink['href']) ?>"><?php echo
  <?php foreach($this->data['backlink_urls'] as $navlink) { ?>
htmlspecialchars($navlink['text']) ?></a></li><?php }
    &lt;li id="<?php echo
?> </ul> </div>
    htmlspecialchars($navlink['id']) ?>">
<!-- end custom code -->
    &lt;a href="<?php echo htmlspecialchars($navlink['href']) ?>"><?php echo htmlspecialchars($navlink['text']) ?></a>
</pre>
    &lt;/li>
Reloading the page after this change produced no immediate results, but
  <?php } ?>
some time later a cache must have expired and some error messages
  </ul>
appeared under the "navigation" box. After that, I defined
</div>
[[MediaWiki:backlinks]] to contain "vbz links", and a box labeled "vbz
&lt;!-- end custom code -->
links" faithfully appeared (with an error message in it).
 
Next, I added the following code to LocalSettings.php (near the end,
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 "?>"):
just before the "?>"):
 
<pre>
## 2005-06-16 Woozle customizations: define "backlinks" and "backlink_urls" for custom skin code:
## 2005-06-16 Woozle customizations: define "backlinks" and
$wgMainsiteLinks = array (
"backlink_urls" for custom skin code:
  array( 'text'=>'sitelink1','href'=>'sitelink1-url' ),
$wgMainsiteLinks = array ( array(
  array( 'text'=>'sitelink2','href'=>'sitelink2-url' ),
'text'=>'sitelink1','href'=>'sitelink1-url' ), array(
  array( 'text'=>'sitelink3','href'=>'sitelink3-url' ),
'text'=>'sitelink2','href'=>'sitelink2-url' ), array(
  array( 'text'=>'sitelink4','href'=>'sitelink4-url' ),
'text'=>'sitelink3','href'=>'sitelink3-url' ), array(
  array( 'text'=>'sitelink5','href'=>'sitelink5-url' ),
'text'=>'sitelink4','href'=>'sitelink4-url' ), array(
  array( 'text'=>'sitelink6','href'=>'sitelink6-url' ),
'text'=>'sitelink5','href'=>'sitelink5-url' ), array(
  array( 'text'=>'sitelink7','href'=>'sitelink7-url' ),
'text'=>'sitelink6','href'=>'sitelink6-url' ), array(
  array( 'text'=>'sitelink8','href'=>'sitelink8-url' ),
'text'=>'sitelink7','href'=>'sitelink7-url' ), array(
  array( 'text'=>'sitelink9','href'=>'sitelink9-url' ),
'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 (MediaWiki)|SkinTemplate.php]] (the top and bottom lines were there already):
## end Woozle customization
$tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
</pre>
$tpl->set( 'mainsite_urls', $this->buildMainsiteUrls() ); // # 2005-06-16 Woozle customization
(Note: I discovered by accident that either "_url" or "-url" will work
$tpl->set( 'nav_urls', $this->buildNavUrls() );
as a prefix, but they're not equivalent; if you change the value and
...and finally [[MonoBook.php (MediaWiki)|MonoBook.php]] (inserted area as indicated by comments):
the control bar doesn't appear to change, make sure you're not
&lt;h5>
confusing them with each other.)
  <?php $this->msg('navigation')?>
Then I modified SkinTemplate.php (the top and bottom lines were there
</h5>
already):
&lt;div class="pBody">
<pre>
  &lt;ul><?php foreach($this->data['navigation_urls'] as $navlink) { ?>
$tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
  &lt;li id="<?php echo htmlspecialchars($navlink['id']) ?>">
$tpl->set( 'mainsite_urls', $this->buildMainsiteUrls() ); //
    &lt;a href="<?php echo htmlspecialchars($navlink['href'])?>"><?php echo htmlspecialchars($navlink['text']) ?></a>
2005-06-16 Woozle customization
  &lt;/li>
$tpl->set( 'nav_urls', $this->buildNavUrls() );
  <?php } ?> </ul>
</pre>
</div>
...and finally MonoBook.php (inserted area as indicated by comments):
&lt;!-- 2005-06-16 Woozle customizations -->
<pre> <h5><?php $this->msg('navigation')
&lt;h5>
?></h5> <div class="pBody"> <ul> <?php
  <?php $this->msg('backlinks') ?>
foreach($this->data['navigation_urls'] as $navlink) { ?> <li
</h5>
id="<?php echo htmlspecialchars($navlink['id']) ?>"><a
&lt;div class="pBody">
href="<?php echo htmlspecialchars($navlink['href'])
  &lt;ul> <?php foreach($this->data['mainsite_urls'] as $navlink) { ?>
?>"><?php echo htmlspecialchars($navlink['text'])
  &lt;li id="<?php echo htmlspecialchars($navlink['id']) ?>">
?></a></li><?php } ?> </ul> </div>
    &lt;a href="<?php echo htmlspecialchars($navlink['href']) ?>"><?php echo htmlspecialchars($navlink['text']) ?></a>
<!-- 2005-06-16 Woozle customizations --> <h5><?php
  &lt;/li>
$this->msg('backlinks') ?></h5> <div class="pBody">
  <?php } ?> </ul>
<ul> <?php foreach($this->data['mainsite_urls'] as
</div>
$navlink) { ?> <li id="<?php echo
<!-- end custom code -->
htmlspecialchars($navlink['id']) ?>"><a href="<?php echo
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 "-".
htmlspecialchars($navlink['href'])
?>"><?php echo htmlspecialchars($navlink['text'])
?></a></li><?php } ?> </ul> </div>
<!-- end custom code -->
</pre>
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
"-".

Latest revision as of 23:22, 14 December 2017

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 "-".