3 # Nuke idle wiki accounts from the wiki's user database.
5 # Copyright (C) 2005 Ralf Baechle (ralf@linux-mips.org)
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version.
12 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 # NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 # You should have received a copy of the GNU General Public License along
24 # with this program; if not, write to the Free Software Foundation, Inc.,
25 # 675 Mass Ave, Cambridge, MA 02139, USA.
28 my $database = "DBI:mysql:database=wikidb;host=localhost";
29 my $dbuser = "wikiuser";
30 my $dbpasswd = "password";
53 my ($ref, $dbh, $sth, $killed);
55 # Connect to the database.
56 $dbh = DBI
->connect($database, $dbuser, $dbpasswd, {RaiseError
=> 1});
58 $sth = $dbh->prepare("SELECT * FROM user");
61 $ref = $sth->fetchrow_hashref();
63 if ($sth->rows == 0) {
64 print "There is no user in this wiki.\n";
68 while ($ref = $sth->fetchrow_hashref()) {
69 my ($user_id, $user_name, $cph, $oph, $edits);
71 $user_name = $ref->{user_name
};
72 $user_id = $ref->{user_id
};
74 print "Annihilating user " . $user_name .
75 " has user_id " . $user_id . ".\n";
78 $cph = $dbh->prepare("SELECT * FROM cur where " .
79 "cur_user = $user_id" .
81 "cur_user_text = " . $dbh->quote("$user_name"));
84 $oph = $dbh->prepare("SELECT * FROM old where " .
85 "old_user = $user_id" .
87 "old_user_text = " . $dbh->quote("$user_name"));
90 $edits = $cph->rows + $oph->rows;
97 print "Keeping user " . $user_name .
98 ", user_id " . $user_id . ".\n";
102 "DELETE FROM user WHERE user_name = " .
103 $dbh->quote("$user_name") .
105 "user_id = $user_id");
116 print "Killed " . $killed . " users\n";
120 my (@users, $user, $this, $opts);
125 foreach $this (@ARGV) {
126 if ($opts == 1 && $this eq '-v') {
128 } elsif ($opts == 1 && $this eq '--verbose') {
130 } elsif ($opts == 1 && $this eq '--') {