Extension:ExtraMagic

From Organic Design wiki
Revision as of 00:29, 29 May 2008 by Nad (talk | contribs) (Add some useful magic words)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<?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');

$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;

} return true; }