Extension:Schedule
<?php /**
- Schedule extension - Allows text in articles to change according to a schedule
Template:PhpCategory:Extensions created with Template:Extension
- See http://www.mediawiki.org/wiki/Extension:Schedule for installation and usage details
- @package MediaWiki
- @subpackage Extensions
- @author User:Nad
- @copyright © 2007 User:Nad
- @licence GNU General Public Licence 2.0 or later
- /
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('SCHEDULE_VERSION','1.0.0, 2008-06-01');
$egScheduleMagic = "schedule"; $egScheduleTag = "bar"; $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 );
}
/** * 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 .= "
\n";
} $text = htmlspecialchars($text);
return "
Tag $egScheduleTag():
\n
- $args
- Content:$text
\n";
}
/** * 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(0,$egScheduleMagic); return true; }