r105689 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105688‎ | r105689 | r105690 >
Date:18:45, 9 December 2011
Author:danwe
Status:deferred
Tags:
Comment:
Tag for 0.2 release
Modified paths:
  • /tags/extensions/ParserFun/REL_0_2 (added) (history)

Diff [purge]

Index: tags/extensions/ParserFun/REL_0_2/RELEASE-NOTES
@@ -0,0 +1,26 @@
 2+ 'Parser Fun' Changelog:
 3+ =======================
 4+
 5+ * December 9, 2011 -- Version 0.2
 6+ - New parser function/variable 'CALLER' to return a templates caller. Comes with the following parameters:
 7+ + <1>/mode - can be the level of the call stack to return (if negative the value will be returned from the
 8+ bottom). Instead of a number a mode can be given: 'count' will return the current callstack level,
 9+ 'list' will return a list of all sites in the stack.
 10+ + linked - boolean whether page(s) should be returned linked.
 11+ + sep - separator between pages in 'list' mode. ', ' by default.
 12+ + offset - first stack item to return in 'list' mode. If negative, the list starts that far from the stacks top.
 13+ + limit - how many items to return in 'list' mode. If negative the list will end that far from the stacks top.
 14+ All parameters with specific meaning in 'list' mode have the same effect for the 'count' mode. In 'count' mode the
 15+ offset is set to 1 by default, in 'list' mode to 0.
 16+
 17+
 18+ * December 2, 2011 -- Version 0.1 (initial release)
 19+ - Magic word prefix 'THIS:', which is working with basically all functions returning page related information:
 20+ 'FULLPAGENAME', 'PAGENAME', 'BASEPAGENAME', 'SUBPAGENAME', 'SUBJECTPAGENAME', 'TALKPAGENAME', 'NAMESPACE',
 21+ 'SUBJECTSPACE', 'ARTICLESPACE', 'TALKSPACE' and their URL-encoded equivalents ending with 'EE'.
 22+ - Hook 'GetThisVariableValueSwitch' allows to make other magic variables work with 'THIS:'.
 23+ - 'parse' parser function with following parameters:
 24+ + <1> - input text (required)
 25+ + unstrip - 'none', 'nowiki', 'general', 'all' to unstrip input first. Allows to parse text inside <nowiki>.
 26+ + parse - whether text should really be parsed (in case you want to unstrip only)
 27+ - Distributed under ISC license and put into mediawiki.org svn repository.
