3 * Info Plugin: Displays information about various DokuWiki internals
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
7 * @author Esther Brunner <wikidesign@gmail.com>
9 // must be run within Dokuwiki
10 if(!defined('DOKU_INC')) die();
12 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC
.'lib/plugins/');
13 require_once(DOKU_PLUGIN
.'syntax.php');
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
19 class syntax_plugin_info
extends DokuWiki_Syntax_Plugin
{
26 'author' => 'Andreas Gohr',
27 'email' => 'andi@splitbrain.org',
28 'date' => '2008-09-12',
29 'name' => 'Info Plugin',
30 'desc' => 'Displays information about various DokuWiki internals',
31 'url' => 'http://dokuwiki.org/plugin:info',
36 * What kind of syntax are we?
43 * What about paragraphs?
58 * Connect pattern to lexer
60 function connectTo($mode) {
61 $this->Lexer
->addSpecialPattern('~~INFO:\w+~~',$mode,'plugin_info');
68 function handle($match, $state, $pos, &$handler){
69 $match = substr($match,7,-2); //strip ~~INFO: from start and ~~ from end
70 return array(strtolower($match));
76 function render($format, &$renderer, $data) {
77 if($format == 'xhtml'){
78 //handle various info stuff
81 $renderer->doc
.= getVersion();
84 $renderer->doc
.= $this->_syntaxmodes_xhtml();
87 $renderer->doc
.= $this->_syntaxtypes_xhtml();
90 $this->_plugins_xhtml('syntax', $renderer);
93 $this->_plugins_xhtml('admin', $renderer);
96 $this->_plugins_xhtml('action', $renderer);
98 case 'rendererplugins':
99 $this->_plugins_xhtml('renderer', $renderer);
101 case 'helperplugins':
102 $this->_plugins_xhtml('helper', $renderer);
104 case 'helpermethods':
105 $this->_helpermethods_xhtml($renderer);
108 $renderer->doc
.= "no info about ".htmlspecialchars($data[0]);
116 * list all installed plugins
118 * uses some of the original renderer methods
120 function _plugins_xhtml($type, &$renderer){
122 $renderer->doc
.= '<ul>';
124 $plugins = plugin_list($type);
128 foreach($plugins as $p){
129 if (!$po =& plugin_load($type,$p)) continue;
130 list($name,$part) = explode('_',$p,2);
131 $plginfo[$name] = $po->getInfo();
135 foreach($plginfo as $info){
136 $renderer->doc
.= '<li><div class="li">';
137 $renderer->externallink($info['url'],$info['name']);
138 $renderer->doc
.= ' ';
139 $renderer->doc
.= '<em>'.$info['date'].'</em>';
140 $renderer->doc
.= ' ';
141 $renderer->doc
.= $lang['by'];
142 $renderer->doc
.= ' ';
143 $renderer->emaillink($info['email'],$info['author']);
144 $renderer->doc
.= '<br />';
145 $renderer->doc
.= strtr(hsc($info['desc']),array("\n"=>"<br />"));
146 $renderer->doc
.= '</div></li>';
150 $renderer->doc
.= '</ul>';
154 * list all installed plugins
156 * uses some of the original renderer methods
158 function _helpermethods_xhtml(&$renderer){
161 $plugins = plugin_list('helper');
162 foreach($plugins as $p){
163 if (!$po =& plugin_load('helper',$p)) continue;
165 if (!method_exists($po, 'getMethods')) continue;
166 $methods = $po->getMethods();
167 $info = $po->getInfo();
169 $hid = $this->_addToTOC($info['name'], 2, $renderer);
170 $doc = '<h2><a name="'.$hid.'" id="'.$hid.'">'.hsc($info['name']).'</a></h2>';
171 $doc .= '<div class="level2">';
172 $doc .= '<p>'.strtr(hsc($info['desc']), array("\n"=>"<br />")).'</p>';
173 $doc .= '<pre class="code">$'.$p." =& plugin_load('helper', '".$p."');</pre>";
175 foreach ($methods as $method){
176 $title = '$'.$p.'->'.$method['name'].'()';
177 $hid = $this->_addToTOC($title, 3, $renderer);
178 $doc .= '<h3><a name="'.$hid.'" id="'.$hid.'">'.hsc($title).'</a></h3>';
179 $doc .= '<div class="level3">';
180 $doc .= '<table class="inline"><tbody>';
181 $doc .= '<tr><th>Description</th><td colspan="2">'.$method['desc'].
183 if ($method['params']){
184 $c = count($method['params']);
185 $doc .= '<tr><th rowspan="'.$c.'">Parameters</th><td>';
187 foreach ($method['params'] as $desc => $type){
188 $params[] = hsc($desc).'</td><td>'.hsc($type);
190 $doc .= join($params, '</td></tr><tr><td>').'</td></tr>';
192 if ($method['return']){
193 $doc .= '<tr><th>Return value</th><td>'.hsc(key($method['return'])).
194 '</td><td>'.hsc(current($method['return'])).'</td></tr>';
196 $doc .= '</tbody></table>';
201 $renderer->doc
.= $doc;
206 * lists all known syntax types and their registered modes
208 function _syntaxtypes_xhtml(){
209 global $PARSER_MODES;
212 $doc .= '<table class="inline"><tbody>';
213 foreach($PARSER_MODES as $mode => $modes){
215 $doc .= '<td class="leftalign">';
218 $doc .= '<td class="leftalign">';
219 $doc .= join(', ',$modes);
223 $doc .= '</tbody></table>';
228 * lists all known syntax modes and their sorting value
230 function _syntaxmodes_xhtml(){
231 $modes = p_get_parsermodes();
234 foreach ($modes as $mode){
235 $doc .= $mode['mode'].' ('.$mode['sort'].'), ';
243 function _addToTOC($text, $level, &$renderer){
246 if (($level >= $conf['toptoclevel']) && ($level <= $conf['maxtoclevel'])){
247 $hid = $renderer->_headerToLink($text, 'true');
248 $renderer->toc
[] = array(
252 'level' => $level - $conf['toptoclevel'] +
1
259 //Setup VIM: ex: et ts=4 enc=utf-8 :