Content deleted Content added
Updating published sources: General: * Add support for the AssertEdit extension. * BREAKING CHANGE: Assert "bot" by default. This means any non-flagged bot on a wiki with AssertEdit enabled will not be able to edit without |
Updating published sources: General: * New function to load a task (once). * Update the various scripts to use that function. * Update metadata for all tasks. SourceUploader: * Generate a new file, User:AnomieBOT/TaskList, since I keep forgetting |
||
Line 7:
=begin metadata
Task: SourceUploader
BRFA: N/A
Status: Begun 2008-08-15
Rate: On bot startup only, max 6 edits/minute
Created: 2008-08-16
Updates the pages under [[User:AnomieBOT/source]] to reflect the current source
Line 91 ⟶ 92:
my %pages=();
my %tasks=(
'01 Current' => [],
'04 Awaiting approval' => [],
'05 Past' => [],
);
my @dirs=($basedir);
while(my $dir=shift @dirs){
Line 183 ⟶ 189:
$x.="</noinclude>";
$pages{"$pp/metadata"}=$x;
my $section=determine_task_section(".$pp", %metadata);
$tasks{$section}=[] unless exists($tasks{$section});
push @{$tasks{$section}}, $metadata{'created'}." {{User:$bot/source$pp/metadata}}";
}
}
Line 209 ⟶ 218:
$dirpage.="|}";
$pages{substr($dir,length($basedir))}=$dirpage;
}
my $tasklist='';
foreach my $section (sort keys %tasks){
my @links=sort @{$tasks{$section}};
$section=~s/^(\d+) //;
my $n=$1;
$tasklist.="\n" if $tasklist ne '';
$tasklist.="=== $section ===\n";
if(@links){
$tasklist.="{| class=\"wikitable sortable\"\n";
$tasklist.="! Task !! Disable !! ".(($n==1 || $n==2)?'Approval':'Status')." !! Edit Rate !! Description\n";
$tasklist.=join("\n", map { substr($_,11) } @links)."\n";
$tasklist.="|}\n";
} else {
$tasklist.="None at this time.\n";
}
}
$self->{'pages'}={%pages};
$self->{'tasklist'}=$tasklist;
return $self;
}
Line 219 ⟶ 246:
my @keys=keys(%{$self->{'pages'}});
if(!@keys && !exists($self->{'tasklist'})){
$self->warn("Terminating task\n");
return undef;
Line 262 ⟶ 289:
while(@keys){
my $
my $
next if
delete($self->{'pages'}{$page});
}
if(exists($self->{'tasklist'})){
my $ret=$self->upload_page($api, 'User:'.$api->user.'/TaskList', $self->{'tasklist'});
return $
next if $ret>0;
}
return 0;
}
sub upload_page {
my
my $page=shift;
my $text=shift;
my $tok=$api->edittoken($page);
if($tok->{'code'} eq 'shutoff'){
$self->warn("Task disabled: ".$tok->{'content'}."\n");
return 300;
}
return 60 if($tok->{'code'} ne 'success');
my $bot=$api->user;
$text=~s/\x02BOT\x03/$bot/go;
$text=~s/\s+$//o;
$tok->{'revisions'}[0]{'*'}=~s/\s+$//o if !exists($tok->{'missing'});
if(exists($tok->{'missing'}) ||
$tok->{'revisions'}[0]{'*'} ne $text){
my $r=$api->edit($tok, $text, $self->{'summary'}, 0, 1);
if($r->{'code'} ne 'success'){
$self->warn("Write error for $page: ".$r->{'error'}."\n");
return 60;
} else {
$self->warn("
}
} else {
$self->warn("No update needed for $page\n");
}
return 0;
}
sub determine_task_section {
my $file = shift;
my %metadata = @_;
my $t=$file; $t=~s{^.*/}{}; $t=~s/\.pm$//;
return '99 Invalid metadata' unless(exists($metadata{'task'}) && $metadata{'task'} eq $t);
return '99 Invalid metadata' unless exists($metadata{'brfa'});
return '99 Invalid metadata' unless exists($metadata{'status'});
return '99 Invalid metadata' unless exists($metadata{'rate'});
return '99 Invalid metadata' unless(exists($metadata{'created'}) && $metadata{'created'}=~/^\d{4}-\d\d-\d\d$/);
if(exists($metadata{'+brfa'})){
return '99 Invalid metadata' unless exists($metadata{'+status'});
return '99 Invalid metadata' if scalar(@{$metadata{'+status'}}) != scalar(@{$metadata{'+brfa'}});
}
if(exists($metadata{'ondemand'})){
return '99 Invalid metadata' unless($metadata{'ondemand'} eq 'true' || $metadata{'ondemand'} eq 'false');
}
my $status=$metadata{'status'};
AnomieBOT::Task::load($file);
my $task='tasks::'.$metadata{'task'};
return '99 Invalid metadata' unless $task->can('approved');
my $botnum=$task->approved;
if($metadata{'brfa'} eq 'N/A'){
return "01 Current" if($botnum>0 && $status=~/^Begun \d{4}-\d{2}-\d{2}$/);
return "02 On demand" if(exists($metadata{'ondemand'}) && $metadata{'ondemand'} eq 'true');
}
if($status=~/^Approved \d{4}-\d{2}-\d{2}$/){
return "01 Current" if $botnum>0;
return "02 On demand" if(exists($metadata{'ondemand'}) && $metadata{'ondemand'} eq 'true');
return '99 Invalid metadata';
}
return '99 Invalid metadata' if $botnum>0;
return "03 In development" if($status eq 'Coding' || $status eq 'On hold');
return "05 Past" if $status=~/^Completed \d{4}-\d{2}-\d{2}$/;
return '99 Invalid metadata' if($metadata{'brfa'} eq 'N/A');
return "04 Awaiting approval" if($status eq 'BRFA');
return "06 Withdrawn" if $status eq 'Withdrawn';
return "07 Rejected" if $status=~/^Rejected \d{4}-\d{2}-\d{2}$/;
return '99 Invalid metadata';
}
|