Table of Contents

Attribute Plugin

Compatible with DokuWiki

  • 2017-02-19 "Frusterick Manners" yes
  • 2016-06-26 "Elenor Of Tsort" yes
  • 2015-08-10 "Detritus" yes
  • 2014-09-29 "Hrun" unknown

plugin Arbitrary attribute definition and storage for user associated data

Last updated on

Tagged with data, persistent, storage, users


Install the plugin using the Plugin Manager and the download URL above, which points to latest version of the plugin. Refer to Plugins on how to install plugins manually.

After installing the plugin, it will work without additional configuration. However the two existing options allow the wiki administrator to choose a location to store the user data and whether to disable compression. The admin should only disable compression when developing a plugin that uses the attribute module because user data is then exposed in plaintext. It is strongly advised to store user data in a location that is not served by the web server; this can only be achieved by web server configuration, eg .htaccess files and the like.


This plugin is used by plugin developers to store user specific data for their plugins. It removes the need for plugin authors to develop their own per-user storage mechanisms. It is not intended to replace wiki wide configuration settings, and will not store settings for anonymous users.

This module does not provide any admin panel to manage stored attribute data. The developer using this plugin is responsible for all attribute manipulation.

class action_plugin_profilecount extends DokuWiki_Action_Plugin {
    function __construct() {
        $this->attribute = $this->loadHelper('attribute', true);
    function register($controller) {
        $controller->register_hook('HTML_PROFILE_OUTPUT', 'BEFORE', $this, 'test_attribute', array());
    function test_attribute(&$event, &$param) {
        if (!$this->attribute) return;
        $counter = $this->attribute->get("profilecounter", "counter", $success);
        if (!$success) $counter = 0;
        // Show the counter only if we have been here before.
        if (counter > 0) $event->data->addElement("<p>Prior profile page visits: $counter</p>");
        $counter +=1;
        $this->attribute->set("profilecounter", "counter", $counter);

Public Methods

Note: For all functions involving a user:

If $user is null, defaults to the currently logged in user.

If the logged in user is not an admin, $user reverts to the currently logged in user.

While running the login action, if $user is the username being logged in with, that username is used.

Otherwise the method fails if no user is logged in.

public function enumerateUsers($namespace)

Generates a list of users that have assigned attributes in the specified namespace. Returns false on failure or an array of usernames.

public function enumerateAttributes($namespace, $user = null)

Generates a list of users that have assigned attributes in the specified namespace. Returns false on failure or an array of of attribute names the user has.

public function exists($namespace, $attribute, $user = null)

Checks if an attribute exists for a user in a given namespace. Returns true if the attribute is present or false under any other circumstance, including method failure.

public function get($namespace, $attribute, &$success = false, $user = null)

Retrieves a value for an attribute in a specified namespace. $success out-parameter can be checked to check success (you may have false, null, 0, or '' as stored value). Returns false on any error or any single PHP data structure.

public function set($namespace, $attribute, $value, $user = null)

Sets the value of an attribute in a specified namespace to the PHP data in value. Value must be serializable; see PHP: serialize - Manual for data requirements. Returns true on success and false on failure.

public function del($namespace, $attribute, $user = null)

Deletes attribute data in a specified namespace by its name. Returns true if the attribute does not exist after the method is called and false on failure to remove the attribute.

public function purge($namespace, $user)

Deletes all attribute data for a specified namespace for a user. Only usable by an admin. Effectively deletes the user's namespace file from the server. Returns true if the file does not exist after the method is called and false if the file could not be removed.

Configuration and Settings

$conf['store'] = 'data/attribute'; // Point to where the data will be stored. Absolute paths are ok.
$conf['no_compress'] = 0; // Set to 1 to not compress data. ALL DATA WILL BE SAVED IN PLAINTEXT!!!

Change Log

Known Bugs and Issues

Don't know of any bugs but I suspect someone will find a way to break the code.

ToDo/Wish List

I need to create a unit test script. Yuck.

Things I was considering:

At this time there are no plans for any additional features.


Feel free to write anything constructive. My hope is that this plugin will provide many developers with useful functionality.