User:AnomieBOT/source/tasks/RedirectBypasser.pm: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: RedirectBypasser: * Prepare for trial run.
AnomieBOT (talk | contribs)
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= ApprovalApproved requested2012-06-06<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 63]]}}
<syntaxhighlight lang="perl">
package tasks::RedirectBypasser;
Line 10:
Task: RedirectBypasser
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 63
Status: BRFAApproved 2012-06-06
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
ApprovalApproved requested2012-06-06<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 63]]
 
=cut
 
sub approved {
return 0-1;
}
 
Line 121 ⟶ 126:
$skip=qr/$skip/;
 
my $iter=$apiself->iterator({'iter'};
if(!$iter){
generator => 'backlinks',
gbltitle $iter=$api-> [keys %redirects],iterator(
gbllimit generator => 'maxbacklinks',
gbltitle => [keys %redirects],
);
generator gbllimit => 'backlinksmax',
);
$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");
$api->whine("Cannot bypass redirects in [[:$pself->{title'err'}]]", "I cannot bypass redirects in [[:{$p->{'title'}]], because the }="page is protected. Please bypass them manually. Thanks.", Pagename => $notify);
next;
}
if($tok->{'code'} eq 'botexcluded'){
$api->warn("Cannot edit $p->{title}: Bot exclusion applies\n");
$api->whine("Cannot bypass redirects in [[:$pself->{title'err'}]]", "I cannot bypass redirects in [[:{$p->{'title'}]],}="bot because I am excluded from editing that page usingexclusion ({{tl|bots}} or {{tl|nobots}}.) Please bypass them manually. Thanks.applies", Pagename => $notify);
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 {
$api->warn("Cannot# findPurge, redirectsthanks into $p->{title}\n");bug 5382
$res=$api->query(action=>'purge', titles=>$p->{'title'}, forcelinkupdate=>1);
$api->whine("Cannot bypass redirects in [[:$p->{title}]]", "I cannot find the redirects to bypass in [[:$p->{title}]], although the API tells me they are there. Chances are it is either because of links generated by templates or unusual formatting breaking up the link text. Please bypass them manually. Thanks.", Pagename => $notify);
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!");