* @author Esther Brunner */ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_info extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Andreas Gohr', 'email' => 'andi@splitbrain.org', 'date' => '2008-09-12', 'name' => 'Info Plugin', 'desc' => 'Displays information about various DokuWiki internals', 'url' => 'http://dokuwiki.org/plugin:info', ); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } /** * What about paragraphs? */ function getPType(){ return 'block'; } /** * Where to sort in? */ function getSort(){ return 155; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('~~INFO:\w+~~',$mode,'plugin_info'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ $match = substr($match,7,-2); //strip ~~INFO: from start and ~~ from end return array(strtolower($match)); } /** * Create output */ function render($format, &$renderer, $data) { if($format == 'xhtml'){ //handle various info stuff switch ($data[0]){ case 'version': $renderer->doc .= getVersion(); break; case 'syntaxmodes': $renderer->doc .= $this->_syntaxmodes_xhtml(); break; case 'syntaxtypes': $renderer->doc .= $this->_syntaxtypes_xhtml(); break; case 'syntaxplugins': $this->_plugins_xhtml('syntax', $renderer); break; case 'adminplugins': $this->_plugins_xhtml('admin', $renderer); break; case 'actionplugins': $this->_plugins_xhtml('action', $renderer); break; case 'rendererplugins': $this->_plugins_xhtml('renderer', $renderer); break; case 'helperplugins': $this->_plugins_xhtml('helper', $renderer); break; case 'helpermethods': $this->_helpermethods_xhtml($renderer); break; default: $renderer->doc .= "no info about ".htmlspecialchars($data[0]); } return true; } return false; } /** * list all installed plugins * * uses some of the original renderer methods */ function _plugins_xhtml($type, &$renderer){ global $lang; $renderer->doc .= ''; } /** * list all installed plugins * * uses some of the original renderer methods */ function _helpermethods_xhtml(&$renderer){ global $lang; $plugins = plugin_list('helper'); foreach($plugins as $p){ if (!$po =& plugin_load('helper',$p)) continue; if (!method_exists($po, 'getMethods')) continue; $methods = $po->getMethods(); $info = $po->getInfo(); $hid = $this->_addToTOC($info['name'], 2, $renderer); $doc = '

'.hsc($info['name']).'

'; $doc .= '
'; $doc .= '

'.strtr(hsc($info['desc']), array("\n"=>"
")).'

'; $doc .= '
$'.$p." =& plugin_load('helper', '".$p."');
"; $doc .= '
'; foreach ($methods as $method){ $title = '$'.$p.'->'.$method['name'].'()'; $hid = $this->_addToTOC($title, 3, $renderer); $doc .= '

'.hsc($title).'

'; $doc .= '
'; $doc .= ''; $doc .= ''; if ($method['params']){ $c = count($method['params']); $doc .= ''; } if ($method['return']){ $doc .= ''; } $doc .= '
Description'.$method['desc']. '
Parameters'; $params = array(); foreach ($method['params'] as $desc => $type){ $params[] = hsc($desc).''.hsc($type); } $doc .= join($params, '
').'
Return value'.hsc(key($method['return'])). ''.hsc(current($method['return'])).'
'; $doc .= '
'; } unset($po); $renderer->doc .= $doc; } } /** * lists all known syntax types and their registered modes */ function _syntaxtypes_xhtml(){ global $PARSER_MODES; $doc = ''; $doc .= ''; foreach($PARSER_MODES as $mode => $modes){ $doc .= ''; $doc .= ''; $doc .= ''; $doc .= ''; } $doc .= '
'; $doc .= $mode; $doc .= ''; $doc .= join(', ',$modes); $doc .= '
'; return $doc; } /** * lists all known syntax modes and their sorting value */ function _syntaxmodes_xhtml(){ $modes = p_get_parsermodes(); $doc = ''; foreach ($modes as $mode){ $doc .= $mode['mode'].' ('.$mode['sort'].'), '; } return $doc; } /** * Adds a TOC item */ function _addToTOC($text, $level, &$renderer){ global $conf; if (($level >= $conf['toptoclevel']) && ($level <= $conf['maxtoclevel'])){ $hid = $renderer->_headerToLink($text, 'true'); $renderer->toc[] = array( 'hid' => $hid, 'title' => $text, 'type' => 'ul', 'level' => $level - $conf['toptoclevel'] + 1 ); } return $hid; } } //Setup VIM: ex: et ts=4 enc=utf-8 :