It's better when it's simple

User Tools

Site Tools


Attribute Plugin

Compatible with DokuWiki

  • 2024-02-06 "Kaos" unknown
  • 2023-04-04 "Jack Jackrum" yes
  • 2022-07-31 "Igor" yes
  • 2020-07-29 "Hogfather" yes

plugin Arbitrary attribute definition and storage for user associated data

Last updated on

Tagged with data, persistent, storage, users

Needed for twofactor


Search and install the plugin using the Extension Manager. 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 attributes that have assigned values for the specified user 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

plugin/attribute.txt · Last modified: 2023-09-08 14:12 by dodotori

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki