Extension:EmbedPDF
From MediaWiki.org
|
EmbedPDF Release status: beta |
|||
|---|---|---|---|
| Implementation | Parser function | ||
| Description | Allows to embed .pdf documents on a wiki page. | ||
| Author(s) | Dmitry Shurupovtalk | ||
| Last version | 0.2 | ||
| MediaWiki | 1.12+ | ||
| Database changes | no | ||
| License | GPL | ||
| Download | see below | ||
|
|||
|
|||
| Check usage and version matrix | |||
| 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. |
The EmbedPDF extension adds the <pdf> tag for embedding PDF files. It supports remote and local (uploaded to MediaWiki) files.
Installation [edit]
- 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("$IP/extensions/EmbedPDF.php");
Usage [edit]
- <pdf>http://some.site.com/with/a/document.pdf</pdf>
- <pdf>Your_uploaded_document.pdf</pdf>
Options [edit]
There are no options yet. EmbedPDF will create HTML <object> with predefined width (700 px) and height (600 px). That's all.
Source of EmbedPDF.php [edit]
<?php /** * MediaWiki EmbedPDF extension * * @file * @ingroup Extensions * @version 0.2 * @author Dmitry Shurupov * @link https://www.mediawiki.org/wiki/Extension:EmbedPDF Documentation */ if ( !defined( 'MEDIAWIKI' ) ) { die( 'This is not a valid entry point to MediaWiki.' ); } // Extension credits that will show up on Special:Version $wgExtensionCredits['parserhook'][] = array( 'name' => 'EmbedPDF', 'author' => 'Dmitry Shurupov', 'version' => '0.2', 'url' => 'https://www.mediawiki.org/wiki/Extension:EmbedPDF', 'description' => 'Allows to embed .pdf documents on a wiki page.', ); $wgHooks['ParserFirstCallInit'][] = 'registerEmbedPDFHandler'; // Register the <pdf> tag with the parser function registerEmbedPDFHandler( &$parser ) { $parser->setHook( 'pdf', 'embedPDFHandler' ); return true; } function makeHTMLforPDF( $path, $argv ) { // Use user-supplied values for the width and height parameters, if // they are set and also do some very basic input validation if ( empty( $argv['width'] ) ) { $width = '1000'; } else { $width = ( is_numeric( $argv['width'] ) ? $argv['width'] : 1000 ); } if ( empty( $argv['height'] ) ) { $height = '700'; } else { $height = ( is_numeric( $argv['height'] ) ? $argv['height'] : 700 ); } return '<object data="' . $path . '" width="' . $width . '" height="' . $height . '" type="application/pdf"></object>'; } function embedPDFHandler( $input, $argv ) { if ( !$input ) { return '<span style="color: red;">Error: empty param in <pdf>!</span>'; } if ( preg_match( '/^[^\/]+\.pdf$/i', $input ) ) { $img = wfFindFile( $input ); if ( is_object( $img ) ) { return makeHTMLforPDF( $img->getURL(), $argv ); } } if ( preg_match( '/^http\:\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@\?\^\=\%\&:\/\~\+\#]*[\w\-\@\?\^\=\%\&\/\~\+\#])?\.pdf$/i', $input ) ) { return makeHTMLforPDF( $input, $argv ); } else { return '<span style="color: red;">Error: bad URI in <pdf>!</span>'; } }