Extension:MiniMp3
![]() |
This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
MiniMp3 Release status: beta |
|
---|---|
Implementation | Tag |
Description | Allows to streams MP3 files |
Author(s) | Reddo (Redekopmarktalk) |
Latest version | 0.2 (2012-01-05) |
MediaWiki | 1.18+ |
Database changes | No |
License | No license specified |
Download | See the Code section |
Translate the MiniMp3 extension if it is available at translatewiki.net |
|
Check usage and version matrix; code metrics |
The MiniMp3 extension inserts a really light Flash player which streams an uploaded (or external) MP3 file. It's based on Extension:Mp3 but uses a different flash player and has more options and is compatible with newer versions of MediaWiki.
You can download the player from flash-mp3-player.net.
Contents
Usage[edit | edit source]
<mp3 bg="00FF00" color="FF0000">702 Promo.mp3</mp3> <mp3 bg="00FF00" color="FF0000">http://www.aiowiki.com/w/images/4/40/702_Promo.mp3</mp3> {{#tag:mp3|bg="00FF00"|color="FF0000"|{{{Mp3FileName}}} }} (this way allows usage of template variables) [[file:702 Promo.mp3]] - can't use custom colors
If the bg (background) value is not given it will default to silver, if the color value is not given it defaults to black
Installation[edit | edit source]
Note: player_mp3_mini.swf is required to be in your extensions/MiniMp3 directory for this extension to work
- Copy the code into a file and extract the file(s) in a directory called
MiniMp3
in yourextensions/
folder. - Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/MiniMp3/MiniMp3.php";
- If you want to accept mp3 uploads, add .mp3 to the list of allowed files:
-
$wgFileExtensions = array('png','gif',...,'mp3');
- Done! Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.
Code[edit | edit source]
Save the below code as MiniMp3.php and put it in your extensions/MiniMp3 directory
# Stream MP3 with http://flash-mp3-player.net/players/mini/ mini mp3 player
#
# Requires :
# player_mp3_mini.swf in the extensions/MiniMp3 directory
#
$wgHooks['ParserFirstCallInit'][] = 'wfMp3';
$wgMediaHandlers['audio/mp3'] = 'MiniMp3Handler';
$wgFileExtensions[] = 'mp3';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'MiniMp3',
'description' => 'Uses a very small flash player to stream your mp3 files',
'author' => array( 'Sylvain Machefert', 'Sam J Watkins', 'Reddo' ),
'version' => '0.2',
'url' => 'https://www.mediawiki.org/wiki/Extension:MiniMp3'
);
function wfMp3( Parser &$parser ) {
$parser->setHook('mp3', 'renderMp3');
return true;
}
# The callback function for converting the input text to HTML output
function renderMp3( $input, $params ) {
global $wgScriptPath;
$output= '';
//get params
//if no color param given for specific element default to general color param
//if no general color param given default to 000000
$Color = isset( $params['color'] ) ? $params['color'] : '000000';
if ( $Color == '')
{
$Color = '000000';
}
$slidColor = isset( $params['slidcolor'] ) ? $params['slidcolor'] : $Color ;
$loadColor = isset( $params['loadcolor'] ) ? $params['loadcolor'] : $Color ;
$buttColor = isset( $params['buttoncolor'] ) ? $params['buttoncolor'] : $Color ;
$bg = isset( $params['bg'] ) ? $params['bg'] : 'C0C0C0';
if ( $bg == '')
{
$bg = 'C0C0C0';
}
//do background code
$backgroundCode = Html::element( 'param', array( 'name' => "wmode", 'value' => "transparent" ) );
if ($bg != ''){
$backgroundCode = Html::element( 'param', array( 'name' => "bgcolor", 'value' => "#{$bg}" ) );
}
//File uploaded or external link ?
$img = wfFindFile($input);
if (!$img) {
$mp3 = $input;
}
else {
$mp3 = $img->getFullURL();
}
unset($img);
$flashFile = $wgScriptPath.'/extensions/MiniMp3/player_mp3_mini.swf';
$output .= '<object type="application/x-shockwave-flash" data="'.$flashFile.'" width="200" height="20">'
. Html::element( 'param', array( 'name' => "movie", 'value' => "{$flashFile}" ) )
. $backgroundCode
. Html::element( 'param', array( 'name' => "buttoncolor", 'value' => "#{$buttColor}" ) )
. Html::element( 'param', array( 'name' => "slidercolor", 'value' => "#{$slidColor}" ) )
. Html::element( 'param', array( 'name' => "FlashVars", 'value' => wfArrayToCGI( array( 'mp3' => $mp3, 'bgcolor' => $bg, 'loadingcolor' => $loadColor, 'buttoncolor' => $buttColor, 'slidercolor' => $slidColor ) ) ) )
. '</object>';
return $output;
}
class MiniMp3Handler extends MediaHandler {
function validateParam( $name, $value ) { return true; }
function makeParamString( $params ) { return ''; }
function parseParamString( $string ) { return array(); }
function normaliseParams( $file, &$params ) { return true; }
function getImageSize( $file, $path ) { return false; }
function getParamMap() {
return array(
'mp3_color' => 'color',
'mp3_slidecolor' => 'slidcolor',
'mp3_loadcolor' => 'loadcolor',
'mp3_buttoncolor' => 'buttoncolor',
'mp3_backColor' => 'bg',
);
}
# Prevent "no higher resolution" message.
function mustRender( $file ) { return true; }
function doTransform ( $file, $dstPath, $dstUrl, $params, $flags = 0 ) {
return new Mp3Output( $this->getParamMap (), $file->getFullUrl () );
}
}
class Mp3Output extends MediaTransformOutput {
var $buttColor, $slidColor, $loadColor, $bg, $mp3;
function __construct( $params, $mp3 ){
$Color = isset( $params['mp3_color'] ) ? $params['mp3_color'] : '50A6C2';
if ( $Color == '')
{
$Color = '50A6C2';
}
$this->slidColor = isset( $params['mp3_slidecolor'] ) ? $params['mp3_slidecolor'] : $Color ;
$this->loadColor = isset( $params['mp3_loadcolor'] ) ? $params['mp3_loadcolor'] : $Color ;
$this->buttColor = isset( $params['mp3_buttoncolor'] ) ? $params['mp3_buttoncolor'] : $Color ;
$this->bg = isset( $params['mp3_backColor'] ) ? $params['mp3_backColor'] : '';
$this->mp3 = $mp3;
}
function toHtml( $options=array () ) {
$backgroundCode = Html::element( 'param', array( 'name' => "wmode", 'value' => "transparent" ) );
if ($bg != ''){
$backgroundCode = Html::element( 'param', array( 'name' => "bgcolor", 'value' => "#{$bg}" ) );
}
$flashFile = '/w/extensions/MiniMp3/player_mp3_mini.swf';
$output .= '<object type="application/x-shockwave-flash" data="'.$flashFile.'" width="200" height="20">'
. Html::element( 'param', array( 'name' => "movie", 'value' => "{$flashFile}" ) )
. $backgroundCode
. Html::element( 'param', array( 'name' => "buttoncolor", 'value' => "#{$this->buttColor}" ) )
. Html::element( 'param', array( 'name' => "slidercolor", 'value' => "#{$this->slidColor}" ) )
. Html::element( 'param', array( 'name' => "loadingcolor", 'value' => "#{$this->loadColor}" ) )
. Html::element( 'param', array( 'name' => "FlashVars", 'value' => wfArrayToCGI( array( 'mp3' => $this->mp3, 'bgcolor' => $this->bg, 'loadingcolor' => $this->loadColor, 'buttoncolor' => $this->buttColor, 'slidercolor' => $this->slidColor ) ) ) )
. '</object>';
return $output;
}
}
To DO[edit | edit source]
- fix any XSS problems
- get [[File:blah.mp3|color=00FF00]] to work, although I've been told on IRC it can't be done without changes to the core