Property changes on: tags/extensions/ParserFun/REL_0_2/RELEASE-NOTES
___________________________________________________________________
Added: svn:eol-style
128 + native
Index: tags/extensions/ParserFun/REL_0_2/includes/PFun_Caller.php
@@ -0,0 +1,281 @@
 2+<?php
 3+
 4+/**
 5+ * Class for the 'CALLER' variable-style parser function.
 6+ *
 7+ * @since 0.2
 8+ *
 9+ * @file PFun_Caller.php
 10+ * @ingroup ParserFun
 11+ *
 12+ * @author Daniel Werner
 13+ */
 14+class ParserFunCaller extends ParserHook {
 15+
 16+ public function __construct() {
 17+ // make this a parser function extension (no tag extension) only:
 18+ parent::__construct( false, true, ParserHook::FH_NO_HASH );
 19+ }
 20+
 21+ /**
 22+ * No LSB in pre-5.3 PHP, to be refactored later
 23+ */
 24+ public static function staticMagic( array &$magicWords, $langCode ) {
 25+ $instance = new self;
 26+ return $instance->magic( $magicWords, $langCode );
 27+ }
 28+
 29+ /**
 30+ * No LSB in pre-5.3 PHP, to be refactored later
 31+ */
 32+ public static function staticInit( Parser &$parser ) {
 33+ global $egParserFunEnabledFunctions;
 34+ if( in_array( ExtParserFun::MAG_CALLER, $egParserFunEnabledFunctions ) ) {
 35+ // only register function if not disabled by configuration
 36+ $instance = new self;
 37+ $instance->init( $parser );
 38+ }
 39+ return true;
 40+ }
 41+
 42+ /**
 43+ * Gets the name of the parser hook.
 44+ * @see ParserHook::getName
 45+ *
 46+ * @return string
 47+ */
 48+ protected function getName() {
 49+ return 'CALLER';
 50+ }
 51+
 52+ /**
 53+ * Returns an array containing the parameter info.
 54+ * @see ParserHook::getParameterInfo
 55+ *
 56+ * @return array
 57+ */
 58+ protected function getParameterInfo( $type ) {
 59+ $params = array();
 60+
 61+ # what to get, index (any number) or certain mode (count, list)
 62+ # since 0.2
 63+ $params['mode'] = new Parameter( 'mode', Parameter::TYPE_STRING );
 64+ $params['mode']->addAliases( 'index' );
 65+
 66+ # where in the stack to start returning.
 67+ # negative value will return that many elements from the top-level caller
 68+ # since 0.2
 69+ $params['offset'] = new Parameter( 'offset', Parameter::TYPE_INTEGER );
 70+ $params['offset']->setDefault( false, false );
 71+
 72+ # max return, if negative stop that many elements from end
 73+ # since 0.2
 74+ $params['limit'] = new Parameter( 'limit', Parameter::TYPE_INTEGER );
 75+ $params['limit']->setDefault( false, false );
 76+ $params['limit']->addAliases( 'len', 'length' );
 77+
 78+ # whether to link the page names
 79+ # since 0.2
 80+ $params['linked'] = new Parameter( 'linked', Parameter::TYPE_BOOLEAN );
 81+ $params['linked']->setDefault( false );
 82+
 83+ # separator between list items
 84+ # since 0.2
 85+ $params['sep'] = new Parameter( 'sep', Parameter::TYPE_STRING );
 86+ $params['sep']->setDefault( ', ', false );
 87+
 88+ return $params;
 89+ }
 90+
 91+ /**
 92+ * Returns the list of default parameters.
 93+ * @see ParserHook::getDefaultParameters
 94+ *
 95+ * @return array
 96+ */
 97+ protected function getDefaultParameters( $type ) {
 98+ return array(
 99+ array( 'mode' ),
 100+ );
 101+ }
 102+
 103+ /**
 104+ * Renders and returns the output.
 105+ * @see ParserHook::renderTag
 106+ *
 107+ * @param array $parameters
 108+ *
 109+ * @return string
 110+ */
 111+ public function render( array $parameters ) {
 112+
 113+ $mode = $parameters['mode'];
 114+ $linked = $parameters['linked'];
 115+ $limit = $parameters['limit'];
 116+ $offset = $parameters['offset'];
 117+
 118+ if( is_numeric( $mode ) ) {
 119+ // get specific caller
 120+ /*
 121+ * do not just set $offset to $mode, $mode to 'list' and $limit to 1 here since handling
 122+ * for negative offset is different in 'list' mode. Here non-existant negative index will
 123+ * return '', in 'list' mode it will jump to the 0 element.
 124+ */
 125+ $index = (int)$mode;
 126+ $frame = self::getFrameStackItem( $this->frame, $index );
 127+
 128+ if( $frame === null ) {
 129+ return '';
 130+ }
 131+ return self::createSiteList(
 132+ array( $frame ),
 133+ $linked
 134+ );
 135+ }
 136+
 137+ $mode = strtolower( $mode );
 138+ switch( $mode ) {
 139+ case 'level':
 140+ // synnonym for 'count'
 141+ $mode = 'count';
 142+ case 'count':
 143+ case '':
 144+ /*
 145+ * '{{CALLER:}}', perhaps with additional parameters, but not in list mode except limit
 146+ * is set. Otherwise tread it similar to '{{CALLER}}' variable but with parameters.
 147+ */
 148+ if( $mode !== 'count' && $limit === false ) {
 149+ $limit = 1;
 150+ }
 151+ if( $offset === false ) {
 152+ // '{{CALLER}}' equals '{{CALLER:1}}', not 0, in count mode ignore current page.
 153+ $offset = 1;
 154+ }
 155+ // no-break, evaluate parameters in 'list' mode but count only
 156+ case 'list':
 157+ $stack = self::getFrameStack( $this->frame );
 158+ $offset = ( $offset === false ) ? 0 : $offset;
 159+ $limit = ( $limit === false ) ? null : $limit; // Validator can't have null as default...
 160+
 161+ $stack = array_slice( $stack, $offset, $limit );
 162+
 163+ if( $mode === 'count' ) {
 164+ // in 'count' mode, return the level
 165+ return count( $stack );
 166+ } else {
 167+ // normal list mode
 168+ return self::createSiteList(
 169+ $stack,
 170+ $linked,
 171+ $parameters['sep']
 172+ );
 173+ }
 174+ }
 175+
 176+ /*
 177+ * No valid operation mode or index given to first parameter!
 178+ * Return error message
 179+ */
 180+ $error = new ValidationError( wfMsgForContent( 'parserfun-invalid-caller-mode' ) );
 181+ return $this->renderFatalError( $error );
 182+ }
 183+
 184+ /**
 185+ * Returns a string, exactly like '{{CALLER}}' as variable would return it.
 186+ *
 187+ * @param PPFrame $frame
 188+ *
 189+ * @return string
 190+ */
 191+ static function getCallerVar( PPFrame $frame ) {
 192+ $siteFrame = ParserFunCaller::getFrameStackItem( $frame, 1 );
 193+ return ( $siteFrame !== null )
 194+ ? self::createSiteList( array( $siteFrame ), false )
 195+ : '';
 196+ }
 197+
 198+ /**
 199+ * Returns a certain parent caller from a given frame by index. 0 returns the given frame, 1 would return
 200+ * the frame of the site which was calling the given frame and so on.
 201+ *
 202+ * @param PPFrame $frame
 203+ * @param int $index can be negative to return the element from the top-level caller. -1 would return
 204+ * the same as {{FULLPAGENAME}} would be. If the index doesn't exist, null will be returned.
 205+ *
 206+ * @return PPFrame|null
 207+ */
 208+ static function getFrameStackItem( PPFrame $frame, $index ) {
 209+ // get the whole stack or just till some certain index
 210+ $stack = self::getFrameStack( $frame, $index );
 211+
 212+ if( $index >= 0 ) {
 213+ if( array_key_exists( $index, $stack ) ) {
 214+ return $stack[ $index ];
 215+ }
 216+ } else {
 217+ // negative index, return from top-level
 218+ $index = count( $stack ) + $index;
 219+ if( $index >= 0 ) {
 220+ return $stack[ $index ];
 221+ }
 222+ }
 223+
 224+ // index doesn't exist!
 225+ return null;
 226+ }
 227+
 228+ /**
 229+ * Gets all parent frames from a frame and returns them as array with the given frame as first element.
 230+ *
 231+ * @param PPFrame $frame
 232+ * @param int $limit how many parent frames should be returned as maximum (in addition to given frame).
 233+ * Limit below 0 means no limit. 0 will just return an array with the given frame.
 234+ *
 235+ * @return PPFrame[]
 236+ */
 237+ static function getFrameStack( PPFrame $frame, $limit = -1 ) {
 238+ $frames = array();
 239+ if( $limit >= 0 ) {
 240+ $limit++; // given $frame doesn't count so this will be returned if 0 is given
 241+ }
 242+
 243+ while( $frame !== null && $limit !== 0 ) {
 244+ $frames[] = $frame;
 245+ $limit--;
 246+
 247+ if( $frame instanceof PPTemplateFrame_DOM ) {
 248+ $frame = $frame->parent;
 249+ } else {
 250+ // frame is no template, so this is the top-level frame (page being rendered)
 251+ $frame = null;
 252+ }
 253+ };
 254+
 255+ return $frames;
 256+ }
 257+
 258+ /**
 259+ * Create a list with page titles from a given array of frames, optionally linked output.
 260+ * The output ist un-parsed wiki markup, no HTML.
 261+ *
 262+ * @param array $frames the titles represented as frames
 263+ * @param bool $link whether or not to link the pages in the list
 264+ * @param string $sep glue between the pages
 265+ *
 266+ * @return string
 267+ */
 268+ protected static function createSiteList( $frames, $link = false, $sep = ', ' ) {
 269+ $out = array();
 270+ foreach( $frames as $frame ) {
 271+ $text = $frame->title->getPrefixedText();
 272+ if( $link ) {
 273+ $out[] = "[[:{$text}]]";
 274+ } else {
 275+ $text = wfEscapeWikiText( $text );
 276+ $out[] = $text;
 277+ }
 278+ }
 279+ return implode( $sep, $out );
 280+ }
 281+
 282+}
