Skip to content

Commit

Permalink
Item13244: change the default to not create a publish history. This i…
Browse files Browse the repository at this point in the history
…s the simplest way to stop the creation of unmanageable histories
  • Loading branch information
cdot committed Apr 18, 2017
1 parent 65ff3b9 commit 0b9a913
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 55 deletions.
4 changes: 2 additions & 2 deletions data/System/PublishPlugin.txt
Expand Up @@ -338,10 +338,10 @@ ISBN=1-56592-149-6
<tr>
<td class="nameCol">Publishing history topic</td>
<td class="inputCol">
<input type="text" name="history" class="foswikiInputField" size="30" value="PublishPluginHistory" />
<input type="text" name="history" class="foswikiInputField" size="30" value="" />
</td>
<td class="infoCol">
This is where the history of your publishing is stored. Each time you publish, this topic is re-written with the log of the publishing process. You have to have "change" access to this topic. You can specify a topic in another web using the standard Web.Topic syntax.
This is where the history of your publishing is stored. Specify a topic name. Each time you publish, this topic is re-written with the log of the publishing process. You have to have "change" access to this topic. You can specify a topic in another web using the standard Web.Topic syntax, or leave this blank if you don't need a history.
</td>
<td class="paramCol">
=history=
Expand Down
14 changes: 12 additions & 2 deletions lib/Foswiki/Plugins/PublishPlugin/BackEnd/file.pm
Expand Up @@ -31,7 +31,12 @@ sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);

my $oldmask = umask( oct(777) - ($Foswiki::cfg{RCS}{dirPermission}||$Foswiki::cfg{Store}{dirPermission}) );
my $oldmask = umask(
oct(777) - (
$Foswiki::cfg{RCS}{dirPermission}
|| $Foswiki::cfg{Store}{dirPermission}
)
);
$this->{params}->{outfile} ||= 'file';

