Extension:YouTube (emijrp)

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
YouTube (emijrp)

Release status: unknown

Implementation Tag
Description provides tag for embedding YouTube videos
Download see below

A modification of original Extension:YouTube (Iubito).


[edit] Code

<?php
# YouTube Videos
# 
# Tag :
#   <youtube>video</youtube>
# Ex :
#   from url http://www.youtube.com/watch?v=xYHsaDDSF
#   <youtube>xYHsaDDSF</youtube>
# Size:
# <youtube size="small">xYHsaDDSF</youtube>
# for a small window
# Other sizes: normal, big
# Personal size:
# <youtube width="100" height="100">xYHsaDDSF</youtube>
# for a window of 100x100
# Align:
# <youtube align="right" width="100" height="100">xYHsaDDSF</youtube>
# for a window of 100x100 on the right
# Other aligns: left
# Enjoy !
 
$wgExtensionFunctions[] = 'wfYouTube';
$wgExtensionCredits['parserhook'][] = array(
                'name' => 'YouTube',
                'description' => 'Display YouTube video',
                'author' => 'Sylvain Machefert & emijrp',
                'url' => 'http://www.mediawiki.org/wiki/Extension:YouTube_%28emijrp%29'
);
 
function wfYouTube() {
                global $wgParser;
                $wgParser->setHook('youtube', 'renderYouTube');
}
 
# The callback function for converting the input text to HTML output
function renderYouTube($input, $argv) {
                //$input = "WZpeeRSk-0A"
 
                if ($argv['align']!='left' and $argv['align']!='right')
                {
                        $align = 'right';
                }else{
                        $align = $argv['align'];
                }
 
                if ($argv['size'])
                {
                        switch($argv['size'])
                        {
                                case 'small':
                                        $width = 210;
                                        $height = 175;
                                        break;
                                case 'medium':
                                        $width = 330;
                                        $height = 260;
                                        break;
                                case 'normal':
                                        $width = 425;
                                        $height = 350;
                                        break;
                                case 'big':
                                        $width = 640;
                                        $height = 525;
                                        break;
                                default:
                                        $width = 425;
                                        $height = 350;
                                        break;
                        }
                }else{
                        if ($argv['width'])
                                $width = $argv['width'];
                        else
                                $width = 425;
 
                        if ($argv['height'])
                                $height = $argv['height'];
                        else
                                $height = 350;
                }
 
                //Validate the video ID
                if (preg_match('%[^A-Za-z0-9_\\-]%',$params['video'])) {
                                return 'YouTube : bad video ID !';
                }
 
                $output='<object align="'.$align.'" width="'.$width.'" height="'.$height.'">'
                                .'<param name="movie" value="http://www.youtube.com/v/'.$input.'">'
                                .'</param><param name="wmode" value="transparent"></param>'
                                .'<embed src="http://www.youtube.com/v/'.$input
                                .'" type="application/x-shockwave-flash" wmode="transparent" width="'.$width
                                .'" height="'.$height.'"></embed></object>';
 
                return $output;
}
Personal tools