Server Time Offset Workaround


On install, there is no option to select the wiki timezone. The wiki may be used in a timezone predominantly used by people in a completely different timezone, as in my case, which is why I went looking for a workaround.
Ticket number #422 suggests that there should be an installation option to make a global offset from the hosting server time to local time of the Wiki Admin's preference. In the meantime, pending an official closing of this ticket, the following workaround can be made. Preferably in the long run ticket #252 will address this issue in a more complete manner, with individually user configurable options including server time offset.

Symptoms

Hosting server time is stamped on all pages, which may be totally different from the bulk of users' timezone.

Cause

No option to specify server timezone offset in config file at install

Applies to

WikkaWiki 1.1.6.2 and previous

Solution

Workaround this problem by making a few hack edits to a couple of pages:

First, in Wikka/actions/recentchanges.php file the following edits are made:

//edit line 17 to remove Time Zone from format that's stamped on the recent changes page
if(!defined('REVISION_TIME_FORMAT')) define('REVISION_TIME_FORMAT', 'H:i');


//edit line 69 to stamp recent changes with label of choosing - in this case "Forum Time"
$timeformatted = date(REVISION_TIME_FORMAT, strtotime($page["time"])) . ' Forum Time';




Then in the Wikka/libs/Wakka.class.php file is edited as follows:

Insert the format and offset constant definitions at the start of the file, just before the class Wakka statement:
(The offset of 18000 is the only thing which should need to be changed in the event of a server move to another timezone.)

//define format for MySQL compatible date and time format to use in SQL insert queries
if(!defined('PAGE_DATE_FORMAT')) define('PAGE_DATE_FORMAT', 'YmdHis');
//set a constant offset in seconds (5 * 60 * 60 = 18000 seconds = 5 hours AHEAD of server time)
if(!defined('FORUMOFFSET')) define('FORUMOFFSET', 18000);



Edit the SavePage() function (which begins at line 401 in the original file) as follows:
(you only have to edit one line and add two others (plus the comments if you want) but the complete function is copied here.)

    function SavePage($tag, $body, $note)
    {
        // get current user
        $user = $this->GetUserName();

        // TODO: check write privilege
        if ($this->HasAccess("write", $tag))
        {
            // is page new?
            if (!$oldPage = $this->LoadPage($tag))
            {
                // current user is owner if user is logged in, otherwise, no owner.
                if ($this->GetUser()) $owner = $user;
            }
            else
            {
                // aha! page isn't new. keep owner!
                $owner = $oldPage["owner"];
            }

            // set all other revisions to old
            $this->Query("update ".$this->config["table_prefix"]."pages set latest = 'N' where tag = '".mysql_real_escape_string($tag)."'");

            // add new revision
            //[SparkOut edit] following two lines added to make offset from server time
            $dtmForumTime = time() + FORUMOFFSET;
            $dtmFormattedForumTime = date(PAGE_DATE_FORMAT,$dtmForumTime);
            $this->Query("insert into ".$this->config["table_prefix"]."pages set ".
                "tag = '".mysql_real_escape_string($tag)."', ".
                //[SparkOut edit] following line (originally line 427 in original file) edited to change SQL query to insert offset time instead of server time
                "time = " . $dtmFormattedForumTime . ", ".
                "owner = '".mysql_real_escape_string($owner)."', ".
                "user = '".mysql_real_escape_string($user)."', ".
                "note = '".mysql_real_escape_string($note)."', ".
                "latest = 'Y', ".
                "body = '".mysql_real_escape_string($body)."'");

            if ($pingdata = $this->GetPingParams($this->config["wikiping_server"], $tag, $user, $note))
                $this->WikiPing($pingdata);
        }
    }



Edit the SaveComment() function (which begins at line 826 in the original file) as follows:
(you only have to edit one line and add two others (plus the comments if you want) but the complete function is copied here.)

    function SaveComment($page_tag, $comment)
    {
        // get current user
        $user = $this->GetUserName();

        // add new comment
        //[SparkOut edit] following two lines added to make offset from server time
        $dtmForumTime = time() + FORUMOFFSET;
        $dtmFormattedForumTime = date(PAGE_DATE_FORMAT,$dtmForumTime);
        $this->Query("INSERT INTO ".$this->config["table_prefix"]."comments SET ".
            "page_tag = '".mysql_real_escape_string($page_tag)."', ".
            //[SparkOut edit] following line (originally line 834 in original file) edited to change SQL query to insert offset time instead of server time
            "time = " . $dtmFormattedForumTime . ", ".
            "comment = '".mysql_real_escape_string($comment)."', ".
            "user = '".mysql_real_escape_string($user)."'");
    }


Refinement

Someone please feel free to improve this hack.


CategoryWorkaround
CategoryUserContributions
There is one comment on this page. [Display comment]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki