1 package System::Introspector::Report::Publish::MediaWiki::Connection;
5 use aliased 'System::Introspector::Report::Publish::MediaWiki::Page';
7 has api => (is => 'lazy');
8 has api_uri => (is => 'ro', required => 1);
9 has username => (is => 'ro', required => 1);
10 has password => (is => 'ro', required => 1);
11 has allow_create => (is => 'ro', default => sub { 0 });
12 has http_auth => (is => 'ro');
13 has http_realm => (is => 'ro');
17 die sprintf "MediaWiki Error %s: %s\n",
19 $api->{error}{details};
24 my $api_uri = URI->new($self->api_uri);
25 my $api = MediaWiki::API->new({ api_url => $self->api_uri });
26 my $passwd = $self->password;
27 if ($ENV{TEST_SI_MEDIAWIKI_GETPW}) {
29 printf "MediaWiki password for '%s': ", $self->username;
35 $api->{ua}->credentials(
36 join(':', $api_uri->host, $api_uri->port),
37 $self->http_realm || 'Wiki',
40 ) if $self->http_auth;
42 lgname => $self->username,
43 lgpassword => $passwd,
44 }) or $api->$_api_fail;
49 my ($self, $page_name) = @_;
50 my $page = $self->api->get_page({ title => $page_name })
51 or $self->api->$_api_fail;
52 if (defined $page->{missing}) {
53 die "MediaWiki page '$page_name' does not exist\n"
54 unless $self->allow_create;
62 timestamp => $page->{timestamp},
63 content => $page->{'*'} || '',
68 my ($self, $page) = @_;
72 text => $page->content,
73 summary => 'System-Introspector-Report Update',
75 ? (basetimestamp => $page->timestamp)
77 }) or $self->api->$_api_fail;