Extension:Widgets
Release status: stable |
|
|---|---|
| Implementation | Parser function |
| Description | Allows adding free-type widgets to the wiki by editing pages in Widget namespace |
| Author(s) | Sergey Chernyshevtalk |
| Latest version | 0.8.3 (2009-02-10) |
| MediaWiki | >= 1.38.0 |
|
|
|
editwidgets |
|
| Licence | GNU General Public License (any version) |
| Download | SVN, tarball, zip |
| Example | Widgets on MediaWikiWidgets.org |
Widgets extension allows adding widgets to wiki by just creating pages in Widget namespace.
This extension was developed by Sergey Chernyshev for Ardorado.com and sponsored by Semantic Communities, LLC.
Usage
To add a widget to MediaWiki installation, just create a page in Widget namespace and then use {{#widget:...}} parser function to include it to the pages of the wiki.
Widget page syntax
Widget extension uses Smarty PHP templating engine to provide simple templating functionality within widget pages. All parameters passed to widget are converted into Smarty parameters.
You should use escape modifiers to make sure that user parameters can not expose hosting website to XSS (or any other) attacks.
{{#widget}} parser function
To add defined widget to pages, users can use {{#widget}} parser function. The syntax is as follows:
{{#widget:WidgetName|param1=value1|param2=value2}}
Where WidgetName is a page name in Widget namespace (e.g. Widget:WidgetName) and param=value pairs are defining parameters defined within widget code.
Arrays
If you use the same parameter multiple times, widget will get an array of values. You can use foreach to go through the array.
Dotted notation
Parameter names can have dots and Smarty will interpret them as associative arrays so you can use foreach with both key and item attributes to traverse through them, or you can just use the same name with dots if you want to reference parameter directly.
Validate modifier
In addition to standard Smarty modifiers (like heavily used escape), Widgets extension implements validate modifier that uses PHP Data filtering to allow validating widget parameters.
To make sure $homepage variable value is a valid URL, you can use following code:
<a href="<!--{$homepage|validate:url}-->">Homepage</a>
Following values for the validate are supported (mapping to PHP's validation filters):
url(FILTER_VALIDATE_URL)int(FILTER_VALIDATE_INT)boolean(FILTER_VALIDATE_BOOLEAN)float(FILTER_VALIDATE_FLOAT)email(FILTER_VALIDATE_EMAIL)ip(FILTER_VALIDATE_IP)
Refreshing widget page
If you're using a call to the widget within the widget page itself, then you will not see the updated widget (and no widget at all when you just created a page). This happens because page contents are not available to Widget extension until page is saved, but the call to {{#widget}} parser function is made before page is saved. After pages is saved, it's being cached by MediaWiki so you don't see the result even if you just reload the page. To make latest edits of the widget code to work, you need to refresh the page in the cache, to do this, you just need to use purge action (see also Purgetab extension).
Download instructions
Download the code archive and extract it to $IP/extension/ folder. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
Installing from tarball
You can download Widgets code here:
- Widgets-0.8.3.tgz - compressed using tar and gzip
- Widgets-0.8.3.zip - compressed using zip
Installing from SVN
To get code from Subversion, just type
svn checkout http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/Widgets/
Installation
To install this extension, add the following to LocalSettings.php:
require_once("$IP/extensions/Widgets/Widgets.php");
Folder permissions
Also, $IP/extensions/Widgets/compiled_templates/ folder should be made writable by web server (this is where Smarty stores pre-compiled templates).
Configuration parameters
You must set the namespace ID. The default, 274, can be changed if you want, but make sure that it's an even number.
To set the namespace ID, paste this code in LocalSettings.php
$widgetNamespaceIndex = 274;
Talk namespace ID will be $widgetNamespaceIndex + 1
User rights
This extension adds Widget namespace, but due to potential security implications that can result from using insecure widget code, this namespace is only editable by users who have editwidgets permission (widgeteditor group is also created to add users to, see Help:User rights management for more details).
To allow widgets to be editable by sysops, add the following to your 'LocalSettings.php' file:
$wgGroupPermissions['sysop']['editwidgets'] = true;
CHANGES
- 0.8.3 (February 10, 2009) - Added 'validate' modifier that makes sure variable value conforms to validation rules (using http://us.php.net/filter).
- 0.8.2 (January 27, 2009) - Fixed a bug when widgets were not showing up correctly on old versions of the pages. Thanks to Max Ingleton for a bug report.
- 0.8.1 (June 25, 2008) - Worked around MediaWiki bug that inserts
</p><p>in front of widget output. - 0.8 (June 10, 2008) - Fixed a bug where variables were carried over from one widget to another on the same page
- 0.7 (May 23, 2008) - Added support for arrays and Smarty's dotted notation
- 0.6 (May 9, 2008) - Minor tweaks and bug fixes, release Makefile
- 0.5 (Feb 11, 2008) - First public release
TODO
- ? Implement page-wide variables. Useful for widgets like JS-Kit that require only one JS include, for example.
Contributing code and widgets
If you would like to contribute patches or found some problems with the code, please send message to the discussion group:
http://groups.google.com/group/mediawiki-widgets
If you created a widget and would like to share it, feel free to post it to MediaWikiWidgets.org or just add it to Widgets library.
Troubleshooting
There are a few common problems users encounter when they start to use Widgets extension - we'll try to document them here:
- On a widget page, right after you just created it (or copied from MediaWikiWidgets.org)you see the message:
Warning: Smarty error: unable to read resource: "Widget:<your-widget-name>" /math-to-your-mediawiki/extensions/Widgets/ smarty/Smarty.class.php on line 1095
- This is most likely caused by widget not yet existing at the moment when widget page itself is being processed - to solve this simply purge the page, e.g. add &action=purge (or ?action=purge if you have nice URLs) to the url.
- If page doesn't load and you see following error message in the log file:
PHP Fatal error: Smarty error: unable to write to $compile_dir '/path-to-your-mediawiki/extensions/Widgets/compiled_templates'. Be sure $compile_dir is writable by the web server user. in /path-to-your-mediawiki/extensions/Widgets/smarty/Smarty.class.php on line 1095, referer: http://your-wiki.com/Widget:<your-widget-name>
- Check if you changed permissions for Smarty to store compiled templates in.
Support
The best way to seek help with this extension is to send you questions to MediaWiki Widgets Google group
http://groups.google.com/group/mediawiki-widgets
extension maintainer and active users and contributors are on this list and will be able to help you.
Widgets library
MediaWikiWidgets.org contains a full library of ready-made widgets, including support for most of the major video sites. Any widget can be used simply by copying over the contents of the page.
Video widgets
|
More widgets
|
Even more widgets
|
To get a most up to date list of widgets click here.
See also
Sites using this extension
- Technical Presentations
- Ardorado.com
- All sites on Referata.com hosting
- Second Life wiki
- New York Semantic Web meetup group
- Armada HQ wiki
- theDIYpal
- The Koç School Knowledgebase and The Koç School Academic Wiki (two wiki's of a Turkish K-12 school, both with restricted access)
- Verwaltungskooperation.at - Cooperation in public administration (German)
- University of Sheffield: teachingcommons project - Case Studies Wiki
- Guida Wiki Comuni-Italiani.it
- MIKE2.0 Wiki
