Hey,
Over the past year I've been working on an extension to facilitate parameter
handling in MediaWiki, with a focus on parser hooks. It's titled Validator
[0], which currently is a bit misleading since it enables a lot more then
simple validation. As the only thing this extension does is facilitate
parameter handling in other extensions, I think it makes sense to include it
into core, or at least in the default MediaWiki distribution.
I created this extension out of frustration as an extension developer that
to create a parser hook, you need to do the same plumbing over and over
again, and have to write a whole mess of parsing and validation code that is
similar for almost every parser hook. Of course this is doable, but it's
error prone, causes small differences in how exactly parameters are handled
in different parser hooks (not very nice for the end users), and is hard to
maintain. If you have done this a few times, it becomes rather obvious that
a more generic framework to handle parameters would be a big win. You want
to describe a parameter, not all the details of how it should be handled.
Using Validator is somewhat similar to how API classes and their
getParameters methods work, but more powerful and extendible. A parser hook
can be created by deriving from the ParserHook class added by Validator, and
implementing or overriding some methods to specify the name, aliases (if
any), parameters (and all their meta data) and actual handling function of
the parser hook. This last method gets called with a list of all parameters
handled by Validator, and in most cases won't need any extra work. This
ParserHook class is just a wrapper around creating parser functions and tag
extensions and using the actual validation class of validator. You can
directly handle parameters using the Validator class. A nice example of
ParserHook usage can be found in the SubPageList extension [1]. The Maps and
Semantic Maps extensions also use Validator, and contain more complex
examples (with parameters dependent on others, ect) that implement the
display_map and display_points parser hooks [2].
Putting this functionality in core would be a big help to everyone writing
new parameter handling code, and would enable cleaning up existing
implementations where this is desired. As this functionality does not
replace anything in core, putting it in would not disrupt anything. I'm
willing to do the little work required to merge Validator into core.
I could just do that right now of course, but I'm quite sure some people
would object to that. So can these people please respond to this email in
some constructive manner, so this request does not simply get ignored for no
good reason?
[0]
https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Extension:Validator
[1]
https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Extension:SubPageList
[2]
http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Maps/includes/pa…
Cheers
--
Jeroen De Dauw
http://blog.bn2vs.com
Don't panic. Don't be evil.
--