Skip to content
Snippets Groups Projects
Commit db47bac3 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- 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
parent f88cfaa2
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
$db_type = substr($db_url, 0, strpos($db_url, "://")); $db_type = substr($db_url, 0, strpos($db_url, "://"));
if (file_exists("includes/database.$db_type.inc")) { if ($db_type == "mysql") {
include_once "includes/database.$db_type.inc"; include_once "includes/database.mysql.inc";
} }
else { else {
include_once "includes/database.pear.inc"; include_once "includes/database.pear.inc";
......
...@@ -12,10 +12,10 @@ function module_iterate($function, $argument = "") { ...@@ -12,10 +12,10 @@ function module_iterate($function, $argument = "") {
} }
// invoke hook $hook of module $name with optional arguments: // 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; $function = $name ."_". $hook;
if (function_exists($function)) { if (function_exists($function)) {
return $function($a1, $a2); return $function($a1, $a2, $a3, $a4);
} }
} }
...@@ -36,6 +36,9 @@ function module_list() { ...@@ -36,6 +36,9 @@ function module_list() {
closedir($handle); closedir($handle);
asort($list); asort($list);
} }
else {
$list = array();
}
} }
return $list; return $list;
......
...@@ -142,7 +142,7 @@ function book_view($node, $main = 0) { ...@@ -142,7 +142,7 @@ function book_view($node, $main = 0) {
*/ */
if ($node->moderate && $mod != "queue") { 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) { ...@@ -233,7 +233,7 @@ function book_tree($parent = "", $depth = 0) {
// take the most recent approved revision: // take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"]; $node = node_revision_load($node, end(node_revision_list($node)));
} }
// output the content: // output the content:
...@@ -260,7 +260,7 @@ function book_render() { ...@@ -260,7 +260,7 @@ function book_render() {
// take the most recent approved revision: // take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"]; $node = node_revision_load($node, end(node_revision_list($node)));
} }
// output the content: // output the content:
...@@ -300,7 +300,7 @@ function book_export_html($id = "", $depth = 1) { ...@@ -300,7 +300,7 @@ function book_export_html($id = "", $depth = 1) {
// take the most recent approved revision: // take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"]; $node = node_revision_load($node, end(node_revision_list($node)));
} }
// output the content: // output the content:
...@@ -325,7 +325,7 @@ function book_export_html_recursive($parent = "", $depth = 1) { ...@@ -325,7 +325,7 @@ function book_export_html_recursive($parent = "", $depth = 1) {
// take the most recent approved revision: // take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"]; $node = node_revision_load($node, end(node_revision_list($node)));
} }
// output the content: // output the content:
......
...@@ -142,7 +142,7 @@ function book_view($node, $main = 0) { ...@@ -142,7 +142,7 @@ function book_view($node, $main = 0) {
*/ */
if ($node->moderate && $mod != "queue") { 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) { ...@@ -233,7 +233,7 @@ function book_tree($parent = "", $depth = 0) {
// take the most recent approved revision: // take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"]; $node = node_revision_load($node, end(node_revision_list($node)));
} }
// output the content: // output the content:
...@@ -260,7 +260,7 @@ function book_render() { ...@@ -260,7 +260,7 @@ function book_render() {
// take the most recent approved revision: // take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"]; $node = node_revision_load($node, end(node_revision_list($node)));
} }
// output the content: // output the content:
...@@ -300,7 +300,7 @@ function book_export_html($id = "", $depth = 1) { ...@@ -300,7 +300,7 @@ function book_export_html($id = "", $depth = 1) {
// take the most recent approved revision: // take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"]; $node = node_revision_load($node, end(node_revision_list($node)));
} }
// output the content: // output the content:
...@@ -325,7 +325,7 @@ function book_export_html_recursive($parent = "", $depth = 1) { ...@@ -325,7 +325,7 @@ function book_export_html_recursive($parent = "", $depth = 1) {
// take the most recent approved revision: // take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"]; $node = node_revision_load($node, end(node_revision_list($node)));
} }
// output the content: // output the content:
......
...@@ -234,6 +234,18 @@ function node_admin_nodes() { ...@@ -234,6 +234,18 @@ function node_admin_nodes() {
return $output; 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) { function node_revision_create($node) {
global $user; global $user;
...@@ -252,14 +264,12 @@ function node_revision_create($node) { ...@@ -252,14 +264,12 @@ function node_revision_create($node) {
return $node; return $node;
} }
function node_revision_rollback($nid, $revision) { /*
global $user; ** Roll-back to the revision with the specified revision number.
*/
/* function node_revision_rollback($node, $revision) {
** Load the original/current node: global $user;
*/
$node = node_load(array("nid" => $nid));
/* /*
** Extract the specified revision: ** Extract the specified revision:
...@@ -298,8 +308,11 @@ function node_revision_rollback($nid, $revision) { ...@@ -298,8 +308,11 @@ function node_revision_rollback($nid, $revision) {
watchdog("special", "node: rollbacked to revision #$revision of '$node->title'"); 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]); unset($node->revisions[$revision]);
...@@ -308,8 +321,17 @@ function node_revision_delete($nid, $revision) { ...@@ -308,8 +321,17 @@ function node_revision_delete($nid, $revision) {
watchdog("special", "node: removed revision #$revision of '$node->title'"); 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() { function node_admin() {
...@@ -344,10 +366,12 @@ function node_admin() { ...@@ -344,10 +366,12 @@ function node_admin() {
print node_admin_edit($id); print node_admin_edit($id);
break; break;
case "rollback revision": 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; break;
case "delete revision": 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; break;
case t("Preview"): case t("Preview"):
print node_preview($edit); print node_preview($edit);
...@@ -492,7 +516,6 @@ function node_form($edit) { ...@@ -492,7 +516,6 @@ function node_form($edit) {
$form .= $function(&$edit, &$help, &$error); $form .= $function(&$edit, &$help, &$error);
} }
$output .= "<div style=\"margin-right: 40px; float: left;\">";
/* /*
** Add the help text: ** Add the help text:
...@@ -502,6 +525,10 @@ function node_form($edit) { ...@@ -502,6 +525,10 @@ function node_form($edit) {
$output .= "<p>$help</p>"; $output .= "<p>$help</p>";
} }
$output .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">";
$output .= " <tr>";
$output .= " <td valign=\"top\">";
/* /*
** Add the default fields: ** Add the default fields:
*/ */
...@@ -554,14 +581,13 @@ function node_form($edit) { ...@@ -554,14 +581,13 @@ function node_form($edit) {
$output .= form_submit(t("Delete")); $output .= form_submit(t("Delete"));
} }
$output .= "</div>";
/* /*
** Add the admin specific parts: ** Add the admin specific parts:
*/ */
if (user_access("administer nodes")) { 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 by"), "name", $edit->name, 20, 25, $error["name"]);
$output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]); $output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]);
$output .= "<br />"; $output .= "<br />";
...@@ -569,9 +595,12 @@ function node_form($edit) { ...@@ -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("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("Promote to front page"), "promote", $edit->promote, array("Disabled", "Enabled"));
$output .= form_select(t("Create new revision"), "revision", $edit->revision, 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); return form($output);
} }
......
...@@ -234,6 +234,18 @@ function node_admin_nodes() { ...@@ -234,6 +234,18 @@ function node_admin_nodes() {
return $output; 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) { function node_revision_create($node) {
global $user; global $user;
...@@ -252,14 +264,12 @@ function node_revision_create($node) { ...@@ -252,14 +264,12 @@ function node_revision_create($node) {
return $node; return $node;
} }
function node_revision_rollback($nid, $revision) { /*
global $user; ** Roll-back to the revision with the specified revision number.
*/
/* function node_revision_rollback($node, $revision) {
** Load the original/current node: global $user;
*/
$node = node_load(array("nid" => $nid));
/* /*
** Extract the specified revision: ** Extract the specified revision:
...@@ -298,8 +308,11 @@ function node_revision_rollback($nid, $revision) { ...@@ -298,8 +308,11 @@ function node_revision_rollback($nid, $revision) {
watchdog("special", "node: rollbacked to revision #$revision of '$node->title'"); 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]); unset($node->revisions[$revision]);
...@@ -308,8 +321,17 @@ function node_revision_delete($nid, $revision) { ...@@ -308,8 +321,17 @@ function node_revision_delete($nid, $revision) {
watchdog("special", "node: removed revision #$revision of '$node->title'"); 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() { function node_admin() {
...@@ -344,10 +366,12 @@ function node_admin() { ...@@ -344,10 +366,12 @@ function node_admin() {
print node_admin_edit($id); print node_admin_edit($id);
break; break;
case "rollback revision": 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; break;
case "delete revision": 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; break;
case t("Preview"): case t("Preview"):
print node_preview($edit); print node_preview($edit);
...@@ -492,7 +516,6 @@ function node_form($edit) { ...@@ -492,7 +516,6 @@ function node_form($edit) {
$form .= $function(&$edit, &$help, &$error); $form .= $function(&$edit, &$help, &$error);
} }
$output .= "<div style=\"margin-right: 40px; float: left;\">";
/* /*
** Add the help text: ** Add the help text:
...@@ -502,6 +525,10 @@ function node_form($edit) { ...@@ -502,6 +525,10 @@ function node_form($edit) {
$output .= "<p>$help</p>"; $output .= "<p>$help</p>";
} }
$output .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">";
$output .= " <tr>";
$output .= " <td valign=\"top\">";
/* /*
** Add the default fields: ** Add the default fields:
*/ */
...@@ -554,14 +581,13 @@ function node_form($edit) { ...@@ -554,14 +581,13 @@ function node_form($edit) {
$output .= form_submit(t("Delete")); $output .= form_submit(t("Delete"));
} }
$output .= "</div>";
/* /*
** Add the admin specific parts: ** Add the admin specific parts:
*/ */
if (user_access("administer nodes")) { 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 by"), "name", $edit->name, 20, 25, $error["name"]);
$output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]); $output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]);
$output .= "<br />"; $output .= "<br />";
...@@ -569,9 +595,12 @@ function node_form($edit) { ...@@ -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("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("Promote to front page"), "promote", $edit->promote, array("Disabled", "Enabled"));
$output .= form_select(t("Create new revision"), "revision", $edit->revision, 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); return form($output);
} }
......
...@@ -51,7 +51,7 @@ function queue_vote($id, $vote) { ...@@ -51,7 +51,7 @@ function queue_vote($id, $vote) {
} }
else if (variable_get($node->type ."_dump", -2) >= $node->score) { else if (variable_get($node->type ."_dump", -2) >= $node->score) {
if ($node->revisions) { 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)"); watchdog("special", "moderation: dumped '$node->title' (rollback)");
} }
else { else {
...@@ -61,7 +61,7 @@ function queue_vote($id, $vote) { ...@@ -61,7 +61,7 @@ function queue_vote($id, $vote) {
} }
else if (variable_get($node->type ."_expire", 6) <= $node->votes) { else if (variable_get($node->type ."_expire", 6) <= $node->votes) {
if ($node->revisions) { 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)"); watchdog("special", "moderation: expired '$node->title' (rollback)");
} }
else { else {
...@@ -108,16 +108,6 @@ function queue_view($id) { ...@@ -108,16 +108,6 @@ function queue_view($id) {
*/ */
$queue_votes = array("neutral (+0)" => "+ 0", "post it (+1)" => "+ 1", "dump it (-1)" => "- 1"); $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: // moderation form:
$output .= "<form action=\"module.php?mod=queue\" method=\"post\">"; $output .= "<form action=\"module.php?mod=queue\" method=\"post\">";
foreach ($queue_votes as $key=>$value) $options .= " <option value=\"$value\">$key</option>"; foreach ($queue_votes as $key=>$value) $options .= " <option value=\"$value\">$key</option>";
......
...@@ -2,37 +2,52 @@ ...@@ -2,37 +2,52 @@
use DBI; use DBI;
# database settings: # Database settings:
my $db_name = 'drop'; my $db_name = 'drop';
my $db_user = 'drop'; my $db_user = 'drop';
my $db_pass = 'drop'; my $db_pass = 'drop';
# read data from stdin: # Read data from stdin:
my @data = <STDIN>; my @data = <STDIN>;
my $data = join '', @data; my $data = join '', @data;
my @chunks = split(/\n\n/, $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])) { foreach $line (split(/\n/, $chunks[0])) {
if ($line =~ /(.*?):\s(.*)/) { # The field-body can be split into a multiple-line representation,
$header{lc($1)} = $2; # 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) { # 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) { foreach $line (@chunks) {
$body .= "$line\n\n"; $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; 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(); $db->disconnect();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment