1<?php 2/** 3 * Info Plugin: Displays information about various DokuWiki internals 4 * 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> 8 */ 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12/** 13 * All DokuWiki plugins to extend the parser/rendering mechanism 14 * need to inherit from this class 15 */ 16class syntax_plugin_info extends DokuWiki_Syntax_Plugin { 17 18 /** 19 * What kind of syntax are we? 20 */ 21 function getType(){ 22 return 'substition'; 23 } 24 25 /** 26 * What about paragraphs? 27 */ 28 function getPType(){ 29 return 'block'; 30 } 31 32 /** 33 * Where to sort in? 34 */ 35 function getSort(){ 36 return 155; 37 } 38 39 40 /** 41 * Connect pattern to lexer 42 */ 43 function connectTo($mode) { 44 $this->Lexer->addSpecialPattern('~~INFO:\w+~~',$mode,'plugin_info'); 45 } 46 47 48 /** 49 * Handle the match 50 */ 51 function handle($match, $state, $pos, &$handler){ 52 $match = substr($match,7,-2); //strip ~~INFO: from start and ~~ from end 53 return array(strtolower($match)); 54 } 55 56 /** 57 * Create output 58 */ 59 function render($format, &$renderer, $data) { 60 if($format == 'xhtml'){ 61 //handle various info stuff 62 switch ($data[0]){ 63 case 'syntaxmodes': 64 $renderer->doc .= $this->_syntaxmodes_xhtml(); 65 break; 66 case 'syntaxtypes': 67 $renderer->doc .= $this->_syntaxtypes_xhtml(); 68 break; 69 case 'syntaxplugins': 70 $this->_plugins_xhtml('syntax', $renderer); 71 break; 72 case 'adminplugins': 73 $this->_plugins_xhtml('admin', $renderer); 74 break; 75 case 'actionplugins': 76 $this->_plugins_xhtml('action', $renderer); 77 break; 78 case 'rendererplugins': 79 $this->_plugins_xhtml('renderer', $renderer); 80 break; 81 case 'helperplugins': 82 $this->_plugins_xhtml('helper', $renderer); 83 break; 84 case 'authplugins': 85 $this->_plugins_xhtml('auth', $renderer); 86 break; 87 case 'remoteplugins': 88 $this->_plugins_xhtml('remote', $renderer); 89 break; 90 case 'helpermethods': 91 $this->_helpermethods_xhtml($renderer); 92 break; 93 default: 94 $renderer->doc .= "no info about ".htmlspecialchars($data[0]); 95 } 96 return true; 97 } 98 return false; 99 } 100 101 /** 102 * list all installed plugins 103 * 104 * uses some of the original renderer methods 105 */ 106 function _plugins_xhtml($type, Doku_Renderer &$renderer){ 107 global $lang; 108 $renderer->doc .= '<ul>'; 109 110 $plugins = plugin_list($type); 111 $plginfo = array(); 112 113 // remove subparts 114 foreach($plugins as $p){ 115 if (!$po =& plugin_load($type,$p)) continue; 116 list($name,$part) = explode('_',$p,2); 117 $plginfo[$name] = $po->getInfo(); 118 } 119 120 // list them 121 foreach($plginfo as $info){ 122 $renderer->doc .= '<li><div class="li">'; 123 $renderer->externallink($info['url'],$info['name']); 124 $renderer->doc .= ' '; 125 $renderer->doc .= '<em>'.$info['date'].'</em>'; 126 $renderer->doc .= ' '; 127 $renderer->doc .= $lang['by']; 128 $renderer->doc .= ' '; 129 $renderer->emaillink($info['email'],$info['author']); 130 $renderer->doc .= '<br />'; 131 $renderer->doc .= strtr(hsc($info['desc']),array("\n"=>"<br />")); 132 $renderer->doc .= '</div></li>'; 133 unset($po); 134 } 135 136 $renderer->doc .= '</ul>'; 137 } 138 139 /** 140 * list all installed plugins 141 * 142 * uses some of the original renderer methods 143 */ 144 function _helpermethods_xhtml(Doku_Renderer &$renderer){ 145 global $lang; 146 147 $plugins = plugin_list('helper'); 148 foreach($plugins as $p){ 149 if (!$po =& plugin_load('helper',$p)) continue; 150 151 if (!method_exists($po, 'getMethods')) continue; 152 $methods = $po->getMethods(); 153 $info = $po->getInfo(); 154 155 $hid = $this->_addToTOC($info['name'], 2, $renderer); 156 $doc = '<h2><a name="'.$hid.'" id="'.$hid.'">'.hsc($info['name']).'</a></h2>'; 157 $doc .= '<div class="level2">'; 158 $doc .= '<p>'.strtr(hsc($info['desc']), array("\n"=>"<br />")).'</p>'; 159 $doc .= '<pre class="code">$'.$p." =& plugin_load('helper', '".$p."');</pre>"; 160 $doc .= '</div>'; 161 foreach ($methods as $method){ 162 $title = '$'.$p.'->'.$method['name'].'()'; 163 $hid = $this->_addToTOC($title, 3, $renderer); 164 $doc .= '<h3><a name="'.$hid.'" id="'.$hid.'">'.hsc($title).'</a></h3>'; 165 $doc .= '<div class="level3">'; 166 $doc .= '<div class="table"><table class="inline"><tbody>'; 167 $doc .= '<tr><th>Description</th><td colspan="2">'.$method['desc']. 168 '</td></tr>'; 169 if ($method['params']){ 170 $c = count($method['params']); 171 $doc .= '<tr><th rowspan="'.$c.'">Parameters</th><td>'; 172 $params = array(); 173 foreach ($method['params'] as $desc => $type){ 174 $params[] = hsc($desc).'</td><td>'.hsc($type); 175 } 176 $doc .= join($params, '</td></tr><tr><td>').'</td></tr>'; 177 } 178 if ($method['return']){ 179 $doc .= '<tr><th>Return value</th><td>'.hsc(key($method['return'])). 180 '</td><td>'.hsc(current($method['return'])).'</td></tr>'; 181 } 182 $doc .= '</tbody></table></div>'; 183 $doc .= '</div>'; 184 } 185 unset($po); 186 187 $renderer->doc .= $doc; 188 } 189 } 190 191 /** 192 * lists all known syntax types and their registered modes 193 */ 194 function _syntaxtypes_xhtml(){ 195 global $PARSER_MODES; 196 $doc = ''; 197 198 $doc .= '<div class="table"><table class="inline"><tbody>'; 199 foreach($PARSER_MODES as $mode => $modes){ 200 $doc .= '<tr>'; 201 $doc .= '<td class="leftalign">'; 202 $doc .= $mode; 203 $doc .= '</td>'; 204 $doc .= '<td class="leftalign">'; 205 $doc .= join(', ',$modes); 206 $doc .= '</td>'; 207 $doc .= '</tr>'; 208 } 209 $doc .= '</tbody></table></div>'; 210 return $doc; 211 } 212 213 /** 214 * lists all known syntax modes and their sorting value 215 */ 216 function _syntaxmodes_xhtml(){ 217 $modes = p_get_parsermodes(); 218 219 $compactmodes = array(); 220 foreach($modes as $mode){ 221 $compactmodes[$mode['sort']][] = $mode['mode']; 222 } 223 $doc = ''; 224 $doc .= '<div class="table"><table class="inline"><tbody>'; 225 226 foreach($compactmodes as $sort => $modes){ 227 $rowspan = ''; 228 if(count($modes) > 1) { 229 $rowspan = ' rowspan="'.count($modes).'"'; 230 } 231 232 foreach($modes as $index => $mode) { 233 $doc .= '<tr>'; 234 $doc .= '<td class="leftalign">'; 235 $doc .= $mode; 236 $doc .= '</td>'; 237 238 if($index === 0) { 239 $doc .= '<td class="rightalign" '.$rowspan.'>'; 240 $doc .= $sort; 241 $doc .= '</td>'; 242 } 243 $doc .= '</tr>'; 244 } 245 } 246 247 $doc .= '</tbody></table></div>'; 248 return $doc; 249 } 250 251 /** 252 * Adds a TOC item 253 */ 254 function _addToTOC($text, $level, Doku_Renderer_xhtml &$renderer){ 255 global $conf; 256 257 if (($level >= $conf['toptoclevel']) && ($level <= $conf['maxtoclevel'])){ 258 $hid = $renderer->_headerToLink($text, 'true'); 259 $renderer->toc[] = array( 260 'hid' => $hid, 261 'title' => $text, 262 'type' => 'ul', 263 'level' => $level - $conf['toptoclevel'] + 1 264 ); 265 } 266 return $hid; 267 } 268} 269 270//Setup VIM: ex: et ts=4 : 271