Extension:Youtube (lubito)

From IntactWiki
Jump to: navigation, search

Template:TNT {{TNT|Extension |name = YouTube |status = beta |type = tag |author = Sylvain Machefert |username = Iubito |image = |version = |update = |mediawiki = 1.16+ |download = see below |readme = |changelog = |description = <youtube> parser tag for displaying YouTube videos on a MediaWiki. |needs-updatephp = No |parameters= |rights = |tags = YouTube : bad video ID ! The file name is video ID code that's at the end of the URL of the video link. That's all. :-)

Installation

Add this line at the end of LocalSettings.php: <source lang="php"> require_once("$IP/extensions/YouTube.php"); </source>

Code

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

Copy the following code into extensions/YouTube.php :
<source lang="php"> <?php

  1. YouTube Videos
  2. Tag:
  3. Ex:
  4. from url http://www.youtube.com/watch?v=WZpeeRSk-0A
  5. 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'); }

  1. 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; } </source>

See also

Template:Languages

Personal tools
Namespaces

Variants
Actions
Navigation
Tools