changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / feature / appendonly.php
1 <?php
2
3 /*
4    If the _APPENDONLY page flag is set, users can further only append
5    text to a page (and not edit the site as whole), while moderators and
6    admins always can.
7 */
8
9
10 $ewiki_plugins["edit_hook"][] = "ewiki_edit_hook_appendonly";
11 $ewiki_plugins["edit_save"][] = "ewiki_edit_save_appendonly";
12
13
14
15
16 function ewiki_edit_hook_appendonly($id, &$data, &$hpdata) {
17
18    global $ewiki_t, $ewiki_ring;
19    
20    if ((($data["flags"] & EWIKI_DB_F_ACCESS) == EWIKI_DB_F_APPENDONLY) && (!EWIKI_PROTECTED_MODE || ($ewiki_ring >= 2))) {
21       if ($data["version"] && strlen($data["content"])) {
22          if (!$_REQUEST["content"] || !$_REQUEST["version"]) {
23
24             #-- only show the editable part in the edit box
25             $data["content"] = "----\n\n";
26
27             #-- change "edit" title to "append"
28             foreach (array_keys($ewiki_t) as $LANG) {
29                if ($ewiki_t[$LANG]["APPENDTOPAGE"]) {
30                   $ewiki_t[$LANG]["EDITTHISPAGE"] = &$ewiki_t[$LANG]["APPENDTOPAGE"];
31                }
32             }
33
34          }
35       }  
36    }
37 }
38
39
40
41 function ewiki_edit_save_appendonly(&$save, &$old) {
42
43    global $ewiki_ring;
44
45    if ((($old["flags"] & EWIKI_DB_F_ACCESS) == EWIKI_DB_F_APPENDONLY) && (!EWIKI_PROTECTED_MODE || ($ewiki_ring >= 2))) {
46       if ($old["version"] && ($old_len=strlen($old_str=&$old["content"]))) {
47
48          #-- add newlines and a horizontal bar
49          $old_str = rtrim($old_str);
50          if (substr($old_str, $old_len-5, 4) == "----") {
51             $old_str = rtrim(rtrim($old_str, "-"));
52          }
53          $old_str .= "\n\n";
54          if (!preg_match("/^\n*----/", $save["content"])) {
55             $save["content"] = "----\n\n" . $save["content"];
56          }
57
58          #-- merge the old not-editable-part with the new append-part
59          $save["content"] = $old["content"]
60                           . "\n\n"
61                           . $save["content"];
62
63       }
64    }
65 }
66
67
68
69 ?>