Extension:PDF Include
PDF Include Release status: stable |
|||
---|---|---|---|
Implementation | Tag | ||
Description | Includes a PDF-File | ||
Author(s) | Chrisi200014 | ||
Last version | 1.1 | ||
MediaWiki | not tested! | ||
License | No license specified | ||
Download | in the article | ||
|
|||
|
|||
Check usage (experimental) |
PDF Include is an extension for Media Wiki 1.16 and higher. With it you are able to include PDF-Files from any URL's (note CHMOD!!). In Version 0.5, I've added the user-right system. The rights can be set in LocalSettings.php. This extension should only be allowed for SysOp's!!! Since Version 1.0 you can block Domains. For more information, look on Variables. In 1.1 I did a workover.
Contents |
[edit] Installing
Copy the code from the bottom and move it into the extension Folder of your Media Wiki. Then add the following code to LocalSettings.php
require_once("$IP/extensions/pdf_include.php");
[edit] Usage
<pdf width="width" height="height">Path</pdf> <pdf width="800px" height="1000px">http://www.example.com/example.pdf</pdf>
[edit] Variables
You can give a standart handicap for the width and the height. You needn't to set the variables, but then the handicap is 800px and 800px (width/height). Since Version 1.0 you can block Domains. To use the pdf Tags, you have to set the GroupPremission Variables:
$wgPDF = array('width'=>'width', 'height'=>'height', 'black'=>array('Blocked Domain','Blocked Domain 2.....')); $wgPDF['black'] = array('Blocked Domain','Blocked Domain 2.....'); //The best way to block Domains/Do only write the hostname. No protocol, no path, otherwhise it will fail. $wgGroupPermissions['*']['pdf'] = true; //Allow it for ALL/SHOULD NOT USED!!!!!!!!! $wgGroupPermissions['user']['pdf'] = true; //Allow it for USERS/MAYBE SHOULD NOT USED!!! $wgGroupPermissions['bot']['pdf'] = true; //Allow it for BOT/SHOULD NOT USED!!!!!!!!! $wgGroupPermissions['sysop']['pdf'] = true; //Allow it for SYSOP/STANDART
[edit] Code
<?php if (!defined ('MEDIAWIKI')) { echo 'This is a MediaWiki-Extension and not meant to be run standalone!'; exit (1); } $wgGroupPermissions['sysop']['pdf'] = true; //To allow the Sysop's to use the pdf-tags $wgPDF = array('width' => '800', 'height' => '800', 'black' => array()); $wgExtensionCredits['parserhook'] [] = array ( 'name' => 'PDF Include', 'author' => 'Christian Schabetsberger', 'url' => 'http://www.mediawiki.org/wiki/Extension:PDF_Include', 'description' => 'Includes PDF-Files', 'version' => '1.1', 'path' => __FILE__, ); if(defined('MW_SUPPORTS_PARSERFIRSTCALLINIT')) { $wgHooks['ParserFirstCallInit'][] = 'pdf_register'; } else { $wgExtensionFunctions[] = 'pdf_register'; } function pdf_register() { global $wgParser; $wgParser->setHook('pdf', 'includePDF'); return true; } function pdfobject($data, $width, $height){ return '<object width="'.$width.'" height="'.$height.'" data="'.htmlentities($data).'" type="application/pdf"></object>'; } function includePDF($obj, $argv, $parser){ global $wgPDF; $parser->disableCache(); $width = (isset($argv['width'])) ? $argv['width'] : $wgPDF['width']; $height = (isset($argv['height'])) ? $argv['height'] : $wgPDF['height']; $user = User::newFromName ($parser->getRevisionUser()); $user->load(); if(!$user->isAllowed('pdf')) { return 'Sry, but you are not allowed to include PDF-Files.'; } if(!$obj) { return 'Sry, but there is no given path.'; } $domain = parse_url($obj); if(in_array($domain['host'],$wgPDF['black'])){ return 'Sry, but the domain of this file is blocked.'; } if(!preg_match('~^\d+~',$width)) { return 'Sry, but the given width is unacceptable.'; } elseif (!preg_match('~^\d+~',$height)) { return 'Sry, but the given height is unacceptable.'; } if(preg_match('~^[^\/]+\.pdf$~', $obj)){ $image = Image::newFromName($obj); if($image != NULL) { return pdfobject($image->getURL(), $width, $height); } } if(filter_var($obj, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) { return pdfobject($obj, $width, $height); } else { return 'Sry, but the given Path isn\'t valid'; } }
Language: | English • Deutsch |
---|