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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: WikiProjectWorker: * Don't choke when trying to assess talk pages for nonexistant subpages, just don't assess them.
AnomieBOT (talk | contribs)
Updating published sources: WikiProjectWorker: * Done with WikiProject Japan tagging. * Start WPVG task force merging. Someone stole most of it, though :( conf.sample.ini: * Add a note about SQLite's coarse locking, which can be worked around with a
Line 32:
@ISA=qw/AnomieBOT::Task/;
 
### Request link, for edit summary.
my $req="[[User:AnomieBOT/req/WikiProjectJapanWPVG 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=12;
 
### How to find the pages?
my @%templates=('WP ShintoMortalKombatProject', => 'JmythMortalKombat', 'GaijinWikiproject tarento',Pro Gaming'Project Owarai',=> 'WikiProject JapanProgaming');
my @iterators=(
{
list => 'embeddedin',
eititle => [ map "Template:$_", @keys %templates ],
eilimit => 'max',
},
);
 
### Filter function: manipulate the found data as necessary, returning the talk
### page to tag (or undef to skip).
sub filter {
return $_[0]->{'title'};
Line 57:
# Banner configurations.
my %banner_cfgs=(
'WikiProject JapanVideo games' => {
meta => 0,
stubauto => undef,
canonicalize => 'WikiProject JapanVideo games',
},
);
Line 101:
}
if(($api->store->{'configured'} // 0) < $seq){
### Initialize configuration here
$api->store->{'conflicting assessments'}='';
#$api->store->{'NAconflicting assessments'}='';
#$api->store->{'conflictingNA 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 ⟶ 184:
 
# Is there a WikiProject Japan template already on the page?
my $need_WPJneed_WPVG=($api->WPBcheck($outtxt, "WikiProject JapanVideo games") == 0);
 
# First, remove the to-be-removed templates and calculate task
Line 191 ⟶ 192:
my $imp=undef;
my %tf=();
},my @templates%found=();
(undef,$outtxt)=$api->WPBcheck($outtxt, sub {
my $banner=shift;
shift; #my $name=shift;
my $oname=shift;
my @params=@{shift()};
 
my $wpj=(tf{$templates{$banner eq 'WikiProject Japan')}}=1;
$tffound{'myth'"{{$name}}"}=1 if $templates{$banner eq }.'Jmyth=yes';
 
$tf{'shinto'}=1 if $banner eq 'WP Shinto';
$tf{'myth'}=1 if $banner eq 'Jmyth';
$tf{'gaijin'}=1 if $banner eq 'Gaijin tarento';
$tf{'owarai'}=1 if $banner eq 'Project Owarai';
foreach (@params) {
if(/^\s*class\s*=\s*(\S.*?)\s*$/s){
Line 211 ⟶ 210:
$fail=1 if(defined($imp) && lc($imp) ne lc($1));
$imp=$1;
}
if($wpj && /^\s*tf[23]?\s*=\s*(\S.*?)\s*$/s){
my $x=lc($1);
$tf{'baseball'}=1 if $x eq 'baseball';
$tf{'car'}=1 if $x eq 'car';
$tf{'CJKV'}=1 if $x eq 'cjkv';
$tf{'dist-muni'}=1 if $x eq 'districts and municipalities';
$tf{'gaijin'}=1 if $x eq 'gaijin tarento';
$tf{'milhist'}=1 if $x eq 'military history';
$tf{'music'}=1 if $x eq 'music';
$tf{'myth'}=1 if $x eq 'mythology';
$tf{'owarai'}=1 if $x eq 'owarai';
$tf{'phototf'}=1 if $x eq 'photo';
$tf{'prefectures'}=1 if $x eq 'prefectures';
$tf{'royalty'}=1 if $x eq 'royalty and nobility';
$tf{'shinto'}=1 if $x eq 'shinto';
$tf{'tokyo'}=1 if $x eq 'tokyo';
$tf{'update'}=1 if $x eq 'update';
}
}
return undef'' ifunless $banner eq 'WikiProject Japan'need_WPVG;
return '' unless $need_WPJneed_WPVG=0;
$need_WPJ=0return '{{WikiProject Video games}}';
}, keys return '{{WikiProject Japan}}'%templates);
}, @templates);
if(ref($outtxt) eq 'HASH'){
$api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
Line 241 ⟶ 221:
}
 
# Second, add (or replace) {{WikiProject JapanVideo games}}
my @tf=map "$_=yes", keys %tf;
my @assess=();
if($fail){
$api->store->{'conflictingwarn assessments'}.="*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';
}
my $assess=undef;
Line 272 ⟶ 253:
my $new=shift;
return undef if $new;
 
$params = [ grep $_!~/^\s*tf[23]?\s*=/, @$params ];
 
foreach my $tf (keys %tf) {
Line 281 ⟶ 260:
if(@assess){
if(defined($class)){
push @$params, "class=$class" unless(grep(s/^(\s*class\s*=(?:\s*(?=\S))?).*?(\s*)$/$1$class$2/s, @$params));{
push @$params, "class=$class" [ unless(grep $_!~(s/^(\s*tf[23]?class\s*=)(\s*)$/$1$class$2/s, @$params ]));
}
}
if(defined($imp)){
push @$params, "importance=$imp" unless(grep(s/^(\s*importance\s*=(?:\s*(?=\S))?).*?(\s*)$/$1$imp$2/s, @$params));{
push @$params, "importance=$imp" unless(grep(s/^(\s*importance\s*=)(\s*)$/$1$imp$2/s, @$params));
my $x=lc($1);}
}
}
Line 290 ⟶ 273:
return "{{$oname}}" unless @$params;
return "{{$oname|".join("|", @$params)."}}";
}, 'WikiProject JapanVideo games', @tf, @assess);
if(ref($outtxt) eq 'HASH'){
$api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
Line 306 ⟶ 289:
}
 
my $summary@found="Adjustingkeys WikiProject tagging for WikiProject Japan per $req $errto"%found;
$found[-1]='and '.$found[-1] if @found>1;
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);