Changeset 991

Show
Ignore:
Timestamp:
03/25/07 00:28:19 (20 months ago)
Author:
nick
Message:

Initial code to revert a user's edits, still needs tests

Location:
trunk
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides.pm

    r974 r991  
    16941694} 
    16951695 
     1696=item B<revert_user_interface> 
     1697 
     1698If C<password> is not supplied then a form for entering the password 
     1699will be displayed, along with a list of all the edits the user made. 
     1700 
     1701If the password is given, will delete all of these versions. 
     1702=cut 
     1703sub revert_user_interface { 
     1704    my ($self, %args) = @_; 
     1705 
     1706    my $password = $args{password} || ''; 
     1707    my $return_tt_vars = $args{return_tt_vars} || 0; 
     1708    my $return_output = $args{return_output} || 0; 
     1709 
     1710    my $wiki = $self->wiki; 
     1711    my $formatter = $self->wiki->formatter; 
     1712    my $script_name = $self->config->script_name; 
     1713 
     1714    my ($type,$value); 
     1715    if($args{'username'}) { 
     1716        ($type,$value) = ('username', $args{'username'}); 
     1717    } 
     1718    if($args{'host'}) { 
     1719        ($type,$value) = ('host', $args{'host'}); 
     1720    } 
     1721    unless($type && $value) { 
     1722        croak("One of username or host must be given"); 
     1723    } 
     1724 
     1725    # Grab everything they've touched, ever 
     1726    my @user_edits = $self->wiki->list_recent_changes( 
     1727                            since => 1, 
     1728                            metadata_is => { $type => $value }, 
     1729    ); 
     1730 
     1731    if ($password) { 
     1732        if ($password ne $self->config->admin_pass) { 
     1733            croak("Bad password supplied"); 
     1734        } else { 
     1735            # Delete all these versions 
     1736            foreach my $edit (@user_edits) { 
     1737                $self->wiki->delete_node( 
     1738                                name => $edit->{name}, 
     1739                                version => $edit->{version}, 
     1740                ); 
     1741            } 
     1742 
     1743            # Grab new list 
     1744            @user_edits = $self->wiki->list_recent_changes( 
     1745                            since => 1, 
     1746                            metadata_is => { $type => $value }, 
     1747            ); 
     1748        } 
     1749    } else { 
     1750        # Don't do anything 
     1751    } 
     1752 
     1753    # Set up our TT variables, including the search parameters 
     1754    my %tt_vars = ( 
     1755                      not_editable  => 1, 
     1756                      not_deletable => 1, 
     1757                      deter_robots  => 1, 
     1758 
     1759                      edits          => \@user_edits, 
     1760                      username       => $args{username}, 
     1761                      host           => $args{host}, 
     1762                      by_type        => $type, 
     1763                      by             => $value, 
     1764 
     1765                      script_name => $script_name 
     1766                  ); 
     1767    return %tt_vars if $return_tt_vars; 
     1768 
     1769    # Render to the page 
     1770    my $output = $self->process_template( 
     1771                                           id       => "", 
     1772                                           template => "admin_revert_user.tt", 
     1773                                           tt_vars  => \%tt_vars, 
     1774                                        ); 
     1775    return $output if $return_output; 
     1776    print $output; 
     1777} 
     1778 
    16961779=item B<display_admin_interface> 
    16971780 
     
    17281811        $node->{'moderation_url'} = $script_name . 
    17291812                        "?action=set_moderation;id=" . $node_param; 
     1813        $node->{'revert_user_url'} = $script_name . "?action=revert_user" . 
     1814                        ";username=".$node->{metadata}->{username}->[0]; 
    17301815 
    17311816        # Filter 
  • trunk/templates/admin_home.tt

    r856 r991  
    2121<a name="nodes"></a> 
    2222<table id="nodes"> 
    23 <tr><th>Node name</th><th>Current Version</th><th>Last modified</th><th>Moderation</th><th>Actions</th></tr> 
     23<tr><th>Node name</th><th>Current Version</th><th>Last modified</th><th>By</th><th>Moderation</th><th>Actions</th></tr> 
    2424  [% FOREACH node = nodes %] 
    2525     <tr> 
     
    2727     <td class="admin_version">[% node.version %]</td> 
    2828     <td class="admin_lastmode">[% node.last_modified %]</td> 
     29     <td class="admin_lastmodby"> 
     30         [% node.metadata.username.0 %] 
     31         <a href="[% node.revert_user_url %]">(revert all)</a> 
     32     </td> 
    2933     <td class="admin_moderate">[% IF node.moderate %]yes[% ELSE %]no[% END %]</td> 
    3034     <td class="admin_action"> 
  • trunk/wiki.cgi

    r974 r991  
    9797        $guide->display_admin_interface( 
    9898                             moderation_completed => $q->param("moderation"), 
     99        ); 
     100    } elsif ( $action eq 'revert_user' ) { 
     101        $guide->revert_user_interface( 
     102                        username => $q->param("username") || "", 
     103                        host     => $q->param("host") || "", 
     104                        password => $q->param("password") || "", 
    99105        ); 
    100106    } elsif ( $action eq 'show_missing_metadata' ) {