Difference between revisions of "Extension:ExtraMagic"

From Organic Design wiki
(IPADDRESS)
(NUMBERINGOFF)
Line 2: Line 2:
 
# Add some useful magic words{{php}}{{Category:Extensions|ExtraMagic}}
 
# Add some useful magic words{{php}}{{Category:Extensions|ExtraMagic}}
  
$wgCustomVariables = array('CURRENTUSER', 'CURRENTLANG', 'CURRENTSKIN', 'IPADDRESS');
+
$wgCustomVariables = array('CURRENTUSER', 'CURRENTLANG', 'CURRENTSKIN', 'IPADDRESS', 'NUMBERINGOFF');
  
 
$wgHooks['MagicWordMagicWords'][]          = 'wfAddCustomVariable';
 
$wgHooks['MagicWordMagicWords'][]          = 'wfAddCustomVariable';
Line 56: Line 56:
 
break;
 
break;
  
 +
case MAG_NUMBERINGOFF:
 +
global $wgUser;
 +
$wgUser->setOption('numberheadings', false);
 +
$ret = '';
 +
break;
 
}
 
}
 
return true;
 
return true;
 
}
 
}

Revision as of 12:14, 6 August 2008

<?php

  1. Add some useful magic wordsTemplate:Php
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

$wgCustomVariables = array('CURRENTUSER', 'CURRENTLANG', 'CURRENTSKIN', 'IPADDRESS', 'NUMBERINGOFF');

$wgHooks['MagicWordMagicWords'][] = 'wfAddCustomVariable'; $wgHooks['MagicWordwgVariableIDs'][] = 'wfAddCustomVariableID'; $wgHooks['LanguageGetMagic'][] = 'wfAddCustomVariableLang'; $wgHooks['ParserGetVariableValueSwitch'][] = 'wfGetCustomVariable';

function wfAddCustomVariable(&$magicWords) { global $wgCustomVariables; foreach($wgCustomVariables as $var) $magicWords[] = "MAG_$var"; return true; }

function wfAddCustomVariableID(&$variables) { global $wgCustomVariables; foreach($wgCustomVariables as $var) $variables[] = constant("MAG_$var"); return true; }

function wfAddCustomVariableLang(&$langMagic, $langCode = 0) { global $wgCustomVariables; foreach($wgCustomVariables as $var) { $magic = "MAG_$var"; $langMagic[defined($magic) ? constant($magic) : $magic] = array(0,$var); } return true; }

function wfGetCustomVariable(&$parser,&$cache,&$index,&$ret) { switch ($index) {

case MAG_CURRENTUSER: global $wgUser; $parser->disableCache(); $ret = $wgUser->mName; break;

case MAG_CURRENTLANG: global $wgUser; $parser->disableCache(); $ret = $wgUser->getOption('language'); break;

case MAG_CURRENTSKIN: global $wgUser; $parser->disableCache(); $ret = $wgUser->getOption('skin'); break;

case MAG_IPADDRESS: $parser->disableCache(); $ret = $_SERVER['REMOTE_ADDR']; break;

case MAG_NUMBERINGOFF: global $wgUser; $wgUser->setOption('numberheadings', false); $ret = ; break; } return true; }