changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / edit / lock.php
1 <?php
2 /*
3    Places an more intrusive warning message in front of the edit screen,
4    if someone else activated the edit box recently (as determined by lock
5    file). An unlock button will be present to override it (spiders may
6    activate the locking feature).
7    This is a poor replacement for the 'patchsaving' extension, and you
8    should normally rather use plugins/edit/warn instead of the lock
9    extension (both use same lock files). Needs EWIKI_TMP set correctly.
10    
11    @feature: edit-lock
12    @title: concurrent edit locking
13    @desc: like the edit-warn extensions, this could be used where 'patchsaving' didn't work
14 */
15
16 $ewiki_plugins["edit_hook"][] = "ewiki_edit_lock";
17
18 function ewiki_edit_lock($id, &$data, $action) {
19
20    $keep = 500;  // in seconds
21    $o = "";
22
23    #-- lock dir
24    if (!file_exists($dir = EWIKI_TMP."/edit.d/")) {
25       mkdir($dir);
26    }
27    
28    #-- check file
29    $lockfile = $dir . ewiki_lowercase($id) . ".lock";
30    $time = 0;
31    if (file_exists($lockfile)) {
32       $time = filemtime($lockfile);
33    }
34
35    #-- force
36    if ($_REQUEST["edit_unlock"]) {
37       unlink($lockfile);
38       $time = -1;
39    }
40
41    #-- automatic unlock on save
42    elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
43       @unlink($lockfile);
44    }
45
46    #-- checking
47    else {
48       if ($time + $keep > time()) {
49          $o = ewiki_t("<p class=\"system-message\"><b>_{Warning}</b>:"
50             . " _{This page is currently being edited by someone else},"
51             . " _{and therefore locked currently}."
52             . " "
53             . '<form action="'.$_SERVER[REQUEST_URI].'" method="POST">'
54             . '<input type="id" name="'."$action/$id".'">'
55             . '<input type="submit" name="edit_unlock" value="_{unlock}">'
56             . '</form>'
57             . "</p>\n");
58       }
59       elseif ($time) {
60          // unlink($lockfile);
61          touch($lockfile);
62       }
63       else {
64          touch($lockfile);
65       }
66    }
67
68    return($o);
69 }
70
71 ?>