SMWCon Fall 2012/Customizing MediaWiki skin actions with SMW

This short talk shows how to customise the MediaWiki page actions based on semantic data stored by SMW.

Example: Download URL
As an example, we want to create a "Download" tab that links to the value of the property Download URL, if such a value exists.

'''Warning: the example takes user input from wiki pages to create HTML interface elements. It will thus allow any user who can edit a page to add such elements to the UI.''' In our case, users are enabled to link to an arbitrary page, which could be unsafe in public wikis (used to trick other users into clicking something). In general, user input must be escaped or sanitised before being used in HTML, or otherwise this could be used to compromise the website. URLs are sanitized, so the risk there is only to link to undesired pages.

The following steps are enough to realise this little example:
 * Create the property Download URL and set its type to "URL"
 * Insert the following at the end of LocalSettings.php:

This code works at least under MediaWiki 1.17 up to 1.21 using SMW 1.7 or 1.8.

While enabled on this wiki, this feature can be demoed on the page SMWCon Fall 2012/Semantic MediaWiki: An Introduction.

Performance considerations
The above code will be executed on many page views, even if the page is not edited. This is no concern for small and medium sites, but one should still keep this in mind when doing similar extensions. If you are using an HTTP cache (Squid, Varnish) then the page HTML will be cached and no code will be executed if it is available from the cache. But the normal MediaWiki parser cache does probably not cache the page actions, so it will not prevent the code to be run on page views.