SYNOPSIS

  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);

DESCRIPTION

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.

CONSTANTS

$VERSION

Update Status

\s-1STATUS_UNKNOWN\s0

Indicates that \*(C`WWW::Mediawiki::Client\*(C' has no information about the file.

\s-1STATUS_UNCHANGED\s0

Indicates that niether the file nor the server page have changed.

\s-1STATUS_LOCAL_ADDED\s0

Indicates that the file is new locally, and does not exist on the server.

\s-1STATUS_LOCAL_MODIFIED\s0

Indicates that the file has been modified locally.

\s-1STATUS_SERVER_MODIFIED\s0

Indicates that the server page was modified, and that the modifications have been successfully merged into the local file.

\s-1STATUS_CONFLICT\s0

Indicates that there are conflicts in the local file resulting from a failed merge between the server page and the local file.

Option Settings

\s-1OPT_YES\s0

Indicates that the setting should always be applied.

\s-1OPT_NO\s0

Indicates that the setting should never be applied.

\s-1OPT_DEFAULT\s0

Indicates that the setting should be applied based on the user profile default on the Wikimedia server.

\s-1OPT_KEEP\s0

Four-state options only. Indicates that the setting should not be changed from its current value on the server.

Mediawiki form widgets

\s-1TEXTAREA_NAME\s0

\s-1COMMENT_NAME\s0

\s-1EDIT_SUBMIT_NAME\s0

\s-1EDIT_SUBMIT_VALUE\s0

\s-1EDIT_PREVIEW_NAME\s0

\s-1EDIT_PREVIEW_VALUE\s0

\s-1EDIT_TIME_NAME\s0

\s-1EDIT_TOKEN_NAME\s0

\s-1EDIT_WATCH_NAME\s0

\s-1EDIT_MINOR_NAME\s0

\s-1CHECKED\s0

\s-1UNCHECKED\s0

\s-1USERNAME_NAME\s0

\s-1PASSWORD_NAME\s0

\s-1REMEMBER_NAME\s0

\s-1LOGIN_SUBMIT_NAME\s0

\s-1LOGIN_SUBMIT_VALUE\s0

Files

\s-1CONFIG_FILE\s0

.mediawiki

\s-1COOKIE_FILE\s0

.mediawiki.cookies

\s-1SAVED_ATTRIBUTES\s0

Controls which attributes get saved out to the config file.

CONSTRUCTORS

new

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.

ACCESSORS

host

my $url = $mvs->host('www.wikipediea.org');

my $url = $mvs->host('www.wikitravel.org');

The \*(C`host\*(C' 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.

Side Effects:

Server defaults

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.

Trailing slashes

Any trailing slashes are deleted before the value of \*(C`host\*(C' is set.

protocol

my $url = $mvs->protocol('www.wikipediea.org');

my $url = $mvs->protocol('www.wikitravel.org');

The \*(C`protocol\*(C' 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 \*(C`http\*(C' or \*(C`https\*(C' with the default value being http.

Side Effects:

Server defaults

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.

language_code

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 \*(C`filename_to_url\*(C' and \*(C`pagename_to_url\*(C' methods encounter the text '_\|_LANG_\|_' in any part of their constructed \s-1URL\s0 the \*(C`language_code\*(C' will be substituted.

\*(C`language_code\*(C' defaults to 'en'.

space_substitute

my $char = $mvs->space_substitute($char);

Mediawiki allows article names to have spaces, for instance the default Meidawiki main page is called \*(L"Main Page\*(R". The spaces need to be converted for the \s-1URL\s0, and to avoid the normal but somewhat difficult to read \s-1URL\s0 escape the Mediawiki software substitutes some other character. Wikipedia uses a '+', as in \*(L"Main+Page\*(R" and Wikitravel uses a '_' as in \*(L"Main_page\*(R". WWW::Mediawiki::Client always writes wiki files using the '_', but converts them to whatever the \*(C`space_substitute\*(C' is set to for the \s-1URL\s0.

Throws:

WWW::Mediawiki::Client::URLConstructionException

escape_filenames

my $char = $mvs->escape_filenames($do_escape);

Mediawiki allows article names to be in \s-1UTF-8\s0 and most international Wikipedias use this feature. That leads us to \s-1UTF-8\s0 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.

wiki_path

my $path = $mvs->wiki_path($path);

\*(C`wiki_path\*(C' 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 \*(C`host\*(C'. Otherwise it defaults to the 'wiki/wiki.phtml' which is what you'll get if you follow the installation instructions that some with Mediawiki.

Side effects

Leading slashes

Leading slashes in any incoming value will be stripped.

encoding

my $encoding = $mvs->encoding($encoding);

\*(C`encoding\*(C' 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.

username

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.

password

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.

commit_message

my $msg = $mvs->commit_message($msg);

A \*(C`commit_message\*(C' must be specified before \*(C`do_commit\*(C' can be run. This will be used as the comment when submitting pages to the Mediawiki server.

watch

my $watch = $mvs->watch($watch);

Mediawiki allows users to add a page to thier watchlist at submit time using using the \*(L"Watch this page\*(R" checkbox. The field \*(C`watch\*(C' allows commits from this library to add or remove the page in question to/from your watchlist.

This is a four-state option: Always add pages to the watchlist. Remove pages from the watchlist. Maintain current watched state. Adhere to user profile default on the server. Watched pages will always remain watched, and all other pages will be watched if the \*(L"watch all pages by default\*(R" option is enabled in the user profile.

Throws:

WWW::Mediawiki::Client::InvalidOptionException

minor_edit

my $minor = $mvs->minor_edit($minor);

Mediawiki allows users to mark some of their edits as minor using the \*(L"This is a minor edit\*(R" checkbox. The field \*(C`minor_edit\*(C' allows a commit from the mediawiki client to be marked as a 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 \*(L"minor changes by default\*(R" option is enabled in the user profile.

Throws:

WWW::Mediawiki::Client::InvalidOptionException

status

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 \*(C`filename\*(C' => \*(C`status\*(C' pairs. Each \*(C`status\*(C' will be one of the following (see \s-1CONSTANTS\s0 for discriptions):

WWW::Mediawiki::Client::STATUS_UNKNOWN;
WWW::Mediawiki::Client::STATUS_UNCHANGED;
WWW::Mediawiki::Client::STATUS_LOCAL_ADDED;
WWW::Mediawiki::Client::STATUS_LOCAL_MODIFIED;
WWW::Mediawiki::Client::STATUS_SERVER_MODIFIED;
WWW::Mediawiki::Client::STATUS_CONFLICT;

site_url \s-1DEPRICATED\s0

my $url = $mvs->site_url($url);

The site \s-1URL\s0 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 \*(C`host\*(C' field which is basically the same thing without the protocol string.

Side Effects:

Server defaults

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.

Trailing slashes

Any trailing slashes are deleted before the value of \*(C`site_url\*(C' is set.

Instance Methods

do_login

$mvs->do_login;

The \*(C`do_login\*(C' method operates like the cvs login command. The \*(C`host\*(C', \*(C`username\*(C', and \*(C`password\*(C' attributes must be set before attempting to login. Once \*(C`do_login\*(C' has been called successfully any successful commit from the same directory will be logged in the Mediawiki server as having been done by \*(C`username\*(C'.

Throws:

WWW::Mediawiki::Client::AuthException
WWW::Mediawiki::Client::CookieJarException
WWW::Mediawiki::Client::LoginException
WWW::Mediawiki::Client::URLConstructionException

do_li

$mvs->do_li;

An alias for \*(C`do_login\*(C'.

do_update

$self->do_update($filename, ...);

The \*(C`do_update\*(C' 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):

********************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.

Throws:

WWW::Mediawiki::Client::URLConstructionException
WWW::Mediawiki::Client::FileAccessException
WWW::Mediawiki::Client::FileTypeException
WWW::Mediawiki::Client::ServerPageException
WWW::Mediawiki::Client::AbsoluteFileNameException

do_up

An alias for \*(C`do_update\*(C'.

do_commit

$self->do_commit($filename);

As with \*(C`do_update\*(C' the \*(C`do_commit\*(C' 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, \*(C`do_commit\*(C' 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 \*(C`do_update\*(C' 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.

Throws:

WWW::Mediawiki::Client::CommitMessageException
WWW::Mediawiki::Client::ConflictsPresentException
WWW::Mediawiki::Client::FileAccessException
WWW::Mediawiki::Client::FileTypeException
WWW::Mediawiki::Client::URLConstructionException
WWW::Mediawiki::Client::UpdateNeededException
WWW::Mediawiki::Client::InvalidOptionException

do_com

This is an alias for \*(C`do_commit\*(C'.

do_preview

$self->do_preview($filename);

The \*(C`do_preview\*(C' method is a non-writing version of the \*(C`do_commit\*(C' method. It uploads the given filename to test its formatting. Its behaviour and arguments are identical to \*(C`do_commit\*(C'.

The behaviour of \*(C`do_preview\*(C' is currently based on the environment. If \*(C`MVS_BROWSER\*(C' 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 \*(C`MVS_PREVIEW\*(C' variable, or preview.html if this is unset. This behaviour is considered a prototype for future functionality, and is \*(C`subject to change\*(C' in the near future.

Returns the name of the preview file, or undef if the file was sent to a web browser.

Throws:

WWW::Mediawiki::Client::ConflictsPresentException
WWW::Mediawiki::Client::FileAccessException
WWW::Mediawiki::Client::FileTypeException
WWW::Mediawiki::Client::URLConstructionException
WWW::Mediawiki::Client::UpdateNeededException

do_clean

$self->do_clean;

Removes all reference files under the current directory that have no corresponding Wiki files.

Throws:

WWW::Mediawiki::Client::FileAccessException

save_state

$mvs->save_state;

Saves the current state of the wmc object in the current working directory.

Throws:

WWW::Mediawiki::Client::FileAccessException

load_state

$mvs = $mvs->load_state;

Loads the state of the wmc object from that saved in the current working directory.

Throws:

WWW::Mediawiki::Client::CorruptedConfigFileException

get_server_page

my $wikitext = $mvs->get_server_page($pagename);

Returns the wikitext of the given Mediawiki page name.

Throws:

WWW::Mediawiki::Client::ServerPageException

get_local_page

my $wikitext = $mvs->get_local_page($filename);

Returns the wikitext from the given local file;

Throws:

WWW::Mediawiki::Client::FileAccessException
WWW::Mediawiki::Client::FileTypeException
WWW::Mediawiki::Client::AbsoluteFileNameException

pagename_to_url

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.

Throws:

WWW::Mediawiki::Client::URLConstructionException;

filename_to_pagename

my $pagename = $mvs->filname_to_pagename($filename);

Returns the cooresponding server page name given a filename.

Throws:

WWW::Mediawiki::Client::AbsoluteFileNameException
WWW::Mediawiki::Client::FileTypeException

filename_to_url

my $pagename = $mvs->filname_to_url($filename);

Returns the cooresponding server \s-1URL\s0 given a filename.

Throws:

WWW::Mediawiki::Client::AbsoluteFileNameException
WWW::Mediawiki::Client::FileTypeException

pagename_to_filename

my $filename = $mvs->pagename_to_filename($pagename);

Returns a local filename which cooresponds to the given Mediawiki page name.

url_to_filename

my $filename = $mvs->url_to_filename($url);

Returns the local filename which cooresponds to a given \s-1URL\s0.

list_wiki_files

@filenames = $mvs->list_wiki_files;

Returns a recursive list of all wikitext files in the local repository.

BUGS

Please submit bug reports to the \s-1CPAN\s0 bug tracker at <http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mediawiki-Client>.

DISCUSSION

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>

AUTHORS

Mark Jaroski <[email protected]>

Original author, maintainer

Mike Wesemann <[email protected]>

Added support for Mediawiki 1.3.10+ edit tokens

Bernhard Kaindl <[email protected]>

Improved error messages.

Oleg Alexandrov <[email protected]>, Thomas Widmann <[email protected]>

Bug reports and feedback.

Adrian Irving-Beer <[email protected]>

Preview support, export support for multi-page update, more 'minor' and 'watch' settings, and bug reports.

Nicolas Brouard <[email protected]>

Fixed content-type bug.

Alex Kapranoff <[email protected]>

Added \*(C`escape_filename\*(C' in order to support \s-1UTF-8\s0 filenames on filesystems lacking \s-1UTF-8\s0 support.

LICENSE

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.