Extension:EmbedPDF

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
EmbedPDF

Release status: beta

Implementation Parser function
Description Allows to embed .pdf documents 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 EmbedPDF extension adds the <pdf> tag for embedding PDF files. It supports remote and local (uploaded to MediaWiki) files.

[edit] Installation

  1. Copy EmbedPDF.php to the new file EmbedPDF.php in your MediaWiki extensions directory.
  2. Enable the extension by adding this line to the bottom of your LocalSettings.php:
require_once("$IP/extensions/EmbedPDF.php");

[edit] Usage

  • <pdf>http://some.site.com/with/a/document.pdf</pdf>
  • <pdf>Your_uploaded_document.pdf</pdf>

[edit] Options

There are no options yet. EmbedPDF will create HTML <object> with predefined width (700 px) and height (600 px). That's all.

[edit] Source of EmbedPDF.php

<?php
        /**
         * MediaWiki EmbedPDF extension
         *
         * @version 0.1
         * @author Dmitry Shurupov
         * @link http://www.mediawiki.org/wiki/Extension:EmbedPDF
         */
 
        $wgExtensionCredits['parserhook'][] = array(
                'name' => 'EmbedPDF',
                'author' => 'Dmitry Shurupov',
                'version' => '0.1',
                'url' => 'http://www.mediawiki.org/wiki/Extension:EmbedPDF',
                'description' => 'Allows to embed .pdf documents on a wiki page.',
                );
 
        $wgExtensionFunctions[] = 'registerEmbedPDFHandler';
 
        function registerEmbedPDFHandler ()
        {
                global $wgParser;
                $wgParser->setHook( 'pdf', 'embedPDFHandler' );
        }
 
        function makeHTMLforPDF ( $path, $argv )
        {
                if (empty($argv['width']))
                {
                        $width = '1000';
                }
                else
                {
                        $width = $argv['width'];
                }
 
                if (empty($argv['height']))
                {
                        $height = '700';
                }
                else
                {
                        $height = $argv['height'];
                }
                return '<object data="'.$path.'" width="'.$width.'" height="'.$height.'" type="application/pdf"></object>';
        }
 
        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 makeHTMLforPDF( $img->getURL(), $argv );
                }
 
                if (preg_match('/^http\:\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@\?\^\=\%\&:\/\~\+\#]*[\w\-\@\?\^\=\%\&\/\~\+\#])?\.pdf$/i', $input))
                        return makeHTMLforPDF( $input, $argv );
                else
                        return '<font color="red">Error: bad URI in &lt;pdf&gt;!</font>';
        }
?>


Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox