Variables extension

From FollowTheScore
Revision as of 10:20, 28 January 2008 by Gero (talk | contribs) (New page: This is a slightly modified version of the <big>'''VariablesExtension extension'''</big>. It contains a bugfix which avoids a runtime error in function ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is a slightly modified version of the VariablesExtension extension. It contains a bugfix which avoids a runtime error in function 'varf'.

Here is the modified source code.

<?php
 
if ( !defined( 'MEDIAWIKI' ) ) {
    die( 'This file is a MediaWiki extension, it is not a valid entry point' );
}
 
$wgExtensionFunctions[] = 'wfSetupVariables';
 
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'Variables',
        'url' => 'http://www.mediawiki.org/wiki/Extension:VariablesExtension',
        'author' => 'Rob Adams',
        'description' => 'Define page-scoped variables'
);
 
$wgHooks['LanguageGetMagic'][]       = 'wfVariablesLanguageGetMagic';
 
class ExtVariables {
    var $mVariables;
 
    function vardefine( &$parser, $expr = '', $value = '' ) {
        $this->mVariables[$expr] = $value;
        return '';
    }
 
    function varf( &$parser, $expr = '' ) {
	    if (isset($this->mVariables) && array_key_exists($expr,$this->mVariables)) return $this->mVariables[$expr];
	    return '';
    }
}
 
function wfSetupVariables() {
    global $wgParser, $wgMessageCache, $wgExtVariables, $wgMessageCache, $wgHooks;
 
    $wgExtVariables = new ExtVariables;
 
    $wgParser->setFunctionHook( 'vardefine', array( &$wgExtVariables, 'vardefine' ) );
    $wgParser->setFunctionHook( 'var', array( &$wgExtVariables, 'varf' ) );
}
 
function wfVariablesLanguageGetMagic( &$magicWords, $langCode ) {
        require_once( dirname( __FILE__ ) . '/Variables.i18n.php' );
        foreach( efVariablesWords( $langCode ) as $word => $trans )
                $magicWords[$word] = $trans;
        return true;
}

?>