Tag Plugin

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

Last updated on 2008-08-30. Provides Syntax, Helper, Action.
Compatible with DokuWiki 2008-05-05.

Requires pagelist.

Tagged with folksonomy, tagging, tags.

Download

Download plugin-tag.tgz

Description

The Tag Plugin lets you assign category tags to wiki pages. It will display a list of links to the tag pages in the tag namespace specified in the configuration.

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 point to the corresponding page in the specified tag namespace. If you want a link to point to a page in another namespace, you have to indicate the namespace before the tag name.

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.

Demo

You can see the plugin in action here.

Bugs

Please report bugs at the Bug tracker.

CSS fix: tag list pushing page content down

FIXME I found that the list of tags generated by {{tag>demo}} would interact badly with a page contents box when placed at the top of the page. Due to clear: both; the tag would be pushed below the contents div, leaving an ugly and (in the case of pages with many contents entries) irritating gap.

I amended the div.dokuwiki div.tags entry in the stylesheet /usr/share/dokuwiki/lib/plugins/tag/style.css to read:

div.dokuwiki div.tags {
  border-top: 2px dotted __border__;
  font-size: 95%;
  text-align: right;
  clear: none;
  overflow-x: hidden;
}

This solves the problem in IE7 and Firefox 3 but I'm unable to test it in any other browsers.

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

Blockword

If a tag name begins with a blockword (eg. 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

Feature requests

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 ?

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

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

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

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

Language Files

Spanish

lang.php

<?php
/**
 * Spanish language file
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Digna González Otero <digna.gonzalezotero [at] gmail [dot] com>
 */
// custom language strings for the plugin
$lang['tags']  = 'Etiquetas';
$lang['topic'] = 'Tema';
 
$lang['missing_pagelistplugin'] = 'Para listas de temas debe estar instalado el Plugin Pagelist Plugin.';
 
$lang['menu'] = 'Gestor de Índice de Etiquetas';
 
//Setup VIM: ex: et ts=2 enc=utf-8 :
?>
=== settings.php ===
<?php
/**
 * Spanish language file
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Digna González Otero <digna.gonzalezotero [at] gmail [dot] com>
 */
 
// for the configuration manager
$lang['namespace']      = 'Espacio de nombres por defecto para las etiquetas';
$lang['pingtechnorati'] = 'Ping Technorati';
 
$lang['sortkey']                = 'ordenar las listas de temas por';
$lang['sortkey_o_cdate']        = 'fecha de creación';
$lang['sortkey_o_mdate']        = 'fecha de modificación';
$lang['sortkey_o_pagename']     = 'nombre de la página';
$lang['sortkey_o_id']           = 'ID de la página';
$lang['sortkey_o_title']        = 'título';
 
$lang['sortorder']              = 'tipo de ordenación';
$lang['sortorder_o_ascending']  = 'ascendente';
$lang['sortorder_o_descending'] = 'descendente';
 
$lang['pagelist_flags'] = 'Flags de formato para la lista de tags (separadas por coma, para ver los flags consultar la documentación del plugin pagelist)';
 
//Setup VIM: ex: et ts=2 enc=utf-8 :
?>
=== intro.txt ===
====== Gestor del índice de etiquetas (TagIndex Manager) ======

Esta página te permite reconstruir el índice usado por el [[http://wiki.splitbrain.org/plugin:tag|Tag Plugin]].
Generalmente esto no es necesario, ya que el índice se construye y actualiza automáticamente mientras
 etiquetas  tus páginas. Sin embargo, si acabas de actualizar, añadir o eliminar muchos archivos,
puede ser una buena idea limpiar el índice.

Este Gestor necesita un navegador reciente ya que usa JavaScript modernos
para llevar a cabo múltiples tareas en segundo plano (usando [[wp>AJAX]]).

Reconstruir el índice lleva mucho tiempo. Debes dejar la página abierta
hasta que haya finalizado el indexado.

:!: Se recomienda hacer una copia de seguridad de ''data/index/tag.idx'' por si algo fuera mal durante el proceso de reconstrucción. :!:
 
plugin/tag.txt · Last modified: 2009/01/06 23:46 by chi
 

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
WikiForumIRCBugsDarcsXRefTranslate