Extension:EmbedPDF
From MediaWiki.org
|
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
- Copy EmbedPDF.php to the new file EmbedPDF.php in your MediaWiki extensions directory.
- Enable the extension by adding this line to the bottom of your LocalSettings.php:
require_once('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) { return '<object data="'.$path.'" width="700" height="600" type="application/pdf"></object>'; } function embedPDFHandler ($input) { if (!$input) return '<font color="red">Error: empty param in <pdf>!</font>'; if (preg_match('/^[^\/]+\.pdf$/', $input)) { $img = Image::newFromName( $input ); if ($img != NULL) return makeHTMLforPDF($img->getURL()); } if (preg_match('/^http\:\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@\?\^\=\%\&:\/\~\+\#]*[\w\-\@\?\^\=\%\&\/\~\+\#])?\.pdf$/', $input)) return makeHTMLforPDF($input); else return '<font color="red">Error: bad URI in <pdf>!</font>'; } ?>