Difference between revisions of "Extension:VideoSectionLink"

From Organic Design wiki
(commented out regexes, function is being called)
(parameters to parser function return properly)
Line 15: Line 15:
 
define('VIDEOSECTIONLINK_VERSION', '0.0.1, 2008-10-31');
 
define('VIDEOSECTIONLINK_VERSION', '0.0.1, 2008-10-31');
 
   
 
   
$egVideoSectionLinkMagic            = "videosectionlink";
+
$egVideoSectionLinkMagic            = "videosection";
 
$wgExtensionFunctions[]        = 'efSetupVideoSectionLink';
 
$wgExtensionFunctions[]        = 'efSetupVideoSectionLink';
 
$wgHooks['LanguageGetMagic'][] = 'efVideoSectionLinkLanguageGetMagic';
 
$wgHooks['LanguageGetMagic'][] = 'efVideoSectionLinkLanguageGetMagic';
Line 34: Line 34:
 
function __construct() {
 
function __construct() {
 
global $wgHooks, $wgParser, $egVideoSectionLinkMagic;
 
global $wgHooks, $wgParser, $egVideoSectionLinkMagic;
+
 
# Add the parser-function
 
# Add the parser-function
 
$wgParser->setFunctionHook($egVideoSectionLinkMagic, array($this, 'magicVideosectionlink'));
 
$wgParser->setFunctionHook($egVideoSectionLinkMagic, array($this, 'magicVideosectionlink'));
+
 
 
}
 
}
 
   
 
   
 
/**
 
/**
* Expand the videosectionlink-magic
+
* Expand the videosection-magic
 
*/
 
*/
function magicVideosectionlink(&$parser) {
+
function magicVideosectionlink(&$parser, $param1 = '', $param2 = '',$param3 = '') {
  
/* global $egVideoSectionLinkMagic;
+
global $egVideoSectionLinkMagic;
# Populate $argv with both named and numeric parameters
+
  /* # Populate $argv with both named and numeric parameters
 
$argv = array();
 
$argv = array();
 
foreach (func_get_args() as $arg) if (!is_object($arg)) {
 
foreach (func_get_args() as $arg) if (!is_object($arg)) {
Line 56: Line 56:
 
foreach ($argv as $k => $v) $args .= "*'''$k:''' ''$v''\n";
 
foreach ($argv as $k => $v) $args .= "*'''$k:''' ''$v''\n";
 
        $args =  htmlspecialchars($args);
 
        $args =  htmlspecialchars($args);
$text = "=== Magic $egVideoSectionLinkMagic(): ===\n$args";
+
$text = "=== Magic $egVideoSectionLinkMagic(): ===\n";
 
   
 
   
 
# Return result with available parser flags
 
# Return result with available parser flags
Line 66: Line 66:
 
'noargs'  => false,
 
'noargs'  => false,
 
'isHTML'  => false
 
'isHTML'  => false
);
+
);*/
*/
+
        $output = "param1 is $param1 and param2 is $param2 and param3 is $param2";
        $output = "brush";
+
        return $output;
        print_r($output);
+
        return $output;
 
 
 
 
 
 
 
 
 
 
}
 
}
 
   
 
   
Line 92: Line 86:
 
print_r("VSL instance: ");
 
print_r("VSL instance: ");
 
print_r($egVideoSectionLink);
 
print_r($egVideoSectionLink);
+
 
}
 
}
 
   
 
   

Revision as of 20:58, 9 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'));

}

/** * Expand the videosection-magic */ function magicVideosectionlink(&$parser, $param1 = , $param2 = ,$param3 = ) {

global $egVideoSectionLinkMagic; /* # Populate $argv with both named and numeric parameters $argv = array(); foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg; }

# Build text of expanded result $args = ; foreach ($argv as $k => $v) $args .= "*$k: $v\n"; $args = htmlspecialchars($args); $text = "=== Magic $egVideoSectionLinkMagic(): ===\n";

# Return result with available parser flags return array( $text, 'found' => true, 'nowiki' => false, 'noparse' => false, 'noargs' => false, 'isHTML' => false );*/ $output = "param1 is $param1 and param2 is $param2 and param3 is $param2"; return $output;

}

/** * 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(); print_r("VSL instance: "); print_r($egVideoSectionLink);

}

/**

* 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); print_r("LGM: "); print_r($magicWords[$egVideoSectionLinkMagic]); return true; }