Subject: | Allow for using external LWP::UserAgent modules |
Hi,
I've extended LWP::UserAgent to work with our external HTTP
authentication system (SiteMinder). You can either put the auth
credentials in a file on the filesystem, or if you run the script that
calls MediaWiki::API from a terminal, you'll get prompted to enter in
your credentials via Term::ReadPassword.
However, there's no way to pass in this user agent to MediaWiki::API as
it's currently written, so I had to hack up API.pm to accept my custom
LWP::UserAgent module.
A patch with my differences would look something like this:
--- API.pm.orig 2010-06-02 17:59:02.000000000 -0700
+++ API.pm 2010-06-02 17:50:03.000000000 -0700
@@ -167,15 +167,17 @@ Other useful parameters and objects in t
sub new {
- my ($class, $config) = @_;
+ my ($class, $config, $ua) = @_;
my $self = { config => $config };
- my $ua = LWP::UserAgent->new();
- $ua->cookie_jar({});
- $ua->agent(__PACKAGE__ . "/$VERSION");
- $ua->default_header("Accept-Encoding" => "gzip, deflate");
- $ua->env_proxy() unless ($config->{no_proxy});
-
+ if ( ! defined $ua ) {
+ $ua = LWP::UserAgent->new();
+ $ua->cookie_jar({});
+ $ua->agent(__PACKAGE__ . "/$VERSION");
+ $ua->default_header("Accept-Encoding" => "gzip, deflate");
+ $ua->env_proxy() unless ($config->{no_proxy});
+ }
+ # add the UserAgent object to this object so it can be used later
Thanks,
Brian
perl -v
This is perl, v5.8.8 built for i386-linux-thread-multi
Red Hat Enterprise Server 5.4