Property changes on: tags/extensions/ParserFun/REL_0_2/includes/PFun_Caller.php
___________________________________________________________________
Added: svn:eol-style
1283 + native
Index: tags/extensions/ParserFun/REL_0_2/includes/PFun_This.php
@@ -0,0 +1,147 @@
 2+<?php
 3+
 4+/**
 5+ * Class for the 'THIS' variable/parser function.
 6+ *
 7+ * @since 0.2 (in 'ExtParserFun' class before)
 8+ *
 9+ * @file PFun_This.php
 10+ * @ingroup ParserFun
 11+ *
 12+ * @author Daniel Werner
 13+ */
 14+class ParserFunThis {
 15+
 16+ /**
 17+ * Magic word 'THIS:' to return certain information about the page the word actually is defined on
 18+ */
 19+ static function pfObj_this( Parser &$parser, PPFrame $frame = null, $args = null ) {
 20+ // if MW version is too old or something is wrong:
 21+ if( $frame === null || $frame->title === null ) {
 22+ return '';
 23+ }
 24+
 25+ // get part behind 'THIS:' if only 'THIS', use 'FULLPAGENAME'
 26+ $index = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
 27+
 28+ $newArgs = array();
 29+
 30+ if( $index !== '' ) {
 31+ // clean up arguments as if first argument never were set:
 32+ unset( $args[0] );
 33+ foreach( $args as $arg ) {
 34+ $newArgs[] = $arg;
 35+ }
 36+
 37+ // get magic word ID of the variable name:
 38+ $mwId = self::getVariablesMagicWordId( $parser, $index );
 39+ if( $mwId === null ) {
 40+ // requested variable doesn't exist, make the thing a template call
 41+ return array( null, 'found' => false );
 42+ }
 43+ }
 44+ else {
 45+ // if only '{{THIS}}', set magic word id to 'FULLPAGENAME'
 46+ $mwId = 'fullpagename';
 47+ }
 48+
 49+ // get value:
 50+ $out = self::getThisVariableValue( $mwId, $parser, $frame, $newArgs );
 51+ if( $out === null ) {
 52+ // requested variable doesn't support 'THIS:', make the thing a template call
 53+ return array( null, 'found' => false );
 54+ }
 55+
 56+ return $out;
 57+
 58+ }
 59+
 60+ /**
 61+ * Returns the magic word ID for a variable like the user would write it. Returns null in case there
 62+ * is no word for the given variables name.
 63+ *
 64+ * @param Parser $parser
 65+ * @param type $word
 66+ *
 67+ * @return string|null
 68+ */
 69+ static function getVariablesMagicWordId( Parser $parser, $word ) {
 70+ // get all local (including translated) magic words IDs (values) with their actual literals (keys)
 71+ // for case insensitive [0] and sensitive [1]
 72+ $magicWords = $parser->mVariables->getHash();
 73+
 74+ if( array_key_exists( strtolower( $word ), $magicWords[0] ) ) {
 75+ // case insensitive word match
 76+ $mwId = $magicWords[0][ strtolower( $word ) ];
 77+ }
 78+ elseif( array_key_exists( $word, $magicWords[1] ) ) {
 79+ // case sensitive word match
 80+ $mwId = $magicWords[1][ $word ];
 81+ }
 82+ else {
 83+ // requested magic word doesn't exist for variables
 84+
 85+ return null;
 86+ }
 87+ return $mwId;
 88+ }
 89+
 90+ /**
 91+ * Returns the value of a variable like '{{FULLPAGENAME}}' in the context of the given PPFrame objects
 92+ * $frame->$title instead of the Parser objects subject. Returns null in case the requested variable
 93+ * does not support '{{THIS:}}'.
 94+ *
 95+ * @param string $mwId magic word ID of the variable
 96+ * @param Parser $parser
 97+ * @param PPFrame $frame
 98+ * @param array $args
 99+ *
 100+ * @return string|null
 101+ */
 102+ static function getThisVariableValue( $mwId, Parser &$parser, $frame, $args = array() ) {
 103+ $ret = null;
 104+ $title = $frame->title;
 105+
 106+ if( $title === null ) {
 107+ return null;
 108+ }
 109+
 110+ // check whether info is available, e.g. 'THIS:FULLPAGENAME' requires 'FULLPAGENAME'
 111+ switch( $mwId ) {
 112+ case 'namespace':
 113+ // 'namespace' function name was renamed as PHP 5.3 came along
 114+ if( is_callable( 'CoreParserFunctions::mwnamespace' ) ) {
 115+ $ret = CoreParserFunctions::mwnamespace( $parser, $title->getPrefixedText() );
 116+ break;
 117+ }
 118+ // else: no different from the other variables
 119+ // no-break, default function call
 120+ case 'fullpagename':
 121+ case 'fullpagenamee':
 122+ case 'pagename':
 123+ case 'pagenamee':
 124+ case 'basepagename':
 125+ case 'basepagenamee':
 126+ case 'subpagename':
 127+ case 'subpagenamee':
 128+ case 'subjectpagename':
 129+ case 'subjectpagenamee':
 130+ case 'talkpagename':
 131+ case 'talkpagenamee':
 132+ case 'namespacee': // special treat for 'namespace', on top
 133+ case 'subjectspace':
 134+ case 'subjectspacee':
 135+ case 'talkspace':
 136+ case 'talkspacee':
 137+ // core parser function information requested
 138+ $ret = CoreParserFunctions::$mwId( $parser, $title->getPrefixedText() );
 139+ break;
 140+
 141+ default:
 142+ // give other extensions a chance to hook up with this and return their own values:
 143+ wfRunHooks( 'GetThisVariableValueSwitch', array( &$parser, $title, &$mwId, &$ret, $frame, $args ) );
 144+ }
 145+ return $ret;
 146+ }
 147+
 148+}
