Difference between revisions of "Extension:Schedule"
(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 | + | $egScheduleMagic = "schedule"; |
− | |||
$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: | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
/** | /** | ||
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( | + | $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
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"; $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; }