4 If a page has the _APPENDONLY and _WRITEABLE flags set, then this plugin
5 allows users to edit anything after the 16+-minus-signs or double
6 horizontal bar. Moderators and admins can however still edit the full
8 (One could also call this plugin the "PartialLock support".)
11 define("EWIKI_APPENDWRITE_AUTOLOCK", 1);
13 $ewiki_plugins["handler"][] = "ewiki_handler_appendwrite";
14 $ewiki_plugins["edit_hook"][] = "ewiki_edit_hook_appendwrite";
15 $ewiki_plugins["edit_save"][] = "ewiki_edit_save_appendwrite";
20 merges the double horizontal bar,
21 this was too late for ["format_source"]
23 function ewiki_handler_appendwrite($id, &$data, $action) {
25 define("EWIKI_DB_F_APPENDWRITE", EWIKI_DB_F_APPENDONLY|EWIKI_DB_F_WRITEABLE);
27 if (($action=="view") && ($data["flags"] & EWIKI_DB_F_APPENDWRITE)) {
28 $data["content"] = preg_replace("/----\n----/", "--------", $data["content"], 1);
35 searches for the page separator and returns its position,
36 and eventually adds one
38 function ewiki_appendwrite_split(&$content) {
40 if ($end = strpos($content, "----------------")) {
43 if ($end1 = strpos($content, "----\n----")) {
51 if (!($end = strpos($content, "\n", $end))) {
53 $end = strlen($content);
56 elseif (EWIKI_APPENDWRITE_AUTOLOCK) {
57 $content .= "\n----------------\n\n";
58 $end = strlen($content);
66 makes users only see the editable part in
69 function ewiki_edit_hook_appendwrite($id, &$data, &$hpdata) {
71 global $ewiki_t, $ewiki_ring;
73 if (($data["flags"] & EWIKI_DB_F_APPENDWRITE) && (!EWIKI_PROTECTED_MODE || ($ewiki_ring >= 2))) {
74 if ($data["version"] && strlen($data["content"]) && !$_REQUEST["content"]) {
75 if ($end = ewiki_appendwrite_split($data["content"])) {
77 #-- only show the editable part in the edit box
78 $data["content"] = substr($data["content"], $end);
80 # change "edit" title to "append"
81 foreach (array_keys($ewiki_t) as $LANG) {
82 if ($ewiki_t[$LANG]["APPENDTOPAGE"]) {
83 $ewiki_t[$LANG]["EDITTHISPAGE"] = &$ewiki_t[$LANG]["APPENDTOPAGE"];
92 merges the not-editable part, with the submitted
93 changes to the appendonly/writable part
95 function ewiki_edit_save_appendwrite(&$save, &$old) {
99 if (($old["flags"] & EWIKI_DB_F_APPENDWRITE) && (!EWIKI_PROTECTED_MODE || ($ewiki_ring >= 2))) {
100 if ($old["version"] && strlen($old["content"])) {
101 if ($end = ewiki_appendwrite_split($old["content"])) {
103 #-- merge the old not-editable-part with the new append-part
104 $save["content"] = substr($old["content"], 0, $end+1)