Extension:KeyValue

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.

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 addresses are: and .

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

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.

SelectTag
This extension is also similar to SelectTag.

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

Revision history

 * 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


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


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


 * v0.9
 * fixed wrong version numbers


 * v0.10
 * removed debug logging


 * v0.11
 * fixed bug where prefixes were not taken into account for checking existing table presence


 * v0.12
 * fixed bug where a keyvalue on a page that is redirected to would be saved multiple times, for each redirect link


 * v0.13
 * sysops now get a button to recreate table (drop and create)
 * multiple parsing rounds no longer create duplicate key/values


 * v0.14
 * fixed bug where table detection on mysql would not work


 * v0.15
 * added link to page where keyvalue is stored in special pages categories view


 * v0.16
 * getting catgeries lists to be displayed in alphabetical order on key


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


 * v0.18
 * removal of unneeded php endings and unneeded globals
 * added a boolean to keep track if actually saving or not as a speedup measure