Extension:MyVariables

This extension is a small example snippet of code which goes into the LocalSettings.php script, and allows the addition of new built in variables. The code snippet adds two example variables, and , which serve as examples to follow when adding others for your own use.

MediaWiki Versions

 * It works on all 1.6.x's
 * Does not work on 1.9.x currently

We first loop through our new variable names and add them to the MediaWiki variable environment, foreach(array('CURRENTUSER','LOGO') as $name) { $wgVariableIDs[] = $index = count($magicWords); define($magicWords[] = "MAG_$name",$index); $wgMagicWordsEn[$index] = array(1,$name); } Then we add a function to the ParserGetVariableValueSwitch hook which can calculate the values of our new variables: $wgHooks['ParserGetVariableValueSwitch'][] = 'GetVariable'; function GetVariable(&$this,&$cache,&$index,&$ret) { if ($index == MAG_CURRENTUSER) $ret = $GLOBALS['wgUser']->mName; else if ($index == MAG_LOGO) $ret = $GLOBALS['wgLogo']; return true; }

This extension should not be confused with VariablesExtension, which allows the use of variables in the computer programming sense.