MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
Release status: unmaintained
Implementation Parser function , Special page
Description Allows for storing key/values under a certain category, and to retrieve them per category as a csv file. Not grouped per article.
Author(s) Pieter Iserbyt (Sandbtalk)
Latest version 0.19 (2011-04-02)
MediaWiki 1.16+
PHP 5.3+
Database changes Yes
License GNU Lesser General Public License 2.1

The KeyValue extension allows you to store one or more key/values on a MediaWiki page by using the keyvalue function. The extension is also focused on keeping it simple, and tries to cover a minimal set of functionality.

The values are not typed and stored as text in a table in the database. A value is stored for a certain key and a certain category.

You can access all categories through a special page, and all key/values for a specific category through a subpage of that special page. You can also download the key/values for a specific category as a "csv" file.


You install the extension using the default approach:

  • Copy the files in your MediaWiki directory under extensions: mediawiki/extensions/keyvalue/.
  • The extension should auto-create the keyvalue table, so no action on the database side should be required.
  • If your database does not have create table rights, or is not a mysql or sqlite database, you can create the table yourself:
CREATE TABLE keyvalue ( article_id INT, kvcategory VARCHAR(255), kvkey VARCHAR(255), kvvalue TEXT);
CREATE INDEX keyvalueindex on keyvalue (article_id, kvcategory);
  • Do not forget to add a prefix to the name if you are using a prefix.


Basic UsageEdit

After installing the extension, you can use it by including the following function on a page:

{{#keyvalue: category | key | value }}

e.g. on a user page, you could include

My computer's mac addresses are: {{#keyvalue: mac | jimmy-laptop-eth0 | 00:11:22:33:44:55 }} and 
{{#keyvalue: mac | jimmy-laptop-wlan0 | 66:77:88:99:aa:bb }}.

Which will render as:

My computer's mac addresses are: 00:11:22:33:44:55 and 66:77:88:99:aa:bb.

This would also automatically define a category mac containing two keyvalues, jimmy-laptop-eth0 = 00:11:22:33:44:55 and jimmy-laptop-wlan0 = 66:77:88:99:aa:bb. After saving this page, this, you should see mac appearing as a category in the KeyValue special page.

Category/Key/Values constraintsEdit

When using the KeyValue extension, you should be aware of these constraints:

  • You need to specify all three of them
  • Category and Key cannot be longer than 255 characters
  • Values can go up to 4kb in size (depending on the database).

KeyValue special pageEdit

You can view all KeyValue categories when going to the KeyValue special page under the section others. The list of key/values for a certain category is available as a subpage, e.g. Special:KeyValue/mac. Each key/value instance is accompanied with a link to the page where it was created.

Categories are created whenever someone uses them, and disappear when the last KeyValue instance referencing that category disappears.

When logged in with sysop rights (Administrator) you can also recreate the table in your database by clicking on the Recreate table button on the main special page (only visible for sysops). Any key value defined on pages will only reappear on the special page after those pages have been saved again though.

Downloading as csvEdit

If you want to download the key/values for a specific category, go to the special page for that keyvalue category e.g. Special:KeyValue/mac and you'll find a link to download as csv at the top of the page:

Download the data for this category as a "csv" file.

The "csv" file will be called category.csv and will contains two fields per record/line, a key and a value. The file will use a comma delimiter.

Similar extensionsEdit

Semantic MediawikiEdit

This extension is similar to Semantic MediaWiki extension but different in that Semantic MediaWiki is page centric while KeyValue is value centric: you can define multiple key/values on one page, and retrieve each one as a separate record in the "csv" file. Semantic MediaWiki is also much more broad, and a super-nice extension for anyone needing a bit more.


This extension is also similar to SelectTag.


You can find the source code of the latest (trunk) version on github on https://github.com/sandb/KeyValueExtension.


No newly planned functionality or bugfixes currently...

Revision historyEdit

  • first version
  • Allowing duplicate keys: no need for these to be unique
  • Improving the auto-table create system (right now you get an error at first use, while in fact everything executed fine)

Note: if you were running 0.1 you'll need to delete the keyvalue table or alter it to the new state.

  • Previous 0.2 version was still referring to 0.1 as it's version so made a new version 0.3 and made sure all files referred to the correct version.
  • fixed a bug where key was a reserved word in mysql but not in sqlite.

Note: if you were running 0.3 or before you'll need to delete the keyvalue table or alter it to the new state.

  • bugfix during index creation: field is called kvcategory iso category.
  • uses autoload to conserve memory and increase reaction time
  • put core functions in a class iso functions, and in a separate file keyvalue.core.php
  • MediaWiki classes are all autoloaded, putting SpecialPages.php in autoload actually made it load everything twice, potentially causing out-of-memory errors. Removed the extra loading of SpecialPages.php.
  • Refactored, did not quite grasp that parsing happens at save time iso at display time. Now works also with templates, got rid of parsing the text, instead letting the parser do the work.
  • fixed wrong version numbers
  • removed debug logging
  • fixed bug where prefixes were not taken into account for checking existing table presence
  • fixed bug where a keyvalue on a page that is redirected to would be saved multiple times, for each redirect link
  • sysops now get a button to recreate table (drop and create)
  • multiple parsing rounds no longer create duplicate key/values
  • fixed bug where table detection on mysql would not work
  • added link to page where keyvalue is stored in special pages categories view
  • getting catgeries lists to be displayed in alphabetical order on key
  • made loading titles from categories optional (efficiency gains, not needed for csv download)
  • added small caching for title objects to improve efficiency
  • rolled my own csv - simpler; removing all coma's no - quoting
  • removal of unneeded php endings and unneeded globals
  • added a boolean to keep track if actually saving or not as a speedup measure