edbfa9b9834ba22be5de604942177899fe6e4421
[atutor.git] / mods / wiki / plugins / edit / warn.php
1 <?php
2 /*
3    Puts a warning message above the edit box, if someone else activated
4    the edit screen recently (spiders often interfer with this). This is
5    a poor replacement for the 'patchsaving' extension (see ../feature/).
6    Needs EWIKI_TMP correctly set.
7    
8    @feature: edit-warn
9    @title: concurrent edit warning
10    @desc: if you cannot use 'patchsaving' you should at least warn people if pages are edited concurrently
11 */
12
13 $ewiki_plugins["edit_form_final"][] = "ewiki_edit_warn";
14
15 function ewiki_edit_warn(&$o, $id, &$data, $action) {
16
17    $keep = 420;  // in seconds
18
19    if (!file_exists($dir = EWIKI_TMP."/edit.d/")) {
20       mkdir($dir);
21    }
22
23    $lockfile = $dir . ewiki_lowercase($id) . ".lock";
24    $time = 0;
25    if (file_exists($lockfile)) {
26       $time = filemtime($lockfile);
27    }
28    
29    if ($_SERVER["REQUEST_METHOD"] == "POST") {
30       @unlink($lockfile);
31    }
32    elseif ($time + $keep > time()) {
33       $o = ewiki_t("<p class=\"system-message\"><b>_{Warning}</b>:"
34          . " _{This page is currently being edited by someone else}."
35          . " _{If you start editing now, your changes may get lost}."
36          . "</p>\n")
37          . $o;
38    }
39    elseif ($time) {
40       // unlink($lockfile);
41       touch($lockfile);
42    }
43    else {
44       touch($lockfile);
45    }
46
47 }
48
49 ?>