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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: WikiProjectWorker: * WikiProject Food and drink run complete.
AnomieBOT (talk | contribs)
Updating published sources: WikiProjectTagger, WikiProjectWorker: * Retire these tasks, WikiProject templates have changed a bunch since I last ran these.
 
(40 intermediate revisions by the same user not shown)
Line 1:
{{ombox|type=notice|text= Approved 2009-04-08<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 28]]}}
{{ombox|type=notice|text= Retired 2024-01-29. Haven't had call to run this in a while, and the related templates have changed so I'd probably have to update this code to run it again.}}
<source lang="perl">
<syntaxhighlight lang="perl">
package tasks::WikiProjectWorker;
 
Line 10 ⟶ 11:
Task: WikiProjectWorker
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 28
Status: ApprovedInactive 20092024-0401-0829
Rate: Max 6 edits/minute
Created: 2009-03-27
OnDemand: true
Line 28:
 
use Data::Dumper;
use Digest::SHA qw/sha256_base64/;
use AnomieBOT::Task;
use vars qw/@ISA/;
Line 34 ⟶ 33:
 
### Request link, for edit summary.
my $req="[[User:AnomieBOT/req/WikiProject FoodHigher and drink 1Education|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=1328;
 
### How to find the pages?
my @cats%catmap = (
"Category:Articles using infobox university" => "WikiProject Higher education",
);
my @cats=keys %catmap;
my @iterators=(
{
generator => 'embeddedincategorymembers',
geititle gcmtitle => [@cats],
gcmlimit => 100,
'Template:WPMIX', 'Template:Cocktails Project', 'Template:WikiProject Mixed Drinks', 'Template:Wpmix', 'Template:WP Mixed Drinks',
'Template:WPSD', 'Template:Soda', 'Template:WikiProject Soft Drinks',
'Template:WikiProject Ice Cream', 'Template:WP Ice Cream',
'Template:WikiProject Bartending', 'Template:WPBAR',
],
geilimit => '100',
},
);
Line 59 ⟶ 55:
### page to tag (or undef to skip).
sub filter {
# $_[0]->{'title'}='Talk:'.$_[0]->{'title'} if $_[0]->{'ns'}==0;
# $_[0]->{'title'}=~s/^([^:]*):/$1 talk:/ if($_[0]->{'ns'}!=0 && ($_[0]->{'ns'}&1)==0);
return $_[0]->{'title'};
}
Line 70 ⟶ 66:
}
 
my $always_copy_importance = 0;
my $set_empty_importance = 0;
sub copy_importance {
#return ($_[0]->WPBmax($_[2]))[1];
#return '';
}
 
# Banner configurations.
my $main_banner='WikiProject FoodHigher and drinkeducation';
my @preprocess_templates=('WikiProject Food and drink');
my %banner_cfgs=(
'WikiProject FoodHigher and drinkeducation' => {
meta => 1,
importance => '',
canonicalize => 'WikiProject Higher education',
},
);
 
# Extra parameters (e.g. workgroup).
my @extra_params=();
my $taggingwith = @extra_params ? '|' . join( '|', @extra_params ) : '';
 
# Regex fragment to match any aliases of params in @extra_params.
my %extra_param_aliases = ();
 
# Possible main banners, usually just $main_banner.
my @main_banners=(
$main_banner,
);
'Food and drink',
 
'WPFOOD',
# Set this to merge these existing banners into $main_banner.
'WPCUISINE',
my @merge_banners=();
'F&D',
 
'Wpfood',
# Set this to tag 'WikiProject FoodBiography andworkgroups Drinkin addition to the project',s own banner.
my @bio_wg = (
'Food',
'Wikiproject Food and drink',
'WP Food',
'Wikiproject Food and Drink',
'WikiProject Food',
'WikiProject FOOD',
'Wpf',
);
 
Line 115 ⟶ 116:
=for info
Approved 2009-04-08<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 28]]
 
=for info
Retired 2024-01-29. Haven't had call to run this in a while, and the related templates have changed so I'd probably have to update this code to run it again.
 
=cut
Line 135 ⟶ 139:
$cfg=$api->WPBMetaConfig($cfg->{'meta'}, %$cfg) if exists($cfg->{'meta'});
$cfg{$banner}=$cfg;
$banner_cfgs{$banner}{'stubauto'}=$cfg->{'stubauto'};
}
$api->WPBconfig(%cfg);
Line 193 ⟶ 198:
$api->log("Checking $title...");
 
my $intxt=$tok->{'revisions'}[0]{'slots'}{'main'}{'*'} // '';
my ($outtxt,$nowiki)=$api->strip_nowiki($intxt);
 
my @params=()@extra_params;
 
