2006-06-06 16:45:04 +00:00
|
|
|
# Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2016-08-16 14:59:13 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2006-06-06 16:45:04 +00:00
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2016-08-16 14:59:13 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-06-06 16:45:04 +00:00
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('publish.pl', 'Publish Page Extension');
|
2006-06-06 16:45:04 +00:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($q, %Action, %Page, $OpenPageName, @MyAdminCode, $ScriptName, $FullUrl);
|
|
|
|
|
our ($PublishTargetUrl);
|
2006-06-06 16:45:04 +00:00
|
|
|
|
|
|
|
|
$PublishTargetUrl = '';
|
|
|
|
|
|
|
|
|
|
$Action{publish} = \&DoPublish;
|
|
|
|
|
|
|
|
|
|
push(@MyAdminCode, \&PublishMenu);
|
|
|
|
|
|
|
|
|
|
sub PublishMenu {
|
|
|
|
|
my ($id, $menuref, $restref) = @_;
|
|
|
|
|
my $name = $id;
|
|
|
|
|
$name =~ s/_/ /g;
|
|
|
|
|
if ($id and $PublishTargetUrl) {
|
|
|
|
|
push(@$menuref, ScriptLink('action=publish;id=' . $id,
|
2006-08-06 11:47:40 +00:00
|
|
|
Ts('Publish %s', $name), 'publish'));
|
2006-06-06 16:45:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub DoPublish {
|
|
|
|
|
my ($id) = @_;
|
|
|
|
|
ReportError(T('No target wiki was specified in the config file.'),
|
|
|
|
|
'500 INTERNAL SERVER ERROR')
|
|
|
|
|
unless $PublishTargetUrl;
|
|
|
|
|
ReportError(T('The target wiki was misconfigured.',
|
|
|
|
|
'500 INTERNAL SERVER ERROR'))
|
|
|
|
|
if $PublishTargetUrl eq $ScriptName or $PublishTargetUrl eq $FullUrl;
|
|
|
|
|
ReportError('LWP::UserAgent is not available',
|
|
|
|
|
'500 INTERNAL SERVER ERROR')
|
|
|
|
|
unless eval {require LWP::UserAgent};
|
|
|
|
|
my $ua = LWP::UserAgent->new;
|
|
|
|
|
OpenPage($id);
|
|
|
|
|
my %params = ( title=>$OpenPageName,
|
|
|
|
|
text=>$Page{text},
|
|
|
|
|
raw=>1,
|
|
|
|
|
username=>$Page{username},
|
|
|
|
|
summary=>$Page{summary},
|
2006-06-08 07:51:58 +00:00
|
|
|
pwd=>GetParam('pwd',''),
|
2006-06-06 16:45:04 +00:00
|
|
|
);
|
|
|
|
|
$params{recent_edit} = 'on' if $Page{minor};
|
|
|
|
|
my $response = $ua->post($PublishTargetUrl, \%params);
|
|
|
|
|
if ($response->code == 302 and $response->header('Location')) {
|
|
|
|
|
print $q->redirect($response->header('Location'));
|
|
|
|
|
} elsif ($response->code == 200) {
|
|
|
|
|
print $q->redirect($PublishTargetUrl . '?' . $id);
|
|
|
|
|
} else {
|
|
|
|
|
ReportError($response->content,
|
|
|
|
|
$response->code . ' ' . $response->message);
|
|
|
|
|
}
|
|
|
|
|
}
|