Difference between revisions of "Caretaker.pl"
(not needed in sub anymore cos not called by wikid.pl) |
(updated after solapac run) |
||
| Line 2: | Line 2: | ||
# {{perl}} | # {{perl}} | ||
use DBI; | 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); | ||
| − | my $dbh = DBI->connect('DBI:mysql: | + | # 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 | # Get id of first article after mediawiki built in articles | ||
| − | my $sth = $dbh->prepare('SELECT | + | my $sth = $dbh->prepare('SELECT page_id FROM '.$::dbpfix.'page WHERE page_title = "Zhconversiontable"'); |
$sth->execute(); | $sth->execute(); | ||
my @row = $sth->fetchrow_array; | my @row = $sth->fetchrow_array; | ||
| Line 23: | Line 30: | ||
# Get last article id | # Get last article id | ||
| − | my $sth = $dbh->prepare('SELECT | + | my $sth = $dbh->prepare('SELECT page_id FROM '.$::dbpfix.'page ORDER BY page_id DESC'); |
$sth->execute(); | $sth->execute(); | ||
@row = $sth->fetchrow_array; | @row = $sth->fetchrow_array; | ||
| Line 30: | Line 37: | ||
# Loop through all articles one per second | # Loop through all articles one per second | ||
| − | my $sth = $dbh->prepare('SELECT | + | my $sth = $dbh->prepare('SELECT page_namespace,page_title,page_is_redirect FROM '.$::dbpfix.'page WHERE page_id=?'); |
my $done = 'none'; | my $done = 'none'; | ||
for ($first..$last) { | for ($first..$last) { | ||
| Line 36: | Line 43: | ||
@row = $sth->fetchrow_array; | @row = $sth->fetchrow_array; | ||
my @comments = (); | my @comments = (); | ||
| − | my $title = $ns[$row[0]] | + | my $title = $ns{$row[0]} ? $ns{$row[0]}.':'.$row[1] : $row[1]; |
if ($title && ($row[2] == 0)) { | if ($title && ($row[2] == 0)) { | ||
| + | print "$title\n"; | ||
# Read the article content | # Read the article content | ||
| − | $ | + | $text = wikiRawPage($::wiki, $title); |
| − | $ | + | $text =~ s/^\s+//; |
| − | $ | + | $text =~ s/\s+$//; |
| − | my $backup = $ | + | my $backup = $text; |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | # ------ REPLACEMENT RULES --------------------------------------------------------------- # | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
# Common typo's - put square brackets around first letter so it doesn't get caretaken itself! | # Common typo's - put square brackets around first letter so it doesn't get caretaken itself! | ||
my $typos | 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; | push @comments, ($typos == 1 ? 'typo' : 'typos') if $typos; | ||
| − | # | + | # ---------------------------------------------------------------------------------------- # |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
# If article changed, write and comment | # If article changed, write and comment | ||
| − | $ | + | $text =~ s/^\s+//; |
| − | $ | + | $text =~ s/\s+$//; |
| − | if ($ | + | if ($text ne $backup) { |
| − | wikiPageEdit $::wiki, $title, $ | + | wikiPageEdit($::wiki, $title, $text, join(', ',@comments), 1); |
$done = $done + 1; | $done = $done + 1; | ||
} | } | ||
} | } | ||
| − | sleep( | + | sleep(0.2); |
} | } | ||
| − | |||
| − | |||
| − | |||
$sth->finish; | $sth->finish; | ||
$dbh->disconnect; | $dbh->disconnect; | ||
Revision as of 06:34, 12 July 2008
- !/usr/bin/perl
- Our Perl scripts.
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;



