User:Jack Phoenix/patches/YouTube

Index: YouTube.php

=
====================================================== --- YouTube.php	(revision 115) +++ YouTube.php	(working copy) @@ -4,10 +4,9 @@ * Parser hook-based extension to show audio and video players * from YouTube and other similar sites. * - * @package MediaWiki - * @subpackage Extensions + * @ingrop Extensions * @author Przemek Piotrowski  for Wikia, Inc. - * @copyright (C) 2006-2008, Wikia Inc. + * @copyright © 2006-2008, Wikia Inc. * @licence GNU General Public Licence 2.0 or later * * This program is free software; you can redistribute it and/or modify @@ -30,24 +29,27 @@ * @todo smart and tag */ -if (!defined('MEDIAWIKI')) -{ -	echo "This is MediaWiki extension.\n"; +if (!defined('MEDIAWIKI')) { +	echo "This is a MediaWiki extension.\n"; exit(1); } -$wgExtensionFunctions[] = 'wfYouTube'; -$wgExtensionCredits['parserhook'][] = array -( +$wgExtensionCredits['parserhook'][] = array( 'name'       => 'YouTube', 'version'    => '1.5', 'author'     => 'Przemek Piotrowski', 'url'        => 'http://help.wikia.com/wiki/Help:YouTube', -	'description' => 'embeds YouTube and Google Video movies + Archive.org audio and video + WeGame video + Tangler forum', +	'description' => 'Embeds YouTube and Google Video movies + Archive.org audio and video + WeGame video + Tangler forum', ); -function wfYouTube -{ +//Avoid unstubbing $wgParser too early on modern (1.12+) MW versions, as per r35980 +if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { +	$wgHooks['ParserFirstCallInit'][] = 'wfYouTube'; +} else { +	$wgExtensionFunctions[] = 'wfYouTube'; +} + +function wfYouTube { 	global $wgParser; 	$wgParser->setHook('youtube', 'embedYouTube'); @@ -56,17 +58,15 @@ 	$wgParser->setHook('aoaudio', 'embedArchiveOrgAudio'); 	$wgParser->setHook('wegame', 'embedWeGame'); 	$wgParser->setHook('tangler', 'embedTangler'); +	return true; } -function embedYouTube_url2ytid($url) -{ +function embedYouTube_url2ytid($url) { 	$id = $url; -	if (preg_match('/^http:\/\/www\.youtube\.com\/watch\?v=(.+)$/', $url, $preg)) -	{ +	if (preg_match('/^http:\/\/www\.youtube\.com\/watch\?v=(.+)$/', $url, $preg)) { 		$id = $preg[1]; -	} elseif (preg_match('/^http:\/\/www\.youtube\.com\/v\/([^&]+)(&autoplay=[0-1])?$/', $url, $preg)) -	{ +	} elseif (preg_match('/^http:\/\/www\.youtube\.com\/v\/([^&]+)(&autoplay=[0-1])?$/', $url, $preg)) { $id = $preg[1]; } @@ -76,46 +76,37 @@ 	return $id; } -function embedYouTube($input, $argv, &$parser) -{ +function embedYouTube($input, $argv, &$parser) { //$parser->disableCache; $ytid  = ''; $width = $width_max  = 425; $height = $height_max = 355; -	if (!empty($argv['ytid'])) -	{ +	if (!empty($argv['ytid'])) { $ytid = embedYouTube_url2ytid($argv['ytid']); -	} elseif (!empty($input)) -	{ +	} elseif (!empty($input)) { $ytid = embedYouTube_url2ytid($input); } -	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) -	{ +	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) { $width = $argv['width']; } -	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) -	{ +	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) { $height = $argv['height']; } -	if (!empty($ytid)) -	{ +	if (!empty($ytid)) { $url = "http://www.youtube.com/v/{$ytid}"; return " "; } } -function embedYouTube_url2gvid($url) -{ +function embedYouTube_url2gvid($url) { $id = $url; -	if (preg_match('/^http:\/\/video\.google\.com\/videoplay\?docid=([^&]+)(&hl=.+)?$/', $url, $preg)) -	{ +	if (preg_match('/^http:\/\/video\.google\.com\/videoplay\?docid=([^&]+)(&hl=.+)?$/', $url, $preg)) { $id = $preg[1]; -	} elseif (preg_match('/^http:\/\/video\.google\.com\/googleplayer\.swf\?docId=(.+)$/', $url, $preg)) -	{ +	} elseif (preg_match('/^http:\/\/video\.google\.com\/googleplayer\.swf\?docId=(.+)$/', $url, $preg)) { $id = $preg[1]; } @@ -125,41 +116,33 @@ 	return $id; } -function embedGoogleVideo($input, $argv, &$parser) -{ +function embedGoogleVideo($input, $argv, &$parser) { $gvid  = ''; $width = $width_max  = 400; $height = $height_max = 326; -	if (!empty($argv['gvid'])) -	{ +	if (!empty($argv['gvid'])) { $gvid = embedYouTube_url2gvid($argv['gvid']); -	} elseif (!empty($input)) -	{ +	} elseif (!empty($input)) { $gvid = embedYouTube_url2gvid($input); } -	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) -	{ +	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) { $width = $argv['width']; } -	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) -	{ +	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) { $height = $argv['height']; } -	if (!empty($gvid)) -	{ +	if (!empty($gvid)) { $url = "http://video.google.com/googleplayer.swf?docId={$gvid}"; return " "; } } -function embedYouTube_url2aovid($url) -{ +function embedYouTube_url2aovid($url) { $id = $url; -	if (preg_match('/http:\/\/www\.archive\.org\/download\/(.+)\.flv$/', $url, $preg)) -	{ +	if (preg_match('/http:\/\/www\.archive\.org\/download\/(.+)\.flv$/', $url, $preg)) { $id = $preg[1]; } @@ -169,41 +152,33 @@ 	return $id; } -function embedArchiveOrgVideo($input, $argv, &$parser) -{ +function embedArchiveOrgVideo($input, $argv, &$parser) { $aovid  = ''; $width = $width_max  = 320; $height = $height_max = 263; -	if (!empty($argv['aovid'])) -	{ +	if (!empty($argv['aovid'])) { $aovid = embedYouTube_url2aovid($argv['aovid']); -	} elseif (!empty($input)) -	{ +	} elseif (!empty($input)) { $aovid = embedYouTube_url2aovid($input); } -	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) -	{ +	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) { $width = $argv['width']; } -	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) -	{ +	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) { $height = $argv['height']; } -	if (!empty($aovid)) -	{ +	if (!empty($aovid)) { $url = "http://www.archive.org/download/{$aovid}.flv"; return " "; } } -function embedYouTube_url2aoaid($url) -{ +function embedYouTube_url2aoaid($url) { $id = $url; -	if (preg_match('/http:\/\/www\.archive\.org\/details\/(.+)$/', $url, $preg)) -	{ +	if (preg_match('/http:\/\/www\.archive\.org\/details\/(.+)$/', $url, $preg)) { $id = $preg[1]; } @@ -213,41 +188,33 @@ 	return $id; } -function embedArchiveOrgAudio($input, $argv, &$parser) -{ +function embedArchiveOrgAudio($input, $argv, &$parser) { $aoaid  = ''; $width = $width_max  = 400; $height = $height_max = 170; -	if (!empty($argv['aoaid'])) -	{ +	if (!empty($argv['aoaid'])) { $aoaid = embedYouTube_url2aoaid($argv['aoaid']); -	} elseif (!empty($input)) -	{ +	} elseif (!empty($input)) { $aoaid = embedYouTube_url2aoaid($input); } -	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) -	{ +	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) { $width = $argv['width']; } -	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) -	{ +	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) { $height = $argv['height']; } -	if (!empty($aoaid)) -	{ +	if (!empty($aoaid)) { $url = urlencode("http://www.archive.org/audio/xspf-maker.php?identifier={$aoaid}"); return " "; } } -function embedYouTube_url2weid($url) -{ +function embedYouTube_url2weid($url) { $id = $url; -	if (preg_match('/^http:\/\/www\.wegame\.com\/watch\/(.+)\/$/', $url, $preg)) -	{ +	if (preg_match('/^http:\/\/www\.wegame\.com\/watch\/(.+)\/$/', $url, $preg)) { $id = $preg[1]; } @@ -257,49 +224,38 @@ 	return $id; } -function embedWeGame($input, $argv, &$parser) -{ +function embedWeGame($input, $argv, &$parser) { $weid  = ''; $width = $width_max  = 488; $height = $height_max = 387; -	if (!empty($argv['weid'])) -	{ +	if (!empty($argv['weid'])) { $weid = embedYouTube_url2weid($argv['weid']); -	} elseif (!empty($input)) -	{ +	} elseif (!empty($input)) { $weid = embedYouTube_url2weid($input); } -	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) -	{ +	if (!empty($argv['width']) && settype($argv['width'], 'integer') && ($width_max >= $argv['width'])) { $width = $argv['width']; } -	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) -	{ +	if (!empty($argv['height']) && settype($argv['height'], 'integer') && ($height_max >= $argv['height'])) { $height = $argv['height']; } -	if (!empty($weid)) -	{ +	if (!empty($weid)) { return " "; - 	} } -function embedYouTube_url2tgid($input) -{ +function embedYouTube_url2tgid($input) { $tid = $gid = 0; -	if (preg_match('/^id=([0-9]+)\|gId=([0-9]+)$/i', $input, $preg)) -	{ +	if (preg_match('/^id=([0-9]+)\|gId=([0-9]+)$/i', $input, $preg)) { $tid = $preg[1]; $gid = $preg[2]; -	} elseif (preg_match('/^gId=([0-9]+)\|id=([0-9]+)$/i', $input, $preg)) -	{ +	} elseif (preg_match('/^gId=([0-9]+)\|id=([0-9]+)$/i', $input, $preg)) { $tid = $preg[2]; $gid = $preg[1]; -	} elseif (preg_match('/^([0-9]+)\|([0-9]+)$/', $input, $preg)) -	{ +	} elseif (preg_match('/^([0-9]+)\|([0-9]+)$/', $input, $preg)) { $tid = $preg[1]; $gid = $preg[2]; } @@ -307,20 +263,16 @@ 	return array($tid, $gid); } -function embedTangler($input, $argv, &$parser) -{ +function embedTangler($input, $argv, &$parser) { $tid = $gid = ''; -	if (!empty($argv['tid']) && !empty($argv['gid'])) -	{ +	if (!empty($argv['tid']) && !empty($argv['gid'])) { list($tid, $gid) = embedYouTube_url2tgid("{$argv['tid']}|{$argv['gid']}"); -	} elseif (!empty($input)) -	{ +	} elseif (!empty($input)) { list($tid, $gid) = embedYouTube_url2tgid($input); } -	if (!empty($tid) && !empty($gid)) -	{ +	if (!empty($tid) && !empty($gid)) { return "  "; } -} +} \ No newline at end of file