From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
AJAX Document Viewer

Release status:Extension status beta

ImplementationTemplate:Extension#type Tag
DescriptionTemplate:Extension#description AJAX Document Viewer Extension. Embed documents using AJAX document viewer .
Author(s)Template:Extension#username John Nidelc
Latest versionTemplate:Extension#version 0.1 (2008-12-18)
LicenseTemplate:Extension#license No license specified
Download see below


Translate the AJAXDocumentViewer extension if it is available at translatewiki.net

Check usage and version matrix.

What can this extension do?[edit]

AJAX Document Viewer is a web-based online document viewer that can be embedded into any web page or be linked from any page. It is customizable and free, although the free version displays a banner ad.


<adv>Document Name</adv>

One can optionally set the width and height of the document viewer:

<adv width="the width you want" height="the height you want">Document Name</adv>

Document Name can be the name of a file you have already uploaded to MediaWiki, i.e. Report.doc.



Create a new file called "extensions/AjaxDocumentViewer.php" in your MediaWiki installation directory and populate it with the following:


$wgExtensionFunctions[] = 'wfADV';
$wgHooks['LanguageGetMagic'][] = 'wfADVParserFunctionMagic';
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'ADV',
        'version' => 0.1,
        'description' => 'Display Documents using [http://www.ajaxdocumentviewer.com]',
        'author' => '[http://www.ajaxdocumentviewer.com AJAXDocumentViewer]',
        'url' => 'http://www.mediawiki.org/wiki/Extension:AJAXDocumentViewer'
function wfADV() {
        global $wgParser;
        $wgParser->setHook('ADV', 'renderADV');
        $wgParser->setFunctionHook('ADV', 'wfADVRender');
function wfADVRender(&$parser, $file = '') {
        return $parser->insertStripItem(renderADV($file, array()), $parser->mStripState);
function wfADVParserFunctionMagic( &$magicWords, $langCode ) {
        $magicWords['ADV'] = array( 0, 'ADV' );
        return true;
# The callback function for converting the input text to HTML output
function renderADV($input, $args) {
        global $wgADVKey;
        global $wgServer;
        $input = htmlspecialchars($input);
        $width = $args['width'];
        $height = $args['height'];
        if($width <= 0) {
                $width = 510;
        if($height <= 0) {
                $height = 660;
        /* is this a URL or an internal file? */
        if(strpos($input, "http://") == FALSE) {
                /* try and treat this like an internal file */
                $input = $wgServer . Image::imageUrl($input);
        $output = '<iframe name="ajaxdocumentviewer" src="http://www.ajaxdocumentviewer.com/embed.asp?key='.$wgADVKey.'&document='.$input.'&viewerheight='.$height.'&viewerwidth='.$width.'" border="0" height="'.$height.'" width="'.$width.'" scrolling="no" align="center" frameborder="0" marginwidth="1" marginheight="1">Your browser does not support inline frames or is currently configured not to display inline frames.</iframe>';
        return $output;



To enable the extension add the following to your "LocalSettings.php" file:


where 'XXXX' is the free AJAX Document Viewer key that can be obtained from http://www.ajaxdocumentviewer.com/linkit.asp#key.


This plugin was (badly) adapted from the Google Calendar extensions.