Property changes on: tags/extensions/ParserFun/REL_0_2/includes/PFun_This.php
___________________________________________________________________
Added: svn:eol-style
1149 + native
Index: tags/extensions/ParserFun/REL_0_2/includes/PFun_Parse.php
@@ -0,0 +1,173 @@
 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 $egParserFunEnabledFunctions;
 47+ if( in_array( 'parse', $egParserFunEnabledFunctions ) ) {
 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 options.
 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+ $text = $parameters['text'];
 131+
 132+ // current parsers StripState object
 133+ $stripState = $this->parser->mStripState;
 134+
 135+ switch( $parameters['unstrip'] ) {
 136+
 137+ // case 'none': <do nothing>
 138+
 139+ case 'nowiki':
 140+ $text = $stripState->unstripNoWiki( $text );
 141+ break;
 142+
 143+ case 'general':
 144+ $text = $stripState->unstripGeneral( $text );
 145+ break;
 146+
 147+ case 'all':
 148+ $text = $stripState->unstripBoth( $text );
 149+ break;
 150+ }
 151+
 152+ // parse if $frame is set (new MW versions) and parsing is not disabled for this one:
 153+ if( $this->frame !== null && $parameters['parse'] === true ) {
 154+
 155+ // we don't need the fallback since $frame is given:
 156+ $this->postParse_fallback = false;
 157+
 158+ /**
 159+ * Doing the parsing here allows to parse <noinclude> / <includeonly> acording to the context
 160+ * of where the function is defined and called. IF we use the parser function 'noparse' return
 161+ * value, it would always be parsed like a page view meaning <includeonly> content would appear.
 162+ */
 163+ $text = $this->parser->preprocessToDom( $text, $this->frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 );
 164+ $text = trim( $this->frame->expand( $text ) );
 165+ }
 166+ else {
 167+ // fallback for old MW versions or in case the 'parse' #parse parameter is set to false
 168+ $this->postParse_fallback = $parameters['parse'];
 169+ }
 170+
 171+ return $text;
 172+ }
 173+
 174+}
