Extension:EmbedImg
From MediaWiki.org
|
EmbedImg Release status: beta |
|
|---|---|
| Implementation | Parser function |
| Description | Allows to embed external images with parameters on a wiki page. |
| Author(s) | Dmitry Shurupov |
| Last version | 0.1 |
| MediaWiki | 1.10.x+ |
| License | GPL |
| Download | see below |
|
Check usage (experimental) |
|
The EmbedImg extension adds the <img> tag for embedding external images. It supports width & height parameters.
[edit] Installation
- Copy EmbedImg.php to the new file EmbedImg.php in your MediaWiki extensions directory.
- Enable the extension by adding this line to the bottom of your LocalSettings.php:
require_once("$IP/extensions/EmbedImg/EmbedImg.php");
[edit] Usage
- <img>http://some.site.com/with/an/image.png</img>
- <img size=420>http://some.site.com/with/an/image.png</img>
- <img size=420x840>http://some.site.com/with/an/image.png</img>
[edit] Options
- size -- defines images width / width and height. Just a number, no "px" required.
[edit] Limitations
- PNG, GIF, JPG/JPEG file extensions only.
- Height only is not available (however, width only is okay).
[edit] Source of EmbedImg.php
<?php /** * MediaWiki EmbedImg extension * * @version 0.1 * @author Dmitry Shurupov * @link http://www.mediawiki.org/wiki/Extension:EmbedImg */ $wgExtensionCredits['parserhook'][] = array( 'name' => 'EmbedImg', 'author' => 'Dmitry Shurupov', 'version' => '0.1', 'url' => 'http://www.mediawiki.org/wiki/Extension:EmbedImg', 'description' => 'Allows to embed external images with parameters on a wiki page.', ); $wgExtensionFunctions[] = 'registerEmbedImgHandler'; function registerEmbedImgHandler () { global $wgParser; $wgParser->setHook( 'img', 'embedImgHandler' ); } function makeHTMLforImg ($path, $width, $height) { return '<img src="'.$path.'" '.(isSet($width) ? 'width="'.$width.'" ' : '').(isSet($height) ? 'height="'.$height.'" ' : '').' />'; } function embedImgHandler ($input, $argv) { if (!isSet($input)) return '<font color="red">Error: empty param in <img>!</font>'; if (preg_match('/^https?\:\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@\?\^\=\%\&:\/\~\+\#]*[\w\-\@\?\^\=\%\&\/\~\+\#])?\.(jpe?g|png|gif|JPE?G|PNG|GIF|jpg|JPG)$/', $input)) { if (isSet($argv['size']) && preg_match('/^([0-9]+)(x([0-9]+))?(px)?$/', $argv['size'], $matches)) { if (isSet($matches[3])) return makeHTMLforImg($input, $matches[1], $matches[3]); else if (isSet($matches[1])) return makeHTMLforImg($input, $matches[1], NULL); } return makeHTMLforImg($input, NULL, NULL); } else return '<font color="red">Error: bad URI in <img>!</font>'; } ?>
