Extension:EmbedAll
From MediaWiki.org
|
EmbedAll Release status: beta |
|
|---|---|
| Implementation | Parser function |
| Description | Allows to embed documents on a wiki page. |
| Author(s) | Dominik Sigmund |
| Last version | 0.4 |
| MediaWiki | 1.10.x or higher |
| License | GPL |
| Download | see below |
|
Check usage (experimental) |
|
|
|
This extension stores its code inside a wiki page. Please be aware that MediaWiki developers do not review or keep track of extensions that put their code on the wiki.
|
The EmbedAll extension adds the <pdf> tag for embedding PDF files, the <svg> tag for embedding SVG files and the the <vsd> tag for embedding VSD files. It supports remote and local (uploaded to MediaWiki) files.
Thanks to Dmitry Shurupov for the basic Idea and Code.
[edit] Installation
- Copy EmbedAll.php to the new file EmbedAll.php in your MediaWiki extensions directory in the new Folder EmbedAll.
- Enable the extension by adding this line to the bottom of your LocalSettings.php:
require_once("$IP/extensions/EmbedAll/EmbedAll.php");
[edit] Usage
- <pdf>http://some.site.com/with/a/document.pdf</pdf>
- <pdf>Your_uploaded_document.pdf</pdf>
- <svg>http://some.site.com/with/a/document.svg</svg>
- <svg>Your_uploaded_document.svg</svg>
- <vsd>http://some.site.com/with/a/document.vsd</vsd>
- <vsd>Your_uploaded_document.vsd</vsd>
[edit] Options
- width
- height
[edit] Source of EmbedAll.php
<?php /** * MediaWiki EmbedAll extension * * @version 0.4 * @author Dominik Sigmund * @link http://www.mediawiki.org/wiki/Extension:EmbedAll */ $wgExtensionCredits['parserhook'][] = array( 'name' => 'EmbedAll', 'author' => 'Dominik Sigmund', 'version' => '0.4', 'url' => 'http://www.mediawiki.org/wiki/Extension:EmbedAll', 'description' => 'Allows to embed documents on a wiki page.', ); $wgExtensionFunctions[] = 'registerEmbedHandler'; function registerEmbedHandler () { global $wgParser; $wgParser->setHook( 'pdf', 'embedPDFHandler' ); $wgParser->setHook( 'svg', 'embedSVGHandler' ); $wgParser->setHook( 'vsd', 'embedVSDHandler' ); } function makeHTML ( $path, $argv ) { if (empty($argv['width'])) { $width = '1000'; } else { $width = $argv['width']; } if (empty($argv['height'])) { $height = '700'; } else { $height = $argv['height']; } return '<iframe src="'.$path.'" width="'.$width.'" height="'.$height.'"></iframe>'; } function embedPDFHandler ( $input, $argv ) { if (!$input) return '<font color="red">Error: empty param in <pdf>!</font>'; if (preg_match('/^[^\/]+\.pdf$/i', $input)) { $img = Image::newFromName( $input ); if ($img != NULL) return makeHTML( $img->getURL(), $argv ); } if (preg_match('/^http\:\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@\?\^\=\%\&:\/\~\+\#]*[\w\-\@\?\^\=\%\&\/\~\+\#])?\.pdf$/i', $input)) return makeHTML( $input, $argv ); else return '<font color="red">Error: bad URI in <pdf>!</font>'; } function embedSVGHandler ( $input, $argv ) { if (!$input) return '<font color="red">Error: empty param in <svg>!</font>'; if (preg_match('/^[^\/]+\.svg$/i', $input)) { $img = Image::newFromName( $input ); if ($img != NULL) return makeHTML( $img->getURL(), $argv ); } if (preg_match('/^http\:\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@\?\^\=\%\&:\/\~\+\#]*[\w\-\@\?\^\=\%\&\/\~\+\#])?\.svg$/i', $input)) return makeHTML( $input, $argv ); else return '<font color="red">Error: bad URI in <svg>!</font>'; } function embedVSDHandler ( $input, $argv ) { if (!$input) return '<font color="red">Error: empty param in <vsd>!</font>'; if (preg_match('/^[^\/]+\.vsd$/i', $input)) { $img = Image::newFromName( $input ); if ($img != NULL) return makeHTML( $img->getURL(), $argv ); } if (preg_match('/^http\:\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@\?\^\=\%\&:\/\~\+\#]*[\w\-\@\?\^\=\%\&\/\~\+\#])?\.vsd$/i', $input)) return makeHTML( $input, $argv ); else return '<font color="red">Error: bad URI in <vsd>!</font>'; } ?>
