source: documentation/trunk/packages/dokuwiki-2011-05-25a/lib/plugins/info/syntax.php@ 25027

Last change on this file since 25027 was 25027, checked in by jmt12, 12 years ago

Adding the packages directory, and within it a configured version of dokuwiki all ready to run

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