Caretaker.pl
From Organic Design wiki
#!/usr/bin/perl
use DBI;
require "wiki.pl";
# Wiki settings
$::wiki = "http://www.organicdesign.co.nz/wiki/index.php";
$::wikiuser = 'bender';
$::wikipass = '******';
# DB settings
$::dbname = 'od';
$::dbpfix = '';
$::dbuser = $::wikiuser;
$::dbpass = $::wikipass;
# Login to wiki
wikiLogin($::wiki, $::wikiuser, $::wikipass);
my %ns = wikiGetNamespaces($::wiki);
# Connect to DB
my $dbh = DBI->connect('DBI:mysql:'.$::dbname, lc $::dbuser, $::dbpass) or die DBI->errstr;
# Get id of first article after mediawiki built in articles
my $sth = $dbh->prepare('SELECT page_id FROM '.$::dbpfix.'page WHERE page_title = "Zhconversiontable"');
$sth->execute();
my @row = $sth->fetchrow_array;
$sth->finish;
my $first = $row[0]+1;
# Get last article id
my $sth = $dbh->prepare('SELECT page_id FROM '.$::dbpfix.'page ORDER BY page_id DESC');
$sth->execute();
@row = $sth->fetchrow_array;
$sth->finish;
my $last = $row[0];
# Loop through all articles one per second
my $sth = $dbh->prepare('SELECT page_namespace,page_title,page_is_redirect FROM '.$::dbpfix.'page WHERE page_id=?');
my $done = 'none';
for ($first..$last) {
$sth->execute($_);
@row = $sth->fetchrow_array;
my @comments = ();
my $title = $ns{$row[0]} ? $ns{$row[0]}.':'.$row[1] : $row[1];
if ($title && ($row[2] == 0)) {
print "$title\n";
# Read the article content
$text = wikiRawPage($::wiki, $title);
$text =~ s/^\s+//;
$text =~ s/\s+$//;
my $backup = $text;
# ------ REPLACEMENT RULES --------------------------------------------------------------- #
# Common typo's - put square brackets around first letter so it doesn't get caretaken itself!
my $typos
= $text =~ s/[i]mpliment/implement/g
+ $text =~ s/[d]ependance/dependence/g
+ $text =~ s/[f]reind/friend/g;
push @comments, ($typos == 1 ? 'typo' : 'typos') if $typos;
# ---------------------------------------------------------------------------------------- #
# If article changed, write and comment
$text =~ s/^\s+//;
$text =~ s/\s+$//;
if ($text ne $backup) {
wikiPageEdit($::wiki, $title, $text, join(', ',@comments), 1);
$done = $done + 1;
}
}
sleep(0.2);
}
$sth->finish;
$dbh->disconnect;