Difference between revisions of "Extension:VideoSectionLink"
(script now returns correct movie as binary stream :)) |
(ffmpeg not accepting urls as input) |
||
Line 51: | Line 51: | ||
global $egVideoSectionLinkMagic,$wgScript; | global $egVideoSectionLinkMagic,$wgScript; | ||
− | |||
− | |||
+ | $text = "[{{SERVER}}" . $wgScript . "?action=videosection&url=" . urlencode($url) . "&start=" . $start . "&duration=" .$duration . " Click to download video]"; | ||
+ | print_r($text); | ||
# Return result with available parser flags | # Return result with available parser flags | ||
return array( | return array( | ||
Line 72: | Line 72: | ||
global $wgOut,$action,$article,$wgRequest; | global $wgOut,$action,$article,$wgRequest; | ||
− | + | ||
$param1 = $wgRequest->getText('url'); | $param1 = $wgRequest->getText('url'); | ||
− | $ | + | $param2 = $wgRequest->getText('start'); |
− | $ | + | $param3 = $wgRequest->getText('duration'); |
− | + | $var = "ffmpeg -i " . $param1 . " winterfest09.mpg"; | |
− | + | print_r($var); | |
− | + | $success = shell_exec($var); | |
− | + | ||
− | |||
$wgOut->disable(); | $wgOut->disable(); | ||
header("Content-Type: video/mpeg"); | header("Content-Type: video/mpeg"); | ||
− | header("Content-Disposition: attachment; filename=\" | + | header("Content-Disposition: attachment; filename=\"winterfest09.mpg\""); |
#return the file as binary back to the client | #return the file as binary back to the client | ||
− | readfile(" | + | readfile("winterfest09.mpg"); |
return true; | return true; | ||
} | } |
Revision as of 02:34, 20 November 2008
<?php /**
Template:PhpCategory:Extensions created with Template:Extension
* VideoSectionLink extension - An extension to enable users to link to defined sections of video. Made with Template:Extension * * See http://www.mediawiki.org/wiki/Extension:VideoSectionLink for installation and usage details * * @package MediaWiki * @subpackage Extensions * @author User:Jack * @copyright © 2008 User:Jack * @licence GNU General Public Licence 2.0 or later */
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('VIDEOSECTIONLINK_VERSION', '0.0.1, 2008-10-31');
$egVideoSectionLinkMagic = 'videosection'; $wgExtensionFunctions[] = 'efSetupVideoSectionLink'; $wgHooks['LanguageGetMagic'][] = 'efVideoSectionLinkLanguageGetMagic';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'VideoSectionLink',
'author' => 'User:Jack',
'description' => 'An extension to enable users to link to defined sections of video. Made with Template:Extension',
'url' => 'http://www.organicdesign.co.nz/Extension:VideoSectionLink',
'version' => VIDEOSECTIONLINK_VERSION
);
class VideoSectionLink {
/** * Constructor */ function __construct() { global $wgHooks, $wgParser, $egVideoSectionLinkMagic;
# Add the parser-function $wgParser->setFunctionHook($egVideoSectionLinkMagic, array($this,'magicVideosectionlink'));
#Add the Unknownaction hook
$wgHooks['UnknownAction'][] = $this;
}
/** * Expand the videosection-magic */ function magicVideosectionlink(&$parser, $url = , $start = ,$duration = ) {
global $egVideoSectionLinkMagic,$wgScript;
$text = "" . $wgScript . "?action=videosection&url=" . urlencode($url) . "&start=" . $start . "&duration=" .$duration . " Click to download video"; print_r($text);
# Return result with available parser flags return array( $text, 'found' => true, 'nowiki' => false, 'noparse' => false, 'noargs' => false, 'isHTML' => false );
}
/** * Callback method executes a shell command returning the section of the movie requested */ function onUnknownAction($action, $article) {
global $wgOut,$action,$article,$wgRequest;
$param1 = $wgRequest->getText('url'); $param2 = $wgRequest->getText('start');
$param3 = $wgRequest->getText('duration'); $var = "ffmpeg -i " . $param1 . " winterfest09.mpg"; print_r($var); $success = shell_exec($var);
$wgOut->disable(); header("Content-Type: video/mpeg"); header("Content-Disposition: attachment; filename=\"winterfest09.mpg\"");
#return the file as binary back to the client
readfile("winterfest09.mpg"); return true; }
/** * Needed in some versions to prevent Special:Version from breaking */ function __toString() { return __CLASS__; }
}
/**
* Called from $wgExtensionFunctions array when initialising extensions */
function efSetupVideoSectionLink() { global $egVideoSectionLink; $egVideoSectionLink = new VideoSectionLink();
}
/**
* Needed in MediaWiki >1.8.0 for magic word hooks to work properly */
function efVideoSectionLinkLanguageGetMagic(&$magicWords, $langCode = 0) { global $egVideoSectionLinkMagic; $magicWords[$egVideoSectionLinkMagic] = array($langCode, $egVideoSectionLinkMagic); return true; }