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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: General: * Fix newline handling in log messages.
AnomieBOT (talk | contribs)
Updating published sources: WikiProjectTagger: * Adjustments to tag even if not assessing * Start run for WP Physics. AutoAssessor2: * Adjustments to tag even if not assessing * Adjust config for WP Physics run, and start running. AutoAssessor2, Wiki
Line 26:
use strict;
 
use Data::Dumper;
use AnomieBOT::Task;
use vars qw/@ISA/;
Line 31 ⟶ 32:
 
# Request link, for edit summary.
my $req="[[User:AnomieBOT/req/WikiProject GlassPhysics 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=23;
 
# If any of the 'verify' or 'params' functions need the page contents, set this
Line 55 ⟶ 56:
# results, the template name, and the existing template parameters. It
# should adjust the parameter array as necessary.
my %cfg_templates=(;
%cfg_templates=(
'Glass' => {
ns'Physics' => {
ns => {
stub => [ 'stub', qr/\S.*/s, undef, undef ],
redirect => [ 'redirect', qr/redirect|red|redir/i, 'NA', qr/na/i ],
disambig => [ 'disambig', qr/disambig|dab/i, 'NA', qr/na/i ],
0 2 => [ undef'NA', undefqr/na/i, undef'NA', undefqr/na/i ], # User
2 4 => [ 'NAproject', qr/naproject/i, 'NA', qr/na/i ], # UserWikipedia
4 6 => [ 'projectimage', qr/projectimage/i, 'NA', qr/na/i ], # WikipediaImage
6 8 => [ 'imageNA', qr/imagena/i, 'NA', qr/na/i ], # ImageMediaWiki
8 10 => [ 'NAtemplate', qr/natemplate|templ|temp/i, 'NA', qr/na/i ], # MediaWikiTemplate
10 12 => [ 'templateNA', qr/template|templ|tempna/i, 'NA', qr/na/i ], # TemplateHelp
12 14 => [ 'NAcategory', qr/nacategory|categ|cat/i, 'NA', qr/na/i ], # HelpCategory
14 100 => [ 'categoryportal', qr/category|categ|catportal/i, 'NA', qr/na/i ], # CategoryPortal
verify => undef },
100 => [ 'portal', qr/portal/i, 'NA', qr/na/i ], # Portal
stubauto => 'auto',
params blp => undef,
activepol => undef,
canonicalize => 'Glass'undef,
verify => undef,
params => sub {
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'} // []});
warn Dumper(\@x);
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);
warn Dumper(\$mark);
 
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));
}
},
},
stubauto => 'auto',
canonicalize => 'Glass',
verify => undef,
params => undef,
},
);
 
Line 94 ⟶ 135:
 
sub approved {
return -1;
}
 
Line 101 ⟶ 142:
my $res;
 
$api->task('AutoAssessor2', 0, 10, qw/d::TemplatesWikiProjectTagging/);
 
# List of templates to assess in this task
Line 139 ⟶ 180:
my %q2=(
pageids => '',
prop => 'info|categories|templates',
cllimit => 'max',
tllimit => 'max',
);
if($need_page_contents){
Line 198 ⟶ 240:
 
# Ok, check the page
my $tok=$api->edittoken($talk, EditRedir => 1, 'categories'=>1, 'templates'=>1);
if($tok->{'code'} eq 'shutoff'){
$api->warn("Task disabled: ".$tok->{'content'}."\n");
Line 224 ⟶ 266:
return undef unless exists($templates{"Template:$name"});
my %cfg=%{$templates{"Template:$name"}};
return undef unless existsif(defined($cfg{'nsverify'}{) && !$nscfg{'verify'}($api,$page,$tok));
my ($class,$classre,$imp,$impre)=@{$cfg{'ns'}{$ns}};
return undef if(definedexists($cfg{'verifyns'}) && !{$cfg{'verify'ns}($page,$tok));{
($class,$classre,$imp,$impre)=@{$cfg{'ns'}{$ns}};
} else {
($class,$classre,$imp,$impre)=(undef,undef,undef,undef);
}
my $impname=exists($cfg{'importance'})?$cfg{'importance'}:'importance';
 
Line 248 ⟶ 294:
 
# Do extra parameters, if necessary
$cfg{'params'}($api,$page,$tok,$name,\@params) if defined($cfg{'params'});
 
my $new_param=join('|', @params);
Line 276 ⟶ 322:
# Need to edit?
if($outtxt ne $intxt && $any){
$outtxt=$api->WPBfixshell($outtxt);
$found[-1]='and '.$found[-1] if @found>1;
my $summary="Assessing ".join((@found>2)?', ':' ', @found)." per $req";