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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: General: * Allow substitution of the data directory into the database store_dsn. WikiProjectWorker: * Done with WikiProject Video games tagging.
AnomieBOT (talk | contribs)
Updating published sources: WikiProjectWorker: * Start run for WikiProject NATO AnomieBOT::API::Iterator * Add access to the arrayref value being used d::WikiProjectTagging: * Doc fixes
Line 33:
 
### Request link, for edit summary.
my $req="[[User:AnomieBOT/req/WPVGWikiProject NATO 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;
 
### How to find the pages?
my %templates=('MortalKombatProject' => 'MortalKombat', 'Wikiproject Pro Gaming' => 'Progaming');
my @iterators=(
{
list => 'embeddedincategorymembers',
eititlecmtitle => [ map "Template:$_", keys %templates ],
eilimit => 'maxCategory:NATO',
'Category:Military facilities of NATO',
'Category:NATO installations by country',
'Category:NATO installations in Belgium',
'Category:NATO installations in Canada',
'Category:NATO installations in Germany',
'Category:NATO installations in Italy',
'Category:NATO installations in Turkey',
'Category:Enlargement of NATO',
'Category:NATO Secretaries General',
'Category:Military operations involving NATO',
'Category:NATO-led peacekeeping in the former Yugoslavia',
'Category:NATO operations in Afghanistan',
'Category:NATO military exercises',
'Category:Military units and formations of NATO',
'Category:NATO Standardisation Agreements',
'Category:NATO agencies',
'Category:NATO reporting names',
'Category:Military ranks of NATO',
'Category:NATO Supreme Allied Commanders',
'Category:NATO summits',
'Category:United States ambassadors to NATO',
],
cmnamespace => '0|1',
cmlimit => 'max',
},
);
Line 52 ⟶ 75:
### page to tag (or undef to skip).
sub filter {
returnmy $t=$_[0]->{'title'};
$t="Talk:$t" if $_[0]->{'ns'} == 0;
return $t;
}
 
# Banner configurations.
my %banner_cfgs=(
'WikiProject Video gamesNATO' => {
meta => 0,
stubauto => undef'auto',
canonicalize => 'WikiProject Video gamesNATO',
},
);
Line 80 ⟶ 105:
 
sub approved {
return -1;
}
 
