Changing Location of Tabs (Modifying a MediaWiki Extension)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
philbar
Forum Newbie
Posts: 1
Joined: Sun Mar 23, 2008 1:45 am

Changing Location of Tabs (Modifying a MediaWiki Extension)

Post by philbar »

Hello,

I'm using a MediaWiki extension called CommentPages. It adds a commentary tab to article page of a mediawiki site. I would like to change the location of this tab from before the "Edit" tab to before the "Discussion" tab. Here is the code:

Code: Select all

<?php
$wgExtensionMessagesFiles['CommentPages'] = dirname(__FILE__) . '/CommentPages.i18n.php';
$wgHooks['SkinTemplateTabs'][]  = 'wfCommentPagesSkinTemplateTabs';
 
function wfCommentPagesSkinTemplateTabs ( &$skin, &$content_actions )
{
    global $wgContLang, $wgCommentPagesNS;
 
    wfLoadExtensionMessages( 'CommentPages' );
 
    $pagename = $skin->mTitle->getText();
    $namespace = $skin->mTitle->getNamespace();
    $class = '';
    $page = '';
    $query = '';
 
    if ($namespace == NS_MAIN || $namespace == NS_TALK) {
        $comments = Title::newFromText($wgContLang->getNSText($wgCommentPagesNS).':'.$pagename);
        $newcontent_actions = array();
 
        if (!$comments->exists()) {
            $class = 'new';
            $query = 'action=edit';
 
            if (wfMsg('commenttab-preload') != '') {
                $query .= '&preload='.wfMsg('commenttab-preload');
            }
 
            if (wfMsg('commenttab-editintro') != '') {
                $query .= '&editintro='.wfMsg('commenttab-editintro');
            }
        } else {
            $class = '';
        }
 
        foreach ($content_actions as $key => $value) {
            // Insert the comment tab before the edit link
            if ($key == 'edit') {
                $newcontent_actions['comments'] = array(
                    'class' => $class,
                    'text'  => wfMsg('nstab-comments'),
                    'href'  => $comments->getFullURL($query),
                );
            }
            $newcontent_actions[$key] = $value;
        }
 
        $content_actions = $newcontent_actions;
    } elseif ($skin->mTitle->getNamespace() == $wgCommentPagesNS) {
        $main = Title::newFromText($pagename);
        $talk = $main->getTalkPage();
        $newcontent_actions = array();
 
        if (!$main->exists()) {
            $class = 'new';
            $query = 'action=edit';
        } else {
            $class = '';
            $query = '';
        }
 
        $newcontent_actions['article'] = array(
            'class' => $class,
            'text'  => wfMsg( 'nstab-main' ),
            'href'  => $main->getFullURL($query),
        );
 
        if (!$talk->exists()) {
            $class = 'new';
            $query = 'action=edit';
        } else {
            $class = '';
            $query = '';
        }
        $newcontent_actions['talk'] = array(
            'class' => $class,
            'text'  => wfMsg( 'talk' ),
            'href'  => $talk->getFullURL($query),
        );
 
        foreach ($content_actions as $key => $value) {
            if ($key != 'talk')
                $newcontent_actions[$key] = $value;
 
            if ($key == 'nstab-comments')
                $newcontent_actions['nstab-comments']['text'] = wfMsg( 'nstab-comments' );
        }
 
        $content_actions = $newcontent_actions;
    }
 
    return true;
}
 
I modified the following part which moved the tab like I want it, but it doesn't seem to work if the current page is the "commentary" page:

Code: Select all

Before:
            // Insert the comment tab before the edit link
            if ($key == 'edit') {
 
After:
            // Insert the comment tab before the discussion link
            if ($key == 'talk') {
 
Here is a link to the page that isn't working properly:
http://www.cabanga.org/library/Commenta ... Holy_Bible

Click between the Commentary and Article tabs to see the Commentary tab move.


I've scanned the code many times and cannot find the culprit. Can anyone help me figure out why this is not working?
Post Reply