Tilde~A: Alexios' Homepage


Table of Contents


The famous MediaWiki project (of Wikipedia fame) is a very flexible tool, and like all good tools, people find uses for it the original designers didn't intend. Many people use Wikis as their personal pages, or as a quick, cheap substitute for a CMS. At my work, I maintain a knowledge base using it. Often, people refer to the pages for outstanding work and announcements. Often, I find it necessary to show notifications about planned work or systems status during a specific period of time only. In CMS terms, this is known as an embargo. This extension adds an embargo feature to Mediawiki. It provides an <embargo> tag that shows its contents:

  • After a certain date (and, optionally, time), and
  • Before another date (and, optionally, time) has passed.

Either of these criteria may be skipped to display content only before a given date, or forever after a given date.


Remember that ‘embargo’ denotes hiding, not showing. In this context, ‘embargo after’ means ‘don't show after’, and ‘embargo before’ means ‘don't show before’.

<embargo before="2009-04-01" after="2009-04-02">
Insert Diabolical April Fools Prank Here.

To display a seasonal message:

<embargo before="2009-12-01" after="2009-12-31">
'Tis the season, etc.

To let people know about an upcoming event until the day of the event:

<embargo after="2009-07-31">
Yearly systems maintenance coming up! Check your email for details!

Displaying a new message after the event:

<embargo before="2009-08-01">
Yearly systems maintenance complete!

The date format in attributes before and after follows the rather flexible format of PHP's strtotime function. In addition to dates, you may specify times using the ISO-like YYYY-MM-DD HH:MM format. You may enter US dates in MM-DD-YYYY, but consult the PHP documentation for other options. Don't use relative dates (next Thursday or now + 2 months): these are interpreted with respect to the time the page is shown, not the time it was last edited!

You can use any wikitext whatsoever inside the <embargo>...</embargo> tags.


Paste the source code into extensions/Embargo/Embargo.php under your MediaWiki installation. Then, load up your LocalSettings.php file and append these two lines:

// Embargo

Source Code

// Embargo MediaWiki Extension.
// Embargoes content outside of certain time/date ranges.

// Copyright (C) 2007, Alexios Chouchoulas.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

$EmbargoVersion = '0.1';

// Credits
$wgExtensionCredits ['parserhook'][] =
        'name' => 'Embargo',
        'version' => $EmbargoVersion,
        'author' => 'Alexios Chouchoulas',
        'url' => '',
        'description' => 'Allows embargo of content outside
                          of certain time/date ranges.'

// Extension initialization
$wgExtensionFunctions[] = "fnEmbargoExtension";

// Registers the extension with the WikiText parser.
function fnEmbargoExtension()
    // Register messages
    global $wgMessageCache, $wgPropertyTableMessages;
    foreach ($wgPropertyTableMessages as $sLang => $aMsgs) {
        $wgMessageCache->addMessages ($aMsgs, $sLang);
    // Register the extension with the WikiText parser
    global $wgParser;
    $wgParser->setHook ('embargo', 'fnEmbargoTag');

// Parse a date/time specification.
function fnEmbargoParseDate ($d)
    return strtotime ($d);

// Processes the 'embargo' tag.
function fnEmbargoTag($input, $params, &$parser)
    $t = time();
    $t0 = $t - 1;
    $t1 = $t + 1;
    $retval = '';
    if (isset ($params ['before'])) {
        $before = $params ['before'];
        if ($before === FALSE) {
            $retval .= "<strong>BEFORE attribute could not be parsed. </strong>";
        } else {
            $t0 = fnEmbargoParseDate ($before);
    if (isset ($params ['after'])) {
        $after = $params ['after'];
        if ($before === FALSE) {
            $retval .= "<strong>AFTER attribute could not be parsed. </strong>";
        } else {
            $t1 = fnEmbargoParseDate ($after);
    if (($t0 <= $t) && ($t < $t1)) {
        $retval .= $input;
    return $parser->internalParse ($retval);

// End of file.