1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
From 6769a57a2eb3f1ca8de4e1f22d26e9cd78570beb Mon Sep 17 00:00:00 2001
From: Benjamin Mako Hill <mako@atdot.cc>
Date: Sat, 12 Feb 2011 16:49:41 -0500
Subject: patched to work with the newest version of MW
---
lib/WWW/Mediawiki/Client.pm | 29 ++++++++++++++++++++++-------
1 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/lib/WWW/Mediawiki/Client.pm b/lib/WWW/Mediawiki/Client.pm
index 18645bb..cfdc0a9 100644
--- a/lib/WWW/Mediawiki/Client.pm
+++ b/lib/WWW/Mediawiki/Client.pm
@@ -278,6 +278,7 @@ use constant PASSWORD_NAME => 'wpPassword';
use constant REMEMBER_NAME => 'wpRemember';
use constant LOGIN_SUBMIT_NAME => 'wpLoginattempt';
use constant LOGIN_SUBMIT_VALUE => 'Log In';
+use constant LOGIN_TOKEN => 'wpLoginToken';
=head2 Files
@@ -814,6 +815,7 @@ sub do_login {
my $lang = $self->language_code;
$host =~ s/__LANG__/$lang/;
$path =~ s/__LANG__/$lang/;
+
my $protocol = $self->protocol;
my $url = "$protocol://$host/$path"
. "?" . ACTION . "=" . LOGIN
@@ -822,14 +824,27 @@ sub do_login {
$self->{ua}->cookie_jar->save
or WWW::Mediawiki::Client::CookieJarException->throw(
"Could not save cookie jar.");
- my $res = $self->{ua}->request(POST $url,
- [
+
+ # get login token
+ my $res = $self->{ua}->request(GET $url);
+ unless ($res->is_success) {
+ WWW::Mediawiki::Client::LoginException->throw(
+ error => "Could not connect to MediaWiki to get login token.\n",
+ res => $res);
+ }
+
+ my $token;
+ $token = $1 if $res->content() =~ /input type=['"]hidden['"] name=['"]wpLoginToken['"] value=['"]([a-fA-F0-9]+)['"]/i;
+
+ $res = $self->{ua}->request(POST $url,
+ [ (
&USERNAME_NAME => $self->username,
&PASSWORD_NAME => $self->password,
&REMEMBER_NAME => 1,
- &LOGIN_SUBMIT_NAME => &LOGIN_SUBMIT_VALUE,
- ]
+ &LOGIN_SUBMIT_NAME => &LOGIN_SUBMIT_VALUE
+ ), defined $token ? (&LOGIN_TOKEN => $token) : () ]
);
+
# success == Mediawiki gave us a Password cookie
if ($self->{ua}->cookie_jar->as_string =~ /UserID=/) {
$self->encoding($self->_get_server_encoding);
@@ -1496,7 +1511,7 @@ sub _get_edit_date {
my $p = HTML::TokeParser->new(\$doc);
my $date;
while (my $tag = $p->get_tag('input')) {
- next unless $tag->[1]->{type} eq 'hidden';
+ next unless exists $tag->[1]->{type} and $tag->[1]->{type} eq 'hidden';
next unless $tag->[1]->{name} eq EDIT_TIME_NAME;
$date = $tag->[1]->{value};
}
@@ -1508,7 +1523,7 @@ sub _get_edit_token {
my $p = HTML::TokeParser->new(\$doc);
my $token;
while (my $tag = $p->get_tag('input')) {
- next unless $tag->[1]->{type} eq 'hidden';
+ next unless exists $tag->[1]->{type} and $tag->[1]->{type} eq 'hidden';
next unless $tag->[1]->{name} eq 'wpEditToken';
$token = $tag->[1]->{value};
}
@@ -1533,7 +1548,7 @@ sub _get_edit_checkbox {
my $p = HTML::TokeParser->new(\$doc);
my $status;
while (my $tag = $p->get_tag('input')) {
- next unless $tag->[1]->{type} eq 'checkbox';
+ next unless exists $tag->[1]->{type} and $tag->[1]->{type} eq 'checkbox';
next unless $tag->[1]->{name} eq $name;
$status = ($tag->[1]->{checked} ? 1 : 0);
}
--
1.7.2.3
|