Inline Uploaded Images
After having installed (and patched) the Upload Plugin? (see
PhpWiki:Upload),
and setup the Inter Wiki Map (to File: /wiki/uploads),
one might well like to upload images, and expect to be able to inline them in a wiki page using the [File:my_image.gif] form.
Well, to do this is not too complicated (phpwiki 1.3.4), patch interwiki.php and stdlib.php.
This actually allows any interwiki image inlining.
- [File:my_image.gif] inlines the image
- File:my_image.gif shows a plain inter-wiki link
- [what a pic|File:my_image.gif] shows a named inter-wiki link
interwiki.php: add method linkImage()
function linkImage ($link, $alt = false) {
list ($moniker, $page) = split (":", $link, 2);
if (!isset($this->_map[$moniker])) {
return HTML::span(array('class' => 'bad-interwiki'),
$linktext ? $linktext : $link);
}
$url = $this->_map[$moniker] . $page;
$link = HTML::img(array('src' => $url, 'alt' => $alt));
$link->setAttr('class', 'inlineimage');
return $link;
}
stdlib.php: use linkImage()
function LinkBracketLink($bracketlink) {
global $request, $AllowedProtocols, $InlineImages;
include_once("lib/interwiki.php");
$intermap = InterWikiMap::GetMap($request);
...
elseif (! $label && preg_match("/^" . $intermap->getRegexp() . ":.*($InlineImages)$/i", $link))
return $intermap->linkImage($link, $link);
elseif (preg_match("/^" . $intermap->getRegexp() . ":/", $link))
return $intermap->link($link, $label);
else {
return WikiLink($wikipage, 'unknown', $label);
}
}
Dernière modification le mardi 3 février 2004 18:29:32



