From db47bac35ec035388cfdab0a9fb27e97f8099742 Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Mon, 5 Nov 2001 22:59:11 +0000
Subject: [PATCH] - node.module:

   + Changed node_form() to use good ol' tables instead of div/CSS-tags.

   + Revised the "revision API": I think we have both an easy and powerful
     API now that should make everyone happy.

   + Improved the usability of the rollback functionality a bit.

   + Removed the "view node" link from the "node overview" page in the
     admin section and added a "delete node" link instead.

   + Added a few missing translations; there might be missing more
     translations though.

- book.module:

   + Made the book module use the "revision API" instead of having it poke
     and use the innards and underlying details of the revision system.

- queue.module:

   + Made the queue module use the improved revision number.

- module.inc:
   + Applied Moshe's patch: added more arguments to module_invoke()

- mail-to-sql.pl:
   + Added support for more header fields and for folded fields

Notes:

- no database updates required
---
 includes/database.inc    |  4 +--
 includes/module.inc      |  7 +++--
 modules/book.module      | 10 +++----
 modules/book/book.module | 10 +++----
 modules/node.module      | 65 +++++++++++++++++++++++++++++-----------
 modules/node/node.module | 65 +++++++++++++++++++++++++++++-----------
 modules/queue.module     | 14 ++-------
 scripts/mail-to-sql.pl   | 39 ++++++++++++++++--------
 8 files changed, 140 insertions(+), 74 deletions(-)

diff --git a/includes/database.inc b/includes/database.inc
index 4022fbc2ab78..be815390ed62 100644
--- a/includes/database.inc
+++ b/includes/database.inc
@@ -2,8 +2,8 @@
 
 $db_type = substr($db_url, 0, strpos($db_url, "://"));
 
