User:Jabrwocky7/theorytab.php

From Lostpedia

Jump to: navigation, search

Below is the code for the 'theorytab.php' extension written for Lostpedia.

This version has a few bugfixes that have not been uploaded to Lostpedia Prod yet.


<?php

if(!defined('MEDIAWIKI')) {
   header("HTTP/1.1 404 Not Found");
   die('<H1>404 Not found</H1>');
   }

/**
 * A hook that adds a theories tab to Lostpedia
 *
 * @package MediaWiki
 * @subpackage Extensions
 *
 * @author Jabberwock @ Lostpedia
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 */
$wgExtensionFunctions[] = 'wfTheoryTab';
$wgExtensionCredits['other'][] = array(
    'name' => 'Theory Tab',
    'description' => 'Adds a theories tab to articles',
    'author' => '[http://lostpedia.com/wiki/User:jabrwocky7 Jabberwock]'
);

# Enable subpages in the main namespace
$wgNamespacesWithSubpages[NS_MAIN] = true;

//install extension hooks
$wgHooks['SkinTemplateTabs'][] = 'TheoryTabHook';


// Intialize 
function wfTheoryTab() {
  global $wgMessageCache, $wgParser, $wgUser, $wgVersion;

// add a tab on the article page
function TheoryTabHook(&$skin , &$content_actions ) {
  global $wgTitle, $tMain, $tTheory, $tHREF, $tTheoryTabName, $tParentTabName, $tAction;

  $tMain = $wgTitle->getLocalUrl('');
  $tTheory = "/Theories";
  $tHREF = $tMain.$tTheory;
  $tTheoryTabName = 'Theories';
  $tParentTabName = 'Main Article';
  $tAction = '?action=edit';
  
//create the theory tab for regular articles in NS_MAIN namespace
if ( $wgTitle->getNamespace() == NS_MAIN 
     && $wgTitle->isTalkPage() !== 1 
     && strstr($wgTitle->getLocalUrl(''),"Main_Page") == FALSE 
     && strstr($wgTitle->getLocalUrl(''),"Portal:") == FALSE 
     && strstr($wgTitle->getLocalUrl(''),"Category:") == FALSE 
     && strstr($wgTitle->getLocalUrl(''),"Template:") == FALSE 
     && strstr($wgTitle->getLocalUrl(''),$tTheoryTabName) == FALSE ) {
  
  $content_actions['TheoryTab'] = array(
    'text'  => $tTheoryTabName,
    'href'  => $tHREF
    );
  }


//If already on the theory page, make a tab for the parent article.
if ( strstr($wgTitle->getLocalUrl(''),$tTheoryTabName) == TRUE
     && $wgTitle->isTalkPage() !== 1 
     && strstr($wgTitle->getLocalUrl(''),"Main_Page") == FALSE 
     && strstr($wgTitle->getLocalUrl(''),"Portal:") == FALSE 
     && strstr($wgTitle->getLocalUrl(''),"Category:") == FALSE 
     && strstr($wgTitle->getLocalUrl(''),"Template:") == FALSE  ) {
  
  $tMain = substr_replace ($tMain, '', -(strlen($tTheory)));
  $content_actions['TheoryTab'] = array(
    'text'  => $tParentTabName,
    'href'  => $tMain
    );
  }

}//endfunction wfTheoryTabHook


}//endfunction wfTheoryTab


?>