On Thu, Jul 23, 2009 at 8:37 PM, Mike<[email protected]> wrote: > 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. > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEARECAAYFAkppAi8ACgkQmUrfmTU1ohWggQCfbrn47FjEubsOYaXoMIISFzrd > Nl0AoKq05aF8Ta5jl6uTzI7RgO9/RppZ > =+ZkV > -----END PGP SIGNATURE----- > > _______________________________________________ > Mediawiki-api mailing list > [email protected] > https://lists.wikimedia.org/mailman/listinfo/mediawiki-api > >
Hey Mike, and welcome to the wonderful world of the MediaWiki API! You are correct, that should work for you. Make sure that $page really contains the article name you want to save to, and if you're still having problems, please post the output of the program if you insert use Data::Dumper; print "$wikiaddurl\n"; print Dumper(\%post); or equivalent, right before you actually make the post request, removing the edittoken for security reasons, that way you and I can see what you are actually sending to the server. HOWEVER, there is an easier way. Rather than using the API directly, there are a number of preexisting perl modules which allow you to easily interface with any MediaWiki wiki. Use CPAN to look up MediaWiki::Bot, which is a complete class, providing you with a login function, an edit function, and many more. If you need any help with that module, or would like to see an example script, you can contact me directly. Hope that helps! -- DCollins/ST47 Administrator, en.wikipedia.org Channel Operator, irc.freenode.net/#wikipedia Maintainer, MediaWiki::Bot module _______________________________________________ Mediawiki-api mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
