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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: AnomieBOT::API: * Add configuration variable (and accessor function) for the bot operator's username * Better logging when testing uploads All tasks: * Remove useless metadata field
AnomieBOT (talk | contribs)
Updating published sources: AutoAssessor2: * Config option for adding empty class/importance * Handle auto-configuring WPBMeta * Start run for WikiProject Radio Stations
Line 31:
 
# Request link, for edit summary.
my $req="[[User:AnomieBOT/req/WikiProject PhysicsRadio Stations 1|request]]";
 
# 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=34;
 
# If any of the 'verify' or 'params' functions need the page contents, set this
Line 49:
# 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 57 ⟶ 58:
my %cfg_templates;
%cfg_templates=(
'PhysicsWikiProject Radio Stations' => {
nsmeta => {1,
stubstubauto => [ 'stub', qr/\S.*/s, undef, undef ],
redirectcanonicalize => [ 'redirect',WikiProject qr/redirect|red|redir/i,Radio Stations'NA', qr/na/i ],
disambigaddempty => [ 'disambig', qr/disambig|dab/i, 'NA', qr/na/i ]0,
2 => [ 'NA', qr/na/i, 'NA', qr/na/i ], # User
4 => [ 'project', qr/project/i, 'NA', qr/na/i ], # Wikipedia
6 => [ 'image', qr/image/i, 'NA', qr/na/i ], # Image
8 => [ 'NA', qr/na/i, 'NA', qr/na/i ], # MediaWiki
10 => [ 'template', qr/template|templ|temp/i, 'NA', qr/na/i ], # Template
12 => [ 'NA', qr/na/i, 'NA', qr/na/i ], # Help
14 => [ 'category', qr/category|categ|cat/i, 'NA', qr/na/i ], # Category
100 => [ 'portal', qr/portal/i, 'NA', qr/na/i ], # Portal
},
stubauto => 'auto',
blp => undef,
activepol => undef,
canonicalize => undef,
verify => undef,
params => sub {undef,
my $api=shift;
my $page=shift;
my $talk=shift;
my $name=shift;
my $params=shift;
 
my @x=(@{$page->{'categories'} // []},@{$page->{'templates'} // []},@{$talk->{'categories'} // []},@{$talk->{'templates'} // []});
my $mark=0;
$mark|=1 if grep($_->{'title'} eq 'Template:WPBiography', @x);
$mark|=1 if grep($_->{'title'} eq 'Template:Blp', @x);
$mark|=8 if grep($_->{'title'} eq 'Template:WPBooks', @x);
$mark|=8 if grep($_->{'title'} eq 'Template:WikiProject Magazines', @x);
$mark|=8 if grep($_->{'title'} eq 'Template:WikiProject Academic Journals', @x);
$mark|=8 if grep($_->{'title'} eq 'Category:Journals', @x);
$mark|=8 if grep($_->{'title'} eq 'Category:Journal articles', @x);
$mark|=8 if grep($_->{'title'} eq 'Category:Scientific journals', @x);
$mark|=8 if grep($_->{'title'} eq 'Category:Scientific literature', @x);
$mark|=8 if grep($_->{'title'} eq 'Category:Academic publishing', @x);
$mark|=16 if grep($_->{'title'} eq 'Template:WikiProject History of Science', @x);
 
if($mark&1){
push @$params, "bio=yes" unless(grep(s/^(\s*bio\s*=(?:\s*(?=\S))?).*?(\s*)$/${1}yes$2/s, @$params));
}
if($mark&2){
push @$params, "fluid-dynamics=yes" unless(grep(s/^(\s*fluid-dynamics\s*=(?:\s*(?=\S))?).*?(\s*)$/${1}yes$2/s, @$params));
}
if($mark&4){
push @$params, "relativity=yes" unless(grep(s/^(\s*relativity\s*=(?:\s*(?=\S))?).*?(\s*)$/${1}yes$2/s, @$params));
}
if($mark&8){
push @$params, "pub=yes" unless(grep(s/^(\s*pub\s*=(?:\s*(?=\S))?).*?(\s*)$/${1}yes$2/s, @$params));
}
if($mark&16){
push @$params, "hist=yes" unless(grep(s/^(\s*hist\s*=(?:\s*(?=\S))?).*?(\s*)$/${1}yes$2/s, @$params));
}
},
},
);
Line 120 ⟶ 72:
my $self=$class->SUPER::new();
$self->{'did_templates'}=0;
$self->{'config loaded'}=0;
bless $self, $class;
return $self;
Line 132 ⟶ 85:
 
sub approved {
return -1;
}
 
Line 140 ⟶ 93:
 
$api->task('AutoAssessor2', 0, 10, qw/d::WikiProjectTagging/);
 
# 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){
Line 290 ⟶ 255:
 
# 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($cfg{'stubauto'})){
Line 301 ⟶ 266:
}
}
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));
blp => undef, }
 
# If requested to add empty parameters, do so
if($mark&1cfg{'addempty'} // 0){
push @$params, "bioclass=yes" unless( grep(s/^(\s*bioclass\s*=(?:\s*(?=\S))?).*?(\s*)$/${1}yes$2/s, @$params));
push @$params, "relativity$impname=yes" unlessif(defined($impname) && !grep(s/^(\s*relativity$impname\s*=(?:\s*(?=\S))?).*?(\s*)$/${1}yes$2/s, @$params));
}
 
Line 312 ⟶ 283:
$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).')';
}