Extension:KeyValue

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
KeyValue

Release status: beta

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
Download Project page
Download snapshot

Git [Help]
Commit history
Note:
No localisation updates are provided by translatewiki.net.

README

Hooks used
ParserFirstCallInit

LanguageGetMagic
ArticleSaveComplete
ArticleDeleteComplete

Translate the KeyValue extension if possible

Check usage and version matrix; code metrics

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 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[edit | edit source]

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.

Usage[edit | edit source]

Basic Usage[edit | edit source]

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 adresses 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 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[edit | edit source]

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[edit | edit source]

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[edit | edit source]

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 extensions[edit | edit source]

Semantic Mediawiki[edit | edit source]

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[edit | edit source]

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[edit | edit source]

This extension is also similar to SelectTag.

Development[edit | edit source]

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

Roadmap[edit | edit source]

No newly planned functionality or bugfixes currently...

Revision history[edit | edit source]

v0.1[edit | edit source]

  • first version

v0.2[edit | edit source]

  • 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[edit | edit source]

  • 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[edit | edit source]

  • 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[edit | edit source]

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

v0.6[edit | edit source]

  • 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[edit | edit source]

  • 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[edit | edit source]

  • 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[edit | edit source]

  • fixed wrong version numbers

v0.10[edit | edit source]

  • removed debug logging

v0.11[edit | edit source]

  • fixed bug where prefixes were not taken into account for checking existing table presence

v0.12[edit | edit source]

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

v0.13[edit | edit source]

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

v0.14[edit | edit source]

  • fixed bug where table detection on mysql would not work

v0.15[edit | edit source]

  • added link to page where keyvalue is stored in special pages categories view

v0.16[edit | edit source]

  • getting catgeries lists to be displayed in alphabetical order on key

v0.17[edit | edit source]

  • 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[edit | edit source]

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