Extension:MyVariables

Материал из ЕЖЕВИКА-Публикаций - pubs.EJWiki.org - Вики-системы компетентных публикаций по еврейским и израильским темам
Перейти к: навигация, поиск

<?php /** * @file * @ingroup Extensions * @author Iris Mersel, thanks to Aran Dunkley for help * @copyright © 2012 * $Made for www.ejwiki-pubs.org */ if( !defined( 'MEDIAWIKI' ) ) die( "Not an entry point." ); define( 'MYVARIABLES_VERSION', "1.1, 2012-11-08" ); /** REGISTRATION */ $wgExtensionCredits['parserhook'][] = array( 'path' => __FILE__, 'name' => 'MyVariables', 'url' => 'http://www.ejwiki-pubs.org/wiki/Extension:MyVariables', 'author' => array( 'Iris Mersel'), 'description' => 'Uses additional variables, like CustomTitle, CustomName and allows assign them via tags in page source', 'version' => MYVARIABLES_VERSION ); /** EXTENSION */ $wgCustomVariables = array('CUSTOMTITLE','CUSTNAME'); $wgMyVar=array('custtitle','custname'); $wgHooks['MagicWordMagicWords'][] = 'wfAddCustomVariable'; $wgHooks['MagicWordwgVariableIDs'][] = 'wfAddCustomVariableID'; $wgHooks['LanguageGetMagic'][] = 'wfAddCustomVariableLang'; $wgHooks['ParserGetVariableValueSwitch'][] = 'wfGetCustomVariable'; $wgHooks['ParserFirstCallInit'][] = 'wfParserInit'; function wfAddCustomVariable(&$magicWords) { $magicWords[] = "MAG_CUSTOMTITLE"; $magicWords[] = "MAG_CUSTOMNAME"; return true; } function wfAddCustomVariableID(&$variables) { $variables[] = "MAG_CUSTOMTITLE"; $variables[] = "MAG_CUSTOMNAME"; return true; } function wfAddCustomVariableLang(&$langMagic, $langCode = 0) { $magic = 'MAG_CUSTOMTITLE'; $langMagic[defined($magic) ? constant($magic) : $magic] = array(0,'CUSTOMTITLE'); $magic = 'MAG_CUSTOMNAME'; $langMagic[defined($magic) ? constant($magic) : $magic] = array(0,'CUSTOMNAME'); return true; } function wfGetCustomVariable(&$parser,&$cache,&$index,&$ret) { global $wgMyVar; switch ($index) { case 'MAG_CUSTOMTITLE': $parser->disableCache(); # Mark this content as uncacheable $ret=$wgMyVar['custtitle']; break; case 'MAG_CUSTOMNAME': $parser->disableCache(); # Mark this content as uncacheable $ret=$wgMyVar['custname']; break; } return true; } function wfParserInit( Parser $parser ) { // When the parser sees the <sample> tag, it executes // the wfSampleRender function (see below) $parser->setHook( 'custtitle', 'wfTitleRender' ); $parser->setHook( 'custname', 'wfNameRender' ); // Always return true from this function. The return value does not denote // success or otherwise have meaning - it just must always be true. return true; } function wfTitleRender($text, $args, $parser, $frame ) { global $wgMyVar; $a='custtitle'; $output = $parser->recursiveTagParse( $text ); $wgMyVar[$a]=$output; return ""; } function wfNameRender($text, $args, $parser, $frame ) { global $wgMyVar; $a='custname'; $output = $parser->recursiveTagParse( $text ); $wgMyVar[$a]=$output; return ""; }