Commit f88cfaa2 authored by Dries's avatar Dries

- Another batch of updates.  The most important bit is that the moderation
  queue should be functional again.  It's not ready yet but I'll be tuning
  it for the next two evenings or so.
parent 4af6c9d2
......@@ -123,7 +123,7 @@ function node_load($conditions) {
function node_save($node, $filter) {
$fields = array("nid", "uid", "type", "title", "teaser", "body", "revisions", "status", "comment", "promote", "moderate", "created", "changed");
$fields = array("nid", "uid", "type", "title", "teaser", "body", "revisions", "score", "status", "comment", "promote", "moderate", "created", "changed", "users", "votes");
foreach ($filter as $key => $value) {
/*
......@@ -186,8 +186,6 @@ function node_save($node, $filter) {
// call the node specific callback (if any):
module_invoke($node->type, "insert", $node);
watchdog("special", "node: added '$node->title'");
}
else {
......@@ -211,7 +209,6 @@ function node_save($node, $filter) {
// call the node specific callback (if any):
module_invoke($node->type, "update", $node);
watchdog("special", "node: updated '$node->title'");
}
/*
......@@ -238,6 +235,11 @@ function node_view($node, $main = 0) {
node_invoke($node, "view", $main);
}
else {
/*
** Default behavior:
*/
$theme->node($node, $main);
}
}
......
......@@ -10,9 +10,17 @@ function book_node($field) {
}
function book_access($op, $node) {
global $user;
if ($op == "view") {
return ($node->nid && $node->status && !$node->moderate);
/*
** Everyone can access all published book pages whether these pages
** are still waiting for approval or not. We might not always want
** to display pages that are waiting for approval, but we take care
** of that problem in the book_view() function.
*/
return $node->status;
}
if ($op == "create") {
......@@ -22,12 +30,13 @@ function book_access($op, $node) {
if ($op == "update") {
/*
** Everyone can upate a book page if the "create new revision"-bit
** is set: that is, only updates that don't overwrite the previous
** conent will be allowed.
** Everyone can upate a book page if there are no suggested updates
** of that page waiting for approval and as long as the "create new
** revision"-bit is set; that is, only updates that don't overwrite
** the current or pending information are allowed.
*/
return $node->revision;
return !$node->moderate && $node->revision;
}
}
......@@ -40,7 +49,7 @@ function book_link($type) {
}
function book_load($node) {
$book = db_fetch_object(db_query("SELECT parent, weight FROM book WHERE nid = '$node->nid'"));
$book = db_fetch_object(db_query("SELECT parent, weight, revision FROM book WHERE nid = '$node->nid'"));
return $book;
}
......@@ -61,7 +70,7 @@ function book_save($node) {
if (user_access("administer nodes")) {
/*
** If a node administrator updates a book page, we don't create a
** new revision unless explicitly specified.
** new revision unless we are explicitly instructed to.
*/
return array("parent", "weight");
......@@ -69,8 +78,8 @@ function book_save($node) {
else {
/*
** If a regular user updates a book page, we always create a new
** revision. These new revisions are subject to moderation, and
** are not or no longer being automatically promoted.
** revision. All new revisions have to be approved (moderation)
** and are not promoted by derault.
*/
return array("created" => time(), "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight");
......@@ -106,7 +115,7 @@ function book_form($node, $help, $error) {
$output .= form_hidden("revision", 1);
$node->uid = $user->uid; // passed by reference
$node->uid = $user->uid; // $node is passed by reference
$node->name = $user->name;
}
......@@ -124,7 +133,23 @@ function book_location($node, $nodes = array()) {
}
function book_view($node, $main = 0) {
global $theme;
global $theme, $mod;
/*
** Always display the most recently approved revision of a node
** unless we have to display it in the context of the moderation
** queue.
*/
if ($node->moderate && $mod != "queue") {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
/*
** Display the node. If not displayed on the main page, we render
** the node as a page in the book with extra links to the previous
** and the next page.
*/
if ($main) {
$theme->node($node, $main);
......@@ -196,14 +221,28 @@ function book_toc($parent = "", $indent = "", $toc = array()) {
function book_tree($parent = "", $depth = 0) {
if ($depth < 3) {
// select all child nodes:
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight, n.title");
/*
** Select all child nodes and render them into a table of contents:
*/
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight, n.title");
// render output:
while ($node = db_fetch_object($result)) {
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
// take the most recent approved revision:
if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
// output the content:
$output .= "<li><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></li>";
// build the sub-tree of each child:
$output .= book_tree($node->nid, $depth + 1);
}
$output = "<ul>$output</ul>";
}
......@@ -213,9 +252,18 @@ function book_tree($parent = "", $depth = 0) {
function book_render() {
global $theme;
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 ORDER BY b.weight");
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 ORDER BY b.weight");
while ($node = db_fetch_object($result)) {
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
// take the most recent approved revision:
if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
// output the content:
$output .= "<dt><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></dt><dd>". check_output($node->body, 1) ."<br /><br /></dd>";
}
......@@ -228,7 +276,6 @@ function book_page() {
global $op, $id, $theme;
if (user_access("access content")) {
switch ($op) {
case "feed":
print book_export_html($id, $depth = 1);
......@@ -245,24 +292,49 @@ function book_page() {
}
function book_export_html($id = "", $depth = 1) {
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND n.nid = '". check_input($id) ."'");
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND n.nid = '". check_input($id) ."'");
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
while ($node = db_fetch_object($result)) {
// take the most recent approved revision:
if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
// output the content:
$output .= "<h$depth>". check_output($node->title) ."</h$depth>";
if ($node->body) $output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
if ($node->body) {
$output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
}
}
$output .= book_export_html_recursive($id, $depth);
return $output;
}
function book_export_html_recursive($parent = "", $depth = 1) {
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND b.parent = '$parent' ORDER BY b.weight");
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND b.parent = '$parent' ORDER BY b.weight");
while ($node = db_fetch_object($result)) {
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
// take the most recent approved revision:
if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
// output the content:
$output .= "<h$depth>". check_output($node->title) ."</h$depth>";
if ($node->body) $output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
if ($node->body) {
$output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
}
$output .= book_export_html_recursive($node->nid, $depth + 1);
}
......
......@@ -10,9 +10,17 @@ function book_node($field) {
}
function book_access($op, $node) {
global $user;
if ($op == "view") {
return ($node->nid && $node->status && !$node->moderate);
/*
** Everyone can access all published book pages whether these pages
** are still waiting for approval or not. We might not always want
** to display pages that are waiting for approval, but we take care
** of that problem in the book_view() function.
*/
return $node->status;
}
if ($op == "create") {
......@@ -22,12 +30,13 @@ function book_access($op, $node) {
if ($op == "update") {
/*
** Everyone can upate a book page if the "create new revision"-bit
** is set: that is, only updates that don't overwrite the previous
** conent will be allowed.
** Everyone can upate a book page if there are no suggested updates
** of that page waiting for approval and as long as the "create new
** revision"-bit is set; that is, only updates that don't overwrite
** the current or pending information are allowed.
*/
return $node->revision;
return !$node->moderate && $node->revision;
}
}
......@@ -40,7 +49,7 @@ function book_link($type) {
}
function book_load($node) {
$book = db_fetch_object(db_query("SELECT parent, weight FROM book WHERE nid = '$node->nid'"));
$book = db_fetch_object(db_query("SELECT parent, weight, revision FROM book WHERE nid = '$node->nid'"));
return $book;
}
......@@ -61,7 +70,7 @@ function book_save($node) {
if (user_access("administer nodes")) {
/*
** If a node administrator updates a book page, we don't create a
** new revision unless explicitly specified.
** new revision unless we are explicitly instructed to.
*/
return array("parent", "weight");
......@@ -69,8 +78,8 @@ function book_save($node) {
else {
/*
** If a regular user updates a book page, we always create a new
** revision. These new revisions are subject to moderation, and
** are not or no longer being automatically promoted.
** revision. All new revisions have to be approved (moderation)
** and are not promoted by derault.
*/
return array("created" => time(), "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight");
......@@ -106,7 +115,7 @@ function book_form($node, $help, $error) {
$output .= form_hidden("revision", 1);
$node->uid = $user->uid; // passed by reference
$node->uid = $user->uid; // $node is passed by reference
$node->name = $user->name;
}
......@@ -124,7 +133,23 @@ function book_location($node, $nodes = array()) {
}
function book_view($node, $main = 0) {
global $theme;
global $theme, $mod;
/*
** Always display the most recently approved revision of a node
** unless we have to display it in the context of the moderation
** queue.
*/
if ($node->moderate && $mod != "queue") {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
/*
** Display the node. If not displayed on the main page, we render
** the node as a page in the book with extra links to the previous
** and the next page.
*/
if ($main) {
$theme->node($node, $main);
......@@ -196,14 +221,28 @@ function book_toc($parent = "", $indent = "", $toc = array()) {
function book_tree($parent = "", $depth = 0) {
if ($depth < 3) {
// select all child nodes:
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight, n.title");
/*
** Select all child nodes and render them into a table of contents:
*/
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight, n.title");
// render output:
while ($node = db_fetch_object($result)) {
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
// take the most recent approved revision:
if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
// output the content:
$output .= "<li><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></li>";
// build the sub-tree of each child:
$output .= book_tree($node->nid, $depth + 1);
}
$output = "<ul>$output</ul>";
}
......@@ -213,9 +252,18 @@ function book_tree($parent = "", $depth = 0) {
function book_render() {
global $theme;
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 ORDER BY b.weight");
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 ORDER BY b.weight");
while ($node = db_fetch_object($result)) {
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
// take the most recent approved revision:
if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
// output the content:
$output .= "<dt><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></dt><dd>". check_output($node->body, 1) ."<br /><br /></dd>";
}
......@@ -228,7 +276,6 @@ function book_page() {
global $op, $id, $theme;
if (user_access("access content")) {
switch ($op) {
case "feed":
print book_export_html($id, $depth = 1);
......@@ -245,24 +292,49 @@ function book_page() {
}
function book_export_html($id = "", $depth = 1) {
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND n.nid = '". check_input($id) ."'");
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND n.nid = '". check_input($id) ."'");
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
while ($node = db_fetch_object($result)) {
// take the most recent approved revision:
if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
// output the content:
$output .= "<h$depth>". check_output($node->title) ."</h$depth>";
if ($node->body) $output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
if ($node->body) {
$output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
}
}
$output .= book_export_html_recursive($id, $depth);
return $output;
}
function book_export_html_recursive($parent = "", $depth = 1) {
$result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND b.parent = '$parent' ORDER BY b.weight");
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND b.parent = '$parent' ORDER BY b.weight");
while ($node = db_fetch_object($result)) {
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
// take the most recent approved revision:
if ($node->moderate) {
$node = $node->revisions[sizeof($node->revisions) - 1]["node"];
}
// output the content:
$output .= "<h$depth>". check_output($node->title) ."</h$depth>";
if ($node->body) $output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
if ($node->body) {
$output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
}
$output .= book_export_html_recursive($node->nid, $depth + 1);
}
......
......@@ -237,6 +237,11 @@ function node_admin_nodes() {
function node_revision_create($node) {
global $user;
/*
** 'revision' is the name of the field used to indicicate that we
** have to create a new revision of a node.
*/
if ($node->nid && $node->revision) {
$prev = node_load(array("nid" => $node->nid));
$node->revisions = $prev->revisions;
......@@ -290,14 +295,21 @@ function node_revision_rollback($nid, $revision) {
node_save($rev, $filter);
watchdog("message", "node: rolled-back '$node->title'");
watchdog("special", "node: rollbacked to revision #$revision of '$node->title'");
}
function node_revision_delete($nid, $revision) {
$node = node_load(array("nid" => $nid));
unset($node->revisions[$revision]);
node_save($node, array("nid", "revisions"));
watchdog("special", "node: removed revision #$revision of '$node->title'");
}
function node_revision_previous($node) {
return end(array_keys($node->revisions));
}
function node_admin() {
......@@ -670,6 +682,7 @@ function node_submit($node) {
node_save($node, array_merge($fields, module_invoke($node->type, "save", $node)));
watchdog("special", "node: updated '$node->title'");
$output = t("The node has been updated.");
}
else {
......@@ -701,6 +714,7 @@ function node_submit($node) {
node_save($node, array_merge($fields, module_invoke($node->type, "save", $node)));
watchdog("special", "node: added '$node->title'");
$output = t("Thanks for your submission.");
}
else {
......
......@@ -237,6 +237,11 @@ function node_admin_nodes() {
function node_revision_create($node) {
global $user;
/*
** 'revision' is the name of the field used to indicicate that we
** have to create a new revision of a node.
*/
if ($node->nid && $node->revision) {
$prev = node_load(array("nid" => $node->nid));
$node->revisions = $prev->revisions;
......@@ -290,14 +295,21 @@ function node_revision_rollback($nid, $revision) {
node_save($rev, $filter);
watchdog("message", "node: rolled-back '$node->title'");
watchdog("special", "node: rollbacked to revision #$revision of '$node->title'");
}
function node_revision_delete($nid, $revision) {
$node = node_load(array("nid" => $nid));
unset($node->revisions[$revision]);
node_save($node, array("nid", "revisions"));
watchdog("special", "node: removed revision #$revision of '$node->title'");
}
function node_revision_previous($node) {
return end(array_keys($node->revisions));
}
function node_admin() {
......@@ -670,6 +682,7 @@ function node_submit($node) {
node_save($node, array_merge($fields, module_invoke($node->type, "save", $node)));
watchdog("special", "node: updated '$node->title'");
$output = t("The node has been updated.");
}
else {
......@@ -701,6 +714,7 @@ function node_submit($node) {
node_save($node, array_merge($fields, module_invoke($node->type, "save", $node)));
watchdog("special", "node: added '$node->title'");
$output = t("Thanks for your submission.");
}
else {
......
......@@ -45,17 +45,29 @@ function queue_vote($id, $vote) {
$node = node_load(array(nid => $id, type => $node->type));
if (variable_get($node->type ."_post", 4) <= $node->score) {
if (variable_get($node->type ."_post", 3) <= $node->score) {
node_save($node, array("nid", "status" => 1, "moderate" => 0));
watchdog("special", "node: posted '$node->title' - moderation");
watchdog("special", "moderation: posted '$node->title'");
}
else if (variable_get($node->type ."_dump", -2) >= $node->score) {
node_save($node, array("nid", "status" => 1, "moderate" => 0));
watchdog("special", "node: dumped '$node->title' - moderation");
if ($node->revisions) {
node_revision_rollback($node->nid, node_revision_previous($node));
watchdog("special", "moderation: dumped '$node->title' (rollback)");
}
else {
node_save($node, array("nid", "status" => 0, "moderate" => 0));
watchdog("special", "moderation: dumped '$node->title'");
}
}
else if (variable_get($node->type ."_expire", 8) <= $node->votes) {
node_save($node, array("nid", "status" => 0, "moderate" => 0));
watchdog("special", "node: expired '$node->title' - moderation");
else if (variable_get($node->type ."_expire", 6) <= $node->votes) {
if ($node->revisions) {
node_revision_rollback($node->nid, node_revision_previous($node));
watchdog("special", "moderation: expired '$node->title' (rollback)");
}
else {
node_save($node, array("nid", "status" => 0, "moderate" => 0));
watchdog("special", "moderation: expired '$node->title'");
}
}
}
}
......
......@@ -145,6 +145,11 @@ ALTER TABLE users CHANGE session sid varchar(32) DEFAULT '' NOT NULL;
# 02/11/01:
ALTER TABLE node ADD revisions TEXT DEFAULT '' NOT NULL;
# 04/11/01:
ALTER TABLE book ADD revision int(2) DEFAULT '1' NOT NULL;
ALTER TABLE book DROP log;
ALTER TABLE book DROP pid;
#
# Run the third part of updates/3.00-to-x.xx.php:
# visit http://www.yoursite.com/3.00-to-x.xx.php?part=3
......
......@@ -48,7 +48,7 @@
while ($object = db_fetch_object($result)) {
$node = node_load(array("nid" => $object->nid));
$body = db_result(db_query("SELECT body_old FROM $node->type WHERE nid = $node->nid"), 0);
switch ($node->type) {
......@@ -63,7 +63,7 @@
default:
print "unknown node $node->nid '$node->title' ($node->type)<br />";
}
unset($node);
unset($body);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment