Tag Plugin

tag plugin by Gina Häußge, Michael Klier
Assign category tags to wiki pages. (previous authors: Esther Brunner)

Last updated on 2009-05-11. Provides Syntax, Helper, Action.
Compatible with DokuWiki 2009-02-14, 2008-05-05.

Requires pagelist.
Similar to blogtng.

Tagged with blog, listing, navigation, tags.

    Download

    Download plugin-tag.tgz

    Description

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

    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.

    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)
    pingtechnorati Enable/disable Technorati pinging.
    sortkey Order in which tagged pages are sorted in the topic overview available options are creation date, modification date, page name, page ID 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

    Ping

    This plugin automatically pings Technorati on the creation of a new page. This behavior can be turned off in the configuration manager.

    Demo

    You can see the plugin in action here.

    Bugs / Feature Requests

    Please report bugs or feature requests at the Bug tracker.

    Further Resources

    Changes

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

    Discussion

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

    Limit tag list by namespace

    It would be an important feature to be able to make a list of pages containing specific tag limited to specific namespace, e.g. listing pages tagged ”pizza” from namespace ”restaurants” (while not listing those from ”recipes”).

    another feature request for easier tag entry

    A plugin to make tag entry easier would be great. I checked out tagentry plugin, which puts checkboxes under the edit form to add tags, but once you're over a few dozen tags, this is cumbersome. A better tagentry solution might be, for instance, auto-complete in a tag entry form or input box.

    show page name not working

    I tried to show a tag with their pagenames but first headline, but failed. I found out there is a if statement has to be remove.

    ./helper.php
    line: 274-280
    

    mark out line 274 and 280 will fix this issue.

                //if (!$this->page['title']) {
                    if($this->showfirsthl) {
                        $this->page['title'] = $this->_getMeta('title');
                    } else {
                        $this->page['title'] = $this->id;
                    }
                //}
    

    I have the same problem

    I first tried configuring it by setting the appropriate pagelist flag:

    $conf['pagelist_flags'] = 'table,nofirsthl,nouser';      // formatting options for the page list plugin
    

    However it did not work (changing the list to table and adding nouser did work so I presume I formatted the options correctly).

    While hoping this will be fixed or perhaps an explanation of the proper configuration for this issue will be available at some point by some kind person :)

    The changes suggested above seems to be for an older version of the code, I did this hack to avoid the issue for now.

    In helper.php line 169, replaced:

    $title = $meta['title'];
    

    with:

    $title = $meta['page'];
    

    Blockword

    If a tag name begins with a blockword (e.g. and_there_was_light) , the {{topic>}} listing for this tag is empty! (DokuWiki darcs devel (2007-01-16) + tag plugin 2.1.2 (2007-01-12) )

    proposed fix:

    --- lib/plugins/tag/helper.php-orig
    +++ lib/plugins/tag/helper.php
    @@ -127,7 +127,9 @@
         $sw    = array(); // we don't use stopwords here
         $matches = idx_lookup(idx_tokenizer($tag, $sw));  // tag may contain specials (_ or .)
         $matches = array_values($matches);
    -    $docs    = array_keys($matches[0]);
    +    $docs    = array();
    +    foreach($matches as $mkey ) { $docs = array_merge(array_keys($mkey),$docs); }
    
         $docs  = array_filter($docs, 'isVisiblePage'); // discard hidden pages
         if (!count($docs)) return $result;
    

    Wrong link in action.php

    little mistake in action.php : in function getInfo

    'url' => 'http://wiki:splitbrain.org/plugin:tag'

    must be

    'url' => 'http://www.dokuwiki.org/plugin:tag'

    :)

    Oh well… the domain here changed one day ago… will be fixed in the next release… — Michael Klier 2008/08/11 22:24

    Move tags line outside page content

    It would be great if tags line would embed into page template (outside the content). Otherwise the “Edit” button (for example) can appear below tags line and it looks like one should edit not section but tags. — Andriy Lesyuk 2009/04/04 01:04

    Generate a list of all tags

    How can I generate a list of all tags, each of item works as

    {{topic>tagN}}

    I am not yet sure, how to represent a list… Horizontally? Like:

    All tags: {{alltags}}

    generates:

    All tags: article picture event

    Oh, found the fine solution: plugin cloud

    Tag as a normal link

    Hi. It'll be great if we can use tag directly in the text, “inline”. I edited the CSS but I can't make the tag appear within the <p></p> of wiki text.

    Any way to use a tag directly in a text?

    For example:

    I know {{tag>PHP}} and {{tag>HTML}}

    Maybe also

    {{tag>CPP|C++}}

    This must be able to be specified many times on a page. This will be a natural way of specifying tags/keywords…

    How about using 'interwiki' mechanism? You can use a syntax of [[tag>XXX]] by adding a line to conf/interwiki.conf like this.
    tag           http://your.domain/doku.php?id=tag:
    #or, nice URL
    tag           http://your.domain/tag/

    > — iobataya 2010/01/28 04:06

    Another feature requests:

    Hi! Another feature requests :

    • I would like to add a tag in a page, and when I click on this tag, I would become a list of pages containing this tag (and not the page exactly named like the tag). I found a solution by editing the code but it is not very elegant. I am sure it exists a better way to do this.
    • Same question for the clouds plugin. I would like to have a list of the available tags displayed as a cloud, but if I click on a tag, I would become a list of pages containing this tag (and not the page exactly named like the tag). Is it a way to do this?
    • Last request :-), in the clouds plugin, by deleting or editing a page, the number of instances of a tag is not updated. It is only updated by adding a tag in a new page. If I add 10 pages with the tag 'test' and then I delete 9 of these pages, the number of instances of the tag 'test' remains 10. Is there a way to always have the right number of tags?

    Thank you very much in advance for your attention and have a good day. Olivier

    Maybe handy to follow the request at the start of this section and report the requests..

    Relative tag links

    Hi, can tag links be relative. Now they are absolute and when I move my wiki, tag links do not work anymore. — Mario 2007-09-21 15:30

    Get count of pages

    Can I anyhow get count of pages, found by topic>-tag1 +tag2 request? May be a special flag to display needed? — mita 2008-08-28 21:08

    Tag refinements doesn't work

    The syntax {{topic>car +honda -track}} doesn't work due to function tagRefine is not invoked at all. I have fixed this issue on my system by adding one line into topic.php file:

      function render($mode, &$renderer, $data){
        list($ns, $tag, $flags) = $data;
     
        if ($my =& plugin_load('helper', 'tag')) $pages = $my->getTopic($ns, '', $tag);
        if (!$pages) return true; // nothing to display
     
        $pages = $my->tagRefine($pages, $tag); // I have added this line
        . . .

    Anton 2008-01-26

    Thanks for this fix Anton!
    Works great. — JeeMan 2008-06-16
    Yes! Thanks for this fix Anton! Hopefully, this will be updated in the plugin source? -JWD 2008-08-08

    Assigning Tags with JavaScript and Frames

    I have to assign a lot of tags for my wiki and tried to simplify the task a little. It is a work in progress, but I would be grateful for comments and improvements, since I do not usually 'program' things like these. The idea is to open DokuWiki in a frameset with a second frame on the right side of the page to display the keywords that can be assigned. One click on the keyword and the tag gets expanded by this keyword. I started playing around with this idea today and currently it looks like this:

    Page to open when assigning keywords, opens the Wiki and the keyword-file in frames, is in the top-level wiki directory (where the doku.php is, named keywordmain.htm, :!: replace ”[…]/wiki/” with the path where your wiki is):

    <html>
    <head>
    <title>Keyword-Help</title>
    </head>
    <frameset cols="600,200">
      <frame src="http://localhost/[...]/wiki/doku.php?id=start" name="wikiframe">
      <frame src="keywords.htm" name="keywordsframe">
    </frameset>
    </html>

    The following file (keywords.htm) is loaded as a frame. It consists of the keywords, which when clicked execute a JavaScript function. This function gets the whole content of the text area (you must click “edit” before clicking on a keyword), searches the tag-code, checks if the keyword is already assigned and if not, adds it to the text area (by replacing the end of the tag-part with the new tag and the end, then replacing the old tag code by the new expanded tag code). It is simply a JavaScript function that replaces the content of the textarea with the content + the new tag. Important: I addressed the form with the textarea by forms[0] however, this is dependent on the skin you are using. The default skin requires all forms[0] changed to forms[4].

    <html>
    <head>
    <script language="JavaScript">
    function transfer(tagline) {
      inhalt = top.wikiframe.document.forms[0].wikitext.value; // gets the Content of the Wiki-Textarea to edit
      Suchdentag = /{{tag>.*}}/;  // finds the part with the tag
      keywordpart = Suchdentag.exec(inhalt);  // finds the part with the tag (executes command)
     
      // very inconvenient piece of code, didn't know the regex for "find either " " + tagline + " " or " " + tagline + "}" so I split it up in two if's
      found = "0";
      searchline = " " + tagline + " ";
      vorhanden = keywordpart[0].search(searchline);
      if(vorhanden != "-1") { found = "1"; };
      searchline2 = " " + tagline + "}";
      vorhanden2 = keywordpart[0].search(searchline2);
      if(vorhanden2 != "-1") { found = "1"; };  
     
      if(found == "0") { // if not already assigned, then assign the keyword
        neueskeyword = keywordpart[0].replace(/}}/g, " " + tagline + "}}");
        replacement = inhalt.replace(/{{tag>.*}}/, neueskeyword);
        top.wikiframe.document.forms[0].wikitext.value = replacement;
        }; // else could be used here to remove a keyword, but since I just want to easily assign them (but not assign them twice, I did not include it
      }
     
    </script>
     
    <style type="text/css">
    body { background-color:#FFFFCC; }
    p,li  { font-size:80%;
            line-height:120%;
            font-family:Helvetica,Arial,sans-serif; }
    </style>
     
    </head>
    <body>
    Keywords:<br>
    <a href="">Update</a><br>
    <ul>
      <li><b>keyword-category 1</b></li>
      <ul><li><a href="javascript:transfer('keyword1')">keyword1</a></li>
          <li><a href="javascript:transfer('keyword2')">keyword2</a></li>
      </ul>
      <li><b>keyword-category 2</b></li>
      <ul><li><a href="javascript:transfer('keyworda')">keyworda</a></li>
          <li><a href="javascript:transfer('keywordb')">keywordb</a></li>
      </ul>
    <!-- etc. -->
    </ul>
    </body>
    </html>

    As I've written, it's a work in progress. If anyone has some nice ideas or better code, kindly post them here. Possible features would be:

    • create an additional function that explicitly removes a keyword if it was assigned (new function, since I do not want to check the tag-code if I already have assigned a keyword, so if I want to assign a keyword, I simply click on it, if it wasn't already there, it is now. If an additional click would remove it, I could never be sure unless I read the tag-code; assigned tags could be displayed at the beginning of the keyword frame, a click on it would remove the keyword.
    • use JavaScript to display the already assigned tags as bold or in a different color (or marked). After clicking on edit an “update”-function could get the keywords already assigned, and when the possible keywords are displayed this information is used to mark the ones that are already assigned. The function to assign the keywords would have to be expanded to change the display status of the assigned (or removed) keyword.
    • better layout
    • Pop-Up Window instead of a frameset. Could be integrated in the Format-Bar of DokuWiki. One click and a popup-window opens with the possible keywords.
    • Pop-Up window could retrieve the already assigned keywords and make it easy to enter new keywords (or simply enter them manually, save, click edit again, click Keyword-Window-Icon.
    • Better Layout of tag window, e.g. Icons, Fold-Icons, etc.
    • Restrict use of tags to the ones assigned (if a new tag is used that is not in a list, it gets kicked (to force users to keep to the predefined tags)
    • Write the tag-syntax if it does not exist in the textarea
    • Since the keywords are displayed in a frame other keyword-pages can easily be loaded if there is a link from the keyword.htm to the file, e.g. different keywords for different settings.

    There are probably other functions that would be nice to have.

    Templates

    By the way, besides assigning keywords, this solution can easily assign templates for the page. Simply define what should be included on the page in a variable and replace the contents of the textarea with it (useful if your information on the page follows a specific structure and you don't want to retype it every time). Given that JavaScript can calculate some things even templates that react to the current date (if you use a wiki as a personal diary) can be handled …

    Other functions

    • Assigning multiple keywords at once is also possible (just write two or more keywords in the brackets like javascript:transfer('keyworda keywordb keywordc').
    • It should be possible to force a reload in the Wikiframe with a generated URL that included the name of the page and the edit command (e.g. “doku.php?id=pagename&do=edit&rev=”). This should make it possible to make a text field in the keyword frame to enter the name of the page, and after pressing a button the Wikiframe is reloaded which creates the page. If the keyword-frame keeps the name in the text field, an additional command could be used to format the page with the name in the text field (should make data entry easier).
    • It is possible to insert information, e.g. before the tag-command. I have this command at the end of the page, so if I write a journal entry and want to make a new entry, a function writes the current time (e.g. 10:22) at the end of the already written text (simply replaces the tag-part with the time, some newline commands and the tag).

    Searching Tags

    It should be possible to use this keyword-frame to “enter” a custom query. Instead of inserting a tag, a click would save the keyword in a string variable and when the query is completed this is used to specify a search (via forcing a reload in the Wikiframe, with pagelist-URL including the selected tags. Is there a way to used the URL but ask for two or more tags to be present or not? If you click on a tag, the URL is “doku.php?id=tag:TAGNAME&do=showtag&tag=TAGNAME” – if this URL could be used to enter the query directly, then JavaScript could play the interface for a nice click on keywords and click on search query.

    National Characters

    Will tags work with national (non-7 bits ASCII) letters or should they be avoided? Those would be funny characters like ø as well as accented characters like å.

    Good idea, I've had some ideas for a slicker tag interface for a while. I've not begun to research the feasibility of my approach, but rather than an IFRAME, my notes call for AJAX callbacks. If you are going to the trouble of program-applying tags, you might also provide a configurable auto-creation of a topic page. Tag-management should probably be a separate plugin. — abr 2008/10/25 21:30
    Does this mean that tags like accessibility should not be used? Is there any other way to have accents included in tags? (e.g. using HTML entities does not work, i.e. accessibility&agrave;). giorgio 2008/11/21 18:30
    National characters worked until I turned on romanisation option, when it is links to national tags without corresponding page doesn't work. It seems to be a bug in plugin. The plugin romanises tag value in 'tag=…' just like page name. I've found a solution.
    Insert a line of code in file tag/helper.php at #126 in function tagLinks():
                 $title = str_replace('_', ' ', noNS($tag));
    +            $otag = $tag; // just save original tag name
                 resolve_pageid($this->namespace, $tag, $exists); // resolve shortcuts
    
    And replace line #138:
                     $class = 'wikilink1';
    *                $url   = wl($tag, array('do'=>'showtag', 'tag'=>$otag)); // need $otag, not noNS($tag)!
                 }
    

    Get list of tags

    Is there any way to get a static listing of all tags used? the cloud plugin shows a cloud-like listing which works for now but I want something like pagelist but to list tags instead.

    There's no such thing yet, please feel free to submit a feature request on the bug tracker linked on this page. — Michael Klier 2009/01/06 23:45

    Tag-based Search

    I would like to have a Searchform to search for Pages with a specific tag or tag +tag or tag -tag. Do you understand what I mean? In Addition to the standard search.

    Toolbar Button

    There should be a possibility to add a button in the toolbar, perhaps configurable.

    — ⇑ You can get a simple and dirty toolbar button by adding this code to the lib/plugins/tag/script.js file:

    if(toolbar){ 
        toolbar[toolbar.length] = 
            {"type":"insert", "title":"Tag", "key":"", 
             "icon":"../../plugins/tag/images/tag.gif", 
             'insert': '{{tag>}}'
            }; 
    }

    Davor 2009/07/02 11:19

    Non existent pages for tabs do not use right CSS

    DokuWiki uses two CSS classes for non existent and existent pages: wikilink1 and wikilink2. The tab plugin do not use wikilink2 in my installation. Is there anyone else with this problem and how I can solve this? I get the newest version and rebuild the index, but the problem still exists. Please email me for any solution. Thanks for help! — Nadir 2008/10/05 16:38

    Orphan tag entries not disappearing after index rebuild

    In my tag cloud I keep getting a tag that just won't disappear. The tag is in brackets [tag] which is also strange. Clicking on the tag gets you to a page that says “Nothing found”. Rebuilding the index does not help. There also is no tag.idx file anywhere in my DokuWiki stack. Can anybody help?

    Language Files

     
    plugin/tag.txt · Last modified: 2010/02/02 01:24 by 74.93.99.97
     
    Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
    Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
    WikiForumIRCBugsGitXRefTranslate