Extension:Validator

The ParamProcessor extension, formerly known as Validator, is a parameter processing framework that provides a way to declaratively define a set of parameters and how they should be processed. It can take such declarations together with a list of raw parameters and provide the processed values.

Functionality overview
A brief description of the core functionality.

Parameter validation
You can validate a list of raw parameters against a set of parameter definitions using the Validator class. Validator will then determine which criteria are not met, which parameters are missing and which ones are unknown. Incorrect or missing values are replaced by the default value for their parameter, and all errors are stored.

The raw parameters can be either key value pairs, such as provided by tag extensions, or 'foo=bar' elements, such as provided by parser functions. In case of the later, Validator takes care of the parsing and provides out-of-the-box support for default parameters. Validator also provides a ParserHook class which enables you to create parser hooks (tag extensions and parser functions) that seamlessly integrate with the other functionality provided by Validator.

Parameter manipulation
Validator not only Validates your parameters, but also further handles them so that you get them into a convenient format and don't need to do any further manipulations. A simple example is a parameter which expects a list of "yes" and "no", such as. What validator will return is an array containing booleans. This removes the need for defining the same handling all over your code, and allows you to get right to what you actually want to write. Validator provides a set of common manipulations, which is easily extendible by other extensions to add more specific handling.

Errors and warnings
Validator provides several classes to describe and keep track of parameter validation related errors. Such errors can be shown inline or at the end of the page using the listerrors parser hook. All errors have a severity, and you can configure which actions need to be taken for errors with a certain severity. For example if they should be shown inline or not. This functionality works out-of-the-box when using the ParserHook class and the criteria classes provided by Validator in your parameter definitions, but can easily be used and extended by in other situations.

Automatic documentation generation
Since version 0.4.3, Validator has a "describe" parser hook which automatically generates documentation for one or more parser hooks. This documentation includes a description of the parser hook, a table with its parameters and syntax examples. The result can be either directly viewed in a wiki page, or displayed as wikitext, so it can be copied over to another page. (example)

Prerequisites

 * It requires the DataValues extension.

Download
Quick link: Download Validator 0.5.1 (.zip file)

Installation
Once you have downloaded the code, place the 'Validator' directory within your MediaWiki 'extensions' directory. Then add the following code to your LocalSettings.php file:

Note that you need to place this code before the inclusion of any extensions depending on Validator.

Change log
This list only contains the versions and their release dates. For a list of all changes made, view the release notes.




 * Version 0.5 (2012-11-05)


 * Version 0.4 (2010-10-15)
 * Version 0.4.1 (2010-10-20)
 * Version 0.4.2 (2010-10-28)
 * Version 0.4.3 (2011-01-11)
 * Version 0.4.4 (2011-02-16)
 * Version 0.4.5 (2011-03-05)
 * Version 0.4.6 (2011-03-24)
 * Version 0.4.7 (2011-06-15)
 * Version 0.4.8 (2011-07-19)
 * Version 0.4.9 (2011-07-30)
 * Version 0.4.10 (2011-08-04)
 * Version 0.4.11 (2011-09-14)
 * Version 0.4.12 (2011-10-15)
 * Version 0.4.13 (2011-11-30)
 * Version 0.4.14 (2012-03-10)


 * Version 0.3 (2010-05-31)
 * Version 0.3.1 (2010-06-04)
 * Version 0.3.2 (2010-06-07)
 * Version 0.3.3 (2010-06-20)
 * Version 0.3.4 (2010-07-08)
 * Version 0.3.5 (2010-07-26)
 * Version 0.3.6 (2010-08-26)


 * Version 0.2 (2009-12-25)
 * Version 0.2.1 (2010-02-01)
 * Version 0.2.2 (2010-03-01)


 * Version 0.1 (2009-12-17)

listerrors
Description: Lists errors (and warnings) that occured in parser hooks added via Validator. Only lists for parser hooks added above where listerrors is inserted; place listerrors at or near the bottom of the page to get all errors.

Implemented as both parser function and as tag extension.

Syntax
Tag extension with only the required parameters.

Tag extension with all parameters.

 Tag extension with all parameters using the default parameter notation.

{minseverity, Text} Parser function with only the required parameters.

Parser function with all parameters.

Parser function with all parameters using the default parameter notation.

describe
Description: Generates documentation for one or more parser hooks defined via Validator.

Implemented as both parser function and as tag extension.

Syntax
Tag extension with only the required parameters.

Tag extension with all parameters.

 Tag extension with all parameters using the default parameter notation.

{hooks, List of text items} Parser function with only the required parameters.

Parser function with all parameters.

Parser function with all parameters using the default parameter notation.

Supported languages
Validator has support for over 45 languages, including English, Afrikaans, Gheg Albanian, Arabic, Belarusian, Bulgarian, Breton, Bosnian, Czech, German, Lower Sorbian, Greek, Esperanto, Spanish, Finnish, French, Franco-Provençal, Galician, Swiss German, Hebrew, Upper Sorbian, Hungarian, Interlingua, Indonesian, Italian, Japanese, Colognian, Luxembourgish, Macedonian, Dutch, Norwegian, Occitan, Polish, Piedmontese, Portuguese, Brazilian Portuguese, Romanian, Russian, Sinhala, Swedish, Telugu, Tagalog, Turkish, Ukrainian, Vietnamese, Simplified Chinese and others.

Bugs and patches
If you found some bug and fixed it, please create a patch by going to the "Validator" directory, and typing:

git diff >descriptivename.patch

Then upload it somewhere and link to it from the talk page. Bug reports should also be added here. You can also send them to Jeroen De Dauw, jeroendedauw -at- gmail.com.

Feature requests
Feel free to add feature requests to the discussion page.

Translating
Translation of Validator is done through translatewiki.net. The translation for this extension can be found here. To add language values or change existing ones, you should create an account on translatewiki.net, then request permission from the administrators to translate a certain language or languages on this page (this is a very simple process). Once you have permission for a given language, you can log in and add or edit whatever messages you want to in that language.

Translations for this documentation, especially the extension description, are also welcome.

Extensions that use Validator

 * Maps (Since 0.5)
 * Semantic Maps (Since 0.5)
 * SubPageList
 * Include WP
 * Ratings
 * PAMELA
 * Semantic MediaWiki (Since 1.6)
 * Semantic Result Formats (Since 1.6)
 * Parser Fun

Sites that use Validator

 * see here for sites that use Validator