Control the links that appear in Mediawiki’s toolbox and make it vanish for anonymous users

ninja-sidebar-mediawiki
I wanted to simplify the toolbox for a special purpose wiki, but everywhere I searched all I could find was how to change the name of the toolbox, or how to show it only to logged in users, etc. In the /skins/MonoBook.php file, you can easily make it disappear unless the user is logged in by adding two lines of php to skip the meat and potatoes of the toolbox function. If the user is logged in, they’ll see whatever links you allow. You can check for ‘loggedin’ for individual links too if you only want some of the links available.

edit /skins/MonoBook.php and add this code
near the top…

<?php if($this->data['loggedin']) { ?>

and near the bottom…

<?php } ?>

To delete one of the default toolbox links, just change the data value to something it will never see. You could remove the if statements completely for each link you want removed, or just change the data value to something that will never result in entering the if statement. It’s less intrusive than removing the code completely. Either way, you won’t be deleting the toolbox function, only the link from the interface — which is exactly what I wanted. If you ever want to add the links back in, just change the data back to the default or add the if statements. (make a backup before you mess with this file). If you just want to test it out, make a copy of the skin and switch to it on your wiki. Anyone using another skin will have whatever options are available through that skin. So you may have to edit the others or remove them. On my intranet wiki, everyone will be using MonoBook and there won’t be any other skins at all.

Examples:
If you want to remove the permalink button from the toolbox, find the if/elseif section for permalink. I replaced “nav_urls” with “ROOTNINJA” in mine so it will always skip both.

if(!empty($this->data['ROOTNINJA']['permalink']['href'])) { ?>
      <li id="t-permalink"><a href="<?php echo htmlspecialchars($this->data['nav_urls']['permalink']['href'])
      ?>"<?php echo $this->skin->tooltipAndAccesskey('t-permalink') ?>><?php $this->msg('permalink') ?></a></li><?php
} elseif ($this->data['ROOTNINJA']['permalink']['href'] === '') { ?>
      <li id="t-ispermalink"<?php echo $this->skin->tooltip('t-ispermalink') ?>><?php $this->msg('permalink') ?></li><?php
}

I’ll delete the What links here page by randomly throwing in something orange when it looks for ‘notspecialpage’.

if($this->data['SOMETHINGORANGEnotspecialpage']) { ? >

And delete the printable version link by mucking up its section too.

if(!empty($this->data['AKSDJFKAJFGLDSF']['print']['href'])) { ?>

Here’s how to just make the whole toolbox appear only for logged in users.

function toolbox() {
?>
   <div class="portlet" id="p-tb">

    <?php if($this->data['loggedin']) { ?>

<h5><?php $this->msg('toolbox') ?></h5>
<div class="pBody">
     <ul>
...
...
            wfRunHooks( 'MonoBookTemplateToolboxEnd', array( &$this ) );
            wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) );
?>
                    </ul>
            </div>

     <?php } ?>

    </div>
<?php
    }

Here’s how mine looks:

If you want to trim the navigation part of the sidebar, that’s built right in. Just go to Mediawiki:Sidebar and edit that page.

The default for that page is this list:

* navigation
** mainpage|mainpage-description
** portal-url|portal
** currentevents-url|currentevents
** recentchanges-url|recentchanges
** randompage-url|randompage
** helppage|help
* SEARCH
* TOOLBOX
* LANGUAGES

If you want to remove the current events and portal, just remove those two lines and save the page.

Posted by admica   @   10 March 2009

Related Posts

Like this post? Share it!

Digg Twitter StumbleUpon Delicious Technorati Facebook RSS

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Random conversations with strangers through Project Upstream
Next Post
I configured $wgSMTP in LocalSettings.php, but password resets just weren’t working… »
Powered by Wordpress   |   Lunated designed by ZenVerse