Extension:OFlash

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon alert-invert.svg
OFlash
Release status: unstable
Implementation Tag
Description Easy syntax for inserting Flash SWFs and FLV videos.
Author(s) Orifice Software (Fergal Hainey)
Latest version 1.0.0 (2008-11-20)
MediaWiki 1.18
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
Translate the OFlash extension if it is available at translatewiki.net
Check usage and version matrix.

What can this extension do?[edit]

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.

Usage[edit]

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 . You can also use the {{filepath:FileName.ext}} notation to reference an uploaded file. 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.

Examples:

<oflash file="movie.swf" caption="A cool flash movie that I made" width=500 height=900 />
<oflash file="{{filepath:AnotherMovie.swf}}" caption="A flash movie I Uploaded in MediaWiki" width=500 height=900 />

Download instructions[edit]

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.

Installation[edit]

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

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

New Working Version (version 1.18)[edit]

This new version has been cleaned up and rewritten, with a lot of unneeded code removed. 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'] ) && strtolower( substr( $argv['file'], 0, 11 ) ) == '{{filepath:' ) {
		// filename wraped in {{filepath:FileName.ext}}
		$argv['file'] = CoreParserFunctions::filepath( $parser, substr( $argv['file'], 11, -2 ) );
		if( '' == $argv['file'] ) unset( $argv['file'] );
	}
	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 Width argument for oflash";


	if ( isset( $argv['height'] ) )
		$height	= htmlspecialchars( $argv['height'] ) + 20;
	else
		return "Error: Missing Height 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['flashvars'] ) )
		$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;

}