URL: http://metabolomics.jp/ */ if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension, see GetEnvironment.php.' ); } $wgExtensionFunctions[] = 'efSetupGetEnvironment'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'GetEnvironment', 'version' => '0.1', 'author' => 'K, Suwa', 'description' => 'get php enviroment variables.', 'url' => 'http://metabolomics.jp/wiki/Help:Extension/GetEnvironment', ); $wgHooks['LanguageGetMagic'][] = 'efGetEnvironmentLanguageGetMagic'; class GetEnvFunctions { /** * Extracting string * e.g. {{#substring:Hello world|1}} => "ello world" * e.g. {{#substring:Hello world|1|4}} => "ell" * * @param $parser Parser Parent parser * @param $str string Target string * @param $start int Start index (including value) * @param $end int End index (not including value) * @return string Parts string */ function get( &$parser, $id ) { $id = strtolower( $id ); if( strcmp( $id, "lang" ) != 0 ){ return ""; } $langs = getenv( "HTTP_ACCEPT_LANGUAGE" ); if( strlen( $langs ) == 0 ){ return ""; } $a_lang = explode( ",", $langs ); return $a_lang[0]; } } function efSetupGetEnvironment() { global $wgParser; $geFunctions = new GetEnvFunctions; $wgParser->setFunctionHook( 'getenv', array( &$geFunctions, 'get' ) ); } function efGetEnvironmentLanguageGetMagic( &$magicWords, $langCode ) { $magicWords['getenv'] = array( 0, 'getenv' ); return true; }