Extension:OFlash

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

Release status: stable

Implementation Tag
Description Easy syntax for inserting Flash SWFs and FLV videos.
Author(s) Orifice Software (Fergal Hainey)
Last version 1.0.0 (20/11/08)
MediaWiki Probably 1.8
License Some parts use Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported license
Download http://bfot.co.uk/orifice/oflash/
Example http://arse.kyru.co.uk

Check usage (experimental)

Contents

[edit] What can this extension do?

Embed flash files with standards compliance, no javascript, prompts popular browsers for missing Flash plug-ins and has a built in media player for FLV or H.264 media.

[edit] Usage

OFlash uses a self-closing <oflash /> tag with these attributes:

  • file: The path of the flash SWF or video. Can be given as an absolute or relative path (like src in <img>) or a URI like http://bleh.com/bleh.swf . If the path ends in .swf (case insensitive) it will be embedded as a standard flash file. If the path ends in anything else (doesn't have to be .flv or .mp4) it will be treated as a flash video and the included media player will be embedded.
  • thumb: If you define this as anything other than "false" it will default to true. If you omit the attribute it will default to false. If true the flash will be placed within the same <div>s that the MonoBook MediaWiki skin uses to make thumbnail images that float to the right. Also the flash will be scaled down (or possibly up) to 180px in width.
  • caption: If thumb is true, then this caption will be used and will use MonoBooks thumbnail caption style. You can use wiki formatting in it like [[Bleh]] and stuff.
  • width & height: The width and height of the animation or video. If a video, the right amount of height will be added for the player controls. If thumb is true, still give the original width and height, as these values will be used for the scaling.
  • flashvars: Any FlashVars to be passed to the animation. Only applies to animations (.swf files), does not forward any further FlashVars to the media player.

[edit] Download instructions

The latest version can be downloaded from http://bfot.co.uk/orifice/oflash. The download includes a combined README/VERSION and the video player flash file.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

require_once("extensions/oflash/orificeflash.php");

[edit] New Working Version (version 1.16.4)

This new version has a lot of unneeded code removed, it has been cleaned up and rewrote. The same functionality, except now the "thumb" argument and the "flashvars" argument are both optional.

<?php
//Orifice Software's (Fergal's) flash video and swf player for mediawiki.
//Add to the end of LocalSettings.php: require_once("extensions/oflash/orificeflash.php");
 
//adding hook
$wgExtensionFunctions[]='wfOrificeFlashExtension';
$wgExtensionCredits['parserhook'][]=array(
        'name'=>'Orifice Flash',
        'author'=>'Fergal Hainey',
        'url'=>'http://bfot.co.uk/orifice/',
        'description'=>'Easy syntax for inserting Flash SWFs and FLV videos.'
);
 
//hook callback
function wfOrificeFlashExtension() {
 
        global $wgParser;
 
        //install parser hook for <oflash> tags
        $wgParser->sethook( 'oflash', 'doOFlash' );
 
}
 
//parser hook callback
function doOFlash( $input, $argv, $parser ) {
 
        if (!$parser) $parser = $GLOBALS['wgParser'];
 
        global $wgOutputEncoding;
        $oflashswf = false;
        $out = '';
 
        $DefaultEncoding='ISO-8859-1';
 
        //get parameters from argv
        if ( isset( $argv['file'] ) )
                $file  = htmlspecialchars( $argv['file'] );
        else
                return "Error: Missing File argument for oflash";
 
        if ( isset( $argv['width'] ) )
                $width = htmlspecialchars( $argv['width'] );
        else
                return "Error: Missing File argument for oflash";
 
 
        if ( isset( $argv['height'] ) )
                $height        = htmlspecialchars( $argv['height'] ) + 20;
        else
                return "Error: Missing File argument for oflash";
 
        if ( isset( $argv['thumb'] ) && 'false' != $argv['thumb'] )
                $thumb = htmlspecialchars( $argv['thumb'] );
        else
                $thumb = false;
 
        if ( isset( $argv['caption'] ) )
                $caption= $parser->recursiveTagParse( $argv['caption'] );
        else
                $caption = false;
 
        if ( isset( $argv['caption'] ) )
                $flashvars = htmlspecialchars( $argv['flashvars'] );
        else
                $flashvars = '';
 
        if ( '.swf' == strtolower( substr( $file,-4,4 ) ) ) {
 
                $height -= 20;
                $oflashswf = true;
 
        }
 
        if ( $thumb ) { 
 
                $out = '<div class="thumb tright"><div class="thumbinner" style="width:182px;">';
 
                if ( !$oflashswf ) 
                        $height-=20;
 
                $height = round( ( 180 / $width ) * $height );
 
                if ( !$oflashswf )
                        $height+=20;
 
                $width = 180;
 
        }
 
        if ( $oflashswf ) {
 
                $out .= "<object type=\"application/x-shockwave-flash\" data=\"$file\" width=\"$width\" height=\"$height\"><param name=\"movie\" value=\"$file\"><param name=\"FlashVars\" value=\"$flashvars\"><p>This is supposed to be a flash animation. You'll need the flash plugin and a browser that supports it to view it.</object>";
 
        } else {
 
                global $wgScriptPath;
                $out .= "<object type=\"application/x-shockwave-flash\" data=\"$wgScriptPath/extensions/oflash/jwplayer.swf\" width=\"$width\" height=\"$height\"><param name=\"movie\" value=\"$wgScriptPath/extensions/oflash/jwplayer.swf\"><param name=\"FlashVars\" value=\"file=$file\"><param name=\"allowfullscreen\" value=\"true\"><param name=\"allowscriptaccess\" value=\"always\"><p>This is supposed to be a flash video. You'll need the flash plugin and a browser that supports it to view to it.</p></object>";
 
        }
 
        if ( $caption ) 
 
                $out .= "<div class=\"thumbcaption\">$caption</div>";
 
        if ( isset( $GLOBALS['oflashAlready'] ) && !$GLOBALS['oflashAlready'] ) 
 
                $out .= "<div style=\"height:0;outline;0;padding:0;margin:0;overflow:hidden;\"><object type=\"application/x-shockwave-flash\" width=\"1\" height=\"1\" codebase=\"http://download.macromedia.com
/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\"><param name=\"pluginspage\" value=\"http://www.macromedia.com/go/getflashplayer\"></object></div>";
 
        if ( $thumb ) {
 
                $out .= '</div></div>';
 
        }
 
        $GLOBALS['oflashAlready'] = true;
 
        return $out;
 
}
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox