Extension:Schedule

From Organic Design wiki

<?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; }