Extension:CustomData

Installation
To install this extension, add the following to :

ParserOutput class
After the Parser class has extracted all relevant data out of the wiki markup, it saves it's output in the ParserOutput object.

The ParserOutput is cached either in the database or by an external caching server.

Thus, wiki markup only needs to be parsed once, usually when an article is saved.

When you push the "save" button after having edited an article, your browser sends a POST request to the server.

There, the edited wiki markup is parsed and saved in the database.

The server responds with a 300 (Moved) HTTP code that tells your browser to send a new GET request that loads the new version of the edited article.

It is important to understand that all information about a previously saved article comes out of the cache, not from the actual wiki markup.

This means that extensions that need to process additional data need to store them inside the ParserOutput object after having parsed the wiki markup.

Unfortunately, there is (not yet) a custom data field in the ParserOutput object.

That's what the CustomData extension does.

It is a little hack that adds such a custom data field to the ParserOutput object and provides a handy API for other extensions.

OutputPage class
All cached ParserOutput data that is needed to build up the final HTML page are merged into the OutputPage.

The CustomData API makes extraction of custom data from the OutputPage object easy.

SkinTemplate and QuickTemplate
Every Skin inherited from the SkinTemplate class, e.g. SkinMonobook, uses a data collection class inherited from QuickTemplate.

If you want to modify the Skin in order to display your custom data, you need to store your data somewhere in the QuickTemplate object, first.

Fortunately, there is a hook called 'SkinTemplateOutputPageBeforeExec' usefull to inject custom data into the QuickTemplate.

Extensions that use the CustomData extension as backend should have a function or method triggered by this hook.

From this function, you can call the CustomData object's getPageData method for getting your data stored in the global OutputPage object (usualy $wgOut).

After having processed your data, just call the setSkinData method of the CustomData object in order to store your data in the QuickTemplate object.

Now you can hook into some of the Skin object hooks an call the getSkinData method of the CustomData object for retrieving your data for HTML output.

Functions
If your extension uses parser hooks, you need to store your custom data by invoking setParserData in order to make it survive the subsequent GET request.

You can choose an arbitrary, but unique, string as $key. $value might be of mixed type.

This is how to get your custom data back.

Save your custom data for final HTML output.

You can use the SkinTemplateOutputPageBeforeExec hook for triggering your function.

The $key need not to be (but might be) the same as used in setParserData.

Call this from a function triggered by an appropriate Skin hook.

Feedback
Open tickets in Phabricator under the "MediaWiki-extensions-CustomData" project. CustomData tickets ]
 * [https://phabricator.wikimedia.org/tag/MediaWiki-extensions-CustomData Open