DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:tag

Tag Plugin

Compatible with DokuWiki

  • 2013-12-08 "Binky" yes
  • 2013-05-10 "Weatherwax" yes
  • 2012-10-13 "Adora Belle" unknown
  • 2012-01-25 "Angua" unknown

plugin Assign category tags to wiki pages. (previous authors: Esther Brunner)

Last updated on
2014-02-16
Provides
Syntax, Helper, Action
Repository
Source
Requires
pagelist

:!: The 2013-02-15 release fixed a security issue (XSS vulnerability), if you are using an older version of the tag plugin you should upgrade ASAP! :!:

Description

The Tag Plugin lets you assign category tags to wiki pages.

Updating from before 2012-08-24: Please remove the tag plugin and re-install it as the plugin manager has a bug so the update won't remove no longer needed parts of the plugin. This is a large change to the way the tag plugin stores the tags. If you don't want to wait till the tag index is automatically rebuilt by visiting the pages with the tags, you can rebuild the tag index manually. You also need to update the cloud plugin or the tag cloud won't work anymore.

Components

Tag

{{tag>[list of tags]}}
[list of tags] a space separated list of tags that describe the content of the current page required

Allows you to categorize your wiki pages. The resulting links either point to the corresponding page in the specified tag namespace (only if it exists). If you want a link to point to a page in another namespace, you have to indicate the namespace before the tag name. If this page doesn't exist, just the list of pages with the same tag is shown when you follow one of those links.

Examples:

  • {{tag>tag1 tag2 tag3}}
  • with namespaces: {{tag>:ns1:tag1 ns1:tag2 ns2:subns1:tag3}}

Topic

{{topic>[tag]&[flags]}}
[tag] the category tag for which you want a list of pages required
[flags] pagelist flags delimited by &, see flags optional

This displays a list of all pages that contain the given category tag. The list is sorted alphabetically by page ID. You can also prepend the modifiers + and -. + creates an intersection between the list of pages created by the already defined tags and the pages matching the tag following the + (AND), - removes all pages tagged with the given tag from the list of already found pages.

Example:

  • {{topic>tag1 -tag2}} – Lists all pages tagged with tag1 but not with tag2.
  • {{topic>tag1 +tag2}} – Lists all pages tagged with tag1 and tag2.
  • {{topic>tag1 tag2}} – Lists all pages tagged with either tag1 or tag2 or both.
  • {{topic>ns1?tag1 tag2}} – List all pages inside namespace ns1 tagged with either tag1 or tag2
  • {{topic>.?tag1 tag2}} – List all pages inside the current namespace tagged with either tag1 or tag2
  • {{topic>tag1 tag2 tag3&nodate&desc&sort}} (Adding pagelist options to change the design)

Searchtags

 {{searchtags&[flags]}}
[flags] pagelist flags delimited by &, see flags optional

This displays a search form with the possibility to select a namespace and to select tags from a table of all tags that should either be in- or excluded with the option to choose if the tags should be associated with AND or OR. The results are displayed as in the topic component.

Example:

  • {{searchtags}} – The basic syntax
  • {{searchtags&nodate&desc&sort}} – with pagelist options to change the design

Count

{{count>[tag]}}
[tag] the category tag for which you want the list the occurrence required

This part allows you to display an overview of your current used tags. It prints the tag and the related occurrence (how often is the tag used?) in your wiki. Either you can specify a + as tag-name, which results in a list of all used tags or just specify some tags separated by spaces.

Example:

  • {{count>+}} – List all tags with related occurrences.
  • {{count>tag1 tag2}} – List the occurrence of tag1 and tag2.
  • {{count>tag1 tag2 tag3&. ns1 ns2}} – List all occurrences for the given tags inside the namespaces (the dot specifies the root namespace)

Tagpage

 {{tagpage>[tag][&dynamic][|title]}}

This displays a link to the listing of all tags as it is done by the Tag syntax but without tagging the page with that tag. With the optional dynamic flag the link becomes red when the listing of all pages with that tag is empty for the current user. The dynamic flag automatically disables the cache of the current page in order to ensure that the link color is always correct. Optionally a title can be specified that will be used as link name.

Example:

  • {{tagpage>test_foo}} – The basic syntax
  • {{tagpage>test_foo&dynamic}} – A link with dynamic link color
  • {{tagpage>test_foo|my title}} – A link with custom title
  • {{tagpage>test_foo&dynamic|my | title}} – A link with dynamic link color and custom title (that can also contain |)

Configuration

The plugin can be configured with the DokuWiki configuration manager available in the admin menu.

