Extension:EmbedImg
From MediaWiki.org
| This extension is obsolete! It has been replaced by core functionality in the MediaWiki software (which was added in version 1.17.0). See $wgAllowImageTag |
| This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
|
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+ |
| Database changes | no |
| License | GPL |
| Download | see below |
| Check usage and version matrix | |
The EmbedImg extension adds the <img> tag for embedding external images. It supports width & height parameters.
Installation [edit]
- Create a new EmbedImg folder in your MediaWiki extensions directory.
- Copy EmbedImg.php to the new file EmbedImg.php in the folder that you just created.
- Enable the extension by adding this line to the bottom of your LocalSettings.php:
require_once("$IP/extensions/EmbedImg/EmbedImg.php");
Usage [edit]
- <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>
Other Uses [edit]
Despite the ObsoleteExtension tag shown above, this extension is still required to do fancier tricks with external images, like this one:
<div class="thumb tright"><div class="thumbinner" style="width:400px;"> <span class="plainlinks">[http://some.site.com/ <img size=400>http://some.site.com/with/an/image.png</img>]</span> <div class="thumbcaption"><span class="plainlinks">[http://some.site.com/ Your caption.]</span></div></div></div>
Options [edit]
- size -- defines images width / width and height. Just a number, no "px" required.
Limitations [edit]
- PNG, GIF, JPG/JPEG file extensions only.
- Height only is not available (however, width only is okay).
Source of EmbedImg.php [edit]
<?php /** * MediaWiki EmbedImg extension * * @version 0.1 * @author Dmitry Shurupov * @link https://www.mediawiki.org/wiki/Extension:EmbedImg */ if ( !defined( 'MEDIAWIKI' ) ) die( 'This file is part of MediaWiki. It is not a valid entry point.' ); $wgExtensionCredits['parserhook'][] = array( 'name' => 'EmbedImg', 'author' => 'Dmitry Shurupov', 'version' => '0.1', 'url' => 'https://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>'; }