Index: trunk/extensions/ParserFun/RELEASE-NOTES |
— | — | @@ -0,0 +1,13 @@ |
| 2 | + 'Parser Fun' Changelog:
|
| 3 | + =======================
|
| 4 | +
|
| 5 | + * (trunk) -- Version 0.1rc (initial release)
|
| 6 | + - Magic word prefix 'THIS:', which is working with basically all functions returning page related information:
|
| 7 | + 'FULLPAGENAME', 'PAGENAME', 'BASEPAGENAME', 'SUBPAGENAME', 'SUBJECTPAGENAME', 'TALKPAGENAME', 'NAMESPACE',
|
| 8 | + 'SUBJECTSPACE', 'ARTICLESPACE', 'TALKSPACE' and their URL-encoded equivalents (ending with '...EE').
|
| 9 | + - Hook 'GetThisVariableValueSwitch' allows to make other magic variables work with 'THIS:'.
|
| 10 | + - 'parse' parser function with following parameters:
|
| 11 | + + <1> - input text (required)
|
| 12 | + + unstrip - 'none', 'nowiki', 'general', 'all' to unstrip input first. Allows to parse text inside <nowiki>.
|
| 13 | + + parse - whether text should really be parsed (in case you want to unstrip only)
|
| 14 | + - Distributed under ISC license and put into mediawiki.org svn repository.a |
\ No newline at end of file |
Index: trunk/extensions/ParserFun/COPYING |
— | — | @@ -0,0 +1,13 @@ |
| 2 | +Copyright (c) 2011 by Daniel Werner < danweetz@web.de >
|
| 3 | +
|
| 4 | +Permission to use, copy, modify, and/or distribute this software for any
|
| 5 | +purpose with or without fee is hereby granted, provided that the above
|
| 6 | +copyright notice and this permission notice appear in all copies.
|
| 7 | +
|
| 8 | +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
| 9 | +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 10 | +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
| 11 | +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 12 | +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 13 | +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
| 14 | +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
\ No newline at end of file |
Index: trunk/extensions/ParserFun/PFun_Parse.php |
— | — | @@ -0,0 +1,176 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class for the '#parse' parser function. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file PFun_Parse.php |
| 10 | + * @ingroup ParserFun |
| 11 | + * |
| 12 | + * @author Daniel Werner |
| 13 | + */ |
| 14 | +class ParserFunParse extends ParserHook { |
| 15 | + |
| 16 | + /** |
| 17 | + * Whether or not the input text should be parsed by Parser::braceSubstitution() |
| 18 | + * after the function has returned its value (this is possible by returning function |
| 19 | + * result as array with 'noparse' set to false). |
| 20 | + * This is always set to 'true' for new MW versions which support object style parser |
| 21 | + * function arguments sinc we call the parsing process manually in this case. |
| 22 | + * |
| 23 | + * @since 0.1 |
| 24 | + * |
| 25 | + * @var boolean |
| 26 | + */ |
| 27 | + protected $postParse_fallback; |
| 28 | + |
| 29 | + public function __construct() { |
| 30 | + // make this a parser function extension (no tag extension) only: |
| 31 | + parent::__construct( false, true ); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * No LSB in pre-5.3 PHP, to be refactored later |
| 36 | + */ |
| 37 | + public static function staticMagic( array &$magicWords, $langCode ) { |
| 38 | + $instance = new self; |
| 39 | + return $instance->magic( $magicWords, $langCode ); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * No LSB in pre-5.3 PHP, to be refactored later |
| 44 | + */ |
| 45 | + public static function staticInit( Parser &$parser ) { |
| 46 | + global $egParserFunDisabledFunctions; |
| 47 | + if( ! in_array( 'parse', $egParserFunDisabledFunctions ) ) { |
| 48 | + // only register function if not disabled by configuration |
| 49 | + $instance = new self; |
| 50 | + $instance->init( $parser ); |
| 51 | + } |
| 52 | + return true; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Gets the name of the parser hook. |
| 57 | + * @see ParserHook::getName |
| 58 | + * |
| 59 | + * @return string |
| 60 | + */ |
| 61 | + protected function getName() { |
| 62 | + return 'parse'; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Returns an array containing the parameter info. |
| 67 | + * @see ParserHook::getParameterInfo |
| 68 | + * |
| 69 | + * @return array |
| 70 | + */ |
| 71 | + protected function getParameterInfo( $type ) { |
| 72 | + $params = array(); |
| 73 | + |
| 74 | + # input text. |
| 75 | + # since 0.1 |
| 76 | + $params['text'] = new Parameter( 'text' ); |
| 77 | + |
| 78 | + # if 'true', this will prevent parsing. Usful if something should be unstripped only. |
| 79 | + # since 0.1 |
| 80 | + $params['parse'] = new Parameter( 'parse', Parameter::TYPE_BOOLEAN ); |
| 81 | + $params['parse']->setDefault( true ); |
| 82 | + |
| 83 | + # Whether the input text should be unstripped first. |
| 84 | + # since 0.1 |
| 85 | + $params['unstrip'] = new Parameter( 'unstrip', Parameter::TYPE_STRING ); |
| 86 | + $params['unstrip']->addCriteria( new CriterionInArray( 'none', 'nowiki', 'general', 'all' ) ); |
| 87 | + $params['unstrip']->setDefault( 'none' ); |
| 88 | + |
| 89 | + /** |
| 90 | + * @ToDo: Perhaps a 'context' parameter would be quite interesting. |
| 91 | + */ |
| 92 | + |
| 93 | + return $params; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Returns the list of default parameters. |
| 98 | + * @see ParserHook::getDefaultParameters |
| 99 | + * |
| 100 | + * @return array |
| 101 | + */ |
| 102 | + protected function getDefaultParameters( $type ) { |
| 103 | + return array( |
| 104 | + array( 'text', Validator::PARAM_UNNAMED ), |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Returns the parser function otpions. |
| 110 | + * @see ParserHook::getFunctionOptions |
| 111 | + * |
| 112 | + * @return array |
| 113 | + */ |
| 114 | + protected function getFunctionOptions() { |
| 115 | + return array( |
| 116 | + 'noparse' => !$this->postParse_fallback, |
| 117 | + 'isHTML' => false |
| 118 | + ); |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Renders and returns the output. |
| 123 | + * @see ParserHook::renderTag |
| 124 | + * |
| 125 | + * @param array $parameters |
| 126 | + * |
| 127 | + * @return string |
| 128 | + */ |
| 129 | + public function render( array $parameters ) { |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + $text = $parameters['text']; |
| 134 | + |
| 135 | + // current parsers StripState object |
| 136 | + $stripState = $this->parser->mStripState; |
| 137 | + |
| 138 | + switch( $parameters['unstrip'] ) { |
| 139 | + |
| 140 | + // case 'none': <do nothing> |
| 141 | + |
| 142 | + case 'nowiki': |
| 143 | + $text = $stripState->unstripNoWiki( $text ); |
| 144 | + break; |
| 145 | + |
| 146 | + case 'general': |
| 147 | + $text = $stripState->unstripGeneral( $text ); |
| 148 | + break; |
| 149 | + |
| 150 | + case 'all': |
| 151 | + $text = $stripState->unstripBoth( $text ); |
| 152 | + break; |
| 153 | + } |
| 154 | + |
| 155 | + // parse if $frame is set (new MW versions) and parsing is not disabled for this one: |
| 156 | + if( $this->frame !== null && $parameters['parse'] === true ) { |
| 157 | + |
| 158 | + // we don't need the fallback since $frame is given: |
| 159 | + $this->postParse_fallback = false; |
| 160 | + |
| 161 | + /** |
| 162 | + * Doing the parsing here allows to parse <noinclude> / <includeonly> acording to the context |
| 163 | + * of where the function is defined and called. IF we use the parser function 'noparse' return |
| 164 | + * value, it would always be parsed like a page view meaning <includeonly> content would appear. |
| 165 | + */ |
| 166 | + $text = $this->parser->preprocessToDom( $text, $this->frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); |
| 167 | + $text = trim( $this->frame->expand( $text ) ); |
| 168 | + } |
| 169 | + else { |
| 170 | + // fallback for old MW versions or in case the 'parse' #parse parameter is set to false |
| 171 | + $this->postParse_fallback = $parameters['parse']; |
| 172 | + } |
| 173 | + |
| 174 | + return $text; |
| 175 | + } |
| 176 | + |
| 177 | +} |
Property changes on: trunk/extensions/ParserFun/PFun_Parse.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 178 | + native |
Index: trunk/extensions/ParserFun/ParserFun.i18n.magic.php |
— | — | @@ -0,0 +1,37 @@ |
| 2 | +<?php |
| 3 | +#coding: utf-8 |
| 4 | + |
| 5 | +/** |
| 6 | + * Internationalization file for magic words of the 'Parser Fun' extension. |
| 7 | + * |
| 8 | + * @since 0.1 |
| 9 | + * |
| 10 | + * @file ParserFun.i18n.magic.php |
| 11 | + * @ingroup ParserFun |
| 12 | + * @author Daniel Werner < danweetz@web.de > |
| 13 | + */ |
| 14 | + |
| 15 | +$magicWords = array(); |
| 16 | + |
| 17 | +/** English |
| 18 | + * @author Daniel Werner |
| 19 | + */ |
| 20 | +$magicWords['en'] = array( |
| 21 | + 'parse' => array( false, 'parse' ), |
| 22 | + ExtParserFun::MAG_THIS => array( 1, 'THIS' ), |
| 23 | +); |
| 24 | + |
| 25 | +/** Message documentation (Message documentation) |
| 26 | + * @author Daniel Werner |
| 27 | + */ |
| 28 | +$messages['qqq'] = array( |
| 29 | + 'parse' => array( 1, 'Keyword to put in front of a variable like "{{THIS:PAGENAME}}". This will output the pagename of the page where it is defined on instead of the page actually being parsed. "THIS" refers to that page.' ), |
| 30 | +); |
| 31 | + |
| 32 | +/** German (Deutsch) |
| 33 | + * @author Daniel Werner |
| 34 | + */ |
| 35 | +$magicWords['de'] = array( |
| 36 | + 'parse' => array( false, 'parse' ), |
| 37 | + ExtParserFun::MAG_THIS => array( 1, 'DIESER', 'DIESE', 'DIESES' ), |
| 38 | +); |
Property changes on: trunk/extensions/ParserFun/ParserFun.i18n.magic.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 39 | + native |
Index: trunk/extensions/ParserFun/ParserFun.i18n.php |
— | — | @@ -0,0 +1,28 @@ |
| 2 | +<?php |
| 3 | +#coding: utf-8 |
| 4 | + |
| 5 | +/** |
| 6 | + * Internationalization file of the 'Parser Fun' extension. |
| 7 | + * |
| 8 | + * @since 0.1 |
| 9 | + * |
| 10 | + * @file ParserFun.i18n.php |
| 11 | + * @ingroup ParserFun |
| 12 | + * @author Daniel Werner < danweetz@web.de > |
| 13 | + */ |
| 14 | + |
| 15 | +$messages = array(); |
| 16 | + |
| 17 | +/** English |
| 18 | + * @author Daniel Werner |
| 19 | + */ |
| 20 | +$messages['en'] = array( |
| 21 | + 'parserfun-desc' => "Adds a parser function <code>#parse</code> for parsing wikitext and introduces <code>THIS:</code> prefix for page information related magic variables", |
| 22 | +); |
| 23 | + |
| 24 | +/** German (Deutsch) |
| 25 | + * @author Daniel Werner |
| 26 | + */ |
| 27 | +$messages['de'] = array( |
| 28 | + 'parserfun-desc' => "Macht eine Parser-Funktion <code>#parse</code> zum Parsen von Wikitext verfügbar und führt das <code>THIS:</code> Präfix für von Wiki-Seiten Information beziehende Variablen ein" |
| 29 | +); |
Property changes on: trunk/extensions/ParserFun/ParserFun.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 30 | + native |
Index: trunk/extensions/ParserFun/ParserFun.php |
— | — | @@ -0,0 +1,264 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * 'Parser Fun' adds a parser function '#parse' for parsing wikitext and introduces the |
| 6 | + * 'THIS:' prefix for page information related magic variables |
| 7 | + * |
| 8 | + * Documentation: http://www.mediawiki.org/wiki/Extension:Parser_Fun |
| 9 | + * Support: http://www.mediawiki.org/wiki/Extension_talk:Parser_Fun |
| 10 | + * Source code: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/ParserFun |
| 11 | + * |
| 12 | + * @version: 0.1rc |
| 13 | + * @license: ISC license |
| 14 | + * @author: Daniel Werner < danweetz@web.de > |
| 15 | + * |
| 16 | + * @file ParserFun.php |
| 17 | + * @ingroup Parse |
| 18 | + */ |
| 19 | + |
| 20 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 21 | + die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
| 22 | +} |
| 23 | + |
| 24 | +// Include the Validator extension if not loaded already: |
| 25 | +if ( ! defined( 'Validator_VERSION' ) ) { |
| 26 | + @include_once( dirname( __FILE__ ) . '/../Validator/Validator.php' ); |
| 27 | +} |
| 28 | + |
| 29 | +// Only initialize the extension when Validator extension is present: |
| 30 | +if ( ! defined( 'Validator_VERSION' ) ) { |
| 31 | + die( '<p><b>Error:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Parse">Parse</a>.</p>' ); |
| 32 | +} |
| 33 | + |
| 34 | + |
| 35 | +// Extension info & credits: |
| 36 | +$wgExtensionCredits['parserhook'][] = array( |
| 37 | + 'path' => __FILE__, |
| 38 | + 'name' => 'Parser Fun', |
| 39 | + 'descriptionmsg' => 'parserfun-desc', |
| 40 | + 'version' => ExtParserFun::VERSION, |
| 41 | + 'author' => '[http://www.mediawiki.org/wiki/User:Danwe Daniel Werner]', |
| 42 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:Parser_Fun', |
| 43 | +); |
| 44 | + |
| 45 | + |
| 46 | +// Include the settings file: |
| 47 | +require_once ExtParserFun::getDir() . '/ParserFun_Settings.php'; |
| 48 | + |
| 49 | + |
| 50 | +// magic words and message files: |
| 51 | +$wgExtensionMessagesFiles['ParserFun' ] = ExtParserFun::getDir() . '/ParserFun.i18n.php'; |
| 52 | +$wgExtensionMessagesFiles['ParserFunMagic'] = ExtParserFun::getDir() . '/ParserFun.i18n.magic.php'; |
| 53 | + |
| 54 | + |
| 55 | +$wgHooks['ParserFirstCallInit' ][] = 'ExtParserFun::init'; |
| 56 | + |
| 57 | + |
| 58 | +// for magic word 'THISPAGENAME': |
| 59 | +$wgHooks['MagicWordwgVariableIDs'][] = 'ExtParserFun::onMagicWordwgVariableIDs'; |
| 60 | + |
| 61 | +$wgHooks['MagicWordwgVariableIDs' ][] = 'ExtParserFun::onMagicWordwgVariableIDs'; |
| 62 | +$wgHooks['ParserGetVariableValueSwitch'][] = 'ExtParserFun::onParserGetVariableValueSwitch'; |
| 63 | + |
| 64 | + |
| 65 | +// 'parse' parser function initialization: |
| 66 | +$wgAutoloadClasses['ParserFunParse'] = ExtParserFun::getDir() . '/PFun_Parse.php'; |
| 67 | + |
| 68 | +$wgHooks['ParserFirstCallInit'][] = 'ParserFunParse::staticInit'; |
| 69 | +$wgHooks['LanguageGetMagic' ][] = 'ParserFunParse::staticMagic'; |
| 70 | + |
| 71 | + |
| 72 | +/** |
| 73 | + * Extension class of the 'Parser Fun' extension. |
| 74 | + * Handling the functionality around the 'THIS' magic word feature. |
| 75 | + */ |
| 76 | +class ExtParserFun { |
| 77 | + |
| 78 | + /** |
| 79 | + * Version of the 'Parser Fun' extension. |
| 80 | + * |
| 81 | + * @since 0.1 |
| 82 | + * |
| 83 | + * @var string |
| 84 | + */ |
| 85 | + const VERSION = '0.1rc'; |
| 86 | + |
| 87 | + const MAG_THIS = 'this'; |
| 88 | + |
| 89 | + public static function init( Parser &$parser ) { |
| 90 | + global $egParserFunDisabledFunctions; |
| 91 | + if( ! in_array( self::MAG_THIS, $egParserFunDisabledFunctions ) ) { |
| 92 | + // only register function if not disabled by configuration |
| 93 | + $parser->setFunctionHook( self::MAG_THIS, array( __CLASS__, 'this_' ), SFH_NO_HASH | SFH_OBJECT_ARGS ); |
| 94 | + } |
| 95 | + return true; |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Returns the extensions base installation directory. |
| 100 | + * |
| 101 | + * @since 0.1 |
| 102 | + * |
| 103 | + * @return boolean |
| 104 | + */ |
| 105 | + public static function getDir() { |
| 106 | + static $dir = null; |
| 107 | + |
| 108 | + if( $dir === null ) { |
| 109 | + $dir = dirname( __FILE__ ); |
| 110 | + } |
| 111 | + return $dir; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Magic word 'THIS:' to return certain information about the page the word actually is defined on |
| 116 | + */ |
| 117 | + static function this_( Parser &$parser, PPFrame $frame = null, $args = null ) { |
| 118 | + // if MW version is too old or something is wrong: |
| 119 | + if( $frame === null || $frame->title === null ) { |
| 120 | + return ''; |
| 121 | + } |
| 122 | + |
| 123 | + // get part behind 'THIS:' if only 'THIS', use 'FULLPAGENAME' |
| 124 | + $index = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
| 125 | + |
| 126 | + $newArgs = array(); |
| 127 | + |
| 128 | + if( $index !== '' ) { |
| 129 | + // clean up arguments as if first argument never were set: |
| 130 | + unset( $args[0] ); |
| 131 | + foreach( $args as $arg ) { |
| 132 | + $newArgs[] = $arg; |
| 133 | + } |
| 134 | + |
| 135 | + // get magic word ID of the variable name: |
| 136 | + $mwId = self::getVariablesMagicWordId( $parser, $index ); |
| 137 | + if( $mwId === null ) { |
| 138 | + // requested variable doesn't exist, make the thing a template call |
| 139 | + return array( null, 'found' => false ); |
| 140 | + } |
| 141 | + } |
| 142 | + else { |
| 143 | + // if only '{{THIS}}', set magic word id to 'FULLPAGENAME' |
| 144 | + $mwId = 'fullpagename'; |
| 145 | + } |
| 146 | + |
| 147 | + // get value: |
| 148 | + $out = self::getThisVariableValue( $mwId, $parser, $frame, $newArgs ); |
| 149 | + if( $out === null ) { |
| 150 | + // requested variable doesn't support 'THIS:', make the thing a template call |
| 151 | + return array( null, 'found' => false ); |
| 152 | + } |
| 153 | + |
| 154 | + return $out; |
| 155 | + |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Returns the magic word ID for a variable like the user would write it. Returns null in case there |
| 160 | + * is no word for the given variables name. |
| 161 | + * |
| 162 | + * @param Parser $parser |
| 163 | + * @param type $word |
| 164 | + * @return string|null |
| 165 | + */ |
| 166 | + static function getVariablesMagicWordId( Parser $parser, $word ) { |
| 167 | + // get all local (including translated) magic words IDs (values) with their actual literals (keys) |
| 168 | + // for case insensitive [0] and sensitive [1] |
| 169 | + $magicWords = $parser->mVariables->getHash(); |
| 170 | + |
| 171 | + if( array_key_exists( strtolower( $word ), $magicWords[0] ) ) { |
| 172 | + // case insensitive word match |
| 173 | + $mwId = $magicWords[0][ strtolower( $word ) ]; |
| 174 | + } |
| 175 | + elseif( array_key_exists( $word, $magicWords[1] ) ) { |
| 176 | + // case sensitive word match |
| 177 | + $mwId = $magicWords[1][ $word ]; |
| 178 | + } |
| 179 | + else { |
| 180 | + // requested magic word doesn't exist for variables |
| 181 | + |
| 182 | + return null; |
| 183 | + } |
| 184 | + return $mwId; |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * Returns the value of a variable like '{{FULLPAGENAME}}' in the context of the given PPFrame objects |
| 189 | + * $frame->$title instead of the Parser objects subject. Returns null in case the requested variable |
| 190 | + * doesn't support {{THIS:}}. |
| 191 | + * |
| 192 | + * @param string $mwId magic word ID of the variable |
| 193 | + * @param Parser $parser |
| 194 | + * @param PPFrame $frame |
| 195 | + * @param array $args |
| 196 | + * |
| 197 | + * @return string|null |
| 198 | + */ |
| 199 | + static function getThisVariableValue( $mwId, Parser &$parser, $frame, $args = array() ) { |
| 200 | + $ret = null; |
| 201 | + $title = $frame->title; |
| 202 | + |
| 203 | + if( $title === null ) { |
| 204 | + return null; |
| 205 | + } |
| 206 | + |
| 207 | + // check whether info is available, e.g. 'THIS:FULLPAGENAME' requires 'FULLPAGENAME' |
| 208 | + switch( $mwId ) { |
| 209 | + case 'fullpagename': |
| 210 | + case 'fullpagenamee': |
| 211 | + case 'pagename': |
| 212 | + case 'pagenamee': |
| 213 | + case 'basepagename': |
| 214 | + case 'basepagenamee': |
| 215 | + case 'subpagename': |
| 216 | + case 'subpagenamee': |
| 217 | + case 'subjectpagename': |
| 218 | + case 'subjectpagenamee': |
| 219 | + case 'talkpagename': |
| 220 | + case 'talkpagenamee': |
| 221 | + case 'namespacee': // for 'namespace', see bottom |
| 222 | + case 'subjectspace': |
| 223 | + case 'subjectspacee': |
| 224 | + case 'talkspace': |
| 225 | + case 'talkspacee': |
| 226 | + // core parser function information requested |
| 227 | + $ret = CoreParserFunctions::$mwId( $parser, $title->getPrefixedText() ); |
| 228 | + break; |
| 229 | + |
| 230 | + case 'namespace': |
| 231 | + // 'namespace' function name was renamed as PHP 5.3 came along |
| 232 | + if( is_callable( 'CoreParserFunctions::mwnamespace' ) ) { |
| 233 | + $ret = CoreParserFunctions::mwnamespace( $parser, $title->getPrefixedText() ); |
| 234 | + } else { |
| 235 | + $ret = CoreParserFunctions::$mwId( $parser, $title->getPrefixedText() ); |
| 236 | + } |
| 237 | + break; |
| 238 | + |
| 239 | + default: |
| 240 | + // give other extensions a chance to hook up with this and return their own values: |
| 241 | + wfRunHooks( 'GetThisVariableValueSwitch', array( &$parser, $title, &$mwId, &$ret, &$frame, &$args ) ); |
| 242 | + } |
| 243 | + return $ret; |
| 244 | + } |
| 245 | + |
| 246 | + static function onParserGetVariableValueSwitch( Parser &$parser, &$cache, &$magicWordId, &$ret, $frame = null ) { |
| 247 | + switch( $magicWordId ) { |
| 248 | + /** THIS **/ |
| 249 | + case self::MAG_THIS: |
| 250 | + $ret = self::this_( $parser, $frame, null ); |
| 251 | + break; |
| 252 | + } |
| 253 | + return true; |
| 254 | + } |
| 255 | + |
| 256 | + static function onMagicWordwgVariableIDs( &$variableIds ) { |
| 257 | + global $egParserFunDisabledFunctions; |
| 258 | + if( ! in_array( self::MAG_THIS, $egParserFunDisabledFunctions ) ) { |
| 259 | + // only register variable if not disabled by configuration |
| 260 | + $variableIds[] = self::MAG_THIS; |
| 261 | + } |
| 262 | + return true; |
| 263 | + } |
| 264 | + |
| 265 | +} |
Property changes on: trunk/extensions/ParserFun/ParserFun.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 266 | + native |
Index: trunk/extensions/ParserFun/ParserFun_Settings.php |
— | — | @@ -0,0 +1,31 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File defining the settings for the 'Parser Fun' extension. |
| 6 | + * More info can be found at http://www.mediawiki.org/wiki/Extension:Parser_Fun#Configuration |
| 7 | + * |
| 8 | + * NOTICE: |
| 9 | + * ======= |
| 10 | + * Changing one of these settings can be done by copying and placing |
| 11 | + * it in LocalSettings.php, AFTER the inclusion of 'Parser Fun'. |
| 12 | + * |
| 13 | + * @file ParserFun_Settings.php |
| 14 | + * @ingroup ParserFun |
| 15 | + * @since 0.1 |
| 16 | + * |
| 17 | + * @author Daniel Werner |
| 18 | + */ |
| 19 | + |
| 20 | +/** |
| 21 | + * Allows to define which functionalities provided by 'Parser Fun' should be disabled for the wiki. |
| 22 | + * |
| 23 | + * @example |
| 24 | + * # disable 'THIS' prefix functionality: |
| 25 | + * $egParserFunDisabledFunctions = array( 'this' ); |
| 26 | + * # disable '#parse' parser function: |
| 27 | + * $egParserFunDisabledFunctions = array( 'parse' ); |
| 28 | + * |
| 29 | + * @since 1.0.1 |
| 30 | + * @var array |
| 31 | + */ |
| 32 | +$egParserFunDisabledFunctions = array(); |
Property changes on: trunk/extensions/ParserFun/ParserFun_Settings.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 33 | + native |
Index: trunk/extensions/ParserFun/README |
— | — | @@ -0,0 +1,47 @@ |
| 2 | +== About ==
|
| 3 | +
|
| 4 | +The 'Parser Fun' extension Enhances MediaWiki with the following features:
|
| 5 | +
|
| 6 | +(1) A new parser function to do several parser tasks manually on wikitext.
|
| 7 | + The following can be achieved by the '#parse' parser function:
|
| 8 | + - Parsing wikitext
|
| 9 | + - Un-stripping '<nowiki>' and general stripped text
|
| 10 | +
|
| 11 | +(2) Prefix 'THIS:' (available in some other languages) which can be put in front
|
| 12 | + of site information related magic words like '{{THIS:PAGENAME}}'. This
|
| 13 | + allows to get the information from the page the phrase actually is literally
|
| 14 | + defined on instead of the page which is being parsed and where the phrase was
|
| 15 | + expanded into. '{{THIS}}' simply is synonym for '{{THIS:FULLPAGENAME}}'.
|
| 16 | + IF 'THIS:' is used with an un-supported variable it will be interpreted as
|
| 17 | + template call. Currently the following functions are supported:
|
| 18 | + 'FULLPAGENAME', 'PAGENAME', 'BASEPAGENAME', 'SUBPAGENAME', 'SUBJECTPAGENAME',
|
| 19 | + 'TALKPAGENAME', 'NAMESPACE', 'SUBJECTSPACE', 'ARTICLESPACE', 'TALKSPACE'
|
| 20 | + as well as their URL-encoded equivalents (ending with '...EE').
|
| 21 | + It is possible for other extensions to support the 'THIS:' prefix, currently:
|
| 22 | + - All 'Subpage Fun' extension variables:
|
| 23 | + http://www.mediawiki.org/wiki/Extension:Subpage_Fun
|
| 24 | +
|
| 25 | +* Website: http://www.mediawiki.org/wiki/Extension:Parser_Fun
|
| 26 | +* Author: Daniel Werner < danweetz@web.de >
|
| 27 | +
|
| 28 | +
|
| 29 | +== Installation ==
|
| 30 | +
|
| 31 | +Once you have downloaded the code, place the 'ParserFun' directory within your
|
| 32 | +MediaWiki 'extensions' directory. Then add the following code to your
|
| 33 | +[[Manual:LocalSettings.php|LocalSettings.php]] file:
|
| 34 | +
|
| 35 | + # Parser Fun
|
| 36 | + require_once( "$IP/extensions/ParserFun/ParserFun.php" );
|
| 37 | +
|
| 38 | +This extension requires Jeroen De Dauws 'Validator' extension in a version higher
|
| 39 | +than 0.4.11. It must be included before the 'Parser Fun' extension.
|
| 40 | +You can get it at: http://www.mediawiki.org/wiki/Extension:Validator
|
| 41 | +
|
| 42 | +
|
| 43 | +== Contributing ==
|
| 44 | +
|
| 45 | +If you have bug reports or feature requests, please add them to the 'Parser Fun'
|
| 46 | +Talk page [0]. You can also send them to Daniel Werner < danweetz@web.de >
|
| 47 | +
|
| 48 | +[0] http://www.mediawiki.org/w/index.php?title=Extension_talk:Parser_Fun
|