namespace Namespace where the tag plugin looks for existing tag pages and links to them instead of the default tag overview. You could use the topic component to display the list of tags on such a page for example. (default tag)
sortkey Order in which tagged pages are sorted in the topic overview; available options are creation date, modification date, page name, page ID, namespace and title
sortorder Sort order of the topic overview.
pagelist_flags Comma separated Flags of the pagelist plugin which is used to display the topic overview
toolbar_icon Show icon in page editor toolbar to add tags.
list_tags_of_subns When counting tags in specified namespaces include also tags in subnamespaces.

Tagindex Rebuild

If the tag index becomes corrupted somehow (such as by using page move), then you can rebuild it by using the searchindex plugin or bin/indexer.php.

Demo / Screenshots

Changes

  • 2014-02-16
    • New and updated translations
    • Fixed tag searching with out of date indexes and numbers
    • Drop compatibility with DokuWiki versions older than 2013-05-10 “Weatherwax” in order to be able to use newer DokuWiki features
  • 2013-04-14
    • New sorting key “ns” which lists for each namespace first all pages in the namespace sorted by name and then all subnamespaces sorted by namespace name
    • Sort by page name (as displayed by the pagelist plugin) when no title exists and the sort key is title
    • In the topic syntax an implicit query for all pages is assumed if the query starts with a tag with ”+” or ”-”, this means that ”+tag +tag2” is now the same as “tag +tag2” and that ”-tag1” will return all pages without tag1.
    • The tagRefine-function (used by the blog plugin) now also supports tags without ”+” or ”-”
    • Revert the tag query change that was introduced in version 2012-08-24, before this change the query was executed as if all tags with a ”+” or ”-” were at the end while the documentation actually describes that the order matters. Each part of the query modifies the existing result set and either adds new pages (tag without ”+” or ”-”) or removes all pages with (”-”) or without a tag (”+”).
  • 2013-04-05:
    • New tagpage feature for creating a link to the list of all pages with a certain tag without tagging the page
    • Removed the Technorati ping feature as Technorati is no longer using any pings
    • zh-tw translation updated
  • 2013-02-15:
    • :!: fixed a security issue (XSS vulnerability), if you are using an older version of the tag plugin you should upgrade ASAP!
  • 2012-11-25
    • New searchtags feature, displays a search form for the topic syntax
    • Fix section edit button styles for the new dokuwiki template
    • In the topic syntax now really only namespaces and not pages are matched by namespace parameter
    • When sorting by the title the case is ignored now
    • The topic syntax of the tag plugin is now used instead of the topic syntax of the blogtng plugin when both are installed
    • Fix problems that tags could be missing when another page is rendered during the preview or when an old revision is diplayed
  • 2012-08-24
    • The tag plugin is now using the metadata index of DokuWiki instead of its own index for storing tags. Most plugins that need the tag plugin need to be adapted.
    • Tags are now normalized in the same way as page ids are normalized

Development changelog:

Sites using this Plugin

Feel free to add yours here:

FAQ

How to use tags which consist of multiple words?

Just use an “_”, it gets automatically replaced by a ” ” i.e.:

{{tag>tag_with_multiple_words}}

Also, quotes seem to work:

{{tag>"tag with multiple words"}}

Change CSS styles depending on existing tags

This colors the background of the page to red if the keyword 'deprecated' is specified as a tag.

function _handle_keywords(&$data) {
        global $ID;
 
        // Fetch tags for the page; stop proceeding when no tags specified
        $tags = p_get_metadata($ID, 'subject', METADATA_DONT_RENDER);
        if(is_null($tags)) true;
 
        // Replace underscores with blanks
        foreach($data->data['meta'] as &$meta) {
            if($meta['name'] == 'keywords') {
                $meta['content'] = str_replace('_', ' ', $meta['content']);
 
                $t = explode(',', $meta['content']);
                if(in_array('deprecated', $t)) {
                    $data->data['style'][] = array('type'  => 'text/css',
                                                     '_data' => '.dokuwiki .page {background-color: red;}');
                }
            }
        }       
}

Customizing the breadcrumbs

If you add at pagelist/helper.php

function tpl_youarehere2_help($id){
    $result = '';
    global $conf;
    global $ID;
    global $lang;
    // check if enabled
    if(!$conf['youarehere']) return false;
    $parts = explode(':', $id);
    $count = count($parts);
    // always print the startpage
    $result .= html_wikilink(':'.$conf['start']);
    // print intermediate namespace links
    $part = '';
    for($i=0; $i<$count - 1; $i++){
        $part .= $parts[$i].':';
        $page = $part;
        if ($page == $conf['start']) continue; // Skip startpage
        // output
        $result .= ' &raquo '.html_wikilink($page);
    }
    // print current page, skipping start page, skipping for namespace index
    resolve_pageid('',$page,$exists);
    if(isset($page) && $page==$part.$parts[$i]) return $result;
    $page = $part.$parts[$i];
    if($page == $conf['start']) return $result;
    $result .= ' &raquo '.html_wikilink($page);
    return $result;
}
 
