Extension:KeyValue

KeyValue is an extension that allows you to store one or more key/values on a mediawiki page by using the keyvalue function. The extension is also focussed 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.

Installation
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 Usage
After installing the extension, you can use it by including the following function on a page:

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

My computer's mac adresses are: and .

Which will render as:

My computer's mac adresses 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 constraints
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 page
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.

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

Downloading as csv
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 and quoting enclosure if the key's or values contain commas or double quotes by default. If you want, you can add two parameters to link to control delimiter and enclosure:


 * delimiter=
 * enclosure=

e.g. if you want to use a ';' delimiter and a single quote for enclosure, you could change this link:

http://localhost/mediawiki/wiki/Special:KeyValue/mac&csv=true

into this link:

http://localhost/mediawiki/wiki/Special:KeyValue/mac&csv=true&delimiter=;&enclosure='

to get the desired result.

Semantic Mediawiki
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.

Data
This extension is also similar to Data extension which is value centric, but this extension focuses on keeping everything as simple as possible. You might want to try the Data extension if this extension does not cover your needs.

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

Roadmap
No newly planned functionality or bugfixes currently...

v0.1

 * first version

v0.2

 * 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.

v0.3

 * 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.

v0.4

 * 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.

v0.5

 * bugfix during index creation: field is called kvcategory iso category.

v0.6

 * 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