Extension:PDF

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

Release status: unknown

Implementation Tag
Description Set up MediaWiki to react to the "<PDF>" tag
License No license specified
Download See below

Check usage (experimental)

Possible alternative: Extension:PdfHandler

[edit] PDF extension

Create a new file pdf.php in the "extensions" directory and copy the second code-paragraph into it. Additionally add the following string to LocalSettings.php:

require_once("$IP/extensions/pdf.php"); 

This will include a PDF file to your media wiki, put it into pdf.php:

<?php
// MediaWiki PDF Extension Ver 0.2
// Set up MediaWiki to react to the "<PDF>" tag
// Original file by Nilam Doctor
// <ceo@qualifiedtutorsinc.com> to allow local PDF files
 
        $wgExtensionFunctions[] = "wfPDF";
        function wfPDF() {
                global $wgParser;
                $wgParser->setHook( "pdf", "RenderPDF" );
        }
        function RenderPDF( $input, $argv ) {
            global $wgScriptPath;
            $output = "";
                // safety check: only .pdf files
                clearstatcache(); 
                if ( stripos($input, ".pdf") === strlen($input)-4 ) {
                        if ( stripos($input , "http") === 0 || stripos($input , "ftp") === 0 ) {
                                // external URL
                                if (!preg_match("/;/", $input )) 
                                        $url = $input;
                                else
                                        $output = "Error: The link \"$input\" contains a \";\", which is not allowed.";
                        }
                        else { 
                                // internal Media:
                                if (file_exists ( $input )) //safety check: if file exists, we assume it is safe.
                                        $url = $input;
                                else 
                                        $output = "Error: The file \"$input\" was not found.";
                        }
                        if (empty($output)) { //no error occured
                            $width  = isset($argv['width']) ? $argv['width']  : 800;
                            $height = isset($argv['height'])? $argv['height'] : 600;
                            $id = basename($input, ".pdf");
                                $output = '<iframe width="' . $width . '" height="' . $height . '" src="' . $url . '" frameborder="0" framebordercolor="#000000"></iframe>';
                        }
                }
                else $output = "Error: The file \"$input\" was not recognized as pdf. The file extension must be .pdf.";
                return $output;
        }
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox