Glenn's Junk Chest

An assortment of Glenn's writings, photography, gaming resources, flash movies, and other creative output.


Saturday, March 05, 2005

Wiki: Adding Extensions to MediaWiki

Since I often use Flash to illustrate topics and create animations, and may use it for maps, I wanted to have the capability to use flash in my new wiki. (see previous post). Alas, by default, my installation of mediaWiki doesn't seem to include this capability.

However, using just a bit of php, one can write an extension to mediaWiki that allows for custom tags that can do just about anything, so, with some programming, I've added this capability. Now, if you include

<gflash>480 340 http://www.somewhere.com/someflash.swf</gflash>

in your wiki markup, it should embed the flash at the url inline, 480 wide by 340 tall, in your wiki page. Here's a working example on the GlennGameWiki. For people that want the code of the extension, I'm including it as a comment, below.

Update: Since being indexed by Google, this post appears to have become something of a resource for people looking into how to do this. For instance, a large business linked to this article from the main page of their internal wiki for a while. Since my business Clotho Advanced Media, Inc. does internet development work of this sort, I'd certainly invite anyone who is having trouble with this, or needs custom php extensions to mediawiki, to contact my office (608-294-7900, ask for Glenn) or email me. I might be able to help you out, and Clotho can always stand to develop new business-to-business relationships.

Update 2: (5/26/05). My wiki server isn't up to much bandwidth, so I don't allow the uploading of images. Perforce, this means that the flash content referred to by my extension is hosted elsewhere. However, if you're interested in making an extension to allow the inclusion of uploaded content (such as swfs), I refer you to this page. The extension there also has a more sophisticated parameter passing methodology, which may be of interest as well.

6 Comments:

At 4:00 PM, Blogger Glenn said...

<?php
# Example WikiMedia extension
# with WikiMedia's extension mechanism it is possible to define
# new tags of the form
# <TAGNAME> some text </TAGNAME>
# the function registered by the extension gets the text between the
# tags as input and can transform it into arbitrary HTML code.
# Note: The output is not interpreted as WikiText but directly
# included in the HTML output. So Wiki markup is not supported.
# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/gflash.php");

$wgExtensionFunctions[] = "wfGFlashExtension";

function wfGFlashExtension() {
global $wgParser;
# register the extension with the WikiText parser
# the first parameter is the name of the new tag.
# the second parameter is the callback function for processing the text between the tags
$wgParser->setHook( "gflash", "renderGFlash" );
}

# The callback function for converting the input text to HTML output
function renderGFlash( $input ) {

$exploin = explode(" ",$input);

$output = "<div><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='" . $exploin[0] . "' height='" . $exploin[1] . "' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='" . $exploin[2] . "' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='" . $exploin[2] . "' quality='high' bgcolor='#ffffff' width='" . $exploin[0] . "' height='" . $exploin[1] . "' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object></div><br />";

return $output;
}
?>

 
At 3:24 PM, Blogger Tom said...

Hey thanks for this great little extension. Very easy. Very wiki.

 
At 4:27 AM, Anonymous Anonymous said...

Can you apply this to other files? Like WMV or MOV?
If so, how would I adjust your code? I am very interested in this!! zumiez@b3an.com

 
At 7:10 AM, Blogger Cuttlefish said...

Hi,

If you want to show YouTube videos or some other flash videos with dynamic content, you may have to add:

flashvars='" . $exploin[3] . "'

and put the flashvars value as the fourth string in gflash.

 
At 4:11 AM, Anonymous planetoid said...

Thanks for your great work!

 
At 11:40 PM, Anonymous Esben Thomsen said...

Glenn,

Theappletree.dk is eternal greatfull for this :-) Good job

 

Post a Comment

Links to this post:

Create a Link

<< Home