Property changes on: tags/extensions/ParserFun/REL_0_2/includes/PFun_Parse.php
___________________________________________________________________
Added: svn:eol-style
1175 + native
Index: tags/extensions/ParserFun/REL_0_2/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
Property changes on: tags/extensions/ParserFun/REL_0_2/COPYING
___________________________________________________________________
Added: svn:eol-style
115 + native
Index: tags/extensions/ParserFun/REL_0_2/ParserFun.i18n.magic.php
@@ -0,0 +1,39 @@
 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( 0, 'parse' ),
 22+ ExtParserFun::MAG_THIS => array( 1, 'THIS' ),
 23+ ExtParserFun::MAG_CALLER => array( 1, 'CALLER' ),
 24+);
 25+
 26+/** Message documentation (Message documentation)
 27+ * @author Daniel Werner
 28+ */
 29+$messages['qqq'] = array(
 30+ 'parse' => array( 0, 'Do not translate this! This is the magic word for the "#parse" function' ),
 31+ ExtParserFun::MAG_THIS => 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.' ),
 32+ ExtParserFun::MAG_CALLER => array( 1, 'Variable/Parser function returning an templates direct initiator or with options even all or just specific initiators.' ),
 33+);
 34+
 35+/** German (Deutsch)
 36+ * @author Daniel Werner
 37+ */
 38+$magicWords['de'] = array(
 39+ ExtParserFun::MAG_THIS => array( 1, 'DIESER', 'DIESE', 'DIESES' ),
 40+);