function tpl_youarehere2($id) {
    $str = $this->tpl_youarehere2_help($id);
    $pos = strrpos($str , '&raquo');
    if ($pos == -1)
    return $str;
    return substr($str, 0, $pos);
}
 
function addPage2($page) {
    $id = $page['id'];
    if (!$id) return false;
    $this->page = $page;
    $this->_meta = NULL;
    // priority and draft
    if (!isset($this->page['draft'])) {
        $this->page['draft'] = ($this->_getMeta('type') == 'draft');
    }
    $class = '';
    if (isset($this->page['priority'])) $class .= 'priority'.$this->page['priority']. ' ';
    if ($this->page['draft']) $class .= 'draft ';
    if ($this->page['class']) $class .= $this->page['class'];
    if(!empty($class)) $class = ' class="' . $class . '"';
    $this->doc .= DOKU_TAB.'<tr'.$class.'>'.DOKU_LF;
    $this->_pageCell($id);
    if ($this->column['date']) $this->_dateCell();
    if ($this->column['user']) $this->_userCell();
    if ($this->column['desc']) $this->_descCell();
    foreach ($this->plugins as $plug => $col) {
        if ($this->column[$col]) $this->_pluginCell($plug, $col, $id);
    }
    $this->doc .= DOKU_TAB.'</tr>'.DOKU_LF;
    $this->doc .= DOKU_TAB.'<tr'.$class.'>'.DOKU_LF;
    $this->doc .= DOKU_TAB.DOKU_TAB.'<td style="padding-left:19px; padding-right:15px; padding-bottom:15px; font-size:10px;">';
    $this->doc .= $this->tpl_youarehere2($id);
    $this->doc .='</td>'.DOKU_LF;
    $this->doc .= DOKU_TAB.'</tr>'.DOKU_LF;
    return true;
}

And change tag/action.php

$pagelist->setFlags($flags);
$pagelist->startList();
foreach ($pages as $page) {
    $pagelist->addPage($page);
}

to

$pagelist->setFlags($flags);
$pagelist->startList();
foreach ($pages as $page) {
    $pagelist->addPage2($page);
}

After that, the list of pages that contain the tag, except for the names of pages themselves under them will also be bread crumbs to these pages.

Bad appearance when displaying tags at top of page

When you insert the syntax at the top of a wiki page, the output of the plugin will be displayed below the TOC (Table of Contents). To make the visual appearance more smooth, change your lib/plugins/tag/style.css to the following code:

div.dokuwiki div.tags {
  border-top: 2px dotted __border__;
  font-size: 95%;
  text-align: right;
/*  clear: both; */
}

How to change the word tag and topic to another language

Is it possible to change the word tag used in syntax to something else, like another language {{tagInMylanguage>someTag}} –damascenedamascene

2012/04/10

Discussion

For bugs or feature requests, there is the bug tracker linked here : Bug tracker.

This plugin clashes with the include module of the mediasyntax plugin. One workaround is to disable that part of the mediasyntax plugin by renaming the include.php file.

If you have a tag name that is the same as a page name that already exists, the tag links will point to that page in the current namespace rather than the page name in the tag namespace. Is this a bug or a feature? (3-Aug-2011)?

Found the issue. If you do not specify a namespace, it defaults to whatever is defined as the default namespace (ie. root:tag). If you do specify a namespace, it makes whatever you specify as the location for the data file (ie. root:mynamespace), NOT root:tag:mynamespace.
  • Is there no way to display all used tags? This would be very useful for finding typos and (nearly) duplicate entries. (2012-02-21)
    • Sry, me stupid, it works with count… BUG except that the table-entries are empty in my wiki! Latest DW/Plugin, with ~~NOCACHE~~ Screenshot. Sry for not registering at github for this.
      • In most of my installation it works, in some not… clueless!
    • How to sort the taglist (count>+) alphabetical?

My wiki has about 7000 pages with tags. It takes 25 seconds to display ~~TAGCLOUD~~ (My server runs with latest NGINX, UBUNTU 12.04, 4 core i5 cpu with 8gb ram, intel SSD ). Anyone have any other suggestion? or Do I need SQL-based tagging solution? — S.C. YooS.C. Yoo
goldseed

Seoul, Korea
2014/04/19 06:02

Individual Search Form

I'd like a form where the user could just type in the tag name, click search, and then a list is generated below. I know you got the searchtags but its just going to get unwieldy with the amount of tags I'm envisioning having. Thanks

plugin/tag.txt · Last modified: 2014/04/19 06:03 by goldseed