24f329605dde340c71c29087c4a8dc5a4aa6d166
[atutor.git] / mods / wiki / tools / t_revert.php
1 <?php
2    include("t_config.php");
3 ?>
4 <html>
5 <head>
6  <title>Revert changes</title>
7  <link rel="stylesheet" type="text/css" href="t_config.css">
8 </head>
9 <body bgcolor="#ffffff" text="#000000">
10 <h1>RevertChanges</h1>
11 <?php
12
13
14 if (($do = $_REQUEST["proceed"]) || ($_REQUEST["list"])) {
15
16    if (!$do) {
17       echo "<b>Warning</b>: running in <i>dummy mode</i> (--no-act), nothing will happen, all following messages are lies:\n<br><br>\n";
18    }
19
20    #-- params
21    $m_author = $_REQUEST["match_author"];
22    $m_time = $_REQUEST["time_slice"] * 3600;
23    $action = $_REQUEST["action"];
24    ($depth = $_REQUEST["version_depth"] - 1) or ($depth = 0);
25
26    #-- walk through
27    $result = ewiki_db::GETALL(array("id", "author", "lastmodified"));
28    while ($row = $result->get()) {
29
30          $id = $row["id"];
31
32          #-- which versions to check
33          $verZ = $row["version"];
34          if ($action=="lastonly") {
35             $verA = $verZ;
36          }
37          else {
38             $verA = $verZ-$depth;
39             if ($verA <= 0) { 
40                $verA = 1;
41             }
42          }
43
44
45          for ($ver=$verA; $ver<=$verZ; $ver++) {
46
47             #-- load current $ver database entry
48             if ($verA != $verZ) {
49                $row = ewiki_db::GET($id, $ver);
50             }
51  
52             #-- match
53             if (stristr($row["author"], $m_author) && ($row["lastmodified"] + $m_time > time())) {
54                echo "rm($id";
55                #-- delete multiple versions
56                if ($action=="allsince") {
57                   while ($ver<=$verZ) {
58                      echo " .$ver";
59                      if ($do) {
60                         ewiki_db::DELETE($id, $ver);
61                      }
62                      $ver++;
63                   }
64                }
65                #-- or just the affected one
66                else {
67                   echo " .$ver";
68                   if ($do) {
69                      ewiki_db::DELETE($id, $ver);
70                   }
71                }
72                echo ")<br>\n";
73                break;
74             }
75
76          }#-- for($ver)
77
78    }#-- while($row)
79
80
81 }
82 else {
83
84    ?>
85      If someone garbaged lots of pages in your Wiki, you may want to
86      automatically revert those changes, by making this script delete any
87      page versions that carry a certain string in the {author} field
88      (usually the IP address or host name).<br><br>
89      <form action="<?php echo $PHP_SELF; ?>" method="GET">
90        {author} field pattern <input name="match_author" size="30" value="127.127.127.127:">
91        <br>
92        <small>This must be a fixed string (you cannot use * or regex), at
93        best use the attackers` IP address or host name, but don't include
94        the port number (because it increased with every http access).
95        </small>
96        <br><br>
97        changes within the last <input name="time_slice" size="4" value="72"> hours
98        <br><br>
99        how to operate:<br>
100        <select name="action" size="3">
101          <option selected value="lastonly">delete only if it was the last change</option>
102          <option value="allsince">version diving, also delete changes made after</option>
103          <option value="the">version diving, but only purge the affected one</option>
104        </select>
105        <br>
106        delete the last <input name="version_depth" size="2" value="5"> versions at max
107        <br><br>
108        <input type="submit" name="list" value="--no-act">
109        <input type="submit" name="proceed" value="revert changes">
110      </form>
111      <?php 
112
113 }
114
115
116
117 ?>
118 </body>
119 </html>