Property changes on: tags/extensions/ParserFun/REL_0_2/ParserFun.i18n.magic.php
___________________________________________________________________
Added: svn:eol-style
141 + native
Index: tags/extensions/ParserFun/REL_0_2/ParserFun.i18n.php
@@ -0,0 +1,93 @@
 2+<?php
 3+
 4+/**
 5+ * Internationalization file of the 'Parser Fun' extension.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file ParserFun.i18n.php
 10+ * @ingroup ParserFun
 11+ * @author Daniel Werner < danweetz@web.de >
 12+ */
 13+
 14+$messages = array();
 15+
 16+/** English
 17+ * @author Daniel Werner
 18+ */
 19+$messages['en'] = array(
 20+ 'parserfun-desc' => "Adds a parser function <code>#parse</code> for parsing wikitext and introduces <code>THIS:</code> prefix for page information related magic variables",
 21+ 'parserfun-invalid-caller-mode' => 'No valid operation mode or numeric index given.',
 22+);
 23+
 24+/** Message documentation (Message documentation)
 25+ * @author Fryed-peach
 26+ */
 27+$messages['qqq'] = array(
 28+ 'parserfun-desc' => '{{desc}}',
 29+);
 30+
 31+/** German (Deutsch)
 32+ * @author Daniel Werner
 33+ * @author Kghbln
 34+ */
 35+$messages['de'] = array(
 36+ 'parserfun-desc' => 'Ergänzt die Parserfunktion <code>#parse</code> zum Parsen von Wikitext, sowie das <code>THIS:</code>-Präfix für Variablen, die von Wikiseiten Informationen abrufen',
 37+);
 38+
 39+/** French (Français)
 40+ * @author Gomoko
 41+ */
 42+$messages['fr'] = array(
 43+ 'parserfun-desc' => "Ajoute une fonction de l'analyseur <code>#parse</code> pour analyser le wikitext et introduit le préfixe <code>THIS:</code> pour l'information sur la page liée aux variables magiques",
 44+);
 45+
 46+/** Galician (Galego)
 47+ * @author Toliño
 48+ */
 49+$messages['gl'] = array(
 50+ 'parserfun-desc' => 'Engade unha función analítica <code>#parse</code> para analizar texto wiki e introduce o prefixo <code>THIS:</code> para as páxinas de información relacionadas coas variables máxicas',
 51+);
 52+
 53+/** Upper Sorbian (Hornjoserbsce)
 54+ * @author Michawiki
 55+ */
 56+$messages['hsb'] = array(
 57+ 'parserfun-desc' => 'Přidawa parserowu funkciju <code>#parse</code> za parsowanje wikiteksta a zawjeduje prefiks <code>THIS:</code> za magiske wariable, kotrež informacije stronow wotwołuja',
 58+);
 59+
 60+/** Interlingua (Interlingua)
 61+ * @author McDutchie
 62+ */
 63+$messages['ia'] = array(
 64+ 'parserfun-desc' => 'Adde al analysator syntactic un function <code>#parse</code> pro interpretar wikitexto e introduce le prefixo <code>THIS:</code> pro variabiles magic connexe a information de paginas',
 65+);
 66+
 67+/** Japanese (日本語)
 68+ * @author Fryed-peach
 69+ */
 70+$messages['ja'] = array(
 71+ 'parserfun-desc' => 'ウィキテキストの構文解析を行うパーサー関数 <code>#parse</code> を追加し、ページ情報に関連するマジック変数のための接頭辞 <code>THIS:</code> を導入する',
 72+);
 73+
 74+/** Macedonian (Македонски)
 75+ * @author Bjankuloski06
 76+ */
 77+$messages['mk'] = array(
 78+ 'parserfun-desc' => 'Додава парсерска функција <code>#parse</code> за парсирање на викитекст и го воведува префиксот <code>THIS:</code> за волшебни променливи што се однесуваат на информации за страници',
 79+);
 80+
 81+/** Malay (Bahasa Melayu)
 82+ * @author Anakmalaysia
 83+ */
 84+$messages['ms'] = array(
 85+ 'parserfun-desc' => 'Menambahkan fungsi penghurai <code>#parse</code> untuk menghuraikan teks wiki serta memperkenalkan awalan <code>THIS:</code> untuk pembolehubah sakti berkenaan maklumat laman',
 86+);
 87+
 88+/** Dutch (Nederlands)
 89+ * @author Siebrand
 90+ */
 91+$messages['nl'] = array(
 92+ 'parserfun-desc' => 'Voegt een parserfunctie <code>#parse</code> toe voor het parsen van wikitekst, en introduceert het voorvoegsel <code>THIS:</code> voor aan magische variabelen gerelateerde paginagegevens',
 93+);
 94+
