4 If you activate this plugin, then additions for pages with the
5 _DB_F_APPENDONLY flag will get saved into a secondary page with a
6 name like "CurrentPage/Comments" if an ordinary user attempts to
7 edit the "CurrentPage" (which remains editable for moderators and
9 This plugin has the drawback, that moderators cannot edit the
10 /Comments page part for brevity - they first needed to log out
11 (a drawback of the _DB_F_PART type setting for the /Comments part).
13 Warning: this is hack in progress!
17 $ewiki_plugins["edit_hook"][] = "ewiki_edit_hook_appendcomments";
18 $ewiki_plugins["edit_save"][] = "ewiki_edit_save_appendcomments";
19 $ewiki_plugins["handler"][] = "ewiki_aview_appendcomments";
21 define("EWIKI_APPENDONLY_COMMENTSPART", "/Comments");
26 Add the /Comments entries contents to the current pages
27 $data["content"] for rendering.
29 function ewiki_aview_appendcomments($id, &$data, $action) {
31 if (($action=="view") && ($data["flags"] & EWIKI_DB_F_APPENDONLY)) {
33 #-- fetch /Comments part
34 $c_id = $id.EWIKI_APPENDONLY_COMMENTSPART;
35 $row = ewiki_db::GET($c_id);
37 #-- add to current pages content
38 if ($row && (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_PART|EWIKI_DB_F_TYPE)) {
39 $data["content"] .= "\n" . $row["content"];
46 swaps currently edit/ed pages content with that from the /Coments
49 function ewiki_edit_hook_appendcomments(&$id, &$data, &$hpdata) {
53 if ($data["flags"] & EWIKI_DB_F_APPENDONLY) {
54 if (!EWIKI_PROTECTED_MODE || ($ewiki_ring >= 2)) {
56 #-- fill edit box with contents from "$id/Content" page
57 $c_id = $id.EWIKI_APPENDONLY_COMMENTSPART;
58 $data = ewiki_db::GET($c_id);
59 if (!$data["version"]) {
63 "flags" => EWIKI_DB_F_PART|EWIKI_DB_F_TEXT,
65 "lastmodified" => time(),
67 "meta" => array("parent" => $id),
72 $data["flags"] = EWIKI_DB_F_TEXT; # another ugly workaround
74 #-- change "edit" title to "append"
75 foreach (array_keys($ewiki_t) as $LANG) {
76 if ($ewiki_t[$LANG]["APPENDTOPAGE"]) {
77 $ewiki_t[$LANG]["EDITTHISPAGE"] = &$ewiki_t[$LANG]["APPENDTOPAGE"];
87 manages ewiki_edit_page() to store the currently edited /Comments
88 part back into the correct database entry (and not the main page)
90 function ewiki_edit_save_appendcomments(&$save, &$old) {
92 if ($old["meta"]["parent"] == $save["id"]) {
93 if (!EWIKI_PROTECTED_MODE || ($ewiki_ring >= 2)) {
95 #-- transform $save entry into "/Comments" page request
96 $save["id"] = $old["id"];
97 $save["flags"] = EWIKI_DB_F_TEXT|EWIKI_DB_F_PART;
98 $save["created"] = $old["created"];
99 $save["hits"] = $old["hits"];
100 $save["meta"] = $old["meta"];
101 # leaving as is: content, refs, author, lastmodified