diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..71485e4 --- /dev/null +++ b/CREDITS @@ -0,0 +1,4 @@ +Original version developed by Jim R. Wilson (jimbojw) +Subsequent improvements added by (alphabetical order) + +Andrew Whitworth (Whiteknight) diff --git a/EmbedVideo.php b/EmbedVideo.php new file mode 100644 index 0000000..8f4bada --- /dev/null +++ b/EmbedVideo.php @@ -0,0 +1,193 @@ +'EmbedVideo', + 'author'=>'Jim R. Wilson and Andrew Whitworth', + 'url'=>'http://www.mediawiki.org/wiki/Extension:EmbedVideo', + 'description'=>'Adds a parser function embedding video from popular sources.', + 'version'=>'0.1.2' +); + +/** + * Wrapper class for encapsulating EmbedVideo related parser methods + */ +class EmbedVideo { + + /** + * Sets up parser functions. + */ + function setup( ) { + + # Setup parser hook + global $wgParser, $wgVersion; + $hook = (version_compare($wgVersion, '1.7', '<')?'#ev':'ev'); + $wgParser->setFunctionHook( $hook, array($this, 'parserFunction')); + + # Add system messages + global $wgMessageCache; + $wgMessageCache->addMessage('embedvideo-missing-params', 'EmbedVideo is missing a required parameter.'); + $wgMessageCache->addMessage('embedvideo-bad-params', 'EmbedVideo received a bad parameter.'); + $wgMessageCache->addMessage('embedvideo-unparsable-param-string', 'EmbedVideo received the unparsable parameter string "$1".'); + $wgMessageCache->addMessage('embedvideo-unrecognized-service', 'EmbedVideo does not recognize the video service "$1".'); + $wgMessageCache->addMessage('embedvideo-bad-id', 'EmbedVideo received the bad id "$1" for the service "$2".'); + $wgMessageCache->addMessage('embedvideo-illegal-width', 'EmbedVideo received the illegal width parameter "$1".'); + $wgMessageCache->addMessage('embedvideo-embed-clause', + ''. + ''. + ''. + ''. + '' + ); + } + + /** + * Adds magic words for parser functions. + * @param Array $magicWords + * @param $langCode + * @return Boolean Always true + */ + function parserFunctionMagic( &$magicWords, $langCode='en' ) { + $magicWords['ev'] = array( 0, 'ev' ); + return true; + } + + /** + * Embeds video of the chosen service + * @param Parser $parser Instance of running Parser. + * @param String $service Which online service has the video. + * @param String $id Identifier of the chosen service + * @param String $width Width of video (optional) + * @return String Encoded representation of input params (to be processed later) + */ + function parserFunction( $parser, $service=null, $id=null, $width=null ) { + global $wgScriptPath; + + if ($service===null || $id===null) return '
'.wfMsg('embedvideo-missing-params').'
'; + + $params = array( + 'service' => trim($service), + 'id' => trim($id), + 'width' => ($width===null?null:trim($width)), + ); + + global $wgEmbedVideoMinWidth, $wgEmbedVideoMaxWidth; + if (!is_numeric($wgEmbedVideoMinWidth) || $wgEmbedVideoMinWidth<100) $wgEmbedVideoMinWidth = 100; + if (!is_numeric($wgEmbedVideoMaxWidth) || $wgEmbedVideoMaxWidth>1024) $wgEmbedVideoMaxWidth = 1024; + + global $wgEmbedVideoServiceList; + $service = $wgEmbedVideoServiceList[$params['service']]; + if (!$service) return '
'.wfMsg('embedvideo-unrecognized-service', @htmlspecialchars($params['service'])).'
'; + + $id = htmlspecialchars($params['id']); + $idpattern = ( isset($service['id_pattern']) ? $service['id_pattern'] : '%[^A-Za-z0-9_\\-]%' ); + if ($id==null || preg_match($idpattern,$id)) { + return '
'.wfMsgForContent('embedvideo-bad-id', $id, @htmlspecialchars($params['service'])).'
'; + } + + $parser->disableCache(); + $clause = $service['extern']; + if (isset($clause)) { + $path = $wgScriptPath . "/extensions/EmbedVideo"; + return array(wfMsgReplaceArgs($clause, array($path, $id)), 'noparse' => true, 'isHTML' => true); + } + + # Build URL and output embedded flash object + $ratio = 425 / 350; + $width = 425; + + if ($params['width']!==null) { + if ( + !is_numeric($params['width']) || + $params['width'] < $wgEmbedVideoMinWidth || + $params['width'] > $wgEmbedVideoMaxWidth + ) return + '
'. + wfMsgForContent('embedvideo-illegal-width', @htmlspecialchars($params['width'])). + '
'; + $width = $params['width']; + } + $height = round($width / $ratio); + $url = wfMsgReplaceArgs($service['url'], array($id, $width, $height)); + + return $parser->insertStripItem( + wfMsgForContent('embedvideo-embed-clause', $url, $width, $height), + $parser->mStripState + ); + } + +} + +/** + * Wrapper function for language magic call (hack for 1.6 + */ + +# Create global instance and wire it up! +$wgEmbedVideo = new EmbedVideo(); +$wgExtensionFunctions[] = array($wgEmbedVideo, 'setup'); +if (version_compare($wgVersion, '1.7', '<')) { + # Hack solution to resolve 1.6 array parameter nullification for hook args + function wfEmbedVideoLanguageGetMagic( &$magicWords ) { + global $wgEmbedVideo; + $wgEmbedVideo->parserFunctionMagic( $magicWords ); + return true; + } + $wgHooks['LanguageGetMagic'][] = 'wfEmbedVideoLanguageGetMagic'; +} else { + $wgHooks['LanguageGetMagic'][] = array($wgEmbedVideo, 'parserFunctionMagic'); +} + +# Build services list (may be augmented in LocalSettings.php) +$wgEmbedVideoServiceList = array( + 'dailymotion' => array( + 'url' => 'http://www.dailymotion.com/swf/$1' + ), + 'funnyordie' => array( + 'url' => + 'http://www.funnyordie.com/v1/flvideo/fodplayer.swf?file='. + 'http://funnyordie.vo.llnwd.net/o16/$1.flv&autoStart=false' + ), + 'teachertube' => array( + 'extern' => '' + ), + 'googlevideo' => array( + 'id_pattern'=>'%[^0-9\\-]%', + 'url' => 'http://video.google.com/googleplayer.swf?docId=$1' + ), + 'sevenload' => array( + 'url' => 'http://page.sevenload.com/swf/en_GB/player.swf?id=$1' + ), + 'revver' => array( + 'url' => 'http://flash.revver.com/player/1.0/player.swf?mediaId=$1' + ), + 'youtube' => array( + 'url'=>'http://www.youtube.com/v/$1' + ) +); + +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..418109f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +Copyright (c) 2007-2010 EmbedVideo contributors. See CREDITS for complete +list of contributors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/TeacherTube.html b/TeacherTube.html new file mode 100644 index 0000000..0604158 --- /dev/null +++ b/TeacherTube.html @@ -0,0 +1,14 @@ +