1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Martin Schulte <lebowski[at]corvus[dot]uberspace[dot]de>
5 */
6//error_reporting (E_ALL | E_STRICT);
7//ini_set ('display_errors', 'On');
8
9
10// must be run within Dokuwiki
11if (!defined('DOKU_INC')) die();
12
13if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
14if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
15if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
16
17require_once(DOKU_PLUGIN.'action.php');
18
19class action_plugin_authorlist extends DokuWiki_Action_Plugin{
20
21
22    function register(Doku_Event_Handler $contr) {
23       // $contr->register_hook('TPL_ACT_RENDER','AFTER',$this,'renderAuthorlist');
24       $contr->register_hook('PARSER_WIKITEXT_PREPROCESS','BEFORE',$this,'appendAuthors');
25
26    }
27
28
29    /**
30     * Add heading and ~~AUTHORS~~ to each wikipage.
31     */
32    function appendAuthors(&$event, $param){
33		global $ID;
34		global $ACT;
35		global $INFO;
36		global $conf;
37		if(preg_match('/'.$conf['sidebar'].'$/',$ID)) return false;
38		//var_dump($INFO);
39		if(!page_exists($ID) && $ACT == 'preview' ) return false; // Don't show on "This topic does not exist yet" pages
40		if(strpos($event->data, '~~AUTHORS:off~~') != false) return false; //Disabled manually
41		if($this->getConf('automatic')){	// on every page by default?
42			//if($ACT != 'show') return false;
43			if(isset($INFO) && $ACT != 'preview') return false; // We are on a "real" wikipage, not 'Recent-', 'Login-', ...-page
44			if($this->getConf('showheading'))  $event->data .= DOKU_LF."======".strip_tags($this->getConf('heading'))."======".DOKU_LF;
45			$event->data .= "~~AUTHORS~~";
46			return true;
47		}
48	}
49
50
51    // old stuff
52    function renderAuthorlist(&$event, $param){
53		global $INFO;
54		if($event->data != 'show' && $event->data != 'preview') return false;
55		if(!$INFO['exists'] && $event->data != 'preview') return false;
56		$al = $this->loadHelper('authorlist',false);
57		if (!$al) return false;
58		$al->setOptions($INFO['id'],array());
59		$al->fetchAuthorsFromMetadata();
60		$al->sortAuthors();
61        $al->startList();
62		$al->renderAllAuthors();
63        $al->finischList();
64        echo($al->getOutput());
65        return true;
66	}
67
68}
69