Content deleted Content added
Updating published sources: General: * New task, AFDMergeFromCleaner. |
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>. |
||
(23 intermediate revisions by the same user not shown) | |||
Line 1:
{{ombox|type=notice|text=
<
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 38 ⟶ 39:
=for info
=cut
sub approved {
return
}
Line 50 ⟶ 51:
my $res;
$api->task('AFDMergeFromCleaner', 0, 10, qw/d::Templates d::Redirects/);
my $t=$api->store->{'nextrun'};
$self->{'nextrun'}=$t if $t=~/^\d+$/;
}
my $starttime=time();
Line 58 ⟶ 61:
return $t if $t>0;
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");
}
my %
my %deleted=();
my $ret=21600;
my $linktmpl='User:'.$api->user.'/la';
MAINLOOP:
Line 89 ⟶ 82:
# Get the list of pages to check
my %q=(
list => 'embeddedin',
eititle => "Template:$template",
eilimit => 'max',
);
do {
$res=$api->query(%q);
if($res->{'code'} ne 'success'){
$
$ret=60;
last MAINLOOP;
Line 116 ⟶ 110:
}
$
if($res->{'code'} ne 'success'){
$api->warn("Failed to retrieve redirect target for $subject: ".$res->{'error'}."\n");
$ret=60;
last MAINLOOP;
}
my $rsubject=$subject;
foreach (@{$res->{'query'}{'redirects'}}){
$rsubject=$_->{'to'} if($_->{'from'} eq $rsubject);
}
$api->log("Checking for $template in $title");
# WTF?
if(exists($_->{'missing'})){
$
next;
}
Line 127 ⟶ 132:
my $tok=$api->edittoken($title);
if($tok->{'code'} eq 'shutoff'){
$
return 300;
}
if($tok->{'code'} ne 'success'){
$
last MAINLOOP;
}
next if exists($tok->{'missing'});
# 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 152 ⟶ 158:
# Now, query the found pages
my %
while(@from){
my @f=splice(@from, 0, 500);
$res=$api->query(titles => join('|',@f), redirects=>1);
if($res->{'code'} ne 'success'){
$
$ret=60;
last MAINLOOP;
Line 164 ⟶ 170:
foreach (@{$res->{'query'}{'redirects'}}){
my ($f,$t)=($_->{'from'}, $_->{'to'});
if($t eq $subject || $t eq $rsubject){
$f=$norm{$f} if exists($norm{$f});
$
} elsif($subject ne $rsubject){
$redirected{"$f>$rsubject>$t"}="| {{$linktmpl|$f}} || {{$linktmpl|$subject}}<br />→ {{$linktmpl|$rsubject}} || {{$linktmpl|$t}} || ";
} else {
$
}
}
foreach (values %{$res->{'query'}{'pages'}}){
next unless exists($_->{'missing'});
# Missing pages should have the template removed, and
# be logged.
my $f=$_->{'title'};
$f=$norm{$f} if exists($norm{$f});
$remove{$f}=2;
$deleted{"$f>$subject"}="| {{$linktmpl|$f}} || {{$linktmpl|$subject}} || ";
}
}
# Remove the
my $outtxt=$
my @params=@{shift()};
shift; # $wikitext
shift; # $data
my $oname=shift;
return undef unless exists($templates{'Template:'.$name});
my $f=undef;
foreach ($
($f=$_->{'value'})=~s/^\s+|\s+$//g if $_->{'name'} eq 1;
}
return undef unless exists($
return '' if $remove{$f}==2;
$oname=~s/_/ /g;
$oname=~s/^(\s*)\S(?:.*\S)?(\s*)$/${1}afd-merged-from$2/is;
return "{{$oname|".join("|",@params)."}}";
});
Line 186 ⟶ 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 202 ⟶ 224:
}
if($ret==21600){ # No error above
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
if($s=~/^\n?==\s*Redirected\s*==/){
$
foreach (split /\n\|-\n/, $s){
s/[\r\n]\s*$//;
next unless /^\Q| {{$linktmpl|\E([^]]+)\Q}} || {{$linktmpl|\E([^]]+)\Q}} || {{$linktmpl|\E([^]]+)\Q}} ||/;
next unless exists($redirected{"$1>$2>$3"});
$redirected{"$1>$2>$3"}=$_;
}
} elsif($s=~/^\n?==\s*Deleted\s*==/){
$s=~s/\|}.*$//s;
foreach (split /\n\|-\n/, $s){
s/[\r\n]\s*$//;
next unless /^\Q| {{$linktmpl|\E([^]]+)\Q}} || {{$linktmpl|\E([^]]+)\Q}} ||/;
$deleted{"$1>$2"}=$_;
}
}
}
my $outtxt="== Redirected ==\n";
$outtxt.="The following table lists pages referred to by {{tl|afd-merge from}} are redirects to some page other than that with the {{tl|afd-merge from}}. Please correct the {{tl|afd-merge from}}, 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";
$outtxt.="{| class=\"wikitable sortable\"\n";
$outtxt.="! Page !! AFD merge to !! Redirect to !! Note\n";
$outtxt.="|-\n";
$outtxt.=join("\n|-\n", sort values %redirected);
$outtxt.="\n|}\n\n";
$outtxt.="== Deleted ==\n";
$outtxt.="The following table lists deleted pages that were referred to by {{tl|afd-merge from}}; the offending {{tl|afd-merge from}} 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-merge from}}. This table will '''not''' be updated automatically.\n\n";
$outtxt.="{| class=\"wikitable sortable\"\n";
$outtxt.="! Page !! AFD merge to !! Note\n";
$outtxt.="|-\n";
$outtxt.=join("\n|-\n", sort values %deleted);
$outtxt.="\n|}\n\n";
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'){
$
}
}
}
$starttime+=$ret;
$self->{'nextrun'}=$starttime;
$api->store
return $ret;
Line 241 ⟶ 289:
1;
</syntaxhighlight>
|