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.
On Thu, Jul 23, 2009 at 8:37 PM, Mikemediawiki-api@norgie.net 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 Mediawiki-api@lists.wikimedia.org 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!
On Thu, Jul 23, 2009 at 08:56:59PM -0400, Dan Collins wrote:
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!
ST47,
Thanks for getting back to me. I've been doing some major debugging today. I have setup a test wiki since I want to test the code before decimating a live wiki, so I decided I'd just upgrade to the latest code, in case it was a problem in that version. This didn't resolve the problem. I setup a new MediaWiki install from scratch on another server and this time it worked. This narrowed the problem down to either the DB or the config file. After a diff of the config file and some experimenting, it came down to the setting of $wgArticlePath.
I have clean URLs configured and so have it set to $wgArticlePath = '/$1'; This torpedoes the API code. If I comment it out, my code works as expected, uncomment it and I end up with the data written to Api.php again.
This appears to be the symptom. I haven't been able to identify the cause yet. I've done a quick Google and there does appear to be some stories of the API code causing some agro with paths. Namely this:
https://bugzilla.redhat.com/show_bug.cgi?id=484855
I need to do a little more digging into the actual cause though.
I don't know if you have any ideas?
Mike.
On Fri, Jul 24, 2009 at 5:09 PM, Mikemediawiki-api@norgie.net wrote:
ST47,
Thanks for getting back to me. I've been doing some major debugging today. I have setup a test wiki since I want to test the code before decimating a live wiki, so I decided I'd just upgrade to the latest code, in case it was a problem in that version. This didn't resolve the problem. I setup a new MediaWiki install from scratch on another server and this time it worked. This narrowed the problem down to either the DB or the config file. After a diff of the config file and some experimenting, it came down to the setting of $wgArticlePath.
I have clean URLs configured and so have it set to $wgArticlePath = '/$1'; This torpedoes the API code. If I comment it out, my code works as expected, uncomment it and I end up with the data written to Api.php again.
This appears to be the symptom. I haven't been able to identify the cause yet. I've done a quick Google and there does appear to be some stories of the API code causing some agro with paths. Namely this:
https://bugzilla.redhat.com/show_bug.cgi?id=484855
I need to do a little more digging into the actual cause though.
I don't know if you have any ideas?
Mike.
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAkpqIvsACgkQmUrfmTU1ohUsTACg4fiSFGSLqA4/SqhH0GgcfOW+ BekAoMnHAemoyl/euh1qzPtCS3UY7wPT =mqJG -----END PGP SIGNATURE-----
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
I'm tempted to say that it's got to be entirely a bug with the redhat package. Since I don't have such a machine to test it on, I'm afraid I can't be of much help, except to say that downloading the source yourself should work as a long term solution, as you already have done.
2009/7/24 Dan Collins en.wp.st47@gmail.com:
I'm tempted to say that it's got to be entirely a bug with the redhat package. Since I don't have such a machine to test it on, I'm afraid I can't be of much help, except to say that downloading the source yourself should work as a long term solution, as you already have done.
I'm pretty sure this is what's happening.
The Red Hat package has, stupidly, chosen to set $wgArticlePath = "/$1"; and add rewrite rules accordingly. The people in #mediawiki strongly discourage this, because it causes all kinds of annoying bugs; this is one of them. Because the rewrite rules are not aware of the API's existence, they will interpret /api.php as a URL to an article, and rewrite it to /index.php?title=api.php . It does not attempt to rewrite this again, because anything starting with /index.php is exempt from this rule.
There are two solutions. The quick and dirty one is to add another exception for api.php in the Apache rewrite rules similar to the one for index.php . The proper one is to use non-overlapping, different paths for the virtual and real paths, which is what the documentation on short URLs encourages as well. In short, Red Hat's setup has /Page_name being rewritten to /index.php?title=Page_name ; instead, /wiki/Page_name should be rewritten to /w/index.php?title=Page_name .
Roan Kattouw (Catrope)
mediawiki-api@lists.wikimedia.org