Difference between revisions of "Caretaker.pl"

From Organic Design wiki
(add a rule for testing)
(needs to be a function)
Line 1: Line 1:
 
use DBI;
 
use DBI;
my $dbh = DBI->connect('DBI:mysql:wiki',$::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 last article id
+
sub caretaker {
my $sth = $dbh->prepare('SELECT cur_id FROM cur ORDER BY cur_id DESC');
+
my $dbh = DBI->connect('DBI:mysql:wiki',$::peer,$::pwd1) or die DBI->errstr;
$sth->execute();
+
my @ns = ('','Talk:','User:','User talk:','Project:','Project talk:',
my @row = $sth->fetchrow_array;
+
'Image:','Image talk:','Mediawiki:','Mediawiki talk:','Template:',
$sth->finish;
+
'Template talk:','Help:','Help talk:','Category:','Category talk:');
my $last = $row[0];
 
  
# Loop through all articles one per second
+
# Get last article id
my $sth = $dbh->prepare('SELECT cur_namespace,cur_title FROM cur WHERE cur_id=?');
+
my $sth = $dbh->prepare('SELECT cur_id FROM cur ORDER BY cur_id DESC');
my $done = 0;
+
$sth->execute();
my @comments = ();
+
my @row = $sth->fetchrow_array;
for (0..$last) {
+
$sth->finish;
$sth->execute($_);
+
my $last = $row[0];
@row = $sth->fetchrow_array;
 
if (my $title = $ns[$row[0]].$row[1]) {
 
  
# Read the article content
+
# Loop through all articles one per second
my $article = my $backup = wikiRawPage $::wiki, $title;
+
my $sth = $dbh->prepare('SELECT cur_namespace,cur_title FROM cur WHERE cur_id=?');
 +
my $done = 0;
 +
my @comments = ();
 +
for (0..$last) {
 +
$sth->execute($_);
 +
@row = $sth->fetchrow_array;
 +
if (my $title = $ns[$row[0]].$row[1]) {
  
# Apply rules to Xml:Articles
+
# Read the article content
if ($title =~ /^Xml:/) {
+
my $article = my $backup = wikiRawPage $::wiki, $title;
my $comment = '';
+
 
$comment = 'removed empty elements' if $article =~ s/^\s*<(read|write|category|init|data|view|edit|save)>\s*<\/\w+>[\r\n]*//gms;
+
# Apply rules to Xml:Articles
 +
if ($title =~ /^Xml:/) {
 +
my $comment = '';
 +
$comment = '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
 +
wikiPageEdit $::wiki, $title, $article, join(', ',@comments) if $article ne $backup;
 
}
 
}
 +
sleep(1);
 +
}
  
# If article changed, write and comment
+
my $comment = "Daily caretaking tasks completed: $last articles examined, $done adjusted.";
wikiPageEdit $::wiki, $title, $article, join(', ',@comments) if $article ne $backup;
+
logAdd $comment;
}
+
wikiLogin($::wiki, $::peer, $::pwd1);
sleep(1);
+
wikiPageAppend($::wiki, $::wikilog, "\n*".localtime()." : $comment", $comment);
 +
$sth->finish;
 +
$dbh->disconnect;
 
}
 
}
 
my $comment = "Daily caretaking tasks completed: $last articles examined, $done adjusted.";
 
logAdd $comment;
 
wikiLogin($::wiki, $::peer, $::pwd1);
 
wikiPageAppend($::wiki, $::wikilog, "\n*".localtime()." : $comment", $comment);
 
$sth->finish;
 
$dbh->disconnect;
 

Revision as of 02:18, 24 October 2006

use DBI;

sub caretaker { my $dbh = DBI->connect('DBI:mysql:wiki',$::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 last article id my $sth = $dbh->prepare('SELECT cur_id FROM cur ORDER BY cur_id DESC'); $sth->execute(); my @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 FROM cur WHERE cur_id=?'); my $done = 0; my @comments = (); for (0..$last) { $sth->execute($_); @row = $sth->fetchrow_array; if (my $title = $ns[$row[0]].$row[1]) {

# Read the article content my $article = my $backup = wikiRawPage $::wiki, $title;

# Apply rules to Xml:Articles if ($title =~ /^Xml:/) { my $comment = ; $comment = '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 wikiPageEdit $::wiki, $title, $article, join(', ',@comments) if $article ne $backup; } sleep(1); }

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