Difference between revisions of "Extension:Schedule"

From Organic Design wiki
(New page: <?php /** * Schedule extension - Allow...)
 
 
Line 15: Line 15:
 
define('SCHEDULE_VERSION','1.0.0, 2008-06-01');
 
define('SCHEDULE_VERSION','1.0.0, 2008-06-01');
  
$egScheduleMagic             = "schedule";
+
$egScheduleMagic               = "schedule";
$egScheduleTag              = "bar";
 
 
$wgExtensionFunctions[]        = 'efSetupSchedule';
 
$wgExtensionFunctions[]        = 'efSetupSchedule';
 
$wgHooks['LanguageGetMagic'][] = 'efScheduleLanguageGetMagic';
 
$wgHooks['LanguageGetMagic'][] = 'efScheduleLanguageGetMagic';
Line 58: Line 57:
 
$argv = array();
 
$argv = array();
 
foreach (func_get_args() as $arg) if (!is_object($arg)) {
 
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;
+
if (preg_match('/^(.+?)\\s*=\\s*(.+)$/', $arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg;
 
}
 
}
  
Line 78: Line 77:
  
 
}
 
}
 
/**
 
* Convert the <bar> tags to HTML
 
*/
 
function tagBar($text,$argv,&$parser) {
 
global $egScheduleTag;
 
$args = '';
 
foreach ($argv as $k => $v) {
 
$k = htmlspecialchars($k);
 
$v = htmlspecialchars($v);
 
$args .= "<li><b>$k:</b> <i>$v</i></li>\n";
 
}
 
$text =  htmlspecialchars($text);
 
return "<h3>Tag $egScheduleTag():</h3>\n<ul>$args<li>Content:</b>$text</ul>\n";
 
}
 
  
 
/**
 
/**
Line 111: Line 95:
 
* Needed in MediaWiki >1.8.0 for magic word hooks to work properly
 
* Needed in MediaWiki >1.8.0 for magic word hooks to work properly
 
*/
 
*/
function efScheduleLanguageGetMagic(&$magicWords,$langCode = 0) {
+
function efScheduleLanguageGetMagic(&$magicWords, $langCode = 0) {
 
global $egScheduleMagic;
 
global $egScheduleMagic;
$magicWords[$egScheduleMagic] = array(0,$egScheduleMagic);
+
$magicWords[$egScheduleMagic] = array($langCode, $egScheduleMagic);
 
return true;
 
return true;
 
}
 
}

Latest revision as of 00:27, 4 June 2008

<?php /**

  • Schedule extension - Allows text in articles to change according to a schedule
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

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('SCHEDULE_VERSION','1.0.0, 2008-06-01');

$egScheduleMagic = "schedule"; $wgExtensionFunctions[] = 'efSetupSchedule'; $wgHooks['LanguageGetMagic'][] = 'efScheduleLanguageGetMagic';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'Schedule', 'author' => 'User:Nad', 'description' => 'Allows text in articles to change according to a schedule', 'url' => 'http://www.mediawiki.org/wiki/Extension:Schedule', 'version' => SCHEDULE_VERSION );

class Schedule {

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

/** * Constructor */ function __construct() { global $wgHooks,$wgParser, $egScheduleMagic, $egScheduleTag;

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

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

}

/** * Expand the schedule-magic */ function magicSchedule(&$parser) { global $egScheduleMagic; # 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 $egScheduleMagic(): ===\n$args";

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

}

/** * Needed in some versions to prevent Special:Version from breaking */ function __toString() { return 'Schedule'; } }

/**

  • Called from $wgExtensionFunctions array when initialising extensions
  • /

function efSetupSchedule() { global $egSchedule; $egSchedule = new Schedule(); }

/**

  • Needed in MediaWiki >1.8.0 for magic word hooks to work properly
  • /

function efScheduleLanguageGetMagic(&$magicWords, $langCode = 0) { global $egScheduleMagic; $magicWords[$egScheduleMagic] = array($langCode, $egScheduleMagic); return true; }