Intro

This patch allows the regular wiki user to easily sign his name and optionally add a time stamp. It is most useful on discussion wiki pages.

This was done for 'Tavi 0.25. It may or may not work with older or newer versions.

--HermannSchwarting

Syntax

Enter three tildes ~~~ into the edit box and they will be replaced by the username set up in the [Preferences]. Use four of them for your name and an appended timestamp (of the server's time). If your username is a WikiWord, it will become a link anyway. Else double parantheses will be added to mark it as free link.

Examples:

~~~
UserName
~~~
(unwiki name)?
~~~~
UserName 28. Mar 2004 01:15 (CET)

Installation

Affected Files

parse/save.php

Insert this new function before the closing ?>. If needed adapt the date format by modifying the string passed to the date() function (documented [here]).


// Parse and insert automatic signatures
function parse_automatic_signature($text)
{
  global $UserName, $EnableFreeLinks, $LinkPtn;

  if(preg_match('/~~~/', $text) && $UserName != '')
  {
    if($EnableFreeLinks && !preg_match("/$LinkPtn/", $UserName))
    {
      $replacement = "(($UserName))";
    } else {
      $replacement = $UserName;
    }
    $date = date("d. M Y H:i (T)");
    $text = preg_replace('/~~~~/', "$replacement $date", $text);
    $text = preg_replace('/~~~/', $replacement, $text);
  }
  return $text;
}

lib/defaults.php

Insert a new entry 'parse_automatic_signature' into the array $SaveMacroEngine at the bottom of the file.

action/save.php

In the original parsing for save macros is done after saving the page to the database. That is too late to change the text, so the lines


  // Process save macros (e.g., to define interwiki entries).
  parseText($document, $SaveMacroEngine, $page);

from the bottom have to be move further to the top between the lines with str_replace and the one starting with $pg->text (line 52) to read


  // Process save macros (e.g., to define interwiki entries).
  $esc_doc = parseText($esc_doc, $SaveMacroEngine, $page);

tavi-signature.patch

Alternatively to editing the three files by hand save the following to some file and patch your tavi installation with

$ cd /path/to/tavi
$ patch -p1 < /path/to/patchfile

If no error message appears it worked.


diff -Naur tavi.old/action/save.php tavi.new/action/save.php
--- tavi.old/action/save.php 2004-03-25 22:38:45.000000000 +0100
+++ tavi.new/action/save.php 2004-03-28 00:30:37.000000000 +0100
@@ -49,6 +49,9 @@
   $comment = str_replace("\\", "\\\\", $comment);
   $comment = str_replace("'", "\\'", $comment);
 
+  // Process save macros (e.g., to define interwiki entries).
+  $esc_doc = parseText($esc_doc, $SaveMacroEngine, $page);
+
   $pg->text = $esc_doc;
   $pg->hostname = gethostbyaddr($REMOTE_ADDR);
   $pg->username = $UserName;
@@ -68,9 +71,6 @@
   template_save(array('page' => $page,
                       'text' => $document));
 
-  // Process save macros (e.g., to define interwiki entries).
-  parseText($document, $SaveMacroEngine, $page);
-
   $pagestore->unlock();                 // End "transaction".
 
 }
diff -Naur tavi.old/lib/defaults.php tavi.new/lib/defaults.php
--- tavi.old/lib/defaults.php 2004-03-25 22:38:45.000000000 +0100
+++ tavi.new/lib/defaults.php 2004-03-28 00:31:10.000000000 +0100
@@ -291,5 +291,6 @@
 $SaveMacroEngine = array(
                      'parse_define_interwiki',
                      'parse_define_sisterwiki',
-                     'parse_define_links'
+                     'parse_define_links',
+                     'parse_automatic_signature'
                    );
diff -Naur tavi.old/parse/save.php tavi.new/parse/save.php
--- tavi.old/parse/save.php 2004-03-25 22:38:45.000000000 +0100
+++ tavi.new/parse/save.php 2004-03-28 00:36:22.000000000 +0100
@@ -95,4 +95,24 @@
 
   return $text;
 }
+
+// Parse and insert automatic signatures
+function parse_automatic_signature($text)
+{
+  global $UserName, $EnableFreeLinks, $LinkPtn;
+
+  if(preg_match('/~~~/', $text) && $UserName != '')
+  {
+    if($EnableFreeLinks && !preg_match("/$LinkPtn/", $UserName))
+    {
+      $replacement = "(($UserName))";
+    } else {
+      $replacement = $UserName;
+    }
+    $date = date("d. M Y H:i (T)");
+    $text = preg_replace('/~~~~/', "$replacement $date", $text);
+    $text = preg_replace('/~~~/', $replacement, $text);
+  }
+  return $text;
+}
 ?>

Comments