WWW::Mediawiki::Client
use WWW::Mediawiki::Client; my $filename = 'Subject.wiki'; my $wmc = WWW::Mediawiki::Client->new( site_url => 'http://www.wikitravel.org/en' ); # output info messages, but not debug $wmc->set_output_level(WWW::Mediawiki::Client::INFO); # like cvs update $wmc->do_update($filename); # like cvs commit $wmc->do_commit($filename, $message); #aliases $wmc->do_up($filename); $wmc->do_com($filename, $message);
WWW::Mediawiki::Client provides a very simple cvs-like interface for Mediawiki driven WikiWiki websites, such as http://www.wikitravel.org|Wikitravel or http://www.wikipedia.org|Wikipedia. The interface mimics the two most basic cvs commands: update and commit with similarly named methods. Each of these has a shorter alias, as in cvs. Verbosity is controled through an output_level accessor method.
my $wmc = WWW::Mediawiki::Client->new(site_url = 'http://www.wikitravel.org');
Accepts name-value pairs which will be used as initial values for any of the fields which have accessors below. Throws the same execptions as the accessor for any field named.
my $url = $wmc->site_url($url);
The site URL is the base url for reaching the Mediawiki server who's content you wish to edit. There is no default. This has to be set before attempting to use any of the methods which attempt to access the server.
my $char = $wmc->space_substitute($char);
Mediawiki allows article names to have spaces, for instance the default Meidawiki main page is called "Main Page". The spaces need to be converted for the URL, and to avoid the normal but somewhat difficult to read URL escape the Mediawiki software substitutes some other character. Wikipedia uses a '+', as in "Main+Page" and Wikitravel uses a '_' as in "Main_page". WWW::Mediawiki::Client always writes wiki files using the '_', but converts them to whatever the space_substitute is set to for the URL.
space_substitute
my $url = $wmc->username($url);
The username to use if WWW::Mediawiki::Client is to log in to the Mediawiki server as a given user.
my $url = $wmc->password($url);
The password to use if WWW::Mediawiki::Client is to log in to the Mediawiki server as a given user. Note that this password is sent en clair, so it's probably not a good idea to use an important one.
my $path = $wmc->edit_path($path);
The edit path is a string which given the site URL and a page name can be used to construct the balance of the URL to the edit page for that page on the wikimedia server. You shouldn't have to worry about this unless the Mediawiki software on your server has been altered or is very out-of-date.
my $path = $wmc->action_path($path);
The action path is a string which given the site URL and a page name can be used to construct the balance of the URL to the action page for that page on the wikimedia server. You shouldn't have to worry about this unless the Mediawiki software on your server has been altered or is very out-of-date.
my $path = $wmc->login_path($path);
The login path is a string which given the site URL and a page name can be used to construct the balance of the URL to the login page for that page on the wikimedia server. You shouldn't have to worry about this unless the Mediawiki software on your server has been altered or is very out-of-date.
my $ol = $wmc->output_level(WWW::Mediawiki::Client::INFO);
This output level accessor provides for verbosity control. There are a number of different output levels:
my $msg = $wmc->commit_message($msg);
A commit_message must be specified before do_commit can be run. This will be used as the comment when submitting pages to the Mediawiki server.
commit_message
do_commit
my $bool = $wmc->minor_edit($bool);
Mediawiki allows users to mark some of their edits as minor using the "This is a minor edit" checkbox. The field minor_edit allows a commit from the mediawiki client to be marked as a minor edit.
minor_edit
$wmc->do_login;
The do_login method operates like the cvs login command. The site_url, username, and password attributes must be set before attempting to login. Once do_login has been called successfully any successful commit from the same directory will be logged in the Mediawiki server as having been done by username.
do_login
site_url
username
password
$wmc->do_li;
An alias for do_login.
$self->do_update($filename, ...);
The do_update method operates like a much-simplified version of the cvs update command. The argument is a list of filenames, whose contents will be compared to the version on the WikiMedia server and to a locally stored reference copy. Lines which have changed only in the server version will be merged into the local version, while lines which have changed in both the server and local version will be flagged as possible conflicts, and marked as such, somewhate in the manner of cvs (actually this syntax comes from the default conflict behavior of Algorithm::Diff::Apply):
do_update
>>>>>> http://server.somewiki.org/en The line as it appears on the server >>>>>> Filename.wiki The line as it appears locally <<<<<<
After the merging, and conflict marking is complete the server version will be copied into the reference version.
If either the reference version or the local version are empty, or if either file does not exist they will both be created as a copy of the current server version.
Throws:
An alias for do_update.
$self->do_commit($filename);
As with do_update the do_commit method operates like a much simplified version of the cvs commit command. Again, the argument is a filename. In keeping with the operation of cvs, do_commit does not automatically do an update, but does check the server version against the local reference copy, throwing an error if the server version has changed, thus forcing the user to do an update. A different error is thrown if the conflict pattern sometimes created by do_update is found.
After the error checking is done the local copy is submitted to the server, and, if all goes well, copied to the local reference version.
This is an alias for do_commit.
$wmc->save_state;
Saves the current state of the wmc object in the current working directory.
$wmc = $wmc->load_state;
Loads the state of the wmc object from that saved in the current working directory.
Original author
Added support for Mediawiki 1.3.10+ edit tokens
Improved error messages.
Copyright (c) 2004 Mark Jaroski.
All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install WWW::Mediawiki::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Mediawiki::Client
CPAN shell
perl -MCPAN -e shell install WWW::Mediawiki::Client
For more information on module installation, please visit the detailed CPAN module installation guide.