Extension:YouTube (Iubito)
From MediaWiki.org
|
YouTube Release status: unknown |
|
|---|---|
| Implementation | Tag |
| Description | <youtube> parser tag for displaying YouTube videos on a MediaWiki. |
| Author(s) | Sylvain Machefert (Iubito Talk) |
| Download | see below |
| Example | [1] [2] |
YouTube extension displays videos from YouTube. Upload your videos to YouTube and then share them in your wiki!
View a demo in the sandbox of my wiki.
Contents |
[edit] Changes to LocalSettings.php
Add this line at the end of LocalSettings.php:
require_once('extensions/YouTube.php');
[edit] Code
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_\\-]%',$params['video'])) { return 'YouTube : bad video ID !'; } $output='<object 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; }
[edit] Usage
To add the link in the wiki: <youtube>FileNameOfYouTubeVideo</youtube>
That's all. :-)
[edit] See also
- YouTube Widget on MediaWikiWidgets.org site, it uses Widgets extension.

