Difference between revisions of "Caretaker.pl"

From Organic Design wiki
m
(cat maths articles)
Line 50: Line 50:
 
if ($title =~ /^[a-z0-9-]+\.(com?|edu|govt?|net|org|mil|info|school|iwi|ac|geek|aero|biz|coop|museum|name|pro)(\.[a-z]{2})?$/i) {
 
if ($title =~ /^[a-z0-9-]+\.(com?|edu|govt?|net|org|mil|info|school|iwi|ac|geek|aero|biz|coop|museum|name|pro)(\.[a-z]{2})?$/i) {
 
push @links, 'Domain names';
 
push @links, 'Domain names';
push @comments, 'cat in [[:Category:Domain names|Domain names]]';
+
push @comments, 'cat in [[Category:Domain names|Domain names]]';
 +
}
 +
if ($article =~ /<\/math>/) {
 +
push @links, 'Articles containing maths';
 +
push @comments, 'cat in [[Category:Articles containing maths|Maths]]';
 
}
 
}
 
my %links = (); $links{$_} = 1 for @links; @links = sort keys %links; # remove duplicate cats
 
my %links = (); $links{$_} = 1 for @links; @links = sort keys %links; # remove duplicate cats

Revision as of 19:40, 2 November 2006

use DBI;

sub formatLink { my $link = shift; $link =~ tr/_/ /; return $link; }

sub caretaker { my $dbh = DBI->connect('DBI:mysql:wiki',lc $::peer,$::pwd1) or die DBI->errstr; my @ns = (,'Talk:','User:','User talk:','Project:','Project talk:', 'Image:','Image talk:','Mediawiki:','Mediawiki talk:','Template:', 'Template talk:','Help:','Help talk:','Category:','Category talk:');

# Get id of first article after mediawiki built in articles my $sth = $dbh->prepare('SELECT cur_id FROM cur WHERE cur_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 cur_id FROM cur ORDER BY cur_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 cur_namespace,cur_title,cur_is_redirect FROM cur WHERE cur_id=?'); my $done = 'none'; for ($first..$last) { $sth->execute($_); @row = $sth->fetchrow_array; my @comments = (); my $title = $ns[$row[0]].$row[1]; if ($title && ($row[2] == 0)) {

# Read the article content my $article = my $backup = wikiRawPage $::wiki, $title; my $isCode = $title =~ /\.(as|c|cpp|c\+\+|h|css|html?|pl|php|R|tex|xml|xslt)$/i;

# --------------------------------------------------------------------------------------------------------------------- #

if (!$isCode) {

# Format catlinks and normal links my $tmp = $article; my @links = $article =~ /\[{2}category:([^\]]+)\]{2}/ig; if ($title =~ /^[a-z0-9-]+\.(com?|edu|govt?|net|org|mil|info|school|iwi|ac|geek|aero|biz|coop|museum|name|pro)(\.[a-z]{2})?$/i) { push @links, 'Domain names'; push @comments, 'cat in'; } if ($article =~ /<\/math>/) { push @links, 'Articles containing maths'; push @comments, 'cat in'; } my %links = (); $links{$_} = 1 for @links; @links = sort keys %links; # remove duplicate cats if ($#links >= 0) { my $cats = ; for (@links) { tr/_/ /; $cats .= ""; } $article =~ s/\s*\[{2}\s*category:[^\]]+\s*\]{2} *//sig; $article =~ s/^\s+//; } $tmp = ($tmp ne $article); push @comments, 'Format links' if $article =~ s/(\[{2}[^\]\r\n]+\]{2})/formatLink($1)/eg; # Format normal links if ($tmp && ($#links >= 0)) { $article = "$cats\n$article"; push @comments, 'Format cat links' }

# Format headings $tmp = $article; $article =~ s/[\r\n]+(=+)\s*([^\r\n]+?)\s*=+[\r\n]+/\n\n$1 $2 $1\n/g; push @comments, 'Format headings' if $article ne $tmp;

}

# Common typo's - put square brackets around first letter so it doesn't get caretaken itself! my $typos = $article =~ s/[i]mpliment/implement/g + $article =~ s/[d]ependance/dependence/g + $article =~ s/[h]ardwire/hard-wire/g; push @comments, ($typos == 1 ? 'typo' : 'typos') if $typos;

# Apply rules to Xml:Articles if ($title =~ /^Xml:/) {

# Remove empty elements push @comments, 'removed empty elements' if $article =~ s/^\s*<(read|write|category|init|data|view|edit|save)>\s*<\/\w+>[\r\n]*//gms;

}

# --------------------------------------------------------------------------------------------------------------------- #

# If article changed, write and comment if ($article ne $backup) { wikiPageEdit $::wiki, $title, $article, 'Caretaker: '.join(', ',@comments), 1; $done = $done + 1; } } sleep(1); }

my $comment = "Daily caretaking tasks completed: ".($last-$first)." articles examined, $done adjusted."; logAdd $comment; wikiLogin($::wiki, $::peer, $::pwd1); wikiPageAppend($::wiki, $::wikilog, "\n*".localtime()." : $comment", $comment); $sth->finish; $dbh->disconnect; }