[Mediawiki-api] Editing a page with MediaWiki API

Mike mediawiki-api at norgie.net
Fri Jul 24 00:37:04 UTC 2009


Folks,

I'm having some trouble editing a page with the MediaWiki API on 1.13.3.

I have used the following PERL code, which takes a page name and some
content and should add it to my wiki.  This works almost flawlessly,
with the exception that instead of the content going to the page
specified in the title, it goes into a page called "Api.php".

sub add_wiki {
  my $page = shift;
  my $content = shift;

  my $ua = LWP::UserAgent->new;
  $ua->agent("Aquila bot/0.1");

  $ua->credentials(
    'wiki.example.com:443',
    'Restricted Files',
    $wikiuser => $wikipass
  );

  my %post;
  $post{"format"} = "xml";
  $post{"title"} = $page;
  $post{"text"} = $content;
  $post{"section"} = "0";
  $post{"token"} = $edittoken;
  $post{"action"} = "edit";

  my $req = $ua->post($wikiaddurl, ,[ %post ]);

  my $data;
  if ($req->is_success == 1) {
    $data = $req->content;
    return("0", $data);
  } else {
    my $error = $req->status_line;
    return("1", $error);
  }
}

I have checked and the page name is being passed correctly to the
function.  Am I missing something?  I have checked the docs that I can
find, including the API documentation on the MediaWiki site but as far
as I can tell, all I need to do is pass title=name for the page name to
use?

Mike.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://lists.wikimedia.org/pipermail/mediawiki-api/attachments/20090724/9df3d79c/attachment.pgp 


More information about the Mediawiki-api mailing list