Property changes on: tags/extensions/ParserFun/REL_0_2/ParserFun.i18n.php
___________________________________________________________________
Added: svn:eol-style
195 + native
Index: tags/extensions/ParserFun/REL_0_2/ParserFun.php
@@ -0,0 +1,162 @@
 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.2
 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+$wgHooks['ParserGetVariableValueSwitch'][] = 'ExtParserFun::onParserGetVariableValueSwitch';
 61+
 62+
 63+// Parser function initializations:
 64+$wgAutoloadClasses['ParserFunThis' ] = ExtParserFun::getDir() . '/includes/PFun_This.php';
 65+$wgAutoloadClasses['ParserFunParse' ] = ExtParserFun::getDir() . '/includes/PFun_Parse.php';
 66+$wgAutoloadClasses['ParserFunCaller'] = ExtParserFun::getDir() . '/includes/PFun_Caller.php';
 67+
 68+$wgHooks['ParserFirstCallInit'][] = 'ParserFunParse::staticInit';
 69+$wgHooks['LanguageGetMagic' ][] = 'ParserFunParse::staticMagic';
 70+
 71+$wgHooks['ParserFirstCallInit'][] = 'ParserFunCaller::staticInit';
 72+$wgHooks['LanguageGetMagic' ][] = 'ParserFunCaller::staticMagic';
 73+
 74+
 75+/**
 76+ * Extension class of the 'Parser Fun' extension.
 77+ * Handling the functionality around the 'THIS' magic word feature.
 78+ */
 79+class ExtParserFun {
 80+ /**
 81+ * Version of the 'Parser Fun' extension.
 82+ *
 83+ * @since 0.1
 84+ *
 85+ * @var string
 86+ */
 87+ const VERSION = '0.2';
 88+
 89+ const MAG_THIS = 'this';
 90+ const MAG_CALLER = 'caller';
 91+
 92+ static function init( Parser &$parser ) {
 93+ if( self::isEnabledFunction( self::MAG_THIS ) ) {
 94+ // only register function if not disabled by configuration
 95+ $parser->setFunctionHook( self::MAG_THIS, array( 'ParserFunThis', 'pfObj_this' ), SFH_NO_HASH | SFH_OBJECT_ARGS );
 96+ }
 97+ return true;
 98+ }
 99+
 100+ /**
 101+ * returns whether a certain variable/parser function is active by the local wiki configuration.
 102+ *
 103+ * @since 0.2
 104+ *
 105+ * @param type $word
 106+ * @return bool
 107+ */
 108+ static function isEnabledFunction( $word ) {
 109+ global $egParserFunEnabledFunctions;
 110+ return in_array( $word, $egParserFunEnabledFunctions );
 111+ }
 112+
 113+ /**
 114+ * Returns the extensions base installation directory.
 115+ *
 116+ * @since 0.1
 117+ *
 118+ * @return boolean
 119+ */
 120+ static function getDir() {
 121+ static $dir = null;
 122+ if( $dir === null ) {
 123+ $dir = dirname( __FILE__ );
 124+ }
 125+ return $dir;
 126+ }
 127+
 128+
 129+ ##################
 130+ # Hooks Handling #
 131+ ##################
 132+
 133+ static function onParserGetVariableValueSwitch( Parser &$parser, &$cache, &$magicWordId, &$ret, $frame = null ) {
 134+ if( $frame === null ) {
 135+ // unsupported MW version
 136+ return true;
 137+ }
 138+ switch( $magicWordId ) {
 139+ /** THIS **/
 140+ case self::MAG_THIS:
 141+ $ret = ParserFunThis::pfObj_this( $parser, $frame, null );
 142+ break;
 143+
 144+ /** CALLER **/
 145+ case self::MAG_CALLER:
 146+ $ret = ParserFunCaller::getCallerVar( $frame );
 147+ break;
 148+ }
 149+ return true;
 150+ }
 151+
 152+ static function onMagicWordwgVariableIDs( &$variableIds ) {
 153+ // only register variables if not disabled by configuration
 154+ if( self::isEnabledFunction( self::MAG_THIS ) ) {
 155+ $variableIds[] = self::MAG_THIS;
 156+ }
 157+ if( self::isEnabledFunction( self::MAG_CALLER ) ) {
 158+ $variableIds[] = self::MAG_CALLER;
 159+ }
 160+ return true;
 161+ }
 162+
 163+}
