69fb2129029adba6ca5e914937dfd160c20d5c8c
[atutor.git] / mods / wiki / tools / t_holes.php
1 <?php
2   include("t_config.php");
3 ?>
4 <html>
5 <head>
6  <title>strip old versions of ewiki pages</title>
7  <link rel="stylesheet" type="text/css" href="t_config.css">
8 <script language="JavaScript">
9  function sel_all() {
10     var ls = document.forms[0].elements;  // getElementsByTagName("input");
11     for (var i=0; i<ls.count(); i++) {
12        if (ls[i].type == "checkbox") {
13           ls[i].checked = ! ls[i].checked;
14        }
15     }
16  }
17 </script>
18 </head>
19 <body bgcolor="#ffffff" text="#000000">
20 <h1>create page version holes</h1>
21 <?php
22
23
24 define("N_PAGE_VERSIONS", 1);
25
26
27   if (empty($_REQUEST["range"])) {
28
29      echo '
30 This tool can be used to remove old page versions from the database, if
31 they just slow down your wiki. For a db_flat_files/db_fast_files powered
32 ewiki you could just delete the files from the database directory.
33 <br><br>
34 Please note, that the right number is always treated as count from the
35 last existing version. So "2..-10" would delete anything from the 2nd to
36 the "LAST minus 10"-th version.
37 <br><br>
38 <form action="t_holes.php" method="POST">
39 <table class="list" border="0" cellpadding="2" cellspacing="3">
40 ';
41
42      $result = ewiki_db::GETALL(array());
43      while ($row = $result->get()) {
44
45         if (($n=$row["version"]) >= N_PAGE_VERSIONS) {
46
47            $id = $row["id"];
48
49            echo '<tr>';
50            echo "<td>".htmlentities($id)." (#$n)</td>";
51            $n2 = $n - 10;
52            echo '<td> <input type="checkbox" name="id['.rawurlencode($id).']" value="1">'.
53                 ' delete versions ' .
54                 '<input name="range['.rawurlencode($id).']" value="2..'.$n2.'" size="7"> </td>';
55            echo "</tr>\n";
56
57         }
58
59      }
60
61      echo '
62 </table>
63 <br><input type="submit" value="strip page versions"><br>
64 </form>
65 <br>
66 [<a href="javascript:sel_all();">select all</a>]
67 <br>
68 <br>
69 Eventually you should consider using the <tt>ewikictl</tt> cmdline
70 utility in favour of this www script.
71 <br><br>
72      ';
73
74   }
75   else {
76
77      echo "purging page versions:<br>";
78
79      $range = $_REQUEST["range"];
80
81      foreach ($_REQUEST["id"] as $id_ue => $go) {
82         $id = rawurldecode($id_ue);
83
84         if ($go) {
85
86            if (preg_match('/^(\d+)[-\s._:]+(\d+)$/', trim($range[$id_ue]), $uu)) {
87
88               $versA = $uu[1];
89               $versZ = $uu[2];
90               echo "'".htmlentities($id)."' versions {$versA}..{$versZ}<br>\n";
91
92               for ($v=$versA; $v<=$versZ; $v++) {
93
94                  ewiki_db::DELETE($id, $v);
95
96               }
97               
98            }
99            else {
100
101               echo "wrong range param for '$id'!<br>\n";
102
103            }
104
105         }
106      }
107
108   }
109
110
111
112 ?>