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.
| Download | plugin-tag.tgz |
|---|
The Tag Plugin lets you assign category tags to wiki pages.
{{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}} {{tag>:ns1:tag1 ns1:tag2 ns2:subns1:tag3}} {{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. |
pagelist_flags | 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 behavior can be turned off in the configuration manager.
You can see the plugin in action here.
Please report bugs or feature requests at the Bug tracker.
Just use an “_”, it gets automatically replaced by a ” ” i.e.:
{{tag>tag_with_multiple_words}}
For bugs or feature requests, there is the bug tracker linked here : Bug tracker.
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”).
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.
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 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'];
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;
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
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
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
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…
Hi! Another feature requests :
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..
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
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
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
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:
There are probably other functions that would be nice to have.
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 …
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.
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:30Does 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à). 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)!
}
— Vovanium doci [at] vovanius [dot] dyndns [dot] org
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
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.
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
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
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?