Content deleted Content added
Updating published sources: RedirectBypasser: * Prepare for trial run. |
Updating published sources: General: * Update for the addition of 'rvslots'. DatedCategoryDeleterTest: * Disable. It's clear that task won't be needed. BrokenRedirectDeleter: * Handle pages with newlines before the <code>#REDIRECT</code>. |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1:
{{ombox|type=notice|text=
<syntaxhighlight lang="perl">
package tasks::RedirectBypasser;
Line 10:
Task: RedirectBypasser
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 63
Status:
Created: 2012-05-11
OnDemand: true
Line 60:
'User talk:Nard the Bard',
'User talk:N',
'User talk:Anomie',
'User talk:AnomieBOT',
'Wikipedia:Bots/Requests for approval/AnomieBOT 63',
);
Line 66 ⟶ 69:
my $self=$class->SUPER::new();
$self->{'iter'}=undef;
$self->{'err'}={};
$self->{'noerr'}=0;
bless $self, $class;
return $self;
Line 73 ⟶ 78:
=for info
=cut
sub approved {
return
}
Line 121 ⟶ 126:
$skip=qr/$skip/;
my $iter=$
if(!$iter){
generator => 'backlinks',▼
gbltitle => [keys %redirects],
);▼
);
$self->{'iter'}=$iter;
$self->{'err'}={};
$self->{'noerr'}=0;
my $endtime=time()+300;
while(my $p=$iter->next){
return 0 if $api->halting;
Line 135 ⟶ 147:
next if $p->{'title'}=~/$skip/;
delete $self->{'err'}{$p->{'title'}};
my $tok=$api->edittoken($p->{'title'}, EditRedir=>1);
Line 143 ⟶ 156:
if($tok->{'code'} eq 'pageprotected'){
$api->warn("Cannot edit $p->{title}: Page is protected\n");
$
next;
}
if($tok->{'code'} eq 'botexcluded'){
$api->warn("Cannot edit $p->{title}: Bot exclusion applies\n");
$
next;
}
if($tok->{'code'} ne 'success'){
$api->warn("Failed to get edit token for $p->{title}: ".$tok->{'error'}."\n");
$self->{'noerr'}=1;
return 0;
}
my $intxt=$tok->{'revisions'}[0]{'slots'}{'main'}{'*'};
my ($outtxt,$nowiki)=$api->strip_nowiki($intxt);
Line 172 ⟶ 186:
if($res->{'code'} ne 'success'){
$api->warn("Write failed on $p->{title}: ".$res->{'error'}."\n");
$self->{'noerr'}=1;
next;
} else {
# In case one of the "cannot find redirects" pages transcluded
# this one.
$self->{'noerr'}=1;
}
} else {
$res=$api->query(action=>'purge', titles=>$p->{'title'}, forcelinkupdate=>1);
if($res->{'code'} ne 'success'){
$self->{'noerr'}=1;
next;
}
# Now check links again
$res=$api->query(titles=>$p->{'title'}, prop=>'links', pllimit=>'max', pltitles=>$iter->iterval);
if($res->{'code'} ne 'success'){
$self->{'noerr'}=1;
next;
}
$res=(values %{$res->{'query'}{'pages'}})[0]{'links'} // [];
if(grep $_->{'title'} eq $iter->iterval, @$res){
$api->warn("Cannot find redirects in $p->{title}\n");
$self->{'err'}{$p->{'title'}}="cannot find redirects; they are probably template-generated or oddly formatted";
} else {
# Problem resolved!
}
next;
}
# If we've been at it long enough, let another task have a go.
return 0 if time()>$endtime;
}
my $ne=($self->{'noerr'} && %{$self->{'err'}});
if(!$ne && %{$self->{'err'}}){
my $msg="The following issues were encountered while bypassing redirects:\n";
for my $p (sort keys %{$self->{'err'}}) {
$msg.="* [[:$p]]: ".$self->{'err'}{$p}."\n";
}
$msg.="Please bypass the redirects in these pages manually. Thanks.";
$api->whine("Redirect bypass issues", $msg, Pagename => $notify);
}
$self->{'iter'}=undef;
$self->{'err'}={};
$self->{'noerr'}=0;
# Restart the scan immediately to find out if there are any real errors.
return 0 if $ne;
$api->log("Task may be complete!");
|