http://qs321.pair.com?node_id=483964

I'm experimenting with a wiki at work, and I have a bunch of illustrations and various images that I wanted to automatically have available to me as I was editing. There are enough of them that adding by hand was onerous, and adding via FTP & manual manipulation of the database was equally unappealing. Here is a WWW::Mechanize script that will upload pngs to a wikipedia. Alter lines 5 through 9 to suit your installation of wikimedia
#! perl.exe $|++; use strict; use WWW::Mechanize; my $wikilogin = "http://example.com/wiki/index.php?title=Special:Userl +ogin"; my $wikiuploader = "http://example.com/wiki/index.php?title=Special:Up +load"; my $user = 'username'; my $pass = 'password'; my $description = 'Media uploaded via automation'; # # begin real work here # my $agent = WWW::Mechanize->new(); $agent->get ($wikilogin); my $form = $agent->form_name('userlogin'); $agent->field ('wpName',$user); $agent->field ('wpPassword',$pass); $agent->field ('wpRemember',1); $agent->click (); open (ERRFH, ">errored.txt"); while (<*.png>){ $agent->get($wikiuploader); my $form = $agent->forms(1); if ($form) { #we've found the form, fill it out # fill out the body $agent->field('wpUploadFile', $_); $agent->field('wpUploadDescription', $description); $agent->field('wpUploadAffirm',1);# and submit $agent->click('wpUpload'); print "saved $_\n"; } else { #something's gone wrong #simple log for now #TODO: fill out w/ better logic. print ERRFH "$_\n"; } }