User talk:Rich Farmbrough/perl-hack
<syntaxhighlight lang="perl">
use Mediawiki::API; $user="Rich Farmbrough"; $password="YourPasswordHere"; # init the wiki object my $mw = MediaWiki::API->new(); $mw->{config}->{api_url} = 'http://en.wikipedia.org/w/api.php'; # log in to the wiki $mw->login( { lgname => $user, lgpassword => $password } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details}; # init the Second wiki object my $t_mw = MediaWiki::API->new(); $t_mw->{config}->{api_url} = 'http://ne.wikipedia.org/w/api.php'; # log in to the wiki $t_mw->login( { lgname => $user, lgpassword => $password } ) || die $t_mw->{error}->{code} . ': ' . $t_mw->{error}->{details}; open FILE, "<:utf8","list.txt"; while (<>){ chomp; $title=$_; if ((length ($title)) < 6) {next} print "$title\n"; # see what's happening my $page = $mw->get_page( { title => $title } ); $text=$page -> {'*'}; if ((length ($text)) == 0) {next} # if the page is empty (or doesn't exist) skip $t_mw->edit( { action => 'edit', title => $title, # basetimestamp => $timestamp, \ to avoid edit conflicts text => $text , summary => 'Copy template from en:' } ) || die $t_mw->{error}->{code} . ': ' . $t_mw->{error}->{details}; }