Difference between revisions of "Current projects/upload images/upload-images.pl"
CommanderC (talk | contribs) (Created page with "#!/usr/bin/perl my $username = "USERNAME"; my $password = "PASSWORD"; # Set the pause in seconds after each upload my $pause = 60; # List the wiki PHP scripts where you have t...") |
CommanderC (talk | contribs) |
||
| Line 1: | Line 1: | ||
| + | <pre> | ||
#!/usr/bin/perl | #!/usr/bin/perl | ||
| Line 62: | Line 63: | ||
$mw->logout(); | $mw->logout(); | ||
| + | </pre> | ||
Revision as of 01:13, 9 January 2013
#!/usr/bin/perl
my $username = "USERNAME";
my $password = "PASSWORD";
# Set the pause in seconds after each upload
my $pause = 60;
# List the wiki PHP scripts where you have the username/password pair
my $api_url = 'http://crawl.chaosforge.org/api.php';
my $upload_url = 'http://crawl.chaosforge.org/Special:Upload';
#Then run the script on the command line using
#
# $ perl image.pl dirname
#
# where dirname/ is the name of a directory containing the files to
# be uploaded
use strict;
use warnings;
use MediaWiki::API;
use File::Spec;
use IO::Dir;
my $dir = $ARGV[0] or die "Syntax: perl image.pl dirname\n";
my $d = IO::Dir->new($dir);
die unless defined $d;
my @files = grep {m/\.png/ && ! m/-melee/} $d->read();
undef $d;
my $mw = MediaWiki::API->new( {
api_url => $api_url,
upload_url => $upload_url,
on_error => \&on_error
} );
sub on_error {
print "Error code: " . $mw->{error}->{code} . "\n";
print $mw->{error}->{stacktrace}."\n";
die;
}
my $r = $mw->login( { lgname => $username, lgpassword => $password } );
die unless defined($r);
for (@files) {
sleep $pause;
my $f = File::Spec->join($dir, $_);
my $page = $_;
print "Uploading $f to the wiki.\n";
my $r = $mw->edit( {
action => 'upload',
filename => $page,
file => [$f]
} );
die unless defined($r);
}
$mw->logout();