my $assess = undef;
Line 204 ⟶ 209:
next;
}
if($class eq ''){=~s/^\s+|\s+$//g;
$assess=$api->WPBassess($title);
if(ref($assess) eq 'HASH'){
if($assess->{'code'} eq 'pagemissing'){
# No subject page, doesn't matter
$assess=undef;
} else {
$api->warn("Processing $title failed: ".$assess->{'error'}."\n");
next;
}
}
}
 
my $copy_importance = $always_copy_importance; # Always copy?
if($class eq '' || lc($class) eq lc($assess)){
$class='';
} else {
$assess=undef;
push @params, "class=$class";
$copy_importance = 1;
}
 
if($copy_importance){
my $imp = copy_importance($api, $title, $intxt);
if(ref($imp) eq 'HASH'){
Line 222 ⟶ 236:
next;
}
push @params, "importance=$imp" if ( $set_empty_importance || ($imp//'') ne '' );
}
 
my $need_main_banner = ($api->WPBcheck($outtxt, $main_banner@main_banners) == 0);
# grr...if(0){
# grr, already redirected so the above always returns true
$need_main_banner=1;
$api->WPBcheck($outtxt, sub { $need_main_banner=1;
my $banner=shift;api->WPBcheck($outtxt, sub {
my $namebanner=shift;
my $name=shift;
$need_main_banner=0 if(grep $name eq $_, @main_banners);
return undef;
}, $main_banner@main_banners);
}
 
### PROCESSING ###
Line 239 ⟶ 255:
my @merge=();
my @summary=();
my $no_summary = 0;
 
# Special: Different default parent banner depending on source category.
$main_banner = $catmap{$iter->iterval};
 
if(@preprocess_templatesmerge_banners){
(undef,$outtxt)=$api->WPBcheck($outtxt, sub {
my $banner=shift;
Line 250 ⟶ 270:
return undef if(grep $name eq $_, @main_banners);
 
mypush @merge, $soda=undefoname;
$soda='soda=yes' if(grep $name eq $_, ('WPSD','Soda','WikiProject Soft Drinks'));
my $mix=undef;
$mix='mix=yes' if(grep $name eq $_, ('WPMIX', 'Cocktails Project', 'WikiProject Mixed Drinks', 'Wpmix', 'WP Mixed Drinks'));
$mix='bar=yes' if(grep $name eq $_, ('WikiProject Bartending', 'WPBAR'));
my $icecream=undef;
$icecream='ice cream=yes' if(grep $name eq $_, ('WikiProject Ice Cream', 'WP Ice Cream'));
push @merge, $name;
my $pp='';
foreach (@$params){
$soda="$1=yes" if /^\s*(coffee|tea|c&t)\s*=/;
$mix="$1=yes" if /^\s*(bar)\s*=/;
$pp.="|$_" if /^\s*(class|importance|needs-photo)\s*=/;
}
push @params, $soda if defined($soda);
push @params, $mix if defined($mix);
push @params, $icecream if defined($icecream);
 
return '' unless $need_main_banner;
$need_main_banner=0;
return "{{$main_banner$pp}}";
}, @preprocess_templatesmerge_banners);
if(ref($outtxt) eq 'HASH'){
$api->warn("Preprocessing $title failed: ".$outtxt->{'error'}."\n");
Line 279 ⟶ 283:
$merge[-1]='and '.$merge[-1] if @merge>1;
push @summary, "merging ".join((@merge>2)?', ':' ', @merge)." into $main_banner" if @merge;
$no_summary = 1 if @merge;
} else {
# $api->warn("$title contains ".$iter->iterval.", but not in section 0\n");
Line 285 ⟶ 290:
}
 
if ( @bio_wg ) {
my %added_wg=();
(undef,$outtxt)=$api->WPBcheck($outtxt, sub {
my $banner=shift;
my $name=shift;
my $oname=shift;
my $params=shift;
my $wikitext=shift;
 
my %have = ();
foreach ($api->process_paramlist(@$params)) {
$have{$_->{'name'}} = 1;
}
my $any = 0;
foreach my $p (@bio_wg){
next if exists($have{$p});
push @$params, "$p=yes";
$added_wg{"$p=yes"}=1;
$any = 1;
}
return undef unless $any;
 
my $out="{{$oname";
$out.="|".join("|", @$params) if @$params;
$out.="}}";
return $out;
}, 'WikiProject Biography');
if(ref($outtxt) eq 'HASH'){
$api->warn("WPBIO workgroups in $title failed: ".$outtxt->{'error'}."\n");
next;
}
if(%added_wg){
my @added_wg = keys %added_wg;
$added_wg[-1]='and '.$added_wg[-1] if @added_wg>1;
push @summary, "added " . join((@added_wg>2)?', ':' ', @added_wg) . " to {{WikiProject Biography}}";
}
}
 
my $tag;
my $pg=$title;
$pg=~s/^Talk://;
Line 290 ⟶ 334:
$page=$api->query(
titles => $pg,
prop => 'info',
redirects => 1,
);
if($page->{'code'} eq 'shutoff'){
$api->warn("Task disabled: ".$page->{'content'}."\n");
return 300;
}
if($page->{'code'} ne 'success'){
$api->warn("Could not load $pg info: ".$page->{'error'}."\n");
return 60;
}
 
$page=(values %{$page->{'query'}{'pages'}})[0];
}
 
$outtxt=$api->WPBadd($outtxt,my $assess,@process_banners sub= {();
$api->WPBcheck( $outtxt, sub { shiftpush @process_banners, $_[0]; #}, banner@main_banners );
@process_banners = ( $main_banner my) $name=shiftunless @process_banners; # name
for my $process_banner (@process_banners) my $oname=shift;{
my $paramsouttxt=shift;$api->WPBadd($outtxt, $assess, sub {
my $wikitextbanner=shift; # banner
my $newname=shift; # name
return '' if my $newoname=shift;
my $params=shift;
my $wikitext=shift;
my $new=shift;
#return '' if $new;
 
return undef unless(grep $namebanner eq $_, @main_banners);
my %cfg=%{$banner_cfgs{$banner}};
 
foreach my $p (@params){any=0;
nextforeach unlessmy $p=~/^ (.+?@params)=(.*)$/;{
my ( next unless $k,$vp=~/^(.+?)=($1,$2.*)$/;
my ($rek,$v)=qr/\S/($1,$2);
unless(grep( my $kre=qr/^\s*\Q$k\E\s*=\s*$re/, @$params)){;
next if (grep defined(/^\s*\Q $k\E\s*=\s*\Qextra_param_aliases{$v\E\s*$/s,k} @$params) ); {
unshift @ my $params,aliasre "$k=$v" unless(grep(s/^(\s*\Q$extra_param_aliases{$k\E\s*=\s*?)(?:\S.*?)?(\s*)$/$1$v$2/s, @$params))};
$kre = qr/(?:$kre|$aliasre)/;
}
my $re=qr/\S.*?/;
unless(grep(/^\s*$kre\s*=\s*$re\s*$/, @$params)){
next if(grep(/^\s*$kre\s*=\s*(?i:\Q$v\E)\s*$/s, @$params));
unshift @$params, "$k=$v" unless(grep(s/^(\s*$kre\s*=\s*?)(?:\S.*?)?(\s*)$/$1$v$2/s, @$params));
$any=1 unless $v eq '';
if($k eq 'class' && exists($cfg{'meta'}) && ($cfg{'stubauto'}//'')){
my $aa=$cfg{'stubauto'};
$aa=~s/\s*=.*//;
push @$params, "$aa=inherit" unless(grep(s/^(\s*\Q$aa\E\s*=\s*?)(?:\S.*?)?(\s*)$/$1inherit$2/s, @$params));
}
}
}
if($new && $class && (grep /^class=/, @$params) && exists($cfg{'meta'}) && ($cfg{'stubauto'}//'')){
}
my $aa=$cfg{'stubauto'};
$aa=~s/\s*=.*//;
push @$params, "$aa=inherit" unless(grep(s/^(\s*\Q$aa\E\s*=\s*?)(?:\S.*?)?(\s*)$/$1inherit$2/s, @$params));
$any=1;
}
return $wikitext unless $any;
 
my if(defined($out="cfg{'canonicalize'})){$oname";
$out.="|".join("|", @$params) if @ my $n=$paramscfg{'canonicalize'};
$out.oname="}}"~s/_/ /g;
return $oname=~s/^(\s*)\S(?:.*\S)?(\s*)$/$1$n$out2/is;
}, $main_banner, @params); }
if(ref($outtxt) eq 'HASH') my $out="{{$oname";
$api->warn("Processing $title failed: ". $outtxt->{'error'}out.="\n|".join("|", @$params) if @$params;
next $out.="}}";
return $out;
}, $process_banner, @params);
if(ref($outtxt) eq 'HASH'){
$api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
next;
}
push @summary, "Tagging with {{$process_banner$taggingwith}}" unless $no_summary;
}
push @summary, "Tagging with {{$main_banner}}" unless @summary;
 
$outtxt=$api->replace_nowiki($outtxt, $nowiki);
Line 344 ⟶ 417:
my $cat=$iter->iterval;
$summary[-1]='and '.$summary[-1] if @summary>1;
my $summary = ucfirst(join((@summary>2)?', ':' ', @summary))." per $req $errto";
 
my @cleanup=();
Line 353 ⟶ 426:
}
$summary.="; general banner cleanup (".join(', ', @cleanup).")" if @cleanup;
$summary.=". $errto";
 
$api->log("$summary in $title");
Line 380 ⟶ 454:
}
 
1;
</source>
 
</syntaxhighlight>