Extension:YouTube (Iubito)

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

Release status: beta

Implementation Tag
Description <youtube> parser tag for displaying YouTube videos on a MediaWiki.
Author(s) Sylvain Machefert (Iubitotalk)
MediaWiki 1.16+
Database changes No
License No license specified
Download see below
Example [1]
[2]
Tags
<youtube>

Translate the YouTube (Iubito) extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

The YouTube extension displays videos from YouTube. Upload your videos to YouTube and then share them in your wiki!

Usage[edit | edit source]

To add the link in the wiki: <youtube>FileNameOfYouTubeVideo</youtube> The file name is video ID code that's at the end of the URL of the video link. That's all. :-)

Installation[edit | edit source]

Add this line at the end of LocalSettings.php:

require_once("$IP/extensions/YouTube.php");

Code[edit | edit source]

Warning: The code below had major security issues prior to being fixed on 2008-07-09.

Copy the following code into extensions/YouTube.php :

<?php
# YouTube Videos
# 
# Tag:
#   <youtube>v</youtube>
# Ex:
#   from url http://www.youtube.com/watch?v=WZpeeRSk-0A
#   <youtube>WZpeeRSk-0A</youtube>
# 
# Enjoy!

$wgExtensionFunctions[] = 'wfYouTube';
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'YouTube',
	'description' => 'Display YouTube video',
	'author' => 'Sylvain Machefert',
	'url' => 'http://www.mediawiki.org/wiki/Extension:YouTube_(Iubito)'
);
 
function wfYouTube() {
	global $wgParser;
	$wgParser->setHook('youtube', 'renderYouTube');
}
 
# The callback function for converting the input text to HTML output
function renderYouTube($input) {
	//$input = "WZpeeRSk-0A"
 
	$width = 425;
	$height = 350;
 
	//Validate the video ID
	if (preg_match('%[^A-Za-z0-9_!\#\\-]%',$input)) {
		return 'YouTube : bad video ID !';
	}
 
	$url = 'http://www.youtube.com/v/' . $input;
	$output =
		Xml::openElement( 'object',
			array(
				'width' => $width,
				'height' => $height ) ) .
		Xml::openElement( 'param',
			array(
				'name' => 'movie',
				'value' => $url ) ) .
		'</param>' .
		Xml::openElement( 'embed',
			array(
				'src' => $url,
				'type' => 'application/x-shockwave-flash',
				'wmode' => 'transparent',
				'width' => $width,
				'height' => $height ) ) .
		'</embed>' .
		'</object>';
 
	return $output;
}

See also[edit | edit source]

Language: English  • português do Brasil • русский