Content deleted Content added
Updating published sources: SourceUploader: * Redirect source talk pages to the main talk page. |
Updating published sources: SourceUploader: * Improve list handling for doc pages. * Add a TemplateStyles stylesheet to doc pages. * Cleanup some manpage refs. |
||
(16 intermediate revisions by 7 users not shown) | |||
Line 28:
use Storable qw/dclone/;
use URI::Escape;
use tasks::SourceUploader::WikiPod;
use tasks::SourceUploader::Pod;
Line 38 ⟶ 39:
'ini' => 'ini',
'sh' => 'bash',
'css' => 'css',
'js' => 'js',
'json' => 'json',
'html' => 'html',
);
Line 60 ⟶ 65:
my $class=shift;
my $self=$class->SUPER::new();
$self->{'pages'}={};▼
$self->{'loadexisting'}=1;
$self->{'order'}=-1000;
return $self;▼
}
sub build_sources {
my $self = shift;
my $basedir=$AnomieBOT::API::basedir;
$basedir=~s{/$}{};
if(!-d $basedir){
AnomieBOT::API->warn("Cannot find source directory\n");
return
}
$self->{'summary'}='Updating published sources: ';
if(!open(X, "<:utf8", 'ChangeLog')){
$self->{'fail'}=1;
AnomieBOT::API->warn("Cannot load changelog: $!\n"); return
}
local $_;
Line 101 ⟶ 113:
my @dirs=($basedir);
$self->{'shutoff_pages'}=[];
$self->{'check_shutoff_notice'}=[];
while(my $dir=shift @dirs){
if(!opendir(D, $dir)){
AnomieBOT::API->warn("Cannot open directory $dir: $!\n");
return
}
Line 122 ⟶ 136:
next if ($stat[2]&(S_IROTH))!=(S_IROTH);
if(!open(X, '<:utf8', $p)){
$self->{'fail'}=1;▼
AnomieBOT::API->warn("Cannot open file $p: $!\n");
return
}
do {
Line 148 ⟶ 163:
$parser->output_string(\$x);
$parser->parse_string_document($pages{$pp});
$pages{"$pp/doc"}="<templatestyles src=\"User:$mainbot/source-docs.css\"/>\n$x" if($parser->content_seen);
# Handle embedded notices and metadata
Line 172 ⟶ 187:
$x.="|align=\"center\"| <span class=\"plainlinks\">[{{fullurl:User:$bot/shutoff/$task|action=edit}} Here]</span>\n";
push @{$self->{'shutoff_pages'}}, "User:$bot/shutoff/$task";
push @{$self->{'check_shutoff_notice'}}, $bot;
}
if(exists($metadata{'exclusion'}) && $metadata{'exclusion'} eq 'false'){
Line 272 ⟶ 288:
$self->{'pages'}={%pages};
$self->{'tasklists'}=\%tasklists;
▲ return $self;
}
sub run {
my ($self, $api)=@_;
return undef if $self->{'fail'};
$self->build_sources() unless defined( $self->{'pages'} );
return undef if $self->{'fail'};
my @keys=keys(%{$self->{'pages'}});
my @tlkeys=keys(%{$self->{'tasklists'}});
my @shutoff=@{$self->{'shutoff_pages'}};
my @checkshutoffnotice=@{$self->{'check_shutoff_notice'}};
if(!@keys && !@tlkeys && !@shutoff && !@checkshutoffnotice){
$api->debug(2, "Source uploaded, terminating");
return undef;
}
$api->task('SourceUploader', 0, 10, qw/d::Redirects d::Talk/);
my $src='User:'.$api->user.'/source';
if($self->{'loadexisting'}){
my
list => 'allpages',
apprefix => $api->user.'/source/',
apnamespace => '2',
aplimit => 'max'
Line 299 ⟶ 320:
my ($k,$v,$k2,$v2,@x);
if($res->{'code'} ne 'success'){▼
$api->warn("Failed to retrieve source tree: ".$res->{'error'}."\n");▼
return 300;
}
push @keys, $v2;
}
foreach (@{$res->{'query'}{'allpages'}}){▼
▲ if(!exists($self->{'pages'}{$v2})){
▲ $self->{'pages'}{$v2}='';
▲ push @keys, $v2;
▲ }
▲ }
$self->{'loadexisting'}=0;
Line 363 ⟶ 377:
return $ret if $ret;
$self->{'shutoff_pages'}=[@shutoff];
}
my %x=map { $_=>1 } @checkshutoffnotice;
@checkshutoffnotice=keys %x;
$self->{'check_shutoff_notice'}=[@checkshutoffnotice];
while(@checkshutoffnotice){
my $bot=shift @checkshutoffnotice;
my $res=$api->rawpage("Template:Editnotices/Group/User:$bot");
return 300;
}
$res->{'code'}='success' if($res->{'code'} eq 'httperror' && $res->{'httpcode'}==404);
$api->warn("Could not load Template:Editnotices/Group/User:$bot: ".$res->{'error'}."\n");
return 60;
}
$res=$res->{'content'}//'';
unless($res=~/\{\{Editnotice subpages\|shutoff\|on base=no\}\}/){
$api->whine("Please fix [[Template:Editnotices/Group/User:$bot]]", "To display the proper editnotice on shutoff pages for the AnomieBOT bot [[User:$bot]], please ensure that [[Template:Editnotices/Group/User:$bot]] contains <code><nowiki>{{Editnotice subpages|shutoff|on base=no}}</nowiki></code>. Thanks.");
}
$res=$api->rawpage("Template:Editnotices/Group/User:$bot/shutoff");
if($res->{'code'} eq 'shutoff'){
$api->warn("Task disabled: ".$res->{'content'}."\n");
return 300;
}
$res->{'code'}='success' if($res->{'code'} eq 'httperror' && $res->{'httpcode'}==404);
if($res->{'code'} ne 'success'){
$api->warn("Could not load Template:Editnotices/Group/User:$bot/shutoff: ".$res->{'error'}."\n");
return 60;
}
$res=$res->{'content'}//'';
$res=~s/\s*$//;
my $txt="{{#ifeq:{{PAGESIZE:{{FULLPAGENAME}}}}|0|\n{{ombox\n| type = delete\n| image = [[File:Shutdown button.svg|40px|link={{fullurl:Special:Block|wpTarget=".uri_escape($bot)."&wpExpiry=indefinite&wpHardBlock=1&wpAutoBlock=0&wpCreateAccount=0&wpReason=other&wpReason-other=Bot%20malfunctioning:%20}}|Emergency block button]]\n| text = To disable the task {{SUBPAGENAME}}, enter your reasoning in this page. If the task is currently running, the bot may make one more edit before noticing that it has been shut off, but rest assured it ''will'' notice.\n}}\n|{{ombox\n| text = To re-enable the task, blank the page.\n}}\n}}";
unless($res=~/(?:^|\n)\Q$txt\E(?:$|\n)/){
$api->whine("Please fix [[Template:Editnotices/Group/User:$bot/shutoff]]", "To display the proper editnotice on shutoff pages for the AnomieBOT bot [[User:$bot]], please ensure that [[Template:Editnotices/Group/User:$bot/shutoff]] contains the following text:\n<pre>$txt</pre>\nThanks.");
}
$self->{'check_shutoff_notice'}=[@checkshutoffnotice];
}
Line 383 ⟶ 438:
$text=~s/\x02BOT\x03/$bot/go;
$text=~s/\s+$//o;
$tok->{'revisions'}[0]{'slots'}{'main'}{'*'}=~s/\s+$//o if !exists($tok->{'missing'});
if(exists($tok->{'missing'}) ||
$tok->{'revisions'}[0]{'
my $r=$api->edit($tok, $text, $self->{'summary'}, 0, 1, contentmodel => 'wikitext' );
if($r->{'code'} ne 'success'){
$api->warn("Write error for $page: ".$r->{'error'}."\n");
Line 420 ⟶ 476:
}
return 60 if($tok->{'code'} ne 'success');
if(($tok->{'revisions'}[0]{'slots'}{'main'}{'*'} // '') ne $txt){
my $r=$api->edit($tok, $txt, 'Redirect useless unwatched talk page to someplace useful.', 1, 1);
if($r->{'code'} ne 'success'){
Line 437 ⟶ 493:
my $t=$file; $t=~s{^.*/}{}; $t=~s/\.pm$//;
return '99 Invalid metadata (no "Bot")' unless exists($metadata{'bot'});
return '99 Invalid metadata (no/bad "Task")' unless(exists($metadata{'task'}) && $metadata{'task'} eq $t);
return '99 Invalid metadata (no "BRFA")' unless exists($metadata{'brfa'});
return '99 Invalid metadata (no "Status")' unless exists($metadata{'status'});
return '99 Invalid metadata (no/bad "Created")' unless(exists($metadata{'created'}) && $metadata{'created'}=~/^\d{4}-\d\d-\d\d$/);
if(exists($metadata{'+brfa'})){
return '99 Invalid metadata (no "+Status")' unless exists($metadata{'+status'});
return '99 Invalid metadata (mismatched +BRFA/+Status)' if scalar(@{$metadata{'+status'}}) != scalar(@{$metadata{'+brfa'}});
}
if(exists($metadata{'ondemand'})){
return '99 Invalid metadata (bad "OnDemand")' unless($metadata{'ondemand'} eq 'true' || $metadata{'ondemand'} eq 'false');
}
if(exists($metadata{'shutoff'})){
return '99 Invalid metadata (bad "Shutoff")' unless($metadata{'shutoff'} eq 'true' || $metadata{'shutoff'} eq 'false');
}
if(exists($metadata{'exclusion'})){
return '99 Invalid metadata (bad "Exclusion")' unless($metadata{'exclusion'} eq 'true' || $metadata{'exclusion'} eq 'false');
}
my $status=$metadata{'status'};
Line 459 ⟶ 515:
AnomieBOT::API::load($file);
my $task='tasks::'.$metadata{'task'};
return '99 Invalid metadata (missing "approved" method)' unless $task->can('approved');
my $botnum=$task->approved;
Line 470 ⟶ 526:
return "01 Current" if $botnum>0;
return "02 On demand" if(exists($metadata{'ondemand'}) && $metadata{'ondemand'} eq 'true');
return '99 Invalid metadata ("Status: Approved" but not running or OnDemand)';
}
return "03 In trial" if($status=~/^In trial/ && $botnum>0);
return '99 Invalid metadata (Running with a non-running Status)' if $botnum>0;
return "04 In development" if($status eq 'Coding' || $status eq 'On hold');
return "06 Past" if $status=~/^(?:Completed|Inactive) \d{4}-\d{2}-\d{2}$/;
return '99 Invalid metadata (bad "BRFA")' if($metadata{'brfa'} eq 'N/A');
return "05 Awaiting approval" if($status eq 'BRFA');
return "07 Withdrawn" if $status eq 'Withdrawn';
return "08 Rejected" if $status=~/^Rejected \d{4}-\d{2}-\d{2}$/;
return '99 Invalid metadata (no match for Status)';
}
|