Extension:EmbedAll

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
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)

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

  1. Copy EmbedAll.php to the new file EmbedAll.php in your MediaWiki extensions directory in the new Folder EmbedAll.
  2. 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 &lt;pdf&gt;!</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 &lt;pdf&gt;!</font>';
        }
                function embedSVGHandler ( $input, $argv )
        {
                if (!$input)
                        return '<font color="red">Error: empty param in &lt;svg&gt;!</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 &lt;svg&gt;!</font>';
        }
                function embedVSDHandler ( $input, $argv )
        {
                if (!$input)
                        return '<font color="red">Error: empty param in &lt;vsd&gt;!</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 &lt;vsd&gt;!</font>';
        }
?>


Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox