Wiki-Toolkit-Store-Mediawiki

 view release on metacpan or  search on metacpan

lib/Wiki/Toolkit/Store/Mediawiki.pm  view on Meta::CPAN



=head1 NAME

Wiki::Toolkit::Store::Mediawiki - Mediawiki (MySQL) storage backend for
Wiki::Toolkit

=head1 VERSION

Version 0.06

=cut

our $VERSION = '0.06';

=head1 REQUIRES

Subclasses Wiki::Toolkit::Store::Database.

=head1 SYNOPSIS

Implementation of L<Wiki::Toolkit::Store::Database> which reads and writes to a
Mediawiki 1.6 database running in MySQL.  This is module is intended to be
capable of running concurrently with a Mediawiki 1.6 installation without
data corruption.  That said, use it at your own risk.

If you are looking for a general Wiki implementation, you might be better off
looking at L<Wiki::Toolkit::Kwiki>.  It is simpler, more general, and does not
require the database to be initialized by outside software.  Currently,
initializing the database for this module requires a working (PHP) Mediawiki
installation.

I initially wrote this module because I was sick of running both PHP and Perl
on my web server so that I could have the only wiki I could find with the
full featureset I wanted running in parallel with the Perl scripts which
generate the rest of my content dynamically.  Generating my Perl content was
much faster than my Mediawiki installation and I like Perl better, so PHP lost.
Converting the old Mediawiki database into a format that a less fully featured
wiki could read looked generally unrewarding, so here we are.

All date and time values are returned as L<Time::Piece::Adaptive> objects.
This should be transparent for most uses.

See L<Wiki::Toolkit::Store::Database> for more on the general API.

=cut



###
### Globals
###
our $timestamp_fmt = "%Y%m%d%H%M%S";



# Internal method to return the data source string required by DBI.
sub _dsn {
    my ($self, $dbname, $dbhost) = @_;
    my $dsn = "dbi:mysql:$dbname";
    $dsn .= ";mysql_enable_utf8=1" if $self->{_charset}=~/^utf-?8$/i;
    $dsn .= ";host=$dbhost" if $dbhost;
    return $dsn;
}



=head1 METHODS

=head2 check_and_write_node

  $store->check_and_write_node (node     => $node,
				checksum => $checksum,
                                %other_args);

Locks the node, verifies the checksum, calls
C<write_node_post_locking> with all supplied arguments, unlocks the
node. Returns 1 on successful writing, 0 if checksum doesn't match,
croaks on error.

Note:  Uses MySQL's user level locking, so any locks are released when
the database handle disconnects.  Doing it like this because I can't seem
to get it to work properly with transactions.

=cut

sub check_and_write_node
{
    my ($self, %args) = @_;
    my ($node, $checksum) = @args{qw(node checksum)};
    $self->_lock_node ($node) or croak "Can't lock node";
    my $ok = $self->verify_checksum ($node, $checksum);
    unless ($ok)
    {
        $self->_unlock_node ($node) or carp "Can't unlock node";
	return 0;
    }
    eval {$self->write_node_post_locking (%args)};
    my $saverr = $@;
    $self->_unlock_node ($node) or carp "Can't unlock node";
    croak $saverr if $saverr;
    return 1;
}



=head2 new

Like the C<new> function from C<Wiki::Toolkit::Store::MySQL>, but also requires
a `wikiname' argument.

=cut

sub new {
    my ($class, %args) = @_;
    my $self = {};
    bless $self, $class;

    # wikiname is required
    croak "missing required `wikiname' argument" unless $args{wikiname};
    $self->{wikiname} = $args{wikiname};



( run in 0.665 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )