Difference between revisions of "Extension:ExtraMagic"
(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
- Add some useful magic wordsTemplate:Php
$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; }