Difference between revisions of "Extension:VideoSectionLink"

From Organic Design wiki
(Simple version, hardwired output file, works)
(strip trailing spaces)
Line 13: Line 13:
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
  
+
 
  
 
define('VIDEOSECTIONLINK_VERSION', '0.0.1, 2008-10-31');
 
define('VIDEOSECTIONLINK_VERSION', '0.0.1, 2008-10-31');
  
+
 
  
 
$egVideoSectionLinkMagic            = 'videosection';
 
$egVideoSectionLinkMagic            = 'videosection';
Line 25: Line 25:
 
$wgHooks['LanguageGetMagic'][] = 'efVideoSectionLinkLanguageGetMagic';
 
$wgHooks['LanguageGetMagic'][] = 'efVideoSectionLinkLanguageGetMagic';
  
 
  
+
 
 +
 
  
 
$wgExtensionCredits['parserhook'][] = array(
 
$wgExtensionCredits['parserhook'][] = array(
Line 43: Line 43:
 
);
 
);
  
+
 
  
 
class VideoSectionLink {
 
class VideoSectionLink {
  
+
 
  
 
/**
 
/**
Line 59: Line 59:
 
global $wgHooks, $wgParser, $egVideoSectionLinkMagic;
 
global $wgHooks, $wgParser, $egVideoSectionLinkMagic;
  
+
 
  
 
# Add the parser-function
 
# Add the parser-function
Line 65: Line 65:
 
$wgParser->setFunctionHook($egVideoSectionLinkMagic, array($this,'magicVideosectionlink'));
 
$wgParser->setFunctionHook($egVideoSectionLinkMagic, array($this,'magicVideosectionlink'));
  
 
  
+
 
 +
 
  
 
#Add the Unknownaction hook
 
#Add the Unknownaction hook
Line 73: Line 73:
 
$wgHooks['UnknownAction'][] = $this;
 
$wgHooks['UnknownAction'][] = $this;
  
+
 
  
 
}
 
}
  
+
 
  
 
/**
 
/**
Line 87: Line 87:
 
function magicVideosectionlink(&$parser, $url = '', $start = '',$duration = '') {
 
function magicVideosectionlink(&$parser, $url = '', $start = '',$duration = '') {
  
+
 
  
 
global $egVideoSectionLinkMagic,$wgScript;
 
global $egVideoSectionLinkMagic,$wgScript;
Line 115: Line 115:
 
);
 
);
  
+
 
  
 
}
 
}
  
+
 
  
 
/**
 
/**
Line 129: Line 129:
 
function onUnknownAction($action, $article) {
 
function onUnknownAction($action, $article) {
  
+
 
  
 
global $wgOut,$action,$article,$wgRequest,$wgUploadDirectory;
 
global $wgOut,$action,$article,$wgRequest,$wgUploadDirectory;
  
+
 
  
 
#Get the parameters from the title
 
#Get the parameters from the title
  
+
 
  
 
$param1 = $wgRequest->getText('url');
 
$param1 = $wgRequest->getText('url');
Line 145: Line 145:
 
  $param3 = $wgRequest->getText('duration');
 
  $param3 = $wgRequest->getText('duration');
  
+
 
  
 
  #Execute the ffmpeg command
 
  #Execute the ffmpeg command
  
+
 
  
 
  $movieStr = "ffmpeg -i " . $param1 . " -ss " . $param2 . " -t " . $param3 . " -ar 22050 " . $wgUploadDirectory . "/winterfest03.mpg";
 
  $movieStr = "ffmpeg -i " . $param1 . " -ss " . $param2 . " -t " . $param3 . " -ar 22050 " . $wgUploadDirectory . "/winterfest03.mpg";
Line 155: Line 155:
 
  $success = shell_exec($movieStr);
 
  $success = shell_exec($movieStr);
  
+
 
  
 
  #Set headers as video
 
  #Set headers as video
  
+
 
  
 
$wgOut->disable();
 
$wgOut->disable();
Line 169: Line 169:
 
header($wgHfile);
 
header($wgHfile);
  
+
 
  
 
#Return the file as binary back to the client
 
#Return the file as binary back to the client
  
+
 
  
 
readfile($wgUploadDirectory . "/winterfest03.mpg");
 
readfile($wgUploadDirectory . "/winterfest03.mpg");
Line 181: Line 181:
 
}
 
}
  
+
 
  
 
/**
 
/**
Line 193: Line 193:
 
  }
 
  }
  
+
 
  
 
/**
 
/**
Line 207: Line 207:
 
$egVideoSectionLink = new VideoSectionLink();
 
$egVideoSectionLink = new VideoSectionLink();
  
+
 
  
 
}
 
}
  
+
 
  
 
/**
 
/**
Line 219: Line 219:
 
  */
 
  */
  
+
 
  
 
function efVideoSectionLinkLanguageGetMagic(&$magicWords, $langCode = 0) {
 
function efVideoSectionLinkLanguageGetMagic(&$magicWords, $langCode = 0) {

Revision as of 02:50, 22 November 2008

<?php /**

Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

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,$wgUploadDirectory;


#Get the parameters from the title


$param1 = $wgRequest->getText('url');

$param2 = $wgRequest->getText('start');

		$param3 = $wgRequest->getText('duration');


		#Execute the ffmpeg command


		$movieStr = "ffmpeg -i " . $param1 . " -ss " . $param2 . " -t " . $param3 . " -ar 22050 " . $wgUploadDirectory . "/winterfest03.mpg";
		$success = shell_exec($movieStr);


		#Set headers as video


$wgOut->disable();

header("Content-Type: video/mpeg");

$wgHfile = "Content-Disposition: attachment; filename=\"". $wgUploadDirectory . "/winterfest03.mpg\"";

header($wgHfile);


#Return the file as binary back to the client


readfile($wgUploadDirectory . "/winterfest03.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;

}