User:MaxEnt/Bloop
Purpose
editTo employ balloon tags within a template. See Extension:Balloons.
Status
editThis was my first attempt at extension development. Version 0.1 is rather crude.
As a learning exercise, this template demonstrates that it is relatively easy to wrap a tag extension with a parser extension if one requires the use of a tag extension within templates.
Apparently it is possible to add complexity to a tag extension to the same purpose, but my feeble efforts in this direction did not succeed. The documentation here could use some work.
Advantages of parser wrapper
editBonus for wrapping a parser around Balloons is separation of effort and the option to provide an alternate syntax, less verbose.
For the wiki I maintain at work, I can't go around asking inexperienced editors to author the following syntax in order for wiki markup to work as expected:
<span id="myContent" style="display:none"> <font color="red">Hello!</font> I am also a ''balloon'' tooltip </span>
Nor was it previously possible to hide this mess within a template.
Last, but not least, by rewriting bloop parser syntax into balloon tag syntax, I remain blissfully ignorant of the balloon popup JavaScript, where all the hard work is done. Nice.
Name
editI considered naming this Balloon_tooltip_parser which would be fine for embedding inside templates, but I might also use this in article space in my own wiki, so I decided on something short and evocative of my shallow foundation.
Limitations
editNot using load
editIn particular, it should be using the Load method instead, which preserves more wiki markup. I need to dust off my PHP to create an incrementing id counter, so I left that for another day. It's also possible that MediaWiki has a way to embed a token or some magic syntax which will function for this purpose.
Only two parameters
editOnly the basic balloon functions are wrapped, not yet having taken the time to figure out a good mapping for the feature set as a whole.
Source
edit
<?php
# Patterned after http://www.mediawiki.org/wiki/Manual:Parser_functions
$wgExtensionFunctions[] = 'wfBloopExtension';
$wgHooks['LanguageGetMagic'][] = 'bloop_parser_Magic';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Bloop (version 0.1)',
'author' =>'MaxEnt',
'url' => 'http://www.mediawiki.org/wiki/User:MaxEnt/Bloop',
'description' => 'Use balloon tags with template parameters'
);
function wfBloopExtension() { # AKA Starup
global $wgParser;
$wgParser->setFunctionHook( 'bloop', 'bloop_parser_Render' );
}
function bloop_parser_Magic( &$magicWords, $langCode ) {
$magicWords['bloop'] = array( 0, 'bloop' );
return true; # allows other functions to load
}
function bloop_parser_Render( &$parser, $param1 = '', $param2 = '' ) {
# The input parameters are wikitext with templates expanded
# The output should be wikitext too
$title = "title=\"${param2}\"";
$output = "<balloon ${title}>${param1}</balloon>";
# $output = "param1 is $param1 and param2 is $param2";
return $output;
}
?>
Pretty simple, in'it?
Reference
edit- - Automatic numbering in CSS 2.1 is controlled with two properties, 'counter-increment' and 'counter-reset'.