On Fri Apr 16 05:14:10 2010, exobuzz wrote:
Show quoted text> > I figure that it's related to the title beginning with '''. Anyways,
> > just reporting this, not an important issue to me anymore, I manually
> > edited the page (fix a redirect)
>
> It does look like you are passing a string instead of a hashref to one
> of the functions. However, please post a code snippet. I have edited
> pages with all kinds of characters before.
My program is attached. The error came when I tried to run with
--doubleRedirects and --simulate, so line 97's call to get_page failed
and produced the error.
#!/usr/bin/perl
#
## ZacharyBot, for routine maintenance tasks on the English Wikinews
## This bot is GPL--that's GNU Public License
use strict;
use vars qw($MW %CONF);
use lib "$ENV{'HOME'}/lib";
use DBI;
use DBD::mysql;
use LWP::Simple;
use Getopt::Long;
sub usage {
die <<EOF;
Simulate only: --simulate
Broken Redirects: --brokenRedirects
Double Redirects: --doubleRedirects
EOF
}
my %OPT;
GetOptions(
'doubleRedirects' => \$OPT{doubleRedirects},
'brokenRedirects' => \$OPT{brokenRedirects},
'simulate' => \$OPT{simulate},
);
require "$ENV{HOME}/etc/zacharybot.pl";
use MediaWiki::API;
$MW = MediaWiki::API->new;
$MW->{config}->{api_url} = $CONF{host};
$MW->login({ lgname => $CONF{user}, lgpassword => $CONF{pass} })
|| die $MW->{error}->{code} . ': ' . $MW->{error}->{details};
my $dbh;
if ($OPT{doubleRedirects} || $OPT{brokenRedirects}) {
# only get a DB handle if we are doing something that requires one
$dbh = DBI->connect("dbi:mysql:enwikinews_p:enwikinews-p.db.ts.wikimedia.org:3306", 'zach', '') || die("Couldn't get a DB handle!");
}
sub updateWikinews {
my ($title, $content, $opts) = @_;
my $page = $MW->get_page({ title => $title });
unless ($page->{missing}) {
if ($opts->{mode} eq 'prepend' || $opts->{mode} eq 'append') {
# add prepend/append code
my $original = $page->{'*'};
if ($opts->{mode} eq 'prepend') { $content = $content . $original; }
if ($opts->{mode} eq 'append') { $content = $original . $content; }
}
$MW->edit({
action => 'edit',
title => $title,
text => $content,
summary => $opts->{summary} || "Unspecified bot update",
bot => 1,
}) || die $MW->{error}->{code} . ': ' . $MW->{error}->{details};
}
}
sub fixDoubleRedirects {
my %ns = (
'0' => '',
'1' => 'Talk:',
'2' => 'User:',
'3' => 'User talk:',
'4' => 'Wikinews:',
'5' => 'Wikinews talk:',
'6' => 'Image:',
'7' => 'Image talk:',
'8' => 'MediaWiki:',
'9' => 'MediaWiki talk:',
'10' => 'Template:',
'11' => 'Template talk:',
'12' => 'Help:',
'13' => 'Help talk:',
'14' => 'Category:',
'15' => 'Category talk:',
'100' => 'Portal:',
'101' => 'Portal talk:',
'102' => 'Comments:',
'103' => 'Comments talk:',
);
my $sth = $dbh->prepare(qq{
SELECT pa.page_namespace as namespace, pa.page_title as title, pb.page_namespace as nsb, pb.page_title as tb, pc.page_namespace as nsc, pc.page_title as tc
FROM redirect AS ra, redirect AS rb, page AS pa, page AS pb, page AS pc WHERE ra.rd_from=pa.page_id AND ra.rd_namespace=pb.page_namespace
AND ra.rd_title=pb.page_title AND rb.rd_from=pb.page_id AND rb.rd_namespace=pc.page_namespace AND rb.rd_title=pc.page_title
});
$sth->execute();
while (my $doubleredirect = $sth->fetchrow_hashref) {
# main, talk, and comment only (all others must be done manually)
my $ns = $ns{$doubleredirect->{namespace}};
my $pg = $MW->get_page("$ns$doubleredirect->{title}");
my $tb = $doubleredirect->{tb};
my $nsb = $ns{$doubleredirect->{nsb}};
my $nsc = $ns{$doubleredirect->{nsc}};
my $tc = $doubleredirect->{tc};
$tb =~ s/_/ /g;
$tc =~ s/_/ /g;
my $content = "#REDIRECT[[$nsc$tc]]\n";
if ($pg->{'*'} =~ /\[\[$nsb$tb\]\]/) {
# don't update if the page doesn't redirect to the expected place (replag sucks)
if ($OPT{simulate}) { # to simulate what would happen instead of actually doing anything
print "$ns$doubleredirect->{title}:\n$pg->{content}\n to\n$content\n";
} else {
updateWikinews($ns . $doubleredirect->{title}, $content, {
mode => '',
summary => 'Fixing [[Special:Doubleredirects|double redirects]]',
minor => 1,
});
sleep 5;
}
} else {
print "Skipped: $ns$doubleredirect->{title} (already fixed?)\n\n" if $OPT{simulate};
}
}
}
sub flagBrokenRedirects {
my $sth = $dbh->prepare(qq{
SELECT p1.page_namespace AS namespace, p1.page_title AS title, rd_namespace, rd_title FROM redirect AS rd JOIN page p1 ON (rd.rd_from=p1.page_id)
LEFT JOIN page AS p2 ON (rd_namespace=p2.page_namespace AND rd_title=p2.page_title ) WHERE rd_namespace >= 0 AND p2.page_namespace IS NULL
});
$sth->execute();
while (my $brokenredirect = $sth->fetchrow_hashref) {
# main, talk, and comment only (all others must be done manually)
next unless $brokenredirect->{namespace} == 0 || $brokenredirect->{namespace} == 1 || $brokenredirect->{namespace} == 102;
my $ns = "";
$ns = "Talk:" if $brokenredirect->{namespace} == 1;
$ns = "Comments:" if $brokenredirect->{namespace} == 102;
updateWikinews($ns . $brokenredirect->{title}, "{{delete|Broken redirect flagged with ZacharyBot (please check if there's any way to fix the redirect prior to deleting)}}", {
mode => 'prepend',
summary => 'Flagging [[Special:Brokenredirects|broken redirects]] for deletion',
});
sleep 5;
}
}
flagBrokenRedirects() if $OPT{brokenRedirects};
fixDoubleRedirects() if $OPT{doubleRedirects};
1;