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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: General: * New task, AFDMergeFromCleaner.
 
AnomieBOT (talk | contribs)
Updating published sources: PUICloser: * Approved! AFDMergeFromCleaner: * Add handling of deleted pages * Clean up reporting code * Run to completion each time.
Line 65:
my $screwup=' Errors? [[User:'.$api->user.'/shutoff/AFDMergeFromCleaner]]';
my $report='User:'.$api->user.'/Afd-mergefrom report';
 
# Spend a max of 5 minutes on this task before restarting
my $endtime=time()+300;
 
# Get a list of templates redirecting to our targets
Line 82 ⟶ 79:
}
 
my %badredirected=();
my $endtime%deleted=time()+300;
my $ret=21600;
 
Line 89 ⟶ 87:
# Get the list of pages to check
my %q=(
list => 'embeddedin',
eititle => "Template:$template",
eilimiteinamespace => 'max'1,
eilimit } => 'max',
);
do {
Line 152 ⟶ 151:
 
# Now, query the found pages
my %goodremove=();
while(@from){
my @f=splice(@from, 0, 500);
Line 166 ⟶ 165:
if($t eq $subject){
$f=$norm{$f} if exists($norm{$f});
$goodremove{$f}=1;
} else {
$badredirected{"$f>$subject>$t"}="| [[:$f]] || [[:$subject]] || [[:$t]] || \n";
}
}
foreach (values %{$res->{'query'}{'pages'}}){
next unless exists($_->{'missing'});
# Missing pages should have the template removed, and
$ret=0; last MAINLOOP; # be logged.
my $f=$_->{'title'};
$f=$norm{$f} if exists($norm{$f});
$remove{exists($norm{$f})?$norm{$f}:$f}=1;
$deleted{"$f>$subject"}="| [[:$f]] || [[:$subject]] || \n";
}
}
 
# Remove the "good"removable templates
my $outtxt=$self->process_templates($intxt, sub {
return undef unless exists($templates{'Template:'.$_[0]});
Line 180 ⟶ 188:
($f=$_->{'value'})=~s/^\s+|\s+$//g if $_->{'name'} eq 1;
}
return exists($goodremove{$f})?'':undef;
});
 
Line 192 ⟶ 200:
next;
}
}
 
# If we've been at it long enough, let another task have a go.
if(time()>=$endtime){
$ret=0; last MAINLOOP;
}
}
Line 202 ⟶ 205:
}
 
my $tok=$api->edittoken($report);
while(%bad){
my if($tok=$api->edittoken($report{'code'} eq 'shutoff');{
if$self->warn("Task disabled: ".$tok->{'codecontent'} eq 'shutoff'."\n"){;
return 300;
$self->warn("Task disabled: ".$tok->{'content'}."\n");
}
return 300;
if($tok->{'code'} ne 'success'){
$self->warn("TaskFailed disabledto get edit token for $report: ".$tok->{'contenterror'}."\n");
$ret=60;
last;
}
my $intxt=exists($tok->{'revisions'}[0]{'*'})?$tok->{'revisions'}[0]{'*'}:'';
foreach my foreach$s (split (/(?=(?:^|\n)==)/, $intxt)){
if(/^==\s*Redirected\s*==/){
foreach (split /\n/, $s){
next unless /^\| \[\[:([^]]+)\]\] \|\| \[\[:([^]]+)\]\] \|\| \[\[:([^]]+)\]\] \|\|/;
next unless exists($badredirected{"$1>$2>$3"}=$_);
$redirected{"$1>$2>$3"}=$_;
%bad=(); }
} elsif(/^==\s*Deleted\s*==/){
foreach (split /\n/, $s){
next unless /^\| \[\[:([^]]+)\]\] \|\| \[\[:([^]]+)\]\] \|\|/;
if(time()$deleted{"$1>$2"}=$endtime){_;
}
}
}
if($tok->{'code'} ne 'success'){
my $outtxt="== Redirected ==\n";
$self->warn("Failed to get edit token for $report: ".$tok->{'error'}."\n");
$outtxt.="The following table lists pages referred to by {{tl|afd-mergefrom}} are redirects to some page other than that with the {{tl|afd-mergefrom}}. Please correct the {{tl|afd-mergefrom}}, either by removing it (if the page was correctly merged elsewhere), undoing the incorrect redirection, or pointing it to the correct page. This table will be updated automatically.\n\n";
$ret=60;
$outtxt.="{| class=\"wikitable sortable\"\n";
last;
$outtxt.="! Page !! AFD merge to !! Redirect to !! Note\n";
}
$outtxt.="|-\n";
my $intxt=exists($tok->{'revisions'}[0]{'*'})?$tok->{'revisions'}[0]{'*'}:'';
$outtxt.=join("|-\n", sort values %redirected);
foreach (split /\n/, $intxt){
$outtxt.="|}\n\n";
next unless /^\| \[\[:([^]]+)\]\] \|\| \[\[:([^]]+)\]\] \|\| \[\[:([^]]+)\]\] \|\|/;
$outtxt.="== Deleted ==\n";
$bad{"$1>$2>$3"}=$_;
$outtxt.="The following table lists deleted pages that were referred to by {{tl|afd-mergefrom}}; the offending {{tl|afd-mergefrom}} has already been removed. Please double-check whether the deletion was correct. If so, just remove the row from the table; if not, undelete the page and restore the {{tl|afd-mergefrom}}. This table will '''not''' be updated automatically.\n\n";
}
my $outtxt.="{| class=\"wikitable sortable\"\n! Page !! AFD merge to !! Redirect to !! Note\n|-\n".join("|-\n", sort values %bad)."|}";
$outtxt.="! Page !! AFD merge to !! Note\n";
$outtxt.="|-\n";
$outtxt.=join("|-\n", sort values %deleted);
$outtxt.="|}\n\n";
 
if($outtxt ne $intxt){
my $summary="Updating list of non-matching merges";
$self->warn("$summary in $report\n");
my $r=$api->edit($tok, $outtxt, $summary.$screwup, 1, 1);
if($r->{'code'} ne 'success'){
$self->warn("Write failed on $report: ".$r->{'error'}."\n");
next$ret=60;
}
}
%bad=();
}