MW:ZoneDateTime

From ChekMate Security Group

Contents

ZoneDateTime Mediawiki extension

Recently built this new MediaWiki Extension so that the users of our irc.chekmate.org network would be able to know the time for a specific server.

This extension is super simple. It just determines the time differnce from GMT and then displays it.

Modify as you see fit.

Note: Most up to date version of this extension can be found at: http://www.chekmate.org/wiki/index.php/Projects

Change History

  • 10:30, 2 September 2006 (MDT) - ZoneDateTime.php published (Smcnaught)

Maintainer

Shannon McNaught (smcnaught)

Homepage

ChekMate Technical Focus Group

License

ZoneDateTime.php 
  - Displays Location and Current Timestamp

Copyright (C) 2006  Shannon McNaught

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 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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Installation

  • Put this file (ZoneDateTime.php) into the extension directory of your mediawiki installation
  • Add the following to the end of LocalSettings.php: include("extensions/ZoneDateTime.php");

Examples

<ZoneDateTime>
London:0:0
Calgary:1:-7
</ZoneDateTime>
<ZoneDateTime>Location:DaylightSaving:ZoneDifference</ZoneDateTime>

Source Code

<?php
# ZoneDateTime Mediawiki extension
#
# original by smcnaught 01.09.2006
# Installation:
#  * put this file (ZoneDateTime.php) into the extension directory of your mediawiki installation
#  * add the following to the end of LocalSettings.php: include("extensions/ZoneDateTime.php");
#
# Examples:
#    <ZoneDateTime>
#     London:0:0
#     Calgary:1:-7
#    </ZoneDateTime>
#
#    <ZoneDateTime>Location:DaylightSaving:ZoneDifference</ZoneDateTime> 
#

#install extension hook
$wgExtensionFunctions[] = "wfZoneDateTimeExtension";

#extension hook callback function
function wfZoneDateTimeExtension() {
  global $wgParser;
  $wgParser->setHook( "ZoneDateTime", "renderZoneDateTime" );
}

#parser hook callback function
function renderZoneDateTime( $input, $argv, &$parser ) {
  global $wgVersion, $wgTitle, $wgDBprefix, $wgOut, $wgUser, $wgRequest;

  // ###### DEFINE VARIABLES TO Nagios Server ######

  // ###### INVALIDATE CACHE ######

  $ts = mktime();
  $now = gmdate("YmdHis", $ts + 120);
  $ns = $wgTitle->getNamespace();
  $ti = wfStrencode($wgTitle->getDBkey());
  $version = preg_replace("/^([1-9]).([1-9]).*/", "\\1\\2", $wgVersion);
  if ($version>14) $sql = "UPDATE $wgDBprefix"."page SET page_touched='$now' WHERE page_namespace=$ns AND page_title='$ti'";
  else             $sql = "UPDATE $wgDBprefix"."cur SET cur_touched='$now' WHERE cur_namespace=$ns AND cur_title='$ti'";
  wfQuery($sql, DB_WRITE, "");
  $Output = "";
  $aParams = explode("\n", $input);
  foreach($aParams as $location) {
    if ($location != "") {
      list($Location, $DaylightSaving, $ZoneDifference) = explode(",", $location);
      $LocationDate = zonedate('Y-m-d H:i:s',$ZoneDifference,$DayLightSavings);
      $output = $output . "$Location ($LocationDate)\n";
    }
  }
  return $output;
}


function zonedate($layout, $countryzone, $daylightsaving)
{
  if ($daylightsaving){
    $daylight_saving = date('I');
    if ($daylight_saving){$zone=3600*($countryzone+1);}
  }
  else {
    if ($countryzone>>0){$zone=3600*$countryzone;}
    else {$zone=0;}
  }
  $date=gmdate($layout, time() + $zone);
  return $date;
}