Changeset 429


Ignore:
Timestamp:
Jun 25, 2004, 10:40:38 PM (18 years ago)
Author:
kake
Message:

Added 'delete a revision' facility.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r428 r429  
     10.34    25 June 2004
     2        Add facility to delete only certain revisions of a page - access
     3          this from the node history page.
     4
    150.33    20 June 2004
    26        Improve node history page to allow diffing between each version and
  • trunk/PREREQUISITES

    r428 r429  
    1 Modules required by OpenGuides 0.33
     1Modules required by OpenGuides 0.34
    22===================================
    33
  • trunk/lib/OpenGuides.pm

    r428 r429  
    1313use vars qw( $VERSION );
    1414
    15 $VERSION = '0.33';
     15$VERSION = '0.34';
    1616
    1717=head1 NAME
     
    444444        my %node_data = $self->wiki->retrieve_node( name    => $node,
    445445                                                    version => $version );
     446        # $node_data{version} will be zero if this version was deleted.
    446447        push @history, { version  => $version,
    447448                         modified => $node_data{last_modified},
    448449                         username => $node_data{metadata}{username}[0],
    449                          comment  => $node_data{metadata}{comment}[0]   };
     450                         comment  => $node_data{metadata}{comment}[0],
     451                       } if $node_data{version};
    450452    }
    451453    @history = reverse @history;
    452     my %tt_vars = ( node    => $node,
    453                     version => $curr_version,
    454                     history => \@history );
     454    my %tt_vars = ( node          => $node,
     455                    version       => $curr_version,
     456                    not_deletable => 1,
     457                    history       => \@history );
    455458    print $self->process_template(
    456459                                   id       => $node,
     
    458461                                   tt_vars  => \%tt_vars,
    459462                                 );
     463}
     464
     465=item B<delete_node>
     466
     467  $guide->delete_node(
     468                       id       => "FAQ",
     469                       version  => 15,
     470                       password => "beer",
     471                     );
     472
     473C<version> is optional - if it isn't supplied then all versions of the
     474node will be deleted; in other words the node will be entirely
     475removed.
     476
     477If C<password> is not supplied then a form for entering the password
     478will be displayed.
     479
     480=cut
     481
     482sub delete_node {
     483    my ($self, %args) = @_;
     484    my $node = $args{id} or croak "No node ID supplied for deletion";
     485
     486    my %tt_vars = (
     487                    not_editable  => 1,
     488                    not_deletable => 1,
     489                  );
     490    $tt_vars{delete_version} = $args{version} || "";
     491
     492    my $password = $args{password};
     493
     494    if ($password) {
     495        if ($password ne $self->config->{_}->{admin_pass}) {
     496            print $self->process_template(
     497                                     id       => $node,
     498                                     template => "delete_password_wrong.tt",
     499                                     tt_vars  => \%tt_vars,
     500                                   );
     501        } else {
     502            $self->wiki->delete_node(
     503                                      name    => $node,
     504                                      version => $args{version},
     505                                    );
     506            # Check whether any versions of this node remain.
     507            my %check = $self->wiki->retrieve_node( name => $node );
     508            $tt_vars{other_versions_remain} = 1 if $check{version};
     509            print $self->process_template(
     510                                     id       => $node,
     511                                     template => "delete_done.tt",
     512                                     tt_vars  => \%tt_vars,
     513                                   );
     514        }
     515    } else {
     516        print $self->process_template(
     517                                 id       => $node,
     518                                 template => "delete_confirm.tt",
     519                                 tt_vars  => \%tt_vars,
     520                               );
     521    }
    460522}
    461523
  • trunk/templates/delete_confirm.tt

    r428 r429  
    1 [% INCLUDE header.tt page_title = "Confirm delete for $node_name - $site_name" %]
     1[% IF delete_version %]
     2  [% INCLUDE header.tt page_title = "Confirm delete for version $delete_version of $node_name - $site_name" %]
     3[% ELSE %]
     4  [% INCLUDE header.tt page_title = "Confirm delete for $node_name - $site_name" %]
     5[% END %]
    26[% INCLUDE banner.tt %]
    37<div id="content">
     
    610<h1>Confirm Deletion</h1>
    711<p>
    8 Are you sure you want to delete <em>[% node_name %]</em>? If so, please enter the admin
     12[% IF delete_version %]
     13  Are you sure you want to delete version [% delete_version %] of
     14  <em>[% node_name %]</em>?  This will completely erase this version
     15  and you will not be able to get it back.  If all versions are erased
     16  then the page will cease to exist.
     17[% ELSE %]
     18  Are you sure you want to delete <em>[% node_name %]</em>?  This will
     19  completely erase this page and all its history.
     20[% END %]
     21If so, please enter the admin
    922password. If not, you can <a href="[% cgi_url %]?[% node_param %]">go back to the
    1023page</a>.
     
    1326<input type="hidden" name="action" value="delete">
    1427<input type="hidden" name="id" value="[% node_name %]">
     28<input type="hidden" name="version" value="[% delete_version %]" />
    1529<strong>Password:</strong> <input type="password" name="password"> <input type="submit" value="Delete">
    1630</form>
  • trunk/templates/delete_done.tt

    r428 r429  
    1 [% INCLUDE header.tt page_title = "Successfully deleted $node_name - $site_name " %]
     1[% IF delete_version %]
     2  [% INCLUDE header.tt page_title = "Successfully deleted version $delete_version of $node_name - $site_name " %]
     3[% ELSE %]
     4  [% INCLUDE header.tt page_title = "Successfully deleted $node_name - $site_name " %]
     5[% END %]
    26[% INCLUDE banner.tt %]
    37<div id="content">
     
    59<h1>Deleted</h1>
    610<p>
    7 The node '[% node_name %]' was deleted.
     11[% IF delete_version %]
     12  Version [% delete_version %] of the
     13[% ELSE %]
     14  The
     15[% END %]
     16node '[% node_name %]' was deleted.
     17[% IF other_versions_remain %]
     18  <a href="[% cgi_url %]?[% node_param %]">View current version</a>.
     19[% ELSE %]
     20  No other versions are stored, so this node is now completely erased.
     21[% END %]
    822</p>
    923[% INCLUDE footer.tt %]
  • trunk/templates/delete_password_wrong.tt

    r428 r429  
    66<p>
    77Sorry, that was not the correct password. Please <a href="[%
    8 cgi_url %]?id=[% node_param %];action=delete">try again</a>.
     8cgi_url %]?id=[% node_param %];action=delete;version=[% delete_version %]">try again</a>.
    99</p>
    1010[% INCLUDE footer.tt %]
  • trunk/templates/node_history.tt

    r428 r429  
    2121        <b>[[% revision.comment %]]</b>
    2222      [% END %]
     23      [% IF enable_page_deletion %]
     24        [admin: <a href="[% full_cgi_url %]?id=[% node_param %];version=[% revision.version %];action=delete">Delete version [% revision.version %]</a>]
     25      [% END %]
    2326  </li>
    2427[% END %]
  • trunk/wiki.cgi

    r428 r429  
    55
    66use vars qw( $VERSION );
    7 $VERSION = '0.33';
     7$VERSION = '0.34';
    88
    99use CGI qw/:standard/;
     
    8787                    or $config->{_}->{enable_page_deletion} eq "1" )
    8888            ) {
    89         delete_node($node);
     89        $guide->delete_node(
     90                             id       => $node,
     91                             version  => $q->param("version") || "",
     92                             password => $q->param("password") || "",
     93                           );
    9094    } elsif ($action eq 'userstats') {
    9195        show_userstats(
     
    236240}
    237241
    238 sub delete_node {
    239     my $node = shift;
    240 
    241     my %tt_vars = (
    242                     not_editable   => 1,
    243                     page_deletable => 0,
    244                   );
    245 
    246     my $password = $q->param('password');
    247 
    248     if ($password) {
    249         if ($password ne $config->{_}->{admin_pass}) {
    250             process_template("delete_password_wrong.tt", $node, \%tt_vars);
    251         } else {
    252             $wiki->delete_node($node);
    253             process_template("delete_done.tt", $node, \%tt_vars);
    254         }
    255     } else {
    256         process_template("delete_confirm.tt", $node, \%tt_vars);
    257     }
    258 }
    259 
    260242sub get_cookie {
    261243    my $pref_name = shift or return "";
Note: See TracChangeset for help on using the changeset viewer.