1<?php
2/**
3 * Editor Plugin: displays links to all wiki pages edited by a given user or ip
4 *
5 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author   Esther Brunner <wikidesign@gmail.com>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
15
16require_once(DOKU_PLUGIN.'syntax.php');
17
18class syntax_plugin_editor extends DokuWiki_Syntax_Plugin {
19
20    function getType() { return 'substition'; }
21    function getPType() { return 'block'; }
22    function getSort() { return 309; }
23
24    function connectTo($mode) {
25        $this->Lexer->addSpecialPattern('\{\{editor>.+?\}\}',$mode,'plugin_editor');
26    }
27
28    function handle($match, $state, $pos, Doku_Handler $handler) {
29        global $ID;
30
31        $match = substr($match, 9, -2); // strip {{editor> from start and }} from end
32        list($match, $flags) = explode('&', $match, 2);
33        $flags = explode('&', $flags);
34        list($match, $refine) = explode(' ', $match, 2);
35        list($ns, $user) = explode('?', $match);
36
37        if (!$user) {
38            $user = $ns;
39            $ns   = '';
40        }
41
42        if (($ns == '*') || ($ns == ':')) $ns = '';
43        elseif ($ns == '.') $ns = getNS($ID);
44        else $ns = cleanID($ns);
45
46        return array($ns, trim($user), $flags, $refine);
47    }
48
49    function render($mode, Doku_Renderer $renderer, $data) {
50        list($ns, $user, $flags, $refine) = $data;
51
52        if ($user == '@USER@') $user = $_SERVER['REMOTE_USER'];
53
54        if ($my =& plugin_load('helper', 'editor')) $pages = $my->getEditor($ns, '', $user);
55
56        // use tag refinements?
57        if ($refine) {
58            if (plugin_isdisabled('tag') || (!$tag = plugin_load('helper', 'tag'))) {
59                msg('The Tag Plugin must be installed to use tag refinements.', -1);
60            } else {
61                $pages = $tag->tagRefine($pages, $refine);
62            }
63        }
64
65        if (!$pages) return true; // nothing to display
66
67        if ($mode == 'xhtml') {
68
69            // prevent caching to ensure content is always fresh
70            $renderer->info['cache'] = false;
71
72            // let Pagelist Plugin do the work for us
73            if (plugin_isdisabled('pagelist')
74                    || (!$pagelist =& plugin_load('helper', 'pagelist'))) {
75                msg('The Pagelist Plugin must be installed for editor lists to work.', -1);
76                return false;
77            }
78
79            // hide user column, unless for groups
80            if ($user[0] != '@') $pagelist->column['user'] = false;
81
82            $pagelist->setFlags($flags);
83            $pagelist->startList();
84            foreach ($pages as $page) {
85                $pagelist->addPage($page);
86            }
87            $renderer->doc .= $pagelist->finishList();
88            return true;
89
90            // for metadata renderer
91        } elseif ($mode == 'metadata') {
92            foreach ($pages as $page) {
93                $renderer->meta['relation']['references'][$page['id']] = true;
94            }
95
96            return true;
97        }
98        return false;
99    }
100
101}
102// vim:ts=4:sw=4:et:enc=utf-8:
103