Skip to content

Commit

Permalink
Item10311: Restore function should restore prefs
Browse files Browse the repository at this point in the history
This changes restore to no longer proceed to edit.  The restore is
immediately performed with no option to revew/cancel  This is because
edit cannot easily copy preferences from the older revision.

git-svn-id: http://svn.foswiki.org/branches/Release01x01@10762 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Feb 22, 2011
1 parent df0e570 commit df34875
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
53 changes: 51 additions & 2 deletions core/lib/Foswiki/UI/Manage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ sub _parsePreferenceValue {

sub _action_restoreRevision {
my ($session) = @_;
my $query = $session->{request};
my ( $web, $topic ) =
$session->normalizeWebTopicName( $session->{webName},
$session->{topicName} );
Expand All @@ -518,9 +519,57 @@ sub _action_restoreRevision {
params => [ 'change', 'denied' ]
);
}

# read the old topic
my $rev = $query->param('rev');
my $requestedRev = Foswiki::Store::cleanUpRevID( $query->param('rev') );

unless ($requestedRev) {
throw Foswiki::OopsException(
'attention',
def => 'restore_invalid_rev',
params => [$rev, $meta->getLoadedRev()]
);
}

my $oldmeta = Foswiki::Meta->load( $session, $web, $topic, $requestedRev );

#print STDERR "REVS (".$meta->getLoadedRev().") (".$oldmeta->getLoadedRev().") ($requestedRev) \n";

if ( ! defined $oldmeta->getLoadedRev()
|| $meta->getLoadedRev() == $oldmeta->getLoadedRev()
|| $oldmeta->getLoadedRev() != $rev
) {
throw Foswiki::OopsException(
'attention',
def => 'restore_invalid_rev',
params => [$rev, $meta->getLoadedRev()]
);
}

foreach my $k (sort keys %$meta ) {
next if $k =~ m/^_/;
next if $k eq 'TOPICINFO'; # Don't revert topicinfo
next if $k eq 'FILEATTACHMENT'; # Don't revert attachments
$meta->remove($k) unless $oldmeta->{$k};
}

foreach my $k (sort keys %$oldmeta ) {
next if $k =~ m/^_/;
next if $k eq 'TOPICINFO'; # Don't revert topicinfo
next if $k eq 'FILEATTACHMENT'; # Don't revert attachments
$meta->copyFrom( $oldmeta, $k );
}

$meta->text($oldmeta->text()); # copy the old text

$meta->save(( forcenewrevision => 1 ) );

$session->{cgiQuery}->delete('action');
require Foswiki::UI::Edit;
Foswiki::UI::Edit::edit($session);

my $viewURL = $session->getScriptUrl( 0, 'view', $web, $topic );
$session->redirect( $session->redirectto($viewURL) );

}

1;
Expand Down
4 changes: 4 additions & 0 deletions core/templates/messages.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
---+++ %MAKETEXT{"Base web [_1] is missing or does not exist" args="%PARAM1%"}%
%MAKETEXT{"Please go back in your browser and try again."}%
%TMPL:END%
%TMPL:DEF{"restore_invalid_rev"}%
---+++ %MAKETEXT{"Requested revision ([_1]) is illegal or invalid. It does not exist in history, or is the same or later than the current revision ([_2])" args="'%PARAM1%','%PARAM2%'"}%
%MAKETEXT{"Please go back in your browser and try again."}%
%TMPL:END%
%TMPL:DEF{"invalid_web_color"}%
---+++ %MAKETEXT{"Color [_1] has an invalid format" args="=%PARAM1%="}%
%MAKETEXT{"A color starts with a # sign, followed by 6 hexadecimal numbers, e.g. =#FFFF00=."}%
Expand Down
7 changes: 5 additions & 2 deletions core/templates/more.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ id="cssFoswikiDiffOptions"}%%TMPL:END%
%MAKETEXT{"Restore topic to revision:"}% <input class="foswikiInputField" type="text" name="rev" size="6" value="%URLPARAM{currrev}%" /></p>
</div>
<div class="foswikiFormStep foswikiLast">
<p><input type="submit" class="foswikiButton" title="%MAKETEXT{"Restore topic to this revision"}%" value='%MAKETEXT{"Restore..."}%' /></p>
<p><input type="submit" class="foswikiButton" title="%MAKETEXT{"Restore topic to this revision"}%" value='%MAKETEXT{"Restore..."}%' />
<span class="foswikiAlert">
%MAKETEXT{"*CAUTION:* Restore no longer proceeds to edit with an option to cancel! If you click the [Restore...] button, the topic will be *immediately* restored to the requested revision"}%
</span></p>
</div>
</div>
<input type="hidden" name="action" value="restoreRevision" />
Expand All @@ -201,4 +204,4 @@ id="cssFoswikiDiffOptions"}%%TMPL:END%
%TMPL:P{"copy"}%
%TMPL:P{"childtopics"}%
%TMPL:P{"backlinks"}%
%TMPL:END%
%TMPL:END%

0 comments on commit df34875

Please sign in to comment.