#!/usr/bin/perl use 5.010; use strict; use warnings; use open ':encoding(utf8)'; use utf8; use English qw(-no_match_vars); use Carp qw(croak cluck); use MediaWiki::API; my $INPUT_EXTENSION = 'wiki.txt'; my $mw = MediaWiki::API->new(); $mw->{config}->{api_url} = "http://he.wikipedia.org/w/api.php"; $mw->login( { lgname => 'Amire80', lgpassword => 'secret80', # not really } ) or croak $mw->{error}->{code} . ': ' . $mw->{error}->{details}; my $page_prefix = 'User:Amire80'; my $dirname = './out.he/'; # in the next line the word 'category' is actually supposed to be # written in Hebrew characters, but this website doesn't seem # to like it my @filenames = glob "${dirname}category*.$INPUT_EXTENSION"; foreach my $filename (@filenames) { my $pagename = $filename; $pagename =~ s/\A $dirname//xms; $pagename =~ s/\.$INPUT_EXTENSION \z//xms; $pagename = "$page_prefix/$pagename"; say $pagename; my $ref = $mw->get_page({ title => $pagename }); if ($ref->{missing}) { say "page $pagename is missing, trying to create"; } my $timestamp = $ref->{timestamp}; local $INPUT_RECORD_SEPARATOR; open my $file, '<', $filename or croak "Can't open $filename: $OS_ERROR"; my $text = <$file>; close $file; $mw->edit( { action => 'edit', title => $pagename, summary => 'cat 001', basetimestamp => $timestamp, # to avoid edit conflicts text => $text, }, { skip_encoding => 1, } ) or croak $mw->{error}->{code} . ': ' . $mw->{error}->{details}; }