Extension:Embed Document

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
Embed Document

Release status: experimental

Implementation Tag
Description This extension will
show a document
(*.pdf, *.doc, *.wav, ...) file
inside a MediaWiki page.
Author(s) SLohse, DrTrigon
Last Version 0.12
MediaWiki 1.9 - 1.12
License No license specified
Download see below
Example <embed_document>/my/path/myfilename.pdf</embed_document>

Contents

[edit] Purpose

Will show a document like *.pdf, *.doc, *.wav embedded inside a MediaWiki page.

"Here is my sugestion on dealing with pdf files and an answer from a coleague:

-- MarcioCarneiro? - 23-10-2007 16:09

Is it possible to develop a plugin to read a pdf file and write a wiki file? I have clients who need to read a pdf file with legal newspaper every day and I am trying to build a legal document management system inside a wiki engine.

About wiki files, could be a native xml database the management of wiki files such as sedna, eXist or xindice? "

And here is the answer:


"Hi Marcio!

Although you will need some engineering efforts, yes, it's possible (and after, you can publish your own piece of software, better if free software!). Such flux can be stated as:

PDF -> PDF filter -> Wiki format converter -> Input

Well, the PDF block is your newspaper (um Diário Oficial da União, I think),

The PDF can be parsed/manipulated via Perl, for instance (look at http://search.cpan.org/~antro/PDF-111/PDF.pm). That's your filter block.

The Wiki format converter can even be part of the lst module, embedded into the same perl (convertin keywords/tags into wiki tags).

And the insert can be made also via Perl using DBI.

-- MauricioMauad - 23 Oct 2007"

[edit] Usage

<embed_document>/my/path/myfilename.pdf</embed_document>

<embed_document width="50%" height="300">/my/path/myfilename.pdf</embed_document>

Note: The path has to be in your wiki's root directory

[edit] Installation

  1. Copy the code into extensions/embed_document.php
  2. Add
    require_once("$IP/extensions/embed_document.php");
    into LocalSettings.php

[edit] Code

<?php
/**
 * MediaWiki Embed Document extension
 *
 * @version 0.1
 * @author S.Lohse
 * @link http://www.mediawiki.org/wiki/Extension:Embed_Document
 */
 
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'Embed Document',
        'author' => 'SLohse, DrTrigon',
        'version' => '0.12',
        'url' => 'http://www.mediawiki.org/wiki/Extension:Embed_Document',
        'description' => 'Allows embedding *.pdf, *.doc and *.wav files on a wiki page',
);
 
$wgExtensionFunctions[] = 'registerEmbedDocumentHandler';
 
function registerEmbedDocumentHandler() {
         global $wgParser;
         $wgParser->setHook( 'embed_document', 'embedDocumentHandler' );
}
 
function embedDocumentHandler( $input, $argv ) {
    $allowedchars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
                          'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
                          'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
                          'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
                          '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                          '_', '/', '.', '-', ':');
 
    $w = '100%';
    $h = '680';
    foreach( $argv as $name => $value )
    {
        if ($name == 'width')  $w = $value;
        if ($name == 'height') $h = $value;
    }
 
    if( str_replace($allowedchars, '', $input) == '' ) {
       return "<iframe width=" . $w . " height=" . $h . " src=" . htmlspecialchars($input) . " frameborder=0 framebordercolor=#00000></iframe>";
    } else {
       return "<font color=#aa0000>Error: invalid character sequence between <code>&amp;lt;embed_document&amp;gt;...&amp;lt;/embed_document&amp;gt;</code> markers, allowed
are only<ul><li>a...z</li><li>A...Z</li><li>0...9</li><li>_</li><li>/</li><li>.</li><li>-</li><li>:</li></ul></font>";
   }
}

[edit] Template

[edit] PDF

If you are using mediawiki version 1.12 (work only here, because of Extension:Filepath and Extension:TagParser are needed!), it would probably be a good idea to create a template for simple document embedding.

  1. follow Creating template for handling PDF files
  2. open the page Template:Pdf_embed in you wiki, edit and insert this code:
<div style="color:#000000; border:solid 1px #A8A8A8; padding:0.0em 0.em 0.0em 0.em; background-color:#FFFFFF;font-size:80%; vertical-align:middle; width:50%">
{| width="100%"
|align="right" | {{pdf|{{{1}}}|{{{2}}}}}
|-
| {{#tag:embed_document| {{filepath:{{{1}}}}} |height="450"}}
|}
</div>

Now you can use this template to add a pretty looking box (width 50%, height 450) with link and embedded PDF file to your wiki pages. And there is no need to specify the full path anymore!

{{pdf_embed|DOCUMENT TITLE|HYPERLINK TEXT}}
{{pdf_embed|Example PDF document.pdf|Example PDF document}}

[edit] See also

Personal tools