משתמש:Ori229/העברת דפים בAPI

# To avoid the Hebrew from becoming gibrish, save this file as UTF, and from C:\Perl\site\lib\MediaWiki\API.pm remove the line:
# $ref->{$key} = encode_utf8( $ref->{$key} );

  use strict;
  use warnings;
  use utf8;
  binmode(STDOUT, ":utf8"); # to silence: "Wide character in print "
  $| = 1; # unbuffered output
  use MediaWiki::API;
  my $user_name = 'testbot';  my $pw = 'XXXXXXXXXX';

  my $mw = MediaWiki::API->new( {retries=>'3', retry_delay=>'5'} );
  $mw->{config}->{api_url} = 'http://he.wikisource.org/w/api.php';

  # log in to the wiki
  $mw->login( { lgname => $user_name, lgpassword => $pw } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
  print "Logged in.\n";

  # delete a page
  # $mw->edit( { action => 'delete', title => 'test_page', reason => 'בדיקת מחיקה' } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};

  # move a page
  # $mw->edit( { action => 'move', from => 'test_page', to => 'test_page_זמני' } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
  # $mw->edit( { action => 'move', from => 'test_page_זמני', to => 'test_page' } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};

  # rollback edits (all edits done by this user to this page)
  # $mw->edit( { action => 'rollback', title => 'test_page', user => $user_name } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};


  # edit
  my $pagename = "Test page ב";
  my $ref = $mw->get_page( { title => $pagename } );
  unless ( $ref->{missing} ) {
    my $timestamp = $ref->{timestamp};
    $mw->edit( {
      action => 'edit',
      title => $pagename,
      basetimestamp => $timestamp, # to avoid edit conflicts
      # text => $ref->{'*'} . "First line\n\nשורה שניה\n" } )   # add text to the page
      text => "First line\n\nשורה שניה\n" } )   # new page / replace all text in the page
      || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
  }