WWW::Mediawiki::Client
use WWW::Mediawiki::Client; my $filename = 'Subject.wiki'; my $mvs = WWW::Mediawiki::Client->new( host => 'www.wikitravel.org' ); # like cvs update $mvs->do_update($filename); # like cvs commit $mvs->do_commit($filename, $message); #aliases $mvs->do_up($filename); $mvs->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.
Indicates that WWW::Mediawiki::Client has no information about the file.
Indicates that niether the file nor the server page have changed.
Indicates that the file is new locally, and does not exist on the server.
Indicates that the file has been modified locally.
Indicates that the server page was modified, and that the modifications have been successfully merged into the local file.
Indicates that there are conflicts in the local file resulting from a failed merge between the server page and the local file.
Indicates that the setting should always be applied.
Indicates that the setting should never be applied.
Indicates that the setting should be applied based on the user profile default on the Wikimedia server.
Four-state options only. Indicates that the setting should not be changed from its current value on the server.
.mediawiki
.mediawiki.cookies
Controls which attributes get saved out to the config file.
my $mvs = WWW::Mediawiki::Client->new(host = '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 = $mvs->host('www.wikipediea.org'); my $url = $mvs->host('www.wikitravel.org');
The host is the name of the Mediawiki server from which you want to obtain content, and to which your submissions will be made. There is no default. This has to be set before attempting to use any of the methods which attempt to access the server.
host
Side Effects:
If WWW::Mediawiki::Client knows about the path settings for the Mediawiki installation you are trying to use then the various path fields will also be set as a side-effect.
Any trailing slashes are deleted before the value of host is set.
my $url = $mvs->protocol('www.wikipediea.org'); my $url = $mvs->protocol('www.wikitravel.org');
The protocol is the protocol used by the Mediawiki server from which you want to obtain content, and to which your submissions will be made. It can be one of http or https with the default value being http.
protocol
http
https
If WWW::Mediawiki::Client knows about the settings for the Mediawiki installation you are trying to use then the various path fields will also be set as a side-effect.
my $lang = $mvs->language_code($lang);
Most Mediawiki projects have multiple language versions. This field can be set to target a particular language version of the project the client is set up to address. When the filename_to_url and pagename_to_url methods encounter the text '__LANG__' in any part of their constructed URL the language_code will be substituted.
filename_to_url
pagename_to_url
language_code
language_code defaults to 'en'.
my $char = $mvs->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
Throws:
my $char = $mvs->escape_filenames($do_escape);
Mediawiki allows article names to be in UTF-8 and most international Wikipedias use this feature. That leads us to UTF-8 encoded file names and not all filesystems can handle them. So you can set this option to some true value to make all your local file names with wiki articles URL-escaped.
my $path = $mvs->wiki_path($path);
wiki_path is the path to the php page which handles all request to edit or submit a page, or to login. If you are using a Mediawiki site which WWW::Mediawiki::Client knows about this will be set for you when you set the host. Otherwise it defaults to the 'wiki/wiki.phtml' which is what you'll get if you follow the installation instructions that some with Mediawiki.
wiki_path
Side effects
Leading slashes in any incoming value will be stripped.
my $encoding = $mvs->encoding($encoding);
encoding is the charset in which the Mediawiki server expects uploaded content to be encoded. This should be set the first time you use do_login.
encoding
my $url = $mvs->username($url);
The username to use if WWW::Mediawiki::Client is to log in to the Mediawiki server as a given user.
my $url = $mvs->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 $msg = $mvs->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 $watch = $mvs->watch($watch);
Mediawiki allows users to add a page to thier watchlist at submit time using using the "Watch this page" checkbox. The field watch allows commits from this library to add or remove the page in question to/from your watchlist.
watch
This is a four-state option:
OPT_YES
Always add pages to the watchlist.
OPT_NO
Remove pages from the watchlist.
OPT_KEEP
Maintain current watched state.
OPT_DEFAULT
Adhere to user profile default on the server. Watched pages will always remain watched, and all other pages will be watched if the "watch all pages by default" option is enabled in the user profile.
my $minor = $mvs->minor_edit($minor);
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
This is a three-state option:
Always declare change as minor.
Never declare change as minor.
Adhere to user profile default on the server. Edits will be marked as minor if the "minor changes by default" option is enabled in the user profile.
my %status = $mvs->status;
This field will be empty until do_update has been called, after which it will be set to a hash of filename => status pairs. Each status will be one of the following (see CONSTANTS for discriptions):
filename
status
my $url = $mvs->site_url($url);
The site URL is the base url for reaching the Mediawiki server who's content you wish to edit. This field is now depricated in favor of the host field which is basically the same thing without the protocol string.
Any trailing slashes are deleted before the value of site_url is set.
site_url
$mvs->do_login;
The do_login method operates like the cvs login command. The host, 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
username
password
$mvs->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 VCS::Lite):
do_update
********************Start of conflict 1 Insert to Primary, Insert to Secondary ************************************************************ The line as it appears on the server **************************************************************************************************** The line as it appears locally ********************End of conflict 1********************************************************************************
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.
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.
$self->do_preview($filename);
The do_preview method is a non-writing version of the do_commit method. It uploads the given filename to test its formatting. Its behaviour and arguments are identical to do_commit.
do_preview
The behaviour of do_preview is currently based on the environment. If MVS_BROWSER is set, this program (typically a web browser) will be launched on a temporary file. Otherwise, the preview will be saved to the file specified by the MVS_PREVIEW variable, or preview.html if this is unset. This behaviour is considered a prototype for future functionality, and is subject to change in the near future.
MVS_BROWSER
MVS_PREVIEW
subject to change
Returns the name of the preview file, or undef if the file was sent to a web browser.
$self->do_clean;
Removes all reference files under the current directory that have no corresponding Wiki files.
$mvs->save_state;
Saves the current state of the wmc object in the current working directory.
$mvs = $mvs->load_state;
Loads the state of the wmc object from that saved in the current working directory.
my $wikitext = $mvs->get_server_page($pagename);
Returns the wikitext of the given Mediawiki page name.
my $wikitext = $mvs->get_local_page($filename);
Returns the wikitext from the given local file;
my $url = $mvs->pagename_to_url($pagename);
Returns the url at which a given pagename will be found on the Mediawiki server to which this instance of points.
my $pagename = $mvs->filname_to_pagename($filename);
Returns the cooresponding server page name given a filename.
my $pagename = $mvs->filname_to_url($filename);
Returns the cooresponding server URL given a filename.
my $filename = $mvs->pagename_to_filename($pagename);
Returns a local filename which cooresponds to the given Mediawiki page name.
my $filename = $mvs->url_to_filename($url);
Returns the local filename which cooresponds to a given URL.
@filenames = $mvs->list_wiki_files;
Returns a recursive list of all wikitext files in the local repository.
Please submit bug reports to the CPAN bug tracker at http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mediawiki-Client.
There is a discussion list. You can subscribe or read the archives at: http://www.geekhive.net/cgi-bin/mailman/listinfo/www-mediawiki-client-l
Original author, maintainer
Added support for Mediawiki 1.3.10+ edit tokens
Improved error messages.
Bug reports and feedback.
Preview support, export support for multi-page update, more 'minor' and 'watch' settings, and bug reports.
Fixed content-type bug.
Added escape_filename in order to support UTF-8 filenames on filesystems lacking UTF-8 support.
escape_filename
Copyright (c) 2004-2006 Mark Jaroski.
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 '=head2'
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.