Difference between revisions of "Extension:VideoSectionLink"

From Organic Design wiki
(template generated extension)
 
(rationalised tag, magic names)
Line 8: Line 8:
 
  * @subpackage Extensions
 
  * @subpackage Extensions
 
  * @author [http://www.mediawiki.org/wiki/User:Jack User:Jack]
 
  * @author [http://www.mediawiki.org/wiki/User:Jack User:Jack]
  * @copyright © 2007 [http://www.mediawiki.org/wiki/User:Jack User:Jack]
+
  * @copyright © 2008 [http://www.mediawiki.org/wiki/User:Jack User:Jack]
 
  * @licence GNU General Public Licence 2.0 or later
 
  * @licence GNU General Public Licence 2.0 or later
 
  */
 
  */
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
   
 
   
define('VIDEOSECTIONLINK_VERSION', '1.0.0, 2008-10-31');
+
define('VIDEOSECTIONLINK_VERSION', '0.0.1, 2008-10-31');
 
   
 
   
$egVideoSectionLinkMagic            = "MagicVideoSectionLink";
+
$egVideoSectionLinkMagic            = "videosectionlink";
$egVideoSectionLinkTag              = "TagVideoSectionLink";
+
$egVideoSectionLinkTag              = "videosectionlink";
 
$wgExtensionFunctions[]        = 'efSetupVideoSectionLink';
 
$wgExtensionFunctions[]        = 'efSetupVideoSectionLink';
 
$wgHooks['LanguageGetMagic'][] = 'efVideoSectionLinkLanguageGetMagic';
 
$wgHooks['LanguageGetMagic'][] = 'efVideoSectionLinkLanguageGetMagic';
Line 43: Line 43:
 
   
 
   
 
# Add the parser-function
 
# Add the parser-function
$wgParser->setFunctionHook($egVideoSectionLinkMagic, array($this, 'magicMagicVideoSectionLink'));
+
$wgParser->setFunctionHook($egVideoSectionLinkMagic, array($this, 'magicVideosectionlink'));
 
   
 
   
 
# Add the tagHook
 
# Add the tagHook
$wgParser->setHook($egVideoSectionLinkTag, array($this, 'tagTagVideoSectionLink'));
+
$wgParser->setHook($egVideoSectionLinkTag, array($this, 'tagVideosectionlink'));
 
   
 
   
 
}
 
}
 
   
 
   
 
/**
 
/**
* Expand the MagicVideoSectionLink-magic
+
* Expand the videosectionlink-magic
 
*/
 
*/
function magicMagicVideoSectionLink(&$parser) {
+
function magicVideosectionlink(&$parser) {
 
global $egVideoSectionLinkMagic;
 
global $egVideoSectionLinkMagic;
 
# Populate $argv with both named and numeric parameters
 
# Populate $argv with both named and numeric parameters
Line 80: Line 80:
 
   
 
   
 
/**
 
/**
* Convert the <TagVideoSectionLink> tags to HTML
+
* Convert the <videosectionlink> tags to HTML
 
*/
 
*/
function tagTagVideoSectionLink($text,$argv,&$parser) {
+
function tagVideosectionlink($text,$argv,&$parser) {
 
global $egVideoSectionLinkTag;
 
global $egVideoSectionLinkTag;
 
$args = '';
 
$args = '';

Revision as of 08:34, 31 October 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 = "videosectionlink"; $egVideoSectionLinkTag = "videosectionlink"; $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 {

/** * Properties */ var $prop1 = 'default value'; var $prop2 = 'default value';

/** * Constructor */ function __construct() { global $wgHooks, $wgParser, $egVideoSectionLinkMagic, $egVideoSectionLinkTag;

# Add the parser-function $wgParser->setFunctionHook($egVideoSectionLinkMagic, array($this, 'magicVideosectionlink'));

# Add the tagHook $wgParser->setHook($egVideoSectionLinkTag, array($this, 'tagVideosectionlink'));

}

/** * Expand the videosectionlink-magic */ function magicVideosectionlink(&$parser) { 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$args";

# Return result with available parser flags return array( $text, 'found' => true, 'nowiki' => false, 'noparse' => false, 'noargs' => false, 'isHTML' => false );

}

/** * Convert the <videosectionlink> tags to HTML */ function tagVideosectionlink($text,$argv,&$parser) { global $egVideoSectionLinkTag; $args = ; foreach ($argv as $k => $v) { $k = htmlspecialchars($k); $v = htmlspecialchars($v);

$args .= "

  • $k: $v
  • \n";

    } $text = htmlspecialchars($text);

    return "

    Tag $egVideoSectionLinkTag():

    \n

      $args
    • Content:$text

    \n";

    }

    /** * 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; }