Content deleted Content added
Updating published sources: AutoAssessor2 & WikiProjectTagger: * Add "sequence number", so previous runs' database entries don't interfere with the current run's. WikiProjectTagger: * Adjust configuration for upcoming run, but don't run yet. |
Updating published sources: AutoAssessor2: * Retire this task too, I think Lua now tends to handle this sort of thing. |
||
(27 intermediate revisions by the same user not shown) | |||
Line 1:
{{ombox|type=notice|text=
{{ombox|type=notice|text= Retired 2025-02-01. Haven't had call to run this in a while, and I think Lua now handles this sort of thing anyway.}}
<syntaxhighlight lang="perl">
package tasks::AutoAssessor2;
Line 7 ⟶ 8:
=begin metadata
Bot: AnomieBOT
Task: AutoAssessor2
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 15
Status: Inactive 2025-02-01
Created: 2008-11-26
OnDemand: true
Redirects and disambiguation pages will be automatically assessed with
Line 29 ⟶ 32:
# Request link, for edit summary.
my $req="[[User
# Increment this number every time a new run is started, so we don't have to
# mess around with deleting previous runs' database entries.
my $seq=
# If any of the 'verify' or 'params' functions need the page contents, set this
Line 42 ⟶ 45:
# ns => Hash mapping namespace numbers (or 'stub', 'redirect', 'disambig',
# or '' for ns 0) to an array [ $class, $classre, $imp, $impre].
# stubauto =>
# importance => If specified, this is the name of the "importance" parameter
# instead of "importance".
# canonicalize => If defined, any instance of the template will be renamed to
# this when edits are done to the page.
# addempty => If true, add empty "class=" and "importance=" to all banners.
# verify => If defined, must be a subroutine that will be called with the
# page and talkpage results. The subroutine must return a boolean value,
Line 53 ⟶ 57:
# results, the template name, and the existing template parameters. It
# should adjust the parameter array as necessary.
my %cfg_templates
%cfg_templates=(
},
);
Line 79 ⟶ 73:
my $self=$class->SUPER::new();
$self->{'did_templates'}=0;
$self->{'config loaded'}=0;
bless $self, $class;
return $self;
Line 86 ⟶ 81:
=for info
=for info
Retired 2025-02-01. Haven't had call to run this in a while, and I think Lua now handles this sort of thing anyway.
=cut
sub approved {
return
}
Line 98 ⟶ 96:
my $res;
$api->task('AutoAssessor2', 0, 10, qw/d::WikiProjectTagging d::Redirects/);
# Load configs, if necessary
if(!$self->{'config loaded'}){
while(my ($banner,$cfg)=each %cfg_templates){
next unless exists($cfg->{'meta'});
my $ae=$cfg->{'addempty'} // 0;
$cfg=$api->WPBMetaConfig($cfg->{'meta'}, %$cfg) if exists($cfg->{'meta'});
$cfg->{'addempty'}=$ae;
$cfg_templates{$banner}=$cfg;
}
$self->{'config loaded'}=1;
}
if(!exists($api->store->{'metaseq'}) || $api->store->{'metaseq'}<$seq){
delete $api->store->{'template'};
delete $api->store->{'geicontinue'};
$api->store->{'metaseq'}=$seq;
}
# List of templates to assess in this task
if(!$self->{'did_templates'}){
while(my ($t,$c)=each %cfg_templates){
my %redirs=$
return 60;
}
}
$self->{'did_templates'}=1;
Line 125 ⟶ 133:
}
# Spend a max of
my $endtime=time()+
foreach my $template (sort keys %cfg_templates){
next if(exists($api->store->{'template'}) && $template lt $api->store->{'template'});
$api->store->{'template'}=$template;
my %q1=(
generator => 'embeddedin',
geititle => "Template:$template",
geilimit => '
prop => 'info',
inprop => 'subjectid',
);
$q1{'geicontinue'}=$api->store->{'geicontinue'} if exists($api->store->{'geicontinue'});
my %q2=(
pageids => '',
prop => 'info|categories|templates',
cllimit => 'max',
tllimit => 'max',
);
if($need_page_contents){
$q2{'prop'}.='|revisions';
$q2{'rvprop'}='content';
$q2{'rvslots'}='main';
}
# Get the list of pages to check
do {
$api->store->{'geicontinue'}=$q1{'geicontinue'} if exists($q1{'geicontinue'});
$res=$api->query(%q1);
if($res->{'code'} ne 'success'){
$
return 60;
}
Line 161 ⟶ 175:
# Collect page IDs of articles for found talk pages
my @pageids=map { exists($_->{'subjectid'})?($_->{'subjectid'}):() } values %{$res->{'query'}{'pages'}};
@pageids=grep { !exists($api->store->{$_}) || $api->store->{$_}<$seq } @pageids;
# Look up info for found pages, in blocks of 500 because that's the
Line 166 ⟶ 181:
while(@pageids){
$q2{'pageids'}=join('|', splice(@pageids, 0, 500));
$res=$
foreach my $page (values %{$res->{'query'}{'pages'}}){
return 0 if $api->halting;
my $pageid=$page->{'pageid'};
my $title=$page->{'title'};
my $ns=$page->{'ns'};
Line 178 ⟶ 194:
if(($ns&1)==1){
# Talk page, ignore it.
$api->store
next;
}
Line 195 ⟶ 211:
}
$
# Ok, check the page
my $tok=$api->edittoken($talk, EditRedir => 1, 'categories'=>1, 'templates'=>1);
if($tok->{'code'} eq 'shutoff'){
$
return 300;
}
if($tok->{'code'} ne 'success'){
$
next;
}
Line 210 ⟶ 226:
# Get page text
my $intxt=$tok->{'revisions'}[0]{'slots'}{'main'}{'*'};
my ($outtxt,$nowiki)=$
my $any=0;
my @found=();
$outtxt=$
my $name=shift;
my @params=@{shift()};
Line 224 ⟶ 240:
return undef unless exists($templates{"Template:$name"});
my %cfg=%{$templates{"Template:$name"}};
return undef
my ($class,$classre,$imp,$impre)
($class,$classre,$imp,$impre)=@{$cfg{'ns'}{$ns}};
$impname=exists($cfg{'importance'})?$cfg{'importance'}:'importance';
} else {
($class,$classre,$imp,$impre)=(undef,undef,undef,undef);
$impname=undef;
}
my $orig_param=join('|', @params);
# Auto-assess
if($class && defined($classre) && !grep(/^\s*class\s*=\s*$classre\s*$/s, @params)){
push @params, "class=$class" unless(grep(s/^(\s*class\s*=(?:\s*(?=\S))?).*?(\s*)$/$1$class$2/s, @params));
if(defined($
push @params, "$a=yes"
} else {
@params = grep(!/^\s*\Q$a\E\s*=/, @params);
}
}
}
if($imp && defined($impre) && !grep(/^\s*$impname\s*=\s*$impre\s*$/s, @params)){
push @params, "$impname=$imp" unless(grep(s/^(\s*$impname\s*=(?:\s*(?=\S))?).*?(\s*)$/$1$imp$2/s, @params));
}
# If requested to add empty parameters, do so
if($cfg{'addempty'} // 0){
push @params, "class=" unless grep(/^\s*class\s*=/, @params);
push @params, "$impname=" if(defined($impname) && !grep(/^\s*$impname\s*=/, @params));
}
# Do extra parameters, if necessary
$cfg{'params'}($api,$page,$tok,$name,\@params) if defined($cfg{'params'});
my $new_param=join('|', @params);
Line 251 ⟶ 282:
$any=1;
my @s=();
push @s, "class=$class" if($class && defined($classre));
push @s, "$impname=$imp" if($imp && defined($impre));
push @found, "{{$name}} (".join(' ', @s).')';
}
# Add empty parameters for future human taggers,
# after setting $any so we don't make useless
# edits.
push @params, "class=" unless grep(/^\s*class\s*=/, @params);
push @params, "$impname=" if(defined($impname) && !grep(/^\s*$impname\s*=/, @params));
if(defined($cfg{'canonicalize'})){
my $n=$cfg{'canonicalize'};
Line 260 ⟶ 298:
$oname=~s/^(\s*)\S(?:.*\S)?(\s*)$/$1$n$2/is;
}
return "{{$oname|
});
$outtxt=$
# Need to edit?
Line 268 ⟶ 306:
$found[-1]='and '.$found[-1] if @found>1;
my $summary="Assessing ".join((@found>2)?', ':' ', @found)." per $req";
my @cleanup=();
$outtxt=$api->WPBfixshell($outtxt, \@cleanup);
if(ref($outtxt) eq 'HASH'){
$api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
next;
}
$summary.="; general banner cleanup (".join(', ', @cleanup).")" if @cleanup;
$api->log("$summary in $talk");
my $r=$api->edit($tok, $outtxt, $summary, 1, 1);
if($r->{'code'} ne 'success'){
$
next;
}
} else {
$
}
# Save checked revision
$api->store
# If we've been at it long enough, let another task have a
Line 287 ⟶ 334:
}
} while(exists($q1{'geicontinue'}));
delete $api->store->{'geicontinue'};
}
delete $api->store->{'template'};
# No more pages to check, try again in 10 minutes or so in case of errors.
$api->log("AutoAssessor2 may be DONE!");
return 600;
}
Line 295 ⟶ 345:
1;
</syntaxhighlight>
|