tips:namespace_clouds
DokuWiki Cloud Plugin Namespace Discrimination Patch
All this info can be found at the various reference locations. I've added it here for convenience.
None of this work is my own –Jeff 2010-06-07
I made a small modification to this plugin and added the ability to limit the word cloud and tag cloud to specific namespaces. When clicking the word cloud, it will restrict the search to the namespace specified. The tag cloud, however, will still display a full backlinks list. Its only been casually tested, so YMMV. I had to change the syntax up a little bit to allow for namespaces.
–TommyWang 09-05-08, Namespace clouds
References:
-
-
- Old discussion page Namespace clouds
-
Credits:
- Original Patch: TommyWang 09-05-08
- Latest Patch: jayjay 2008/07/16 14:47 CET - updated 2008/08/20 16:18 CET (thanks pan One!)
Patch can only be applied to 2008-07-10 release
Copy/download dokufreaks-plugin-cloud-2008-07-10_release-0-gbeda572.tar.gz to/in DW_PATH/lib/plugins
cd DW_PATH/lib/plugins tar xvzf dokufreaks-plugin-cloud-2008-07-10_release-0-gbeda572.tar.gz rm dokufreaks-plugin-cloud-2008-07-10_release-0-gbeda572.tar.gz mv dokufreaks-plugin-cloud-84509f2 cloud cd cloud
Copy/create below file patch.txt to/in DW_PATH/lib/plugins/cloud
patch syntax.php patch.txt rm patch.txt cd .. chown -R WEBSERVER_USER:WEBSERVER_USER cloud
Syntax
{{cloud>[ns]#[num]}} {{tagcloud>[ns]#[num]}}
Where [ns] and [num] are both optional. default ns is *, and default num is still 501). ns shortcuts (.,:,*) are resolved. If using all defaults, simply {{cloud>}} will do.
- patch.txt
diff U3 syntax.bak.php syntax.php --- syntax.bak.php Wed Jul 16 09:20:49 2008 +++ syntax.php Wed Jul 16 14:08:52 2008 @@ -32,24 +32,37 @@ function getSort() { return 98; } function connectTo($mode) { - $this->Lexer->addSpecialPattern('~~\w*?CLOUD.*?~~', $mode, 'plugin_cloud'); + $this->Lexer->addSpecialPattern('{{\w*?cloud>.*?}}', $mode, 'plugin_cloud'); } function handle($match, $state, $pos, &$handler) { + global $ID; + $match = substr($match, 2, -2); // strip markup - if (substr($match, 0, 3) == 'TAG') $type = 'tag'; - else $type = 'word'; + if (substr($match, 0, 3) == 'tag') { + $match = substr($match, 9); + $type = 'tag'; + } + else { + $match = substr($match, 6); + $type = 'word'; + } + + list($ns, $num) = explode('#', $match, 2); - list($junk, $num) = explode(':', $match, 2); - if (!is_numeric($num)) $num = 50; + if (($ns == '*') || ($ns == ':')) $ns = ''; + elseif ($ns == '.') $ns = getNS($ID); + else $ns = cleanID($ns); - return array($type, $num); + if (!is_numeric($num)) $num = 20; + + return array($type, $ns, $num); } function render($mode, &$renderer, $data) { global $conf; - list($type, $num) = $data; + list($type, $ns, $num) = $data; if ($mode == 'xhtml') { @@ -58,9 +71,9 @@ msg('The Tag Plugin must be installed to display tag clouds.', -1); return false; } - $cloud = $this->_getTagCloud($num, $min, $max, $tag); + $cloud = $this->_getTagCloud($ns, $num, $min, $max, $tag); } else { - $cloud = $this->_getWordCloud($num, $min, $max); + $cloud = $this->_getWordCloud($ns, $num, $min, $max); } if (!is_array($cloud) || empty($cloud)) return false; $delta = ($max-$min)/16; @@ -89,10 +102,16 @@ $class .= ($exists ? '_tag1' : '_tag2'); } else { if($conf['userewrite'] == 2) { - $link = wl($word, array('do'=>'search', 'id'=>$word)); + if ($ns == '') + $link = wl($word, array('do'=>'search', 'id'=>$word)); + else + $link = wl($word, array('do'=>'search', 'id'=>"$word@$ns")); $title = $size; } else { - $link = wl($word, 'do=search'); + if ($ns == '') + $link = wl($word, 'do=search'); + else + $link = wl("$word@$ns", 'do=search'); $title = $size; } } @@ -108,7 +127,7 @@ /** * Returns the sorted word cloud array */ - function _getWordCloud($num, &$min, &$max) { + function _getWordCloud($ns, $num, &$min, &$max){ global $conf; // load stopwords @@ -124,6 +143,7 @@ if (@file_exists($conf['indexdir'].'/page.idx')) { // new word-lenght based index require_once(DOKU_INC.'inc/indexer.php'); + $page_idx = idx_getIndex('page',''); $n = 2; // minimum word length $lengths = idx_indexLengths($n); @@ -131,23 +151,19 @@ $idx = idx_getIndex('i', $len); $word_idx = idx_getIndex('w', $len); - $this->_addWordsToCloud($cloud, $idx, $word_idx, $stopwords); + $this->_addWordsToCloud($cloud, $ns, $idx, $word_idx, $page_idx, $stopwords); } - } else { // old index - $idx = file($conf['cachedir'].'/index.idx'); - $word_idx = file($conf['cachedir'].'/word.idx'); - - $this->_addWordsToCloud($cloud, $idx, $word_idx, $stopwords); } - return $this->_sortCloud($cloud, $num, $min, $max); + if (empty($cloud)) return $cloud; + return $this->_sortCloud($cloud, $num, $min, $max); } /** * Adds all words in given index as $word => $freq to $cloud array */ - function _addWordsToCloud(&$cloud, $idx, $word_idx, &$stopwords) { + function _addWordsToCloud(&$cloud, $ns, $idx, $word_idx, $page_idx, &$stopwords){ $wcount = count($word_idx); // collect the frequency of the words @@ -156,22 +172,41 @@ if (!is_int(array_search("$key\n", $stopwords))) { $value = explode(':', $idx[$i]); if (!trim($value[0])) continue; + if ($ns == '') $cloud[$key] = count($value); - } + else + { + foreach ($value as $v) + { + list($p,$c) = explode('*', $v); + if (substr($page_idx[$p], 0, strlen($ns)) == $ns) + $cloud[$key]++; + } + } + } } } /** * Returns the sorted tag cloud array */ - function _getTagCloud($num, &$min, &$max, &$tag) { + function _getTagCloud($ns, $num, &$min, &$max, &$tag){ $cloud = array(); foreach ($tag->topic_idx as $key => $value) { if (!is_array($value) || empty($value) || (!trim($value[0]))) continue; + if ($ns == '') $cloud[$key] = count($value); - } + else + { + foreach ($value as $idx){ + if (substr($idx, 0, strlen($ns)) == $ns) + $cloud[$key]++; + } + } + } - return $this->_sortCloud($cloud, $num, $min, $max); + if (empty($cloud)) return $cloud; + return $this->_sortCloud($cloud, $num, $min, $max); } /**
1)
Seems to be 20
tips/namespace_clouds.txt · Last modified: 2016-02-03 15:11 by Aleksandr