Table of Contents
ABB Syntax PlugIn
Compatible with DokuWiki
2007-06-26+
This extension is marked as obsoleted. Therefore it is hidden in the Extension Manager and the extension listing. Furthermore, it is candidate for removal.
The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
The following security issue was reported for this extension: XSS vulnerability allows arbitrary JavaScript insertion. Author informed on 2008-02-24.
It is not recommended to use this extension until this issue was fixed. Extension 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.
Usage
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 DokuWiki.
Adding more Parameters
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.
Limitations
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:
src
– the URL of the image is resolved as an internal DokuWiki image.title
– title attributes are processed with DokuWiki's htmlspecialchars()-functionalt
– alt attributes are processed with DokuWiki's htmlspecialchars()-function
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.
Installation
Search and install the plugin using the Extension Manager.
Alternatively, refer to Plugins on how to install plugins manually. It's quite easy to integrate this plugin with your DokuWiki:
- Download the source archive (~5KB) and unpack it in your DokuWiki plugin directory
{dokuwiki}/lib/plugins
(make sure included subdirectories are unpacked correctly); this will create the directory
{dokuwiki}/lib/plugins/abb
- Make sure both the new directory and the files therein are readable by the web-server e.g.
chown apache:apache dokuwiki/lib/plugins/* -Rc
Plugin Source
Here comes the Apache License PHP source for those who'd like to scan it before actually installing it:
- syntax.php
<?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; } }
Changes
- 2007-11-12
- + initial release Ferdinand Soethe 2007-11-12
Discussion
Hints, comments, suggestions…