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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: OnThisDayTagger: * In 'live' mode, create the categories if they don't already exist. * Don't log a warning when the talk page doesn't exist. * Set 'order' in the task object. AnomieBOT::Task: * Doc update.
AnomieBOT (talk | contribs)
Updating published sources: OnThisDayTagger: * Finished processing the list, change to live mode for 7-day trial. * Track the maximum oldid/date parameter used, and complain if {{tl|OnThisDay}} can't handle it. * Include the date in the edit summary
Line 1:
{{ombox|type=notice|text= PartiallyIn approvedtrial<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 30]]}}
<source lang="perl">
package tasks::OnThisDayTagger;
Line 9:
Task: OnThisDayTagger
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 30
Status: BRFAIn trial
Rate: Max 6 edits/minute
Created: 2009-05-14
Line 48:
 
my $whine_to='User talk:AnomieBOT';
my $mode='listlive'; # 'list' or 'live'
my $list='/tmp/otd-pages.txt';
 
Line 64:
 
=for info
PartiallyIn approvedtrial<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 30]]
 
=cut
 
sub approved {
return 04;
}
 
Line 76:
my $res;
 
$api->task('OnThisDayTagger', 0, 10, qw/d::TalkTrial d::Timestamp d::Templates d::Redirects/);
my $screwup=' Errors? [[User:'.$api->user.'/shutoff/OnThisDayTagger]]';
 
$api->store->{'maxotd'}=1 unless exists($api->store->{'maxotd'});
$api->store->{'nextday'}=1904 unless exists($api->store->{'nextday'});
 
my $x=$api->check_trial(1243457635, 'AnomieBOT 30');
return $$x if $x;
 
my $starttime=time;
Line 188 ⟶ 194:
}
close X;
 
my $res=check_maxotd($api);
return $res if $res;
 
return undef;
}
Line 371 ⟶ 381:
my $outtxt=$self->tag($api, $intxt, $fday => $revid);
if($intxt ne $outtxt){
$res=$api->edit($tok, $txtouttxt, "Adding/updating {{OnThisDay}} for $fday. $screwup", 0, 1);
if($res->{'code'} ne 'success'){
$api->warn("Write failed on $title: $res->{error}\n");
Line 397 ⟶ 407:
$api->store->{"nextday"}=++$self->{'nextday'};
}
 
my $res=check_maxotd($api);
return $res if $res;
 
my $next=86400-($starttime%86400)-(time-$starttime);
return$next=0 86400-(time%86400)if if($self->{'nextday'}>=<$today);
return $next;
}
 
Line 600 ⟶ 614:
$output.="<b><i>$buffer</i></b>" if($state eq 'both' && $buffer ne '');
return $output;
}
 
sub check_maxotd {
my $api=shift;
 
# Load template content
my $res=$api->rawpage('Template:OnThisDay');
if($res->{'code'} eq 'shutoff'){
$api->warn("Task disabled: ".$res->{'content'}."\n");
return 300;
}
if($res->{'code'} ne 'success'){
$api->warn("Could not load Template:OnThisDay: ".$res->{'error'}."\n");
return 60;
}
$res=$res->{'content'};
 
# Count date/oldid parameters available
my $i=1;
$i++ while(index($res, "{{{date$i|}}}")>0 && index($res, "{{{oldid$i|}}}")>0);
$i--;
 
# Check if it's enough
my $max=$api->store->{'maxotd'};
return 0 if $max<=$i;
 
# No, complain
$api->log("Whining about insufficient parameters in {{OnThisDay}}");
my $summ="{{[[Template:OnThisDay]]}} needs more parameters";
$res=$api->whine($summ, "It appears that {{tl|OnThisDay}} only supports parameters up to <nowiki>{{{date$i}}} and {{{oldid$i}}}</nowiki>, and I have seen at least one page that needs $max. Please edit the template to include more calls to {{tl|OnThisDay/link}}.", Summary => $summ, Pagename => $whine_to);
if($res->{'code'} eq 'shutoff'){
$api->warn("Task disabled: ".$res->{'content'}."\n");
return 300;
}
if($res->{'code'} ne 'success'){
$api->warn("Could not complain about {{OnThisDay}}: ".$res->{'error'}."\n");
return 60;
}
return 0;
}
 
Line 658 ⟶ 711:
$i++;
}
$api->store->{'maxotd'}=$i-1 if $api->store->{'maxotd'}<$i-1;
$done=1;
return "{{$oname|".join('|', @$params)."}}";
Line 680 ⟶ 734:
$i++;
}
$api->store->{'maxotd'}=$i-1 if $api->store->{'maxotd'}<$i-1;
$templ.="}}";