Table of Contents

DokuWiki Snippets

List all tags of the tag plugin

Run in the page directory:

  grep -Rh '{{tag>' * |grep -v '{{tag>}}'| awk '{print substr($0, 7, length($0)-8)}'|tr ' ' "\n"|tr '[:upper:]' '[:lower:]' |sort| uniq -c|sort -nr

Extract a list from instructions

    public function parseList($page) {
        $instructions = p_cached_instructions(wikiFN($page),false,$page);
        $max = count($instructions);
 
        $list = $this->subList($instructions, $i = 0, $max, 1);
 
        dbg($list);
    }
 
 
    function subList(&$instructions, &$i, $max, $lvl) {
        $count = 0;
        $list = array();
 
 
        for(; $i<$max; $i++){
            if($instructions[$i][0] == 'listu_open'){
                $i++;
                if($count) {
                    $list[$count-1]['sub'] = $this->subList($instructions, $i, $max, $lvl+1);
                }
            }elseif($instructions[$i][0] == 'listu_close'){
                return $list;
            }elseif($instructions[$i][0] == 'listitem_close'){
 
            }elseif($instructions[$i][0] == 'internallink'){
                $page = $instructions[$i][1][0];
                $list[$count] = array(
                    'link'     => $page,
                    'type'     => 'internal',
                    'title'    => $instructions[$i][1][1],
                    'lvl'      => $lvl
                );
                $count++;
            }
        }
 
        return $list; // shouldn't be reached
    }