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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: WikiProjectWorker: * Crap, wrong edit summary.
AnomieBOT (talk | contribs)
Updating published sources: WikiProjectTagger, WikiProjectWorker: * Retire these tasks, WikiProject templates have changed a bunch since I last ran these.
 
(64 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 7 ⟶ 8:
=begin metadata
 
Bot: AnomieBOT
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 27 ⟶ 28:
 
use Data::Dumper;
use Digest::SHA qw/sha256_base64/;
use AnomieBOT::Task;
use vars qw/@ISA/;
Line 33:
 
### Request link, for edit summary.
my $req="[[User:AnomieBOT/req/WikiProject CaliforniaHigher 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=628;
 
### How to find the pages?
my @templates%catmap = (
'Template"Category:Articles using infobox university" => "WikiProject SouthernHigher California'education",
'Template:WikiProject Santa Barbara County',
);
my @cats=keys %catmap;
my @iterators=(
{
list generator => 'embeddedincategorymembers',
eititlegcmtitle => \[@templatescats],
eilimitgcmlimit => 'max'100,
redirects => 1,
},
);
Line 56 ⟶ 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 61 ⟶ 62:
### How to copy other projects' assessments
sub copy_class {
return ''($_[0]->WPBmax($_[2]))[0];
#return '';
}
 
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 CaliforniaHigher education';
my @preprocess_templates=map substr($_,9), @templates;
my %banner_cfgs=(
'WikiProject CaliforniaHigher education' => {
meta => 01,
canonicalizeimportance => 'WikiProject California',
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,
);
 
# Set this to merge these existing banners into $main_banner.
my @merge_banners=();
 
# Set this to tag WikiProject Biography workgroups in addition to the project's own banner.
my @bio_wg = (
);
 
Line 82 ⟶ 106:
my $self=$class->SUPER::new();
$self->{'config loaded'}=0;
$self->{'iter'}=undef;
$self->{'iterators'}=[@iterators];
bless $self, $class;
return $self;
Line 90 ⟶ 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
 
sub approved {
return -1;
}
 
Line 110 ⟶ 139:
$cfg=$api->WPBMetaConfig($cfg->{'meta'}, %$cfg) if exists($cfg->{'meta'});
$cfg{$banner}=$cfg;
$banner_cfgs{$banner}{'stubauto'}=$cfg->{'stubauto'};
}
$api->WPBconfig(%cfg);
 
$self->{'config loaded'}=1;
}
Line 121 ⟶ 152:
my $endtime=time()+300;
 
