Content deleted Content added
Updating published sources: DeletionSortingCleaner: * Shorten edit summary on the main deletion sorting pages |
Updating published sources: DeletionSortingCleaner: * Supplemental BRFA approved! |
||
(26 intermediate revisions by the same user not shown) | |||
Line 1:
{{ombox|type=notice|text= Approved 2010-07-06<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 40]]}}
{{ombox|type=notice|text= Supplemental BFRA approved 2020-06-06<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 79]]}}
{{ombox|type=notice|text= Supplemental BFRA approved 2025-08-22<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 85]]}}
<syntaxhighlight lang="perl">
package tasks::DeletionSortingCleaner;
Line 11 ⟶ 13:
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 40
Status: Approved 2010-07-06
+BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 79
+Status: Approved 2020-06-06
+BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 85
+Status: Approved 2025-08-22
Created: 2010-06-18
Perform certain tasks for [[WP:WikiProject Deletion sorting]]:
* Subst various AfD templates that should be substed
* Archive discussions for closed
* Remove duplicate XfD listings
* Remove deleted XfD listings
If necessary, the bot may be kept off a deletion sorting subpage by adding
{{
=end metadata
Line 38 ⟶ 45:
my $class=shift;
my $self=$class->SUPER::new();
$self->{'pages'}=undef;
$self->{'lasttime'}=0;
$self->{'broken'}=0;
Line 48 ⟶ 56:
=for info
Approved 2010-07-06<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 40]]
=for info
Supplemental BFRA approved 2020-06-06<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 79]]
=for info
Supplemental BFRA approved 2025-08-22<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 85]]
=cut
Line 62 ⟶ 76:
# Get all redirects to templates we need to subst in XfD pages
my %xfdtemplates=$api->
if(exists($xfdtemplates{''})){
$api->warn("Failed to get list of XfD templates: ".$xfdtemplates{''}{'error'}."\n");
Line 84 ⟶ 98:
# Load list of deletion sorting subpages to process
if ( ! defined( $self->{'pages'} ) ) {
$res=$api->query(titles=>'Wikipedia:WikiProject Deletion sorting/Computer-readable.json',prop=>'revisions',rvprop=>"content",rvslots=>"main",rvlimit=>1,formatversion=>2);
if($res->{'code'} ne 'success'){
$api->warn("Failed to get list of pages to process: ".$res->{'error'}."\n"); return 60;
}
my $json;
eval { $json = JSON->new->decode( $res->{'query'}{'pages'}[0]{'revisions'}[0]{'slots'}{'main'}{'content'} // '' ); };
$api->warn("Failed to parse Wikipedia:WikiProject Deletion sorting/Computer-readable.json: $@\n");
my %pages = ();
for my $g (values %$json) {
for my $p (@$g) {
$pages{"Wikipedia:WikiProject Deletion sorting/$p"} = 1;
}
}
$self->{'pages'}=[ sort keys %pages ];
unless(@{$self->{'pages'}}){
$api->warn("No pages in list?");
$self->{'broken'}=1;
$api->store->{'broken'}=1;
return 3600;
}
}
my $endtime=time()+300;
while ( @{$self->{'pages'}} ) {
return 0 if $api->halting;
my $page = shift @{$self->{'pages'}};
# First, load the page to archive from. Allow for opting out using
# {{bots|optout=AnomieBOT/DeletionSortingCleaner}}
Line 119 ⟶ 151:
# pages. For each one, subst any substable templates and then see if it
# looks closed.
my $intxt=$tok->{'revisions'}[0]{'slots'}{'main'}{'*'};
my @archive=@{$api->store->{"archive $page"} // []}; # Load saved archivals
my @summary=();
my $fail=undef;
my $dups=0;
my %dups=();
my $deleted=0;
my $outtxt=$api->process_templates($intxt, sub {
return undef if defined($fail);
my $name=shift;
shift; # $params
my $wikitext=shift;
return undef unless $name=~m!^(?i:Wikipedia|WP) *: *((?:
my $name2=$
# Normalize. People do weird things sometimes.
$name = "Wikipedia:\u$1/$2";
if(exists($dups{$name})){
$dups=1;
return '';
}
$dups{$name}=1;
my $cannoteditreason=undef;
Line 144 ⟶ 190:
titles => $name,
rvprop => 'ids|timestamp|content|flags|user|size|comment',
rvslots => 'main',
);
$xfdtok=(values %{$res->{'query'}{'pages'}})[0];
Line 154 ⟶ 201:
$api->warn("Failed to get edit token for $name: ".$xfdtok->{'error'}."\n");
$broken=1;
return undef;
}
if(exists($xfdtok->{'missing'})){
# Check for a deletion log entry.
my $res2 = $api->query(
letitle => $name,
list => 'logevents',
letype => 'delete',
lelimit => 1,
leprop => 'user|timestamp|comment',
);
if($res2->{'code'} ne 'success'){
$api->warn("Failed to retrieve logs for $name: " . $res2->{'error'} . "\n");
$fail = 60;
return undef;
}
if(exists($res2->{'query'}{'logevents'}[0])){
my $log = $res2->{'query'}{'logevents'}[0];
# Check whether the deletion log entry could reasonably
# belong to this listing.
my %q = (
titles => $page,
prop => 'revisions',
rvprop => 'ids|timestamp|content',
rvslots => 'main',
rvlimit => 10,
formatversion => 2,
);
my %cont = ();
my $wt = $wikitext;
do {
my $res3 = $api->query( %q );
if($res3->{'code'} ne 'success'){
$api->warn("Failed to retrieve revisions for $page: " . $res3->{'error'} . "\n");
$fail = 60;
return undef;
}
for my $rev (@{$res3->{'query'}{'pages'}[0]{'revisions'}}) {
next unless exists( $rev->{'slots'}{'main'}{'content'} ); # Revdel?
my $c = $rev->{'slots'}{'main'}{'content'};
my $found = ( $c =~ /\Q$wt\E/ );
if ( ! $found ) {
$api->process_templates($c, sub {
return undef if $found;
my $name2=shift;
shift; # $params
my $wikitext2=shift;
return undef unless $name2=~m!^(?i:Wikipedia|WP) *: *((?:[Aa]rticles|[Mm]iscellany) for deletion)/(.+)$!;
# Normalize. People do weird things sometimes.
$name2 = "Wikipedia:\u$1/$2";
if ( $name2 eq $name ) {
$wt = $wikitext2;
$found = 1;
}
return undef;
});
}
if ( ! $found ) {
$api->warn("XfD page $name linked from $page does not exist, deleted at $log->{'timestamp'} but newer rev $rev->{'revid'} from $rev->{'timestamp'} did not transclude it.\n");
return undef;
}
if ( $rev->{'timestamp'} le $log->{'timestamp'} ) {
$res3->{'continue'} = {};
last;
}
}
%cont = %{ $res3->{'continue'} // {} };
} while ( %cont );
# Deleted since it was listed, so remove from page.
$deleted=1;
push @summary, "[[$name]] (was deleted)";
return '';
}
$api->warn("XfD page $name linked from $page does not exist\n");
return undef;
}
my %substlist=();
my $xfdintxt=$xfdtok->{'revisions'}[0]{'slots'}{'main'}{'*'};
my $xfdouttxt=$api->process_templates($xfdintxt, sub {
my $name=shift;
Line 166 ⟶ 293:
return undef unless exists($xfdtemplates{"Template:$name"});
$substlist{$name}=1;
$wikitext=~s/^\{\{/{{subst:/; #
return $wikitext;
});
Line 203 ⟶ 330:
# If closed, remove from the main page and note it for archival.
# If still open, do nothing.
return undef unless $xfdintxt=~m!<div class="
my ($result,$date)=('(unknown)','(unknown)');
$result=$1 if $xfdintxt=~m!(?:result was|result of the discussion was:(?:'')?)\s*(?:'''|<(?:b|strong)>)(.+?)(?:'''|</(?:b|strong)>)!;
$date=$1 if $xfdintxt=~m!(\d\d:\d\d, \d+ \w+ \d{4} \(UTC\))!;
unshift @archive, "* [[$name|$name2]] - (".length($xfdintxt).") - $result - <small>closed $date</small>";
push @summary, "[[$name]]";
return '';
});
Line 215 ⟶ 343:
# before saving the original page to minimize chances of being able to
# save one but not the other.
my ($apage,$atok,$atxt)=(undef,undef,undef);
if(@archive){
my ($
($apage = "$page/archive") =~ s/^Wikipedia://;
$res = $api->query(
generator => 'allpages',
gapnamespace => 4,
gapprefix => $apage,
gaplimit => 'max',
prop => 'info',
);
for my $p (values %{$res->{'query'}{'pages'}}) {
if ( $p->{'title'} eq "$page/archive" && $i <= 1) {
($i,$sz) = (1,$p->{'length'});
} elsif ( $p->{'title'} =~ /^\Q$page\/archive\E (\d+)$/ && $i <= $1 ) {
($i,$sz) = ($1,$p->{'length'});
}
}
$i++ if $sz > 1048576;
$apage = $i < 2 ? "$page/archive" : "$page/archive $i";
$atok=$api->edittoken($apage);
if($atok->{'code'} eq 'shutoff'){
$api->warn("Task disabled: ".$atok->{'content'}."\n");
Line 223 ⟶ 370:
}
if($atok->{'code'} ne 'success'){
$api->warn("Failed to get edit token for $
$broken=1;
next;
}
my $n=$page; $n=~s!^[^/]*/!!;
my $aintxt=$atok->{'revisions'}[0]{'slots'}{'main'}{'*'} // '';
$atxt=$aintxt;
if(exists($atok->{'missing'})){
Line 237 ⟶ 384:
$atxt=~s/<!-- add old AfD discussions at the top -->/<!-- add old AfD discussions at the top -->\n$a/;
if($aintxt eq $atxt){
$api->whine("Broken deletion sorting archive page for $n", "The deletion sorting archive page [[$
$broken=1;
next;
Line 245 ⟶ 392:
# Now do the saving
if($outtxt ne $intxt){
my $what = '';
$what .= "[[$apage|Archiving closed XfDs]]" if @archive;
$what .= ( @archive ? ' and removing' : 'Removing' ) . ( $deleted ? ' deleted' : '' ) . ( $dups ? ( $deleted ? ' and duplicate' : ' duplicate' ) : '' ) . ' XfDs' if $deleted || $dups;
my $summary;
$summary=$what . $screwup . ": " . join(" ", @summary);
$summary=$what . $screwup . ": [" . scalar(@summary) . " discussions]" if length($summary)>500;
$res=$api->edit($tok, $outtxt, $summary, 0, 1);
if($res->{'code'} ne 'success'){
$api->warn("Save failed for $page: ".$res->{'error'}."\n");
Line 256 ⟶ 411:
}
if(defined($atok)){
$api->log("Archiving closed XfDs to $apage...");
$res=$api->edit($atok, $atxt, "Archiving closed XfDs from [[$page]]".$screwup, 0, 1);
if($res->{'code'} ne 'success'){
$api->warn("Save failed for $
$broken=1;
next;
Line 265 ⟶ 421:
delete $api->store->{"archive $page"};
}
return 0 if time()>$endtime;
}
# Save checked revision
$self->{'pages'}=undef;
$self->{'lasttime'}=$starttime;
$self->{'broken'}=$broken;
Line 277 ⟶ 436:
1;
</syntaxhighlight>
|