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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: General: * Change 'shutoff' to be checked whenever an edit token is requested, by piggybacking on the edittoken request. SourceUploader: * BUGFIX: Add a subst so the history template works right
AnomieBOT (talk | contribs)
Updating published sources: General: * Have the bot script watch for changes and automatically re-exec itself. SourceUploader: * Change things around so task metadata is stored with the task.
Line 1:
{{ombox|type=notice|text= Per [[WP:BOT#Approval]], any bot or automated editing process that only affects only the operators' user and talk pages (or subpages thereof), and which are not otherwise disruptive, may be run without prior approval.}}
<source lang="perl">
package tasks::SourceUploader;
 
=pod
 
=begin metadata
 
Task: SourceUploader
BRFA: N/A
Status: Begun 2008-08-15
Rate: On bot startup only, max 6 edits/second
 
Updates the pages under [[User:AnomieBOT/source]] to reflect the current source
of the bot.
 
=end metadata
 
=cut
 
use strict;
Line 11 ⟶ 27:
use POSIX qw/strftime/;
use Pod::Simple::Wiki;
use tasks::SourceUploader::Pod;
use Data::Dumper;
use Fcntl ':mode';
Line 20 ⟶ 37:
 
my @sizes=('', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
 
 
=pod
 
=for info
# Per [[WP:BOT#Approval]], any bot or automated editing process that only
# affects only the operators' user and talk pages (or subpages thereof),
# and which are not otherwise disruptive, may be run without prior
# approval.
 
=cut
 
sub approved {
### notice type=notice
# Per [[WP:BOT#Approval]], any bot or automated editing process that only
# affects only the operators' user and talk pages (or subpages thereof),
# and which are not otherwise disruptive, may be run without prior
# approval.
return 1;
}
Line 117 ⟶ 140:
$pages{"$pp/doc"}=$x if($parser->content_seen);
 
# Handle embedded notices and metadata
if($pages{$pp}parser=~/^\s*### notice( .*\S)?\s+((?tasks::SourceUploader::^\s*# .*\s+^)+)/m){Pod->new;
my ($p,$t)=parser->output_string(\$1,$2x);
$p=~s/^\s+|\s+parser->parse_string_document($//gpages{$pp});
$ttop.=~s/^\s+#$x |\s+if($//gmparser->content_seen);
my %metadata=$t=~s/\s+/ /gparser->metadata;
if(keys $top.="\x7b\x7bombox|$p|text=$t\x7d\x7d\n";%metadata){
$x ="<noinclude>\n";
$x.="{| class=\"wikitable\"\n";
$x.="! Task !! Disable !! Status !! Rate !! Description\n";
$x.="</noinclude>\n";
$x.="|- valign=\"top\"\n";
my $task=$metadata{'task'};
my $bot="\x02BOT\x03";
$x.="|align=\"center\"| [[User:$bot/source$pp|$task]]\n";
$x.="|align=\"center\"| <span class=\"plainlinks\">[{{fullurl:User:$bot/shutoff/$task|action=edit&editintro=User:$bot/task-disable-editintro}} Here]</span>\n";
my $brfa=$metadata{'brfa'};
my $status=$metadata{'status'};
if($brfa eq 'N/A'){
$x.="| \x7b\x7bsort|$status|\x7d\x7d\x5b\x5bWikipedia:Bot policy#Approval|N/A\x5d\x5d, only edits bot's/owner's userspace. $status\n";
} elsif($brfa eq 'None'){
$x.="| $status\n";
} else {
$x.="| \x5b\x5b$brfa|$status\x5d\x5d\n";
}
$x.="| ".$metadata{'rate'}."\n";
$x.="|\n".$metadata{'*'}."\n";
$x.="<noinclude>\n";
$x.="|}\n";
$x.="</noinclude>";
$pages{"$pp/metadata"}=$x;
}
}
Line 212 ⟶ 259:
}
next if($tok->{'code'} ne 'success');
my $page=$self->{'pages'}{$k};
my $bot=$api->user;
$page=~s/\x02BOT\x03/$bot/go;
if(exists($tok->{'missing'}) ||
$tok->{'revisions'}[0]{'*'} ne $self->{'pages'}{$k}page){
my $r=$api->edit($tok, $self->{'pages'}{$k}page, $self->{'summary'}, 0, 1);
if($r->{'code'} ne 'success'){
$self->warn("Write error for $k: ".$r->{'error'});