Content deleted Content added
Updating published sources: General: * New function to load a task (once). * Update the various scripts to use that function. * Update metadata for all tasks. SourceUploader: * Generate a new file, User:AnomieBOT/TaskList, since I keep forgetting |
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>. |
||
(10 intermediate revisions by the same user not shown) | |||
Line 1:
{{ombox|type=notice|text= Approved 2009-01-03<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 20]]}}
<
package tasks::AFDMergeFromCleaner;
Line 7:
=begin metadata
Bot: AnomieBOT
Task: AFDMergeFromCleaner
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 20
Status: Approved 2009-01-03
Created: 2008-12-29
Remove instances of {{tl|afd-
Report instances of {{tl|afd-
to a different target.
Line 51:
my $res;
$api->task('AFDMergeFromCleaner', 0, 10, qw/d::Templates d::Redirects/);
if($self->{'nextrun'}==0 && exists($api->store->{'nextrun'})){
my $t=$api->
$self->{'nextrun'}=
}
my $starttime=time();
Line 63 ⟶ 61:
return $t if $t>0;
my @templates=('Afd-
my $screwup=' Errors? [[User:'.$api->user.'/shutoff/AFDMergeFromCleaner]]';
my $report='User:'.$api->user.'/Afd-mergefrom report';
# Get a list of templates redirecting to our targets
my %templates=$api->redirects_to_resolved(map "Template:$_", @templates);
$api->warn("Failed to get redirects to target templates: ".$templates{''}{'error'}."\n");
list => 'backlinks',▼
bllimit => 'max',▼
);▼
$templates{$_->{'title'}}=1 foreach (@{$res->{'query'}{'backlinks'}});▼
}
Line 98 ⟶ 90:
$res=$api->query(%q);
if($res->{'code'} ne 'success'){
$
$ret=60;
last MAINLOOP;
Line 118 ⟶ 110:
}
$
if($res->{'code'} ne 'success'){
$api->warn("Failed to retrieve redirect target for $subject: ".$res->{'error'}."\n");
my $rsubject=$subject;
$rsubject=$_->{'to'} if($_->{'from'} eq $rsubject);
}
$api->log("Checking for $template in $title");
# WTF?
if(exists($_->{'missing'})){
$
next;
}
Line 129 ⟶ 132:
my $tok=$api->edittoken($title);
if($tok->{'code'} eq 'shutoff'){
$
return 300;
}
if($tok->{'code'} ne 'success'){
$
$ret=60;
last MAINLOOP;
Line 140 ⟶ 143:
# Get page text
my $intxt=$tok->{'revisions'}[0]{'slots'}{'main'}{'*'};
# First, find the template and pull out the relevant parameter
my @from=();
$
return undef unless exists($templates{'Template:'.$_[0]});
my $f=undef;
foreach ($
($f=$_->{'value'})=~s/^\s+|\s+$//g if $_->{'name'} eq 1;
}
Line 160 ⟶ 163:
$res=$api->query(titles => join('|',@f), redirects=>1);
if($res->{'code'} ne 'success'){
$
$ret=60;
last MAINLOOP;
Line 167 ⟶ 170:
foreach (@{$res->{'query'}{'redirects'}}){
my ($f,$t)=($_->{'from'}, $_->{'to'});
if($t eq $subject || $t eq $rsubject){
$f=$norm{$f} if exists($norm{$f});
$remove{$f}=1;
} elsif($subject ne $rsubject){
$redirected{"$f>$rsubject>$t"}="| {{$linktmpl|$f}} || {{$linktmpl|$subject}}<br />→ {{$linktmpl|$rsubject}} || {{$linktmpl|$t}} || ";
} else {
$redirected{"$f>$subject>$t"}="| {{$linktmpl|$f}} || {{$linktmpl|$subject}} || {{$linktmpl|$t}} || ";
Line 186 ⟶ 191:
# Remove the removable templates
my $outtxt=$
my $name=shift;
my @params=@{shift()};
Line 195 ⟶ 200:
return undef unless exists($templates{'Template:'.$name});
my $f=undef;
foreach ($
($f=$_->{'value'})=~s/^\s+|\s+$//g if $_->{'name'} eq 1;
}
Line 208 ⟶ 213:
if($outtxt ne $intxt){
my $summary="Removing obsolete {{$template}}";
$
my $r=$api->edit($tok, $outtxt, $summary.$screwup, 1, 1);
if($r->{'code'} ne 'success'){
$
next;
}
Line 222 ⟶ 227:
my $tok=$api->edittoken($report);
if($tok->{'code'} eq 'shutoff'){
$
return 300;
}
if($tok->{'code'} ne 'success'){
$
$ret=60;
last;
}
my $intxt=
foreach my $s (split(/(?=(?:^|\n)==)/, $intxt)){
if($s=~/^\n?==\s*Redirected\s*==/){
Line 250 ⟶ 255:
}
my $outtxt="== Redirected ==\n";
$outtxt.="The following table lists pages referred to by {{tl|afd-
$outtxt.="{| class=\"wikitable sortable\"\n";
$outtxt.="! Page !! AFD merge to !! Redirect to !! Note\n";
Line 257 ⟶ 262:
$outtxt.="\n|}\n\n";
$outtxt.="== Deleted ==\n";
$outtxt.="The following table lists deleted pages that were referred to by {{tl|afd-
$outtxt.="{| class=\"wikitable sortable\"\n";
$outtxt.="! Page !! AFD merge to !! Note\n";
Line 266 ⟶ 271:
if($outtxt ne $intxt){
my $summary="Updating list of non-matching merges";
$
my $r=$api->edit($tok, $outtxt, $summary.$screwup, 1, 1);
if($r->{'code'} ne 'success'){
$
$ret=60;
}
Line 277 ⟶ 282:
$starttime+=$ret;
$self->{'nextrun'}=$starttime;
$api->store
return $ret;
Line 284 ⟶ 289:
1;
</syntaxhighlight>
|