[Mediawiki-l] Defining custom variables

Schmid, Wolfgang W.Schmid at t-systems.com
Fri Oct 12 10:55:42 UTC 2007


I want to define some custom variable returning server specific
content.
As first step I tried to operate the 1st example from
http://www.mediawiki.org/wiki/Manual:Variables
(see listing below, I've only removed several comment lines)

This example doesn't work. If I create a test page containing 
{{NiftyVar}}, MW treats this as a template and not a variable.

I think there're some errors in it.
I didn't find a variable $wfHook in the whole wiki.
Thus I think it's $wgHook and the two $wfHook lines in step 2 and 5
should be:
$wgHooks['...'][] = '...';

But this also doesn't work.
Do you have any hints anything else could be wrong in this example.

MW version 1.11.0

Thanks for your help
Wolfgang

----- Example code from Manual:Variables -----

# Step 1: choose a magic word id
define('MAG_NIFTYVAR', 'mycustomvar1');

# Step 2: define some words to use in wiki markup
$wfHooks['LanguageGetMagic'] = 'wfMyWikiWords';
function wfMyWikiWords(&$aWikiWords, &$langID) {
  $aWikiWords[MAG_NIFTYVAR] = array(0, 'NiftyVar','CoolVar');
  return true;
}

# Step 3: assign a value to our variable
$wgHooks['ParserGetVariableValueSwitch'][] = 'wfMyAssignAValue';
function wfMyAssignAValue(&$parser, &$cache, &$magicWordId, &$ret) {
  if (MAG_NIFTYVAR == $magicWordId) {
     $ret='This is a really silly value';
     return false;
  } else {
     return true;
  }
}

# Step 4: register the custom variables so that it
$wgExtensionCredits['variable'][] = array(
       'name' => 'NiftyVar',
       'author' =>'John Doe',
       'url' => 'http://www.mediawiki.org/wiki/Extension:NiftyVar',
       'description' => 'This variable is an example and performs no
discernable function'
       );

# Step 5: register wiki markup words associated with
$wfHooks['MagicWordwgVariableIDs'] = 'wfMyDeclareVarIds';
function wfMyDeclareVarIds(&$aCustomVariableIds) {
  $aCustomVariableIds[] = MAG_NIFTYVAR;
  return true;
}



More information about the MediaWiki-l mailing list