Материал из RuedaPedia
Перейти к навигации Перейти к поиску
; float: right; background-color: white; width:280px; border-collapse:separate;" cellspacing="0"
Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png

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.


  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:

<source lang="php">require_once("$IP/extensions/EmbedPDF.php");</source>


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


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

<source lang="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 'Error: empty param in <pdf>!';
 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 'Error: bad URI in <pdf>!';


?> </source>