-if (file_exists("includes/database.$db_type.inc")) {
-  include_once "includes/database.$db_type.inc";
+if ($db_type == "mysql") {
+  include_once "includes/database.mysql.inc";
 }
 else {
   include_once "includes/database.pear.inc";
diff --git a/includes/module.inc b/includes/module.inc
index 408b3d7183ef..be1f7fe9f711 100644
--- a/includes/module.inc
+++ b/includes/module.inc
@@ -12,10 +12,10 @@ function module_iterate($function, $argument = "") {
 }
 
 // invoke hook $hook of module $name with optional arguments:
-function module_invoke($name, $hook, $a1 = NULL, $a2 = NULL) {
+function module_invoke($name, $hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
   $function = $name ."_". $hook;
   if (function_exists($function)) {
-    return $function($a1, $a2);
+    return $function($a1, $a2, $a3, $a4);
   }
 }
 
@@ -36,6 +36,9 @@ function module_list() {
       closedir($handle);
       asort($list);
     }
+    else {
+      $list = array();
+    }
   }
 
   return $list;
diff --git a/modules/book.module b/modules/book.module
index 320f1f88f901..1298572512fb 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -142,7 +142,7 @@ function book_view($node, $main = 0) {
   */
 
   if ($node->moderate && $mod != "queue") {
-    $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+    $node = node_revision_load($node, end(node_revision_list($node)));
   }
 
   /*
@@ -233,7 +233,7 @@ function book_tree($parent = "", $depth = 0) {
 
       // take the most recent approved revision:
       if ($node->moderate) {
-        $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+        $node = node_revision_load($node, end(node_revision_list($node)));
       }
 
       // output the content:
@@ -260,7 +260,7 @@ function book_render() {
 
     // take the most recent approved revision:
     if ($node->moderate) {
-      $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+      $node = node_revision_load($node, end(node_revision_list($node)));
     }
 
     // output the content:
@@ -300,7 +300,7 @@ function book_export_html($id = "", $depth = 1) {
 
     // take the most recent approved revision:
     if ($node->moderate) {
-      $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+      $node = node_revision_load($node, end(node_revision_list($node)));
     }
 
     // output the content:
@@ -325,7 +325,7 @@ function book_export_html_recursive($parent = "", $depth = 1) {
 
     // take the most recent approved revision:
     if ($node->moderate) {
-      $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+      $node = node_revision_load($node, end(node_revision_list($node)));
     }
 
     // output the content:
diff --git a/modules/book/book.module b/modules/book/book.module
index 320f1f88f901..1298572512fb 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -142,7 +142,7 @@ function book_view($node, $main = 0) {
   */
 
   if ($node->moderate && $mod != "queue") {
-    $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+    $node = node_revision_load($node, end(node_revision_list($node)));
   }
 
   /*
@@ -233,7 +233,7 @@ function book_tree($parent = "", $depth = 0) {
 
       // take the most recent approved revision:
       if ($node->moderate) {
-        $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+        $node = node_revision_load($node, end(node_revision_list($node)));
       }
 
       // output the content:
@@ -260,7 +260,7 @@ function book_render() {
 
     // take the most recent approved revision:
     if ($node->moderate) {
-      $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+      $node = node_revision_load($node, end(node_revision_list($node)));
     }
 
     // output the content:
@@ -300,7 +300,7 @@ function book_export_html($id = "", $depth = 1) {
 
     // take the most recent approved revision:
     if ($node->moderate) {
-      $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+      $node = node_revision_load($node, end(node_revision_list($node)));
     }
 
     // output the content:
@@ -325,7 +325,7 @@ function book_export_html_recursive($parent = "", $depth = 1) {
 
     // take the most recent approved revision:
     if ($node->moderate) {
-      $node = $node->revisions[sizeof($node->revisions) - 1]["node"];
+      $node = node_revision_load($node, end(node_revision_list($node)));
     }
 
     // output the content:
diff --git a/modules/node.module b/modules/node.module
index 26d40dc085e8..2c1b6d3b1c1f 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -234,6 +234,18 @@ function node_admin_nodes() {
   return $output;
 }
 
+/*
+** Return the revision with the specified revision number.
+*/
+
+function node_revision_load($node, $revision) {
+  return $node->revisions[$revision]["node"];
+}
+
+/*
+** Create and return a new revision of the given node.
+*/
+
 function node_revision_create($node) {
   global $user;
 
@@ -252,14 +264,12 @@ function node_revision_create($node) {
   return $node;
 }
 
-function node_revision_rollback($nid, $revision) {
-  global $user;
+/*
+** Roll-back to the revision with the specified revision number.
+*/
 
-  /*
-  ** Load the original/current node:
-  */
-
-  $node = node_load(array("nid" => $nid));
+function node_revision_rollback($node, $revision) {
+  global $user;
 
   /*
   ** Extract the specified revision:
@@ -298,8 +308,11 @@ function node_revision_rollback($nid, $revision) {
   watchdog("special", "node: rollbacked to revision #$revision of '$node->title'");
 }
 
-function node_revision_delete($nid, $revision) {
-  $node = node_load(array("nid" => $nid));
+/*
+** Delete the revision with specified revision number.
+*/
+
+function node_revision_delete($node, $revision) {
 
   unset($node->revisions[$revision]);
 
@@ -308,8 +321,17 @@ function node_revision_delete($nid, $revision) {
   watchdog("special", "node: removed revision #$revision of '$node->title'");
 }
 
-function node_revision_previous($node) {
-  return end(array_keys($node->revisions));
+/*
+** Return a list of all the existing revision numbers.
+*/
+
+function node_revision_list($node) {
+  if (is_array($node->revisions)) {
+    return array_keys($node->revisions);
+  }
+  else {
+    return array();
+  }
 }
 
 function node_admin() {
@@ -344,10 +366,12 @@ function node_admin() {
         print node_admin_edit($id);
         break;
       case "rollback revision":
-        print node_revision_rollback($id, $revision);
+        print node_revision_rollback(node_load(array("nid" => $id)), $revision);
+        print node_admin_edit($id);
         break;
       case "delete revision":
-        print node_revision_delete($id, $revision);
+        print node_revision_delete(node_load(array("nid" => $id)), $revision);
+        print node_admin_edit($id);
         break;
       case t("Preview"):
         print node_preview($edit);
@@ -492,7 +516,6 @@ function node_form($edit) {
     $form .= $function(&$edit, &$help, &$error);
   }
 
-  $output .= "<div style=\"margin-right: 40px; float: left;\">";
 
   /*
   ** Add the help text:
@@ -502,6 +525,10 @@ function node_form($edit) {
     $output .= "<p>$help</p>";
   }
 
+  $output .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">";
+  $output .= " <tr>";
+  $output .= "  <td valign=\"top\">";
+
   /*
   ** Add the default fields:
   */
@@ -554,14 +581,13 @@ function node_form($edit) {
     $output .= form_submit(t("Delete"));
   }
 
-  $output .= "</div>";
-
   /*
   ** Add the admin specific parts:
   */
 
   if (user_access("administer nodes")) {
-    $output .= "<div style=\"float: right;\">";
+    $output .= "</td><td valign=\"top\">";
+
     $output .= form_textfield(t("Authored by"), "name", $edit->name, 20, 25, $error["name"]);
     $output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]);
     $output .= "<br />";
@@ -569,9 +595,12 @@ function node_form($edit) {
     $output .= form_select(t("Allow users comments"), "comment", $edit->comment, array("Disabled", "Enabled"));
     $output .= form_select(t("Promote to front page"), "promote", $edit->promote, array("Disabled", "Enabled"));
     $output .= form_select(t("Create new revision"), "revision", $edit->revision, array("Disabled", "Enabled"));
-    $output .= "</div>";
   }
 
+  $output .= "  </td>";
+  $output .= " </tr>";
+  $output .= "</table>";
+
   return form($output);
 }
 
diff --git a/modules/node/node.module b/modules/node/node.module
index 26d40dc085e8..2c1b6d3b1c1f 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -234,6 +234,18 @@ function node_admin_nodes() {
   return $output;
 }
 
+/*
+** Return the revision with the specified revision number.
+*/
+
+function node_revision_load($node, $revision) {
+  return $node->revisions[$revision]["node"];
+}
+
+/*
+** Create and return a new revision of the given node.
+*/
+
 function node_revision_create($node) {
   global $user;
 
@@ -252,14 +264,12 @@ function node_revision_create($node) {
   return $node;
 }
 
-function node_revision_rollback($nid, $revision) {
-  global $user;
+/*
+** Roll-back to the revision with the specified revision number.
+*/
 
-  /*
-  ** Load the original/current node:
-  */
-
-  $node = node_load(array("nid" => $nid));
+function node_revision_rollback($node, $revision) {
+  global $user;
 
   /*
   ** Extract the specified revision:
@@ -298,8 +308,11 @@ function node_revision_rollback($nid, $revision) {
   watchdog("special", "node: rollbacked to revision #$revision of '$node->title'");
 }
 
-function node_revision_delete($nid, $revision) {
-  $node = node_load(array("nid" => $nid));
+/*
+** Delete the revision with specified revision number.
+*/
+
+function node_revision_delete($node, $revision) {
 
   unset($node->revisions[$revision]);
 
@@ -308,8 +321,17 @@ function node_revision_delete($nid, $revision) {
   watchdog("special", "node: removed revision #$revision of '$node->title'");
 }
 
-function node_revision_previous($node) {
-  return end(array_keys($node->revisions));
+/*
+** Return a list of all the existing revision numbers.
+*/
+
+function node_revision_list($node) {
+  if (is_array($node->revisions)) {
+    return array_keys($node->revisions);
+  }
+  else {
+    return array();
+  }
 }
 
 function node_admin() {
@@ -344,10 +366,12 @@ function node_admin() {
         print node_admin_edit($id);
         break;
       case "rollback revision":
-        print node_revision_rollback($id, $revision);
+        print node_revision_rollback(node_load(array("nid" => $id)), $revision);
+        print node_admin_edit($id);
         break;
       case "delete revision":
-        print node_revision_delete($id, $revision);
+        print node_revision_delete(node_load(array("nid" => $id)), $revision);
+        print node_admin_edit($id);
         break;
       case t("Preview"):
         print node_preview($edit);
@@ -492,7 +516,6 @@ function node_form($edit) {
     $form .= $function(&$edit, &$help, &$error);
   }
 
-  $output .= "<div style=\"margin-right: 40px; float: left;\">";
 
   /*
   ** Add the help text:
@@ -502,6 +525,10 @@ function node_form($edit) {
     $output .= "<p>$help</p>";
   }
 
+  $output .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">";
+  $output .= " <tr>";
+  $output .= "  <td valign=\"top\">";
+
   /*
   ** Add the default fields:
   */
@@ -554,14 +581,13 @@ function node_form($edit) {
     $output .= form_submit(t("Delete"));
   }
 
-  $output .= "</div>";
-
   /*
   ** Add the admin specific parts:
   */
 
   if (user_access("administer nodes")) {
-    $output .= "<div style=\"float: right;\">";
+    $output .= "</td><td valign=\"top\">";
+
     $output .= form_textfield(t("Authored by"), "name", $edit->name, 20, 25, $error["name"]);
     $output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]);
     $output .= "<br />";
@@ -569,9 +595,12 @@ function node_form($edit) {
     $output .= form_select(t("Allow users comments"), "comment", $edit->comment, array("Disabled", "Enabled"));
     $output .= form_select(t("Promote to front page"), "promote", $edit->promote, array("Disabled", "Enabled"));
     $output .= form_select(t("Create new revision"), "revision", $edit->revision, array("Disabled", "Enabled"));
-    $output .= "</div>";
   }
 
+  $output .= "  </td>";
+  $output .= " </tr>";
+  $output .= "</table>";
+
   return form($output);
 }
 
diff --git a/modules/queue.module b/modules/queue.module
index ea1ba0b11bea..aa70ef656b40 100644
--- a/modules/queue.module
+++ b/modules/queue.module
@@ -51,7 +51,7 @@ function queue_vote($id, $vote) {
       }
       else if (variable_get($node->type ."_dump", -2) >= $node->score) {
         if ($node->revisions) {
-          node_revision_rollback($node->nid, node_revision_previous($node));
+          node_revision_rollback($node, end(node_revision_list($node)));
           watchdog("special", "moderation: dumped '$node->title' (rollback)");
         }
         else {
@@ -61,7 +61,7 @@ function queue_vote($id, $vote) {
       }
       else if (variable_get($node->type ."_expire", 6) <= $node->votes) {
         if ($node->revisions) {
-          node_revision_rollback($node->nid,  node_revision_previous($node));
+          node_revision_rollback($node, end(node_revision_list($node)));
           watchdog("special", "moderation: expired '$node->title' (rollback)");
         }
         else {
@@ -108,16 +108,6 @@ function queue_view($id) {
     */
     $queue_votes = array("neutral (+0)" => "+ 0", "post it (+1)" => "+ 1", "dump it (-1)" => "- 1");
 
-    // TODO: this is where the upcoming versioning system should come in
-    if ($n = node_load(array("nid" => $node->pid))) {
-      $output .= " ". t("The above node is a proposed update of an existing node:") ." \"<a href=\"node.php?id=$n->nid\">". check_output($n->title) ."</a>\".";
-    }
-
-    // TODO: this is where the upcoming versioning system should come in
-    if ($node->log) {
-      $output .= " ". t("The log message to accompany this submission is given below:") ."<p><i>". check_output($node->log, 1) ."</i></p>";
-    }
-
     // moderation form:
     $output .= "<form action=\"module.php?mod=queue\" method=\"post\">";
     foreach ($queue_votes as $key=>$value) $options .= "  <option value=\"$value\">$key</option>";
diff --git a/scripts/mail-to-sql.pl b/scripts/mail-to-sql.pl
index 9085c9af2eb4..6fcb8963153f 100644
--- a/scripts/mail-to-sql.pl
+++ b/scripts/mail-to-sql.pl
@@ -2,37 +2,52 @@
 
 use DBI;
 
-# database settings:
+# Database settings:
 my $db_name = 'drop';
 my $db_user = 'drop';
 my $db_pass = 'drop';
 
-# read data from stdin:
+# Read data from stdin:
 my @data = <STDIN>;
 my $data = join '', @data;
 
 my @chunks = split(/\n\n/, $data);
 
-# parse the header into an associative array:
+# Parse the header into an associative array:
 foreach $line (split(/\n/, $chunks[0])) {
-  if ($line =~ /(.*?):\s(.*)/) {
-    $header{lc($1)} = $2;
+  # The field-body can be split into a multiple-line representation,
+  # which is called "folding".  According to RFC 822, the rule is that
+  # wherever there may be linear-white-space (not simply LWSP-chars),
+  # a CRLF immediately followed by at least one LWSP-char may instead
+  # be inserted.
+
+  if ($line =~ /^\s(.*?)/) {
+    $data = $1;
+  }
+  elsif ($line =~ /(.*?):\s(.*)/) {
+    $key = lc($1);
+    $data = $2;
   }
-  $header{data} .= "$line\n";
-}
 
-$chunks[0] = "";
+  if ($key && $data) {
+    $header{$key} .= $data;
+  }
+}
 
-# debug output:
+# Debug output:
  # foreach $key (sort keys %header) {
- #   print "$key: $header{$key}\n";
+ #   print "$key: $header{$key}\n--------\n";
  # }
 
-# construct the mail body:
+# Store the complete header into a field:
+$header{header} = $chunks[0];
+$chunks[0] = "";
+
+# Construct the mail body:
 foreach $line (@chunks) {
   $body .= "$line\n\n";
 }
 
 my $db = DBI->connect("DBI:mysql:$db_name", "$db_user", "$db_pass") or die "Couldn't connect recepient database: " . DBI->errstr;
-$db->do("INSERT INTO mail (subject, sender, recepient, header, body, timestamp) VALUES (". $db->quote($header{subject}) .", ". $db->quote($header{from}) .", ". $db->quote($header{to}) .", ". $db->quote($header{data}) .", ". $db->quote($body) .", ". $db->quote(time()) .")") or die "Couldn't execute query: " . $db->errstr;
+$db->do("INSERT INTO mail (subject, header_from, header_to, header_cc, header_reply_to, header, body, timestamp) VALUES (". $db->quote($header{"subject"}) .", ". $db->quote($header{"from"}) .", ". $db->quote($header{"to"}) .", ". $db->quote($header{"cc"}) .", ". $db->quote($header{"reply-to"}) .", ". $db->quote($header{"header"}) .", ". $db->quote($body) .", ". $db->quote(time()) .")") or die "Couldn't execute query: " . $db->errstr;
 $db->disconnect();
-- 
GitLab