while(1){
foreach my $itercfg (@iterators) {
my $iter=$apiself->iterator(%$itercfg){'iter'};
if(!defined($iter)){
my $i=shift @{$self->{'iterators'}};
last unless $i;
$iter=$api->iterator(%$i);
$self->{'iter'}=$iter;
}
while(my $page=$iter->next()){
if(!$page->{'_ok_'}){
Line 161 ⟶ 198:
$api->log("Checking $title...");
 
my $intxt=exists($tok->{'revisions'}[0]{'*slots'})?$tok->{'revisionsmain'}[0]{'*'}: // '';
my ($outtxt,$nowiki)=$api->strip_nowiki($intxt);
 
my @params=()@extra_params;
 
my $assess = undef;
my $class = copy_class($api, $title, $intxt);
if(ref($class) eq 'HASH'){
$api->warn("Processing $title failed: ".$class->{'error'}."\n");
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;
}
}
}
#push @params, 'auto=yes' if ($assess // '') eq 'stub';
 
my $copy_importance = $always_copy_importance; # Always copy?
if($class eq '' || lc($class) eq lc($assess)){
$class='';
} else {
$assess=undef;
push @params, "class=$class";
my $impcopy_importance = copy_importance($api, $intxt)1;
}
 
if($copy_importance){
my $imp = copy_importance($api, $title, $intxt);
if(ref($imp) eq 'HASH'){
$api->warn("Processing $title failed: ".$imp->{'error'}."\n");
next;
}
#push @params, "importance=$imp" if ( $set_empty_importance || ($imp//'') eqne '' );
}
 
my $need_main_banner = ($api->WPBcheck($outtxt, $main_banner@main_banners) == 0);
if(0){
# grr, already redirected so the above always returns true
$need_main_banner=1;
$api->WPBcheck($outtxt, sub {
my $banner=shift;
my $name=shift;
$need_main_banner=0 if(grep $name eq $_, @main_banners);
return undef;
}, @main_banners);
}
 
### PROCESSING ###
Line 200 ⟶ 255:
my @merge=();
my @summary=();
my $no_summary = 0;
 
# Special: Different default parent banner depending on source category.
if(@preprocess_templates){
$main_banner = $catmap{$iter->iterval};
 
if(@merge_banners){
(undef,$outtxt)=$api->WPBcheck($outtxt, sub {
my $banner=shift;
Line 209 ⟶ 268:
my $wikitext=shift;
 
myreturn $key=undef if(grep $name eq $_, @main_banners);
$key='southerncalifornia' if $banner eq 'WikiProject Southern California';
$key='santabarbaracounty' if $banner eq 'WikiProject Santa Barbara Country';
return undef unless defined($key);
push @params, "$key=yes" unless grep(s/^(\s*\Q$key\E\s*=\s*).*?(\s*)$/${1}yes$2/s, @params);
push @merge, $banner;
 
foreachpush (@merge, $params){oname;
if(/^\s*class\s*=\s*(\S.*?)\s*$/s){
next if grep(/^\s*class\s*=\s*\S/, @params);
my $c=$1;
push @params, "class=$c" unless grep(s/^(\s*class\s*=)(\s*)$/$1$c$2/, @params);
}
push @params, "$key-importance=$1" if /^\s*importance\s*=\s*(\S.*?)\s*$/s;
}
 
return '' unless $need_main_banner;
$need_main_banner=0;
return "{{$main_banner}}";
}, @preprocess_templatesmerge_banners);
if(ref($outtxt) eq 'HASH'){
$api->warn("Preprocessing $title failed: ".$outtxt->{'error'}."\n");
next;
}
if(@merge){
$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");
next;
}
}
 
$outtxt=$api->WPBaddif ($outtxt, $assess,@bio_wg sub) {
shiftmy %added_wg=(); # banner
shift;(undef,$outtxt)=$api->WPBcheck($outtxt, #sub name{
my $onamebanner=shift;
my $paramsname=shift;
my $wikitextoname=shift;
my $newparams=shift;
return undef if my $newwikitext=shift;
 
foreach my $p%have = (@params){;
next unlessforeach ($p=~/^api->process_paramlist(.+?@$params)=(.*)$/; {
my ( $k,have{$v)_->{'name'}} =($ 1,$2);
unless(grep(/^\s*\Q$k\E\s*=\s*\S/, @$params)){
push @$params, "$k=$v" unless(grep(s/^(\s*\Q$k\E\s*=)(\s*)$/$1$v$2/s, @$params));
}
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 $out="{{$oname"tag;
my $out.pg="|".join("|", @$params) if @$paramstitle;
$out.pg="}}"~s/^Talk://;
return undef if ($outpage->{'title'} eqne $wikitext;pg){
#push @summary, "updating $main_banner";page=$api->query(
return titles => $out;pg,
}, $main_banner, @params); prop => 'info',
if(ref($outtxt) eq 'HASH'){ redirects => 1,
$api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
next;if($page->{'code'} ne 'success'){
$api->warn("Could not load $pg info: ".$page->{'error'}."\n");
return 60;
}
 
$page=(values %{$page->{'query'}{'pages'}})[0];
}
 
my @process_banners = ();
$api->WPBcheck( $outtxt, sub { push @process_banners, $_[0]; }, @main_banners );
@process_banners = ( $main_banner ) unless @process_banners;
for my $process_banner (@process_banners) {
$outtxt=$api->WPBadd($outtxt, $assess, sub {
my $banner=shift; # banner
my $name=shift; # name
my $oname=shift;
my $params=shift;
my $wikitext=shift;
my $new=shift;
#return '' if $new;
 
return undef unless(grep $banner eq $_, @main_banners);
my %cfg=%{$banner_cfgs{$banner}};
 
my $any=0;
foreach my $p (@params){
next unless $p=~/^(.+?)=(.*)$/;
my ($k,$v)=($1,$2);
my $kre=qr/\Q$k\E/;
if ( defined( $extra_param_aliases{$k} ) ) {
my $aliasre = $extra_param_aliases{$k};
$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;
 
if(defined($cfg{'canonicalize'})){
my $n=$cfg{'canonicalize'};
$oname=~s/_/ /g;
$oname=~s/^(\s*)\S(?:.*\S)?(\s*)$/$1$n$2/is;
}
my $out="{{$oname";
$out.="|".join("|", @$params) if @$params;
$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;
}
 
Line 274 ⟶ 415:
next;
}
my $oldcat=$outtxtiter->iterval;
$outtxtsummary[-1]='and '.$apisummary[-1] if @summary>WPBfixshell($outtxt)1;
my $summary = ucfirst(join((@summary>2)?', ':' ', @summary))." per $req";
 
my @cleanup=();
$outtxt=$api->WPBfixshell($outtxt, \@cleanup);
if(ref($outtxt) eq 'HASH'){
$api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
next;
}
push @$summary, .="; general banner cleanup (".join(', if', $outtxt@cleanup).")" neif $old@cleanup;
$summary.=". $errto";
 
my $cat=$iter->iterval;
$summary[-1]='and '.$summary[-1] if @summary>1;
my $summary = ucfirst(join((@summary>2)?', ':' ', @summary))." per $req $errto";
$api->log("$summary in $title");
my $r=$api->edit($tok, $outtxt, $summary, 1, 1);
Line 301 ⟶ 444:
return 0 if time()>=$endtime;
}
$self->{'iter'}=undef;
}
 
# No more pages to check, try again in 10 minutes or so in case of errors.
$self->{'iter'}=undef;
$self->{'iterators'}=[@iterators];
$api->log("WikiProjectWorker may be DONE!");
return 600;
}
 
1;
</source>
 
</syntaxhighlight>