tag plugin by Gina Häußge, Michael Klier
Assign category tags to wiki pages. (previous authors: Esther Brunner)
Last updated on 2008-04-20. Provides Syntax, Helper, Action.
Compatible with DokuWiki 2006-11-06, 2007-06-26b, rc2008-04-11.
| Download | plugin-tag.tgz |
|---|
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.
{{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.
Example: {{tag>tag1 tag2 tag3}}
{{tag>list of tags}}
{{topic>list of tags}}
To make a list of tags site-wide (regardless of the position of the list/tags in namespaces) remove the brackets.
{{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.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. |
pagelistflags | Comma separated Flags of the pagelist plugin which is used to display the topic overview |
This plugin automatically pings Technorati on the creation of a new page. This behaviour can be turned off.
You can try the plugin here.
Please report bugs at the Bug tracker.
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;
little mistake in action.php : in function getInfo
'url' => 'http://wiki:splitbrain.org/plugin:tag'
must be
'url' => 'http://wiki.splitbrain.org/plugin:tag'
:)
I have created 3 pages: 1st with “north” and “south” tags and 3rd with “north” only. i thought that when i list with topic for “nort” all 3 pages have to be shown, but instead only 3rd page is diplayed.
1st two pages:
{{tag>[north south]}}
3rd page:
{{tag>[north]}}
i have tried to create topic with:
{{topic>[north]}}
and only page 3 is shown.
I grew tired of having to follow every new tag link and create a new page with a topic-list manually, so I made a few modifications. It's a hack, and it's far from perfect, but it works alright. Whenever a new tag is created, it figures out where the appropriate file should be located, and if it doesn't exist, creates it, adds a header with the tag name and a topic-tag that lists all the pages. Same, when a tag is removed, it deletes the appropriate file. No warranties at all, but it works well enough on my installation.
Here's the updated functions
From helper.php Adding the file
/**
* Returns the links for given tags
*/
function tagLinks($tags){
global $conf; //added this as well
if (!is_array($tags)) $tags = explode(' ', $tags);
if (empty($tags) || ($tags[0] == '')) return '';
foreach ($tags as $tag){
$title = str_replace('_', ' ', noNS($tag));
resolve_pageid($this->namespace, $tag, $exists); // resolve shortcuts
if ($exists){
$class = 'wikilink1';
if ($conf['useheading']){
$heading = p_get_first_heading($tag);
if ($heading) $title = $heading;
}
} else {
$class = 'wikilink2';
}
$links[] = '<a href="'.wl($tag).'" class="'.$class.'" title="'.hsc($tag).
'" rel="tag">'.hsc($title).'</a>';
$tag_filename=$conf['datadir'].'/'.str_replace(':','/',$this->namespace).'/'.strtolower(noNS($tag)).'.txt';
if (!file_exists($tag_filename)) //this is the magic part
{
$f=fopen($tag_filename,'x');
fwrite($f,'====== '.ucfirst(noNS($tag)).' ======
{{topic>'.strtolower(noNS($tag)).'}}');
fclose($f);
}
$this->references[$tag] = $exists;
}
return implode(', ', $links);
}
Deleting the file
/**
* Update tag index
*/
function _updateTagIndex($id, $tags){
global $ID, $INFO, $conf; //notice I added $conf here. otherwise it can't resolve the correct file path
...
// clear no longer used tags
if ($ID == $id){
$oldtags = $INFO['meta']['subject'];
if (!is_array($oldtags)) $oldtags = explode(' ', $oldtags);
foreach ($oldtags as $oldtag){
if (!$oldtag) continue; // skip empty tags
$oldtag = utf8_strtolower($oldtag);
if (in_array($oldtag, $tags)) continue; // tag is still there
$this->tag_idx[$oldtag] = array_diff($this->tag_idx[$oldtag], array($pid));
$tag_filename=$conf['datadir'].'/'.str_replace(':','/',$this->namespace).'/'.strtolower(noNS($oldtag)).'.txt';
if (file_exists($tag_filename)) unlink($tag_filename); //deleting the file
$changed = true;
}
}
...
}
Since you know the code and system better, I think you can come up with a more elegant solution. But I do think that tags should automatically create their list files. pmWiki could (one of the few things it did better than doku) -Sane Traitor
This was very nice, I was just 'bout to write it myself when I found your code snippet. In your first sections of code, I made the minor change of adding some checking for if the file actually was created, and in that case changing the $class to wikilink1 instead of wikilink2 (which is for pages that don't exist.
Also, it should be noted that this code won't create the actual directory for the tag files to be stored in. Not a big problem since most ppl wanting this addition probably already have the directory in their structure, but still something to remember…
~ Wille Raab raab [at] home [dot] se
Yes, a very handy tweak - however, I had trouble with the fopen() function. I don't know if this is a php 5 thing, but the line$f=fopen($tag_filename,'w');isn't appropriate on my Debian setup. The second argument (mode) must be 'x' for the file to be created in the first place. The function reference is here: http://uk3.php.net/manual/en/function.fopen.php
I tentatively put a change in above, although this must have worked in the past — Nathan Shepperd 2008-02-02 11:42
I tested deleting a tag completely and reinventing it again. In that case the tag site gets generated (with correct code), but the topic list is displayed as empty. Is this a feature of my installation or does anyone else face this problem? Alex Poddey
Please check the errors in tagging on my page. It also lists page contents!!!
MacEntwicklerWiki - Cocoa Konzepte
Thanks! — Kay 2007-02-11 09:38
From http logs:
[Thu Apr 26 11:46:18 2007] [error] PHP Fatal error: Call to undefined function curl_init() in /usr/local/www/data/dokuwiki/lib/plugins/tag/action.php on line 64
— therek 2007-04-26
When using the plugin manager, the helper.php file has a var_dump call in the _generateTagIndex() function. This causes junk to be dumped to some pages. It's simple to comment out, but still … The manager.dat file says it's coming from “http://www.qwik.ch/media/tag.zip”. — Matthew Hayes 2007-06-04 23:18
Since Upgrading to version 2008-05-05, my tags are no longer working. I have Installed the mos trecent version of the plugin and all it's required plugins, and even all of their required plugs, but still nothing. The tags are just appearing as a list of comma separated links. The tag must be workign in some respects if the links display as comma separated but shouldn't they be on the right with a little tag icon? -
I managed to resolve this by copying over my /data/index.tag.idx from my previous installation to my new installation.
Graham Macleod 15/5/2008 9:58am
Hi, Is it possible to make the tag separator a comma instead of a space ? Sometimes you'd like to have a tag consist of multiple words. Thanks in advance,
23-04-2008 charlieMOGUL
Hi! Is it possible to make the tags display after all texts like footnotes? Thanks! — Zorden 2007-02-21 10:46 CET
Same question here, would be great if the tags could be displayed after the footnotes. Just on the postion where mediawiki's tags appear (good for tatewake's monobook skins) Sjoerd - 17 mei 2007No. — Esther Brunner 2007-08-11 16:57
Another one: is it possible to list the corresponding pages in a topic as a comma separated list? — Zorden 2007-02-21 15:49 CET
No, but as unordered list or table with the Pagelist Plugin. — Esther Brunner 2007-08-11 16:57
Missing on this page: An example and good documentation. example: Ping can be turned off ? How?
In the configuration of your site, of course
Add tags with spaces, like “Virtual Machine” (cloud plugin should take care of this too). This feature would be very useful!
Just write “Virtual_Machine”. The underscore won't get displayed, but the Tag Plugin (and the Cloud Plugin for tag clouds) then take the combined words as one tag. — Esther Brunner 2007-08-11 16:57
Can we control the font inside the box?
I get a solution for phrase tag as “Virtual Machine”, just modify syntax/tag.php:
function handle($match, $state, $pos, &$handler){ global $ID; $txt = substr($match, 6, -2); //$tags = explode(' ', $txt); // strip markup and split tags $tags = $this->parseTagList($txt); if (!$my = plugin_load('helper', 'tag')) return false; $my->_updateTagIndex($ID, $tags); return $tags; } function parseTagList($txt) { $tags = explode(' ', $txt); // strip markup and split tags $startDetected = false; $endDetected = false; $word = array(); $newTags = array(); foreach($tags as $tag) { $pos = strpos($tag, '"'); // search for double-quote if ( $pos === 0 ) $startDetected = true; elseif ( $pos > 0 ) $endDetected = true; if ( $endDetected ) { $word[] = substr($tag,0,-1); $startDetected = false; $endDetected = false; $tag = join(' ',$word); $word = array(); } else if ( $startDetected ) { $word[] = substr($tag,1); } if ( ! $startDetected && ! $endDetected ) { $newTags[] = cleanID($tag); } } return $newTags; }
it works up to now. — Marc DeXeT 2007-08-16 10:44
Hi! Another feature requests:
Thank you very much in advance for your attention and have a good day. Olivier
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
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
When I installed the tag plugin, all blog entries were sorted anew but got the wrong date assigned (i.e. an entry starting with “A” was assigned the earliest date, an entry starting with “Z” was assigned the latest date.
I solved it for the moment by sorting my blog entries by “last change” date - but I am not happy about it. I assume it's only a problem when starting tagging after starting blogging but nonetheless someone might like to look at it.
Otherwise - just fine.
And next day - after rebuilding cache and index (because “tagcloud” showed tags that were used in a first test, but deleted afterwards), all was as it should have been before. So, no programming but a caching problem.
Birte 2008-02-17
If blog page include pages with tags, then this page (blog) contains in tag.idx but it is wrong. And therefore tagcloud shows wrong count of tags. — Kirill Bezrukov 2008/04/01 21:51