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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: DatedCategoryCreater: * Ahhh! Accidentally left some testing code in place. Sorry everyone.
AnomieBOT (talk | contribs)
Updating published sources: DatedCategoryCreator: * Use correct key from allcategories response.
 
(12 intermediate revisions by the same user not shown)
Line 35:
# here.
my %catmap=(
'CategoryUncategorized neededpages' => 'Uncategorized from ',
'Articles needing expert attention by month' => 'Articles needing expert attention from ',
'Wikipedia articles with style issues by month' => 'Wikipedia articles with style issues from ',
);
my %rcatmap=reverse %catmap;
Line 43 ⟶ 44:
my %skipcat=(
'Articles with invalid date parameter in template' => 1
);
 
# Categories to allow old dates
my %oldcats=(
'Wikipedia articles in need of updating' => 1
);
 
# Categories to allow future dates, as well as the valid timespan in seconds
# (otherwise, the default is 86400)
my %futurecats=(
'Articles containing potentially dated statements' => 31622400,
'Articles that include images for deletion' => 8*86400,
'Clean-up categories' => 31622400,
);
 
Line 54 ⟶ 68:
$monthnum{$months[$i]}=$i+1;
}
 
my $yearre;
 
sub new {
Line 76 ⟶ 88:
 
sub approved {
return 32;
}
 
Line 87 ⟶ 99:
my %did=();
 
my $curmonth@t=strftime('%B %Y', gmtime(time()+86400));
my $curmonth=strftime('%B %Y', @t);
 
$yearre=join('|', 2004 .. ((gmtime(time()+86400))[5]+1900));
$yearre=qr/$yearre/;
 
# Part 1: Create needed categories for the current month
Line 134 ⟶ 144:
);
while(my $p=$iter->next){
if(!$p->{'_ok_'}){
$api->warn("Could not retrieve category members from iterator: ".$p->{'error'}."\n");
return 60;
}
for my $c (@{$p->{'categories'} // []}) {
# Minimal sanity check; make_dated_cat() will do more
next unless $c->{'title'}=~/ $monthre $yearre\d{4}$/;
next if exists($did{$c->{'title'}});
$did{$c->{'title'}}=1;
Line 142 ⟶ 156:
return $res if $res;
}
}
 
# Part 3: Look for missing dated categories beginning with "Clean-up categories from".
$iter = $api->iterator(
list => 'allcategories',
acprefix => 'Clean-up categories from ',
acprop => 'size|hidden',
aclimit => 'max',
formatversion => 2,
);
while ( my $c = $iter->next ) {
if ( ! $c->{'_ok_'} ) {
$api->warn( "Could not retrieve category list from iterator: " . $c->{'error'} . "\n" );
return 60;
}
next unless $c->{'category'} =~ / $monthre \d{4}$/;
next if $c->{'hidden'} || $c->{'size'} <= 0;
next if exists( $did{'Category:' . $c->{'category'}} );
$did{'Category:' . $c->{'category'}}=1;
$res = $self->make_dated_cat( $api, 'Category:' . $c->{'category'}, 'non-empty month' );
return $res if $res;
}
 
Line 163 ⟶ 198:
 
# Figure out the parent cat, and calculate the parameters for {{Monthly
# clean -up category}}.
my $parent=$title;
my $txttmplparams='{{Monthly clean up category';
$parent=~s/^Category://;
$parent=~s/($monthre) ($yearre\d{4})$//;
my ($m,$y)=($1,$2);
if(exists($rcatmap{$parent})){
$parent=$rcatmap{$parent};
$txttmplparams.="|cat=$parent";
} else {
return 0 unless $parent=~s/ from $//;
return 0 if exists($skipcat{$parent});
}
my $dt = $futurecats{$parent} // 86400;
$txt.='}}';
my @t=gmtime(time()+$dt);
return 0 if $y>$t[5]+1900;
return 0 if($y==$t[5]+1900 && $monthnum{$m}>$t[4]+1);
return 0 if(!exists($oldcats{$parent}) && $y<2010);
 
# Check whether the parent cat actually exists and is a subcat of the meta
Line 182 ⟶ 221:
my $res=$api->query(
titles => "Category:$parent",
prop => 'categories|templates',
clcategories => 'Category:Wikipedia maintenance categories sorted by month|Category:Wikipedia categories sorted by month',
tltemplates => 'Template:Parent monthly maintenance category',
);
if($res->{'code'} ne 'success'){
Line 194 ⟶ 234:
return 0;
}
my ($type, $txt);
if(grep $_->{'title'} eq 'Category:Wikipedia maintenance categories sorted by month', @{$res->{'categories'}}){
if ( grep $type=_->{'title'} eq 'Template:Parent monthly maintenance category';, @{$res->{'templates'}} ) {
$type='maintenance category';
$txt="{{Monthly maintenance category$tmplparams}}";
} else {
$type='clean-up category';
$txt="{{Monthly clean-up category$tmplparams}}";
}
} elsif(grep $_->{'title'} eq 'Category:Wikipedia categories sorted by month', @{$res->{'categories'}}){
$type='category';
$txt="{{Monthly maintenance category$tmplparams}}";
} else {
$api->warn("Did not create category $title, because parent category $parent is not in Category:Wikipedia maintenance categories sorted by month or Category:Wikipedia categories sorted by month");