if ( -e "$this->{path}/$this->{params}->{outfile}" ) {
Expand Down Expand Up @@ -67,7 +72,12 @@ sub param_schema {
sub addDirectory {
my ( $this, $name ) = @_;

my $oldmask = umask( oct(777) - ($Foswiki::cfg{RCS}{dirPermission}||$Foswiki::cfg{Store}{dirPermission}) );
my $oldmask = umask(
oct(777) - (
$Foswiki::cfg{RCS}{dirPermission}
|| $Foswiki::cfg{Store}{dirPermission}
)
);
eval { File::Path::mkpath("$this->{path}$this->{params}->{outfile}/$name") };
$this->{logger}->logError($@) if $@;
umask($oldmask);
Expand Down
4 changes: 3 additions & 1 deletion lib/Foswiki/Plugins/PublishPlugin/PageAssembler.pm
Expand Up @@ -106,9 +106,11 @@ sub _foswiki1x1 {

my $result;
if ( $Foswiki::Plugins::SESSION->can("_renderZones") ) {

# Foswiki 1.1 up to 2.0
$result = $Foswiki::Plugins::SESSION->_renderZones($tmpl);
} else {
}
else {
# Foswiki 2.1 and later
$result = $Foswiki::Plugins::SESSION->zones()->_renderZones($tmpl);
}
Expand Down
112 changes: 62 additions & 50 deletions lib/Foswiki/Plugins/PublishPlugin/Publisher.pm
Expand Up @@ -26,8 +26,8 @@ my %parameters = (
exclusions => { default => '', validator => \&_wildcard2RE },
format => { default => 'file', validator => \&_validateWord },
history => {
default => 'PublishPluginHistory',
validator => \&_validateTopicName
default => '',
validator => \&_validateTopicNameOrNull
},
inclusions => { default => '.*', validator => \&_wildcard2RE },
preferences => { default => '' },
Expand Down Expand Up @@ -101,6 +101,11 @@ sub _validateTopicNameList {
return join( ',', @ts );
}

sub _validateTopicNameOrNull {
return _validateTopicName( $_[0] ) if $_[0];
return $_[0];
}

sub _validateTopicName {
my $v = shift;
unless ( defined &Foswiki::Func::isValidTopicName ) {
Expand Down Expand Up @@ -185,7 +190,8 @@ sub new {

# Try and build the generator first, so we can pull in param defs
$data->{format} ||= 'file';
die "Bad format" unless $data->{format} =~ /^(\w+)$/;
die "Bad output format '$data->{format}'"
unless $data->{format} =~ /^(\w+)$/;
$this->{generator} = 'Foswiki::Plugins::PublishPlugin::BackEnd::' . $1;
eval 'use ' . $this->{generator};

Expand Down Expand Up @@ -375,24 +381,6 @@ sub publish {

my $firstWeb = $webs[0];

my ( $hw, $ht ) =
Foswiki::Func::normalizeWebTopicName( $firstWeb, $this->{history} );
unless (
Foswiki::Func::checkAccessPermission(
'CHANGE', Foswiki::Func::getWikiName(),
undef, $ht, $hw
)
)
{
$this->logError( <<TEXT, $footer );
Can't publish because $this->{publisher} can't CHANGE
$hw.$ht.
This topic must be editable by the user doing the publishing.
TEXT
return;
}
$this->{history} = "$hw.$ht";

# Force static context for all published topics
Foswiki::Func::getContext()->{static} = 1;

Expand Down Expand Up @@ -421,39 +409,61 @@ TEXT
$this->_publishWeb($web);
}

my ( $meta, $text ) = Foswiki::Func::readTopic( $hw, $ht );
my $history =
Foswiki::Func::loadTemplate( 'publish_history', $this->{publishskin} );

# See if we have history template. Unfortunately for compatibility
# reasons, Func::readTemplate doesn't distinguish between no template
# and an empty template :-(
if ($history) {
if ( $this->{history} ) {

# Expand macros *before* we include the history text so we pick up
# session preferences.
Foswiki::Func::setPreferencesValue( 'PUBLISHING_HISTORY',
$this->{historyText} );
$history = Foswiki::Func::expandCommonVariables($history);
}
elsif ( Foswiki::Func::topicExists( $hw, $ht ) ) {
my ( $hw, $ht ) =
Foswiki::Func::normalizeWebTopicName( $firstWeb, $this->{history} );
unless (
Foswiki::Func::checkAccessPermission(
'CHANGE', Foswiki::Func::getWikiName(),
undef, $ht, $hw
)
)
{
$this->logError( <<TEXT, $footer );
Can't publish because $this->{publisher} can't CHANGE
$hw.$ht.
This topic must be editable by the user doing the publishing.
TEXT
return;
}
$this->{history} = "$hw.$ht";

my ( $meta, $text ) = Foswiki::Func::readTopic( $hw, $ht );
my $history =
Foswiki::Func::loadTemplate( 'publish_history',
$this->{publishskin} );

# See if we have history template. Unfortunately for compatibility
# reasons, Func::readTemplate doesn't distinguish between no template
# and an empty template :-(
if ($history) {

# Expand macros *before* we include the history text so we pick up
# session preferences.
Foswiki::Func::setPreferencesValue( 'PUBLISHING_HISTORY',
$this->{historyText} );
$history = Foswiki::Func::expandCommonVariables($history);
}
elsif ( Foswiki::Func::topicExists( $hw, $ht ) ) {

# No template, use the last publish run (legacy)
$text ||= '';
$text =~ s/(^|\n)---\+ Last Published\n.*$//s;
$history =
# No template, use the last publish run (legacy)
$text ||= '';
$text =~ s/(^|\n)---\+ Last Published\n.*$//s;
$history =
"$text---+ Last Published\n<noautolink>\n$this->{historyText}\n</noautolink>";
}
else {
}
else {

# No last run, make something up
$history =
# No last run, make something up
$history =
"---+ Last Published\n<noautolink>\n$this->{historyText}\n</noautolink>";
}
Foswiki::Func::saveTopic( $hw, $ht, $meta, $history,
{ minor => 1, forcenewrevision => 1 } );
my $url = Foswiki::Func::getScriptUrl( $hw, $ht, 'view' );
$this->logInfo( "History saved in", "<a href='$url'>$url</a>" );
}
Foswiki::Func::saveTopic( $hw, $ht, $meta, $history,
{ minor => 1, forcenewrevision => 1 } );
my $url = Foswiki::Func::getScriptUrl( $hw, $ht, 'view' );
$this->logInfo( "History saved in", "<a href='$url'>$url</a>" );

Foswiki::Plugins::PublishPlugin::_display($footer);
}
Expand Down Expand Up @@ -546,7 +556,7 @@ sub _getPageTemplate {
my $topic = $query->param('publishtopic') || $this->{session}->{topicName};
my $tmpl = Foswiki::Func::readTemplate('view');

$tmpl =~ s/%META{.*?}%//g;
$tmpl =~ s/%META\{.*?\}%//g;
for my $tag (qw( REVTITLE REVARG REVISIONS MAXREV CURRREV )) {
$tmpl =~ s/%$tag%//g;
}
Expand Down Expand Up @@ -636,7 +646,9 @@ sub publishUsingTemplate {
# Attempt to render each included page.
my %copied;
foreach my $topic (@topics) {
next if $topic eq $this->{history}; # never publish this
next
if $this->{history}
&& $topic eq $this->{history}; # never publish this
( my $web, $topic ) =
Foswiki::Func::normalizeWebTopicName( $this->{web}, $topic );
try {
Expand Down

0 comments on commit 0b9a913

Please sign in to comment.