Line 102 ⟶ 127:
if(($api->store->{'configured'} // 0) < $seq){
### Initialize configuration here
#$api->store->{'conflicting assessments'}='';
#$api->store->{'NA assessments'}='';
}
 
### Update log page
#if($api->store->{'conflicting assessments'} ne '' || $api->store->{'NA assessments'} ne ''){
# my $tok=$api->edittoken('Wikipedia:WikiProject Japan/Assessment/Tag cleanup');
# if($tok->{'code'} ne 'success'){
# $api->warn("Cannot update log: ".$tok->{'error'}."\n");
# return 60;
# }
# my $txt=$tok->{'revisions'}[0]{'*'};
# my $a=$api->store->{'conflicting assessments'};
# my $b=$api->store->{'NA assessments'};
# unless($txt=~s/(<!-- Insert conflicting assessments above here -->)/$a$1/ &&
# $txt=~s/(<!-- Insert NA assessments above here -->)/$b$1/){
# $api->warn("Log is missing conflicting assessments marker");
# $api->whine("[[Wikipedia:WikiProject Japan/Assessment/Tag cleanup]] is broken", "Help! [[Wikipedia:WikiProject Japan/Assessment/Tag cleanup]] is missing the comments that tell me where to insert new log entries. I can't do anything to that page until someone fixes it.");
# return 60;
# }
# $api->warn("Updating log\n");
# my $r=$api->edit($tok, $txt, "Bot updating log", 0, 0);
# if($r->{'code'} ne 'success'){
# $api->warn("Write failed on log: ".$r->{'error'}."\n");
# return 60;
# }
# $api->store->{'conflicting assessments'}='';
# $api->store->{'NA assessments'}='';
#}
 
# Preload cache
$api->redirects_to(map "Template:$_", keys %templates);
 
# Spend a max of 5 minutes on this task before restarting
Line 183 ⟶ 177:
### PROCESSING ###
 
my @params=();
# Is there a WikiProject Japan template already on the page?
my $need_WPVG=($api->WPBcheck($outtxt, "WikiProject Video games") == 0);
 
my $assess = undef;;
# First, remove the to-be-removed templates and calculate task
#my force($class) parameters.= $api->WPBmax($intxt);
myif($class ne 'FA' && $fail=0;class ne 'GA'){
my ($class) =undef $api->WPBmin($intxt);
my $imp=undef;
my %tf=();
my %found=();
(undef,$outtxt)=$api->WPBcheck($outtxt, sub {
my $banner=shift;
my $name=shift;
my $oname=shift;
my @params=@{shift()};
 
$tf{$templates{$banner}}=1;
$found{"{{$name}}"}=$templates{$banner}.'=yes';
 
foreach (@params) {
if(/^\s*class\s*=\s*(\S.*?)\s*$/s){
$fail=1 if(defined($class) && lc($class) ne lc($1));
$class=$1;
}
if(/^\s*importance\s*=\s*(\S.*?)\s*$/s){
$fail=1 if(defined($imp) && lc($imp) ne lc($1));
$imp=$1;
}
}
return '' unless $need_WPVG;
$need_WPVG=0;
return '{{WikiProject Video games}}';
}, keys %templates);
if(ref($outtxt) eq 'HASH'){
$api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
next;
}
 
# Second, add (or replace) {{WikiProject Video games}}
my @tf=map "$_=yes", keys %tf;
my @assess=();
if($fail){
warn "Conflicting assessments on $title\n";
#$api->store->{'conflicting assessments'}.="* [[:$title]]\n";
} else {
push @assess, "class=$class" if defined($class);
push @assess, "importance=$imp" if defined($imp);
#$api->store->{'NA assessments'}.="* [[:$title]]\n" if ($class // '') eq 'na';
}
myif($class ne 'FA' && $assess=undef;class ne 'GA'){
unless(defined($class)){
$assess=$api->WPBassess($title);
if(ref($assess) eq 'HASH'){
Line 244 ⟶ 195:
}
}
push @params, 'auto=yes' if ($assess // '') eq 'stub';
} else {
push @params, "class=$class";
}
 
$outtxt=$api->WPBadd($outtxt, $assess, sub {
shift; #return $banner_[4];
}, 'WikiProject NATO', shift@params); # $name
my $oname=shift;
my $params=shift;
shift; # $wikitext
my $new=shift;
return undef if $new;
 
foreach my $tf (keys %tf) {
push @$params, "$tf=yes" unless(grep(s/^(\s*\Q$tf\E\s*=(?:\s*(?=\S))?).*?(\s*)$/${1}yes$2/s, @$params));
}
 
if(@assess){
if(defined($class)){
unless(grep(/^\s*class\s*=\s*\S/, @$params)){
push @$params, "class=$class" unless(grep(s/^(\s*class\s*=)(\s*)$/$1$class$2/s, @$params));
}
}
if(defined($imp)){
unless(grep(/^\s*importance\s*=\s*\S/, @$params)){
push @$params, "importance=$imp" unless(grep(s/^(\s*importance\s*=)(\s*)$/$1$imp$2/s, @$params));
}
}
}
 
return "{{$oname}}" unless @$params;
return "{{$oname|".join("|", @$params)."}}";
}, 'WikiProject Video games', @tf, @assess);
if(ref($outtxt) eq 'HASH'){
$api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
Line 289 ⟶ 218:
}
 
my @found$cat=keys %found$iter->iterval;
my $found[-1]summary='and"Assessing for WikiProject NATO based on membership in '.$found[-1[$cat]] ifper @found>1$req $errto";
my $summary="Replacing ".join((@found>2)?', ':' ', @found)." with {{WikiProject Video games|".join('|', values %found)."}} per $req $errto";
$api->warn("$summary in $title\n");
my $r=$api->edit($tok, $outtxt, $summary, 1, 1);