I'm trying to write an extension to an extension (ParserFunctions).
Specifically, I would like to call runReplace from a new extension.
I don't want to extend class, because would like to make backward compatable (1.16 uses different class system).
Can someone give me hint on how to functional perform the following using parser function used by #replace. Perhaps executing the same hook that executes runReplace and if so, what is that hook and how can I find ways to set up the arguments properly?
/** * {{#replace_e:value|from|to}} * Note: If the needle is an empty string, single space is used instead. * From and to will be escaped using c-syntax before checking value (which is not escpace) */ function runReplace_e( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { return (runReplace( &$parser, $inStr, stripcslashes($inReplaceFrom) , stripcslashes($inReplaceFrom))); }
Jack D. Pond "It is the supreme art of the teacher to awaken joy in creative expression and knowledge." -- Albert Einstein. 1879-1955
Jack D. Pond wrote:
function runReplace_e( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { return (runReplace( &$parser, $inStr, stripcslashes($inReplaceFrom) , stripcslashes($inReplaceFrom))); }
Recheck your parameters, $inReplaceFrom is used twice.
What you want is probably this:
{ global $wgExtParserFunctions; return $wgExtParserFunctions->runReplace( ...etc... ); }
Junliano,
Thanks for the help. The suggested approach is excellent, but limited to usage for particular class of hooks and versions of MW, in this case $wgExtParserFunctions.
For all function hooks, the following syntax works without having to worry about different versions and classes of MW (at least I think it does - it does on the ones I've tested). This example (parser function 'replace_e') extends the parser function 'replace' by interpreting escaped characters.
<source lang=php> function runReplace_e( $parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { global $wgParser; list($callback,$flags) = $wgParser->mFunctionHooks['replace']; return @call_user_func_array( $callback, array_merge(array($parser),array($inStr, stripcslashes($inReplaceFrom), stripcslashes($inReplaceTo)) )); } </source>
If someone knows a cleaner/more efficient way, I'd love to hear it!
Jack D. Pond "Believe those who are seeking the truth. Doubt those who find it." -- Andre Gide(1869-1951)
-----Original Message----- From: mediawiki-l-bounces@lists.wikimedia.org [mailto:mediawiki-l-bounces@lists.wikimedia.org] On Behalf Of Juliano F. Ravasi Sent: Tuesday, September 08, 2009 3:14 PM To: MediaWiki announcements and site admin list Subject: Re: [Mediawiki-l] Extending an existing ParserFunction extension
Jack D. Pond wrote:
function runReplace_e( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { return (runReplace( &$parser, $inStr,
stripcslashes($inReplaceFrom)
, stripcslashes($inReplaceFrom))); }
Recheck your parameters, $inReplaceFrom is used twice.
What you want is probably this:
{ global $wgExtParserFunctions; return $wgExtParserFunctions->runReplace( ...etc... ); }
-- Juliano F. Ravasi .. http://juliano.info/ 5105 46CC B2B7 F0CD 5F47 E740 72CA 54F4 DF37 9E96
"A candle loses nothing by lighting another candle." -- Erin Majors
- NOTE: Don't try to reach me through this address, use
"contact@" instead.
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
mediawiki-l@lists.wikimedia.org