Compatible with DokuWiki
2007-06-26+
The following security issue was reported for this plugin: XSS vulnerability allows arbitrary JavaScript insertion. Author informed on 2008-02-24.
It is not recommended to use this plugin until this issue was fixed. Plugin authors should read the plugin security guidelines
This plugin brings the full power of the the IMG-element to Dokuwiki without having to embed raw html.
The easiest use of ABB is just
~~ABB~src=wiki:dokuwiki-128.png~~
where wiki:dokuwiki-128.png is the name of an image file. This will embed something like
<img src="/dokuwiki/lib/exe/fetch.php?media=wiki:dokuwiki-128.png">
into your page.
As you can see, ABB is followed by one ore more key=value pairs (called parameters) that configure the img-element.
src=//image-location//
is the only required parameter providing the URL of the image file.
As you can see, the plugin will automatically resolve the image url the DokuWiki-way so you can simply use a reference like you would for adding images with doku-wiki.
By adding more parameters, you can add further attributes to the image-element created. To create an image with a class attribute (which can be styled by a css-handle in a central stylesheet) simply add a class=MyImageClass parameter.
~~ABB~src=wiki:dokuwiki-128.png~class=MyImageClass~~
To create an image with a id attribute (to be styled individually by a css-handle in a central stylesheet) simply add a id=MyImageID parameter.
~~ABB~src=wiki:dokuwiki-128.png~class=MyImageID~~
To directly style you image the css-way, add a style attribute that contains your css:
~~ABB~src=wiki:dokuwiki-128.png~class=MyImageID~style=width: 30%;float: right;~~
This one sizes the image to 30% of the width of the text column and makes it float right. Please note that I kept the class-attribute so that central style-sheets can add their own css.
The plugin basically translates parameters to html-attributes. The key becomes the attribute name, the value is surrounded by quotation marks and becomes the attribute value. As exceptions to the rule, some attributes get an extra treatment:
Due to the way the parameters are processed, '=' must ony occur once to separate key from value. A '=' in the value will create unpredictable results.
Also note that the plugin does not check the validity of the resulting HTML tag. So you are entirely responsible for the havoc you create by inventing new attributes for the IMG element.
It's quite easy to integrate this plugin with your DokuWiki:
{dokuwiki}/lib/plugins (make sure included subdirectories are unpacked correctly); this will create the directory{dokuwiki}/lib/plugins/abb chown apache:apache dokuwiki/lib/plugins/* -Rc
You might as well use the plugin manager for installing and/or updating this plugin.
Here comes the Apache License PHP source for those who'd like to scan it before actually installing it:
<?php /** * Plugin Abb: Full power IMG embedding" * * @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) * @author Ferdinand Soethe <ferdinand@apache.org> */ if (!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/'); 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_abb extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo() { return array ( 'author' => 'Ferdinand Soethe', 'email' => 'ferdinand@apache.org', 'date' => '2007-11-11', 'name' => 'abb - Enhanced Image Plugin', 'desc' => 'Embed images with the full power of html img-tag', 'url' => 'http://www.dokuwiki.org/wiki:abb', ); } /** * What kind of syntax are we? */ function getType() { return 'substition'; } /** * What about paragraphs? (optional) */ function getPType() { return 'block'; } /** * Where to sort in? */ function getSort() { return 999; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('~~ABB.*?~~', $mode, 'plugin_abb'); } /** * Handle the match */ function handle($match, $state, $pos, & $handler) { $resultStr = ''; $paramsArr = explode('~', $match); for ($i = 0; $i < count($paramsArr); $i++) { $paramPairArr = explode('=', $paramsArr[$i]); switch ($paramPairArr[0]) { case 'ABB' : break; case '' : break; case 'src' : $resultStr .= ' src="' . ml($paramPairArr[1], '') . '"'; break; case 'title' : $resultStr .= ' title="' . htmlspecialchars($paramPairArr[1], ENT_QUOTES, 'UTF-8') . '"'; break; case 'alt' : $resultStr .= ' alt="' . htmlspecialchars($paramPairArr[1], ENT_QUOTES, 'UTF-8') . '"'; break; default : $resultStr .= ' ' . $paramPairArr[0] . '="' . $paramPairArr[1] . '"'; break; } } return '<img' . $resultStr . '>'; } /** * Create output */ function render($mode, & $renderer, $data) { if ($mode == 'xhtml') { $renderer->doc .= $data; // ptype = 'normal' return true; } return false; } }
2007-11-12:
+ initial release
Ferdinand Soethe 2007-11-12
Hints, comments, suggestions …