CMS-MediaWiki

 view release on metacpan or  search on metacpan

lib/CMS/MediaWiki.pm  view on Meta::CPAN

package CMS::MediaWiki;
#######################################################################
# Author: Reto Schär
# Copyright (C) by Reto Schär (find details at the end of this script)
#
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself, either Perl version 5.8.6 or,
# at your option, any later version of Perl 5 you may have available.
#
# Locations:
# http://meta.pgate.net/cms-mediawiki/
# http://search.cpan.org/dist/CMS-MediaWiki/lib/CMS/MediaWiki.pm
#######################################################################
use strict;
my $package = __PACKAGE__;
our $VERSION = '0.8014';

use LWP::UserAgent;
use HTTP::Request::Common;

# GLOBAL VARIABLES
my %Var = ();
my $contentType = "";
my $ua;

$| = 1;

#-----  FORWARD DECLARATIONS & PROTOTYPING
sub Error($);
sub Debug($);

sub new {
	my $type = shift;
	my %params = @_;
	my $self = {};

	$self->{'protocol'} = $params{'protocol'} || 'http'; # optional
	$self->{'host'  } = $params{'host'} || 'localhost';
	$self->{'path'  } = $params{'path'} || '';
	$self->{'debug' } = $params{'debug'} || 0; # 0, 1, 2
	$Var{'SERVER_SIG'} = '*Unknown*';
	$Var{'EDIT_TIME_BEFORE'} = '*Unknown*';

	Debug "$package V$VERSION" if $self->{'debug'};

	$ua = LWP::UserAgent->new(
		agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461)' ,
		'cookie_jar' => {file => "lwpcookies.txt", autosave => 1}
	);

	bless $self, $type;
}

sub login {
	my $self = shift;
	my %args = @_;

	if ($self->{'debug'}) {
		Debug "[login] $_ = $args{$_}" foreach keys %args;
	}

	$args{'protocol'} ||= $self->{'protocol'};
	$args{'path'} ||= $self->{'path'};
	$self->{'path'} = $args{'path'}; # globalize, if it was set here

	$args{'host'} ||= $self->{'host'};
	$self->{'host'} = $args{'host'}; # globalize

	my %tags = ();
	$tags{'wpName'        } = $args{'user'} || 'Perlbot';
	$tags{'wpPassword'    } = $args{'pass'} || 'barfoo';
	$tags{'wpLoginattempt'} = 'Log in';

	my $index_path = "/index.php";
	   $index_path = "/$args{'path'}/index.php" if $args{'path'};

	my $login_url = "$args{'protocol'}://$args{'host'}$index_path?title=Special:Userlogin&action=submitlogin";

	Debug "[login] POST $login_url\..." if $self->{'debug'};



( run in 2.459 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )