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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: General: * BREAKING CHANGE: And it's a big one: ** Data store changed from (binary) Storable to (readable) JSON. update-db.pl will change an existing database. This may affect the exact values storable in the permanent sto
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>.
 
(9 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]]}}
<sourcesyntaxhighlight lang="perl">
package tasks::AFDMergeFromCleaner;
 
Line 7:
=begin metadata
 
Bot: AnomieBOT
Task: AFDMergeFromCleaner
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 20
Status: Approved 2009-01-03
Rate: Max 6 edits/minute
Created: 2008-12-29
 
Remove instances of {{tl|afd-mergefrommerge from}} where the merge has been completed.
Report instances of {{tl|afd-mergefrommerge from}} where the AFDed page is now a redirect
to a different target.
 
Line 51:
my $res;
 
$api->task('AFDMergeFromCleaner', 0, 10, qw/d::UtilTemplates d::Redirects/);
 
if($self->{'nextrun'}==0 && exists($api->store->{'nextrun'})){
Line 61:
return $t if $t>0;
 
my @templates=('Afd-mergefrommerge from');
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);
foreach my $template if(@exists($templates{''})){
$api->warn("Failed to get redirects to target templates: ".$templates{''}{'error'}."\n");
$templates{"Template:$template"}=1;
$res=$api->query([],return 60;
list => 'backlinks',
bltitle => "Template:$template",
blfilterredir => 'redirects',
bllimit => 'max',
);
$templates{$_->{'title'}}=1 foreach (@{$res->{'query'}{'backlinks'}});
}
 
Line 116 ⟶ 110:
}
 
$res=$api->warnquery("Checkingtitles for=> $templatesubject, in $title\n"redirects=>1);
if($res->{'code'} ne 'success'){
$api->warn("Failed to retrieve redirect target for $subject: ".$res->{'error'}."\n");
list $ret=> 'backlinks',60;
bllimit => 'max',last MAINLOOP;
); }
my $rsubject=$subject;
$templates{$_->{'title'}}=1 foreach (@{$res->{'query'}{'backlinksredirects'}});{
$rsubject=$_->{'to'} if($_->{'from'} eq $rsubject);
}
 
$api->log("Checking for $template in $title");
 
# WTF?
Line 138 ⟶ 143:
 
# Get page text
my $intxt=$tok->{'revisions'}[0]{'slots'}{'main'}{'*'};
 
# First, find the template and pull out the relevant parameter
Line 165 ⟶ 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 206 ⟶ 213:
if($outtxt ne $intxt){
my $summary="Removing obsolete {{$template}}";
$api->warnlog("$summary in $title\n");
my $r=$api->edit($tok, $outtxt, $summary.$screwup, 1, 1);
if($r->{'code'} ne 'success'){
Line 228 ⟶ 235:
last;
}
my $intxt=exists($tok->{'revisions'}[0]{'*slots'})?$tok->{'revisionsmain'}[0]{'*'}: // '';
foreach my $s (split(/(?=(?:^|\n)==)/, $intxt)){
if($s=~/^\n?==\s*Redirected\s*==/){
Line 248 ⟶ 255:
}
my $outtxt="== Redirected ==\n";
$outtxt.="The following table lists pages referred to by {{tl|afd-mergefrommerge from}} are redirects to some page other than that with the {{tl|afd-mergefrommerge from}}. Please correct the {{tl|afd-mergefrommerge 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";
Line 255 ⟶ 262:
$outtxt.="\n|}\n\n";
$outtxt.="== Deleted ==\n";
$outtxt.="The following table lists deleted pages that were referred to by {{tl|afd-mergefrommerge from}}; the offending {{tl|afd-mergefrommerge 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-mergefrommerge from}}. This table will '''not''' be updated automatically.\n\n";
$outtxt.="{| class=\"wikitable sortable\"\n";
$outtxt.="! Page !! AFD merge to !! Note\n";
Line 264 ⟶ 271:
if($outtxt ne $intxt){
my $summary="Updating list of non-matching merges";
$api->warnlog("$summary in $report\n");
my $r=$api->edit($tok, $outtxt, $summary.$screwup, 1, 1);
if($r->{'code'} ne 'success'){
Line 282 ⟶ 289:
1;
 
</syntaxhighlight>
</source>