Property changes on: tags/extensions/ParserFun/REL_0_2/ParserFun.php
___________________________________________________________________
Added: svn:eol-style
1164 + native
Index: tags/extensions/ParserFun/REL_0_2/ParserFun_Settings.php
@@ -0,0 +1,32 @@
 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 enabled within the wiki.
 22+ * By default all functionality is enabled.
 23+ *
 24+ * @example
 25+ * # Only enable 'THIS' prefix functionality:
 26+ * $egParserFunEnabledFunctions = array( 'this' );
 27+ * # Only enable '#parse' parser function:
 28+ * $egParserFunEnabledFunctions = array( 'parse' );
 29+ *
 30+ * @since 0.1
 31+ * @var array
 32+ */
 33+$egParserFunEnabledFunctions = array( 'this', 'parse', 'caller' );
Property changes on: tags/extensions/ParserFun/REL_0_2/ParserFun_Settings.php
___________________________________________________________________
Added: svn:eol-style
134 + native
Index: tags/extensions/ParserFun/REL_0_2/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+ - Unstripping '<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 unsupported 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 (version 0.4.13 or
 39+above). 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
Property changes on: tags/extensions/ParserFun/REL_0_2/README
___________________________________________________________________
Added: svn:eol-style
149 + native

Status & tagging log