lib/TWiki/UI/Changes.pm
changeset 0 414e01d06fd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/TWiki/UI/Changes.pm	Sat Jan 26 15:50:53 2008 +0100
     1.3 @@ -0,0 +1,108 @@
     1.4 +# Module of TWiki Enterprise Collaboration Platform, http://TWiki.org/
     1.5 +#
     1.6 +# Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org
     1.7 +# and TWiki Contributors. All Rights Reserved. TWiki Contributors
     1.8 +# are listed in the AUTHORS file in the root of this distribution.
     1.9 +# NOTE: Please extend that file, not this notice.
    1.10 +#
    1.11 +# Additional copyrights apply to some or all of the code in this
    1.12 +# file as follows:
    1.13 +# Based on parts of Ward Cunninghams original Wiki and JosWiki.
    1.14 +# Copyright (C) 1998 Markus Peter - SPiN GmbH (warpi@spin.de)
    1.15 +# Some changes by Dave Harris (drh@bhresearch.co.uk) incorporated
    1.16 +#
    1.17 +# This program is free software; you can redistribute it and/or
    1.18 +# modify it under the terms of the GNU General Public License
    1.19 +# as published by the Free Software Foundation; either version 2
    1.20 +# of the License, or (at your option) any later version. For
    1.21 +# more details read LICENSE in the root of this distribution.
    1.22 +#
    1.23 +# This program is distributed in the hope that it will be useful,
    1.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    1.26 +#
    1.27 +# As per the GPL, removal of this notice is prohibited.
    1.28 +
    1.29 +package TWiki::UI::Changes;
    1.30 +
    1.31 +use strict;
    1.32 +
    1.33 +use Assert;
    1.34 +use Error qw( :try );
    1.35 +
    1.36 +require TWiki;
    1.37 +require TWiki::UI;
    1.38 +require TWiki::Time;
    1.39 +
    1.40 +# Command handler for changes command
    1.41 +sub changes {
    1.42 +    my $session = shift;
    1.43 +
    1.44 +    my $query = $session->{cgiQuery};
    1.45 +    my $webName = $session->{webName};
    1.46 +    my $topic = $session->{topicName};
    1.47 +
    1.48 +    TWiki::UI::checkWebExists( $session, $webName, $topic, 'find changes in' );
    1.49 +
    1.50 +    my $skin = $session->getSkin();
    1.51 +
    1.52 +    my $text = $session->templates->readTemplate( 'changes', $skin );
    1.53 +
    1.54 +    my( $page, $eachChange, $after) = split( /%REPEAT%/, $text );
    1.55 +
    1.56 +    my $showMinor = $query->param( 'minor' );
    1.57 +    unless( $showMinor ) {
    1.58 +        my $comment = CGI::b( 'Note: ' ).
    1.59 +          'This page is showing major changes only. '.
    1.60 +            CGI::a( { href => $query->url()."/$webName?minor=1",
    1.61 +                      rel => 'nofollow' }, 'View all changes' );
    1.62 +        $comment = CGI::div( { class => 'twikiHelp' }, $comment );
    1.63 +        $page .= $comment;
    1.64 +    }
    1.65 +    my %done = ();
    1.66 +
    1.67 +    my $iterator = $session->{store}->eachChange( $webName, 0 );
    1.68 +
    1.69 +    while( $iterator->hasNext() ) {
    1.70 +        my $change = $iterator->next();
    1.71 +        next if (!$showMinor && $change->{more} && $change->{more} =~ /minor/);
    1.72 +        next if $done{$change->{topic}};
    1.73 +        next unless $session->{store}->topicExists( $webName, $change->{topic} );
    1.74 +        try {
    1.75 +            my $summary = $session->renderer->summariseChanges(
    1.76 +                $session->{user}, $webName, $change->{topic}, $change->{revision} );
    1.77 +            my $thisChange = $eachChange;
    1.78 +            $thisChange =~ s/%TOPICNAME%/$change->{topic}/go;
    1.79 +            my $wikiuser = $change->{user} ?
    1.80 +              $session->{users}->webDotWikiName($change->{user}) : '';
    1.81 +            $thisChange =~ s/%AUTHOR%/$wikiuser/go;
    1.82 +            my $time = TWiki::Time::formatTime( $change->{time} );
    1.83 +            $change->{revision} = 1 unless $change->{revision};
    1.84 +            my $srev = 'r' . $change->{revision};
    1.85 +            if( $change->{revision} == 1 ) {
    1.86 +                $srev = CGI::span( { class => 'twikiNew' }, 'NEW' );
    1.87 +            }
    1.88 +            $thisChange =~ s/%TIME%/$time/g;
    1.89 +            $thisChange =~ s/%REVISION%/$srev/go;
    1.90 +            $thisChange = $session->renderer->getRenderedVersion
    1.91 +              ( $thisChange, $webName, $change->{topic} );
    1.92 +            $thisChange =~ s/%TEXTHEAD%/$summary/go;
    1.93 +            $page .= $thisChange;
    1.94 +        } catch TWiki::AccessControlException with {
    1.95 +            # ignore changes we can't see
    1.96 +        };
    1.97 +        $done{$change->{topic}} = 1;
    1.98 +    }
    1.99 +    if( $TWiki::cfg{Log}{changes} ) {
   1.100 +        # write log entry
   1.101 +        $session->writeLog( 'changes', $webName, '' );
   1.102 +    }
   1.103 +    $page .= $after;
   1.104 +
   1.105 +    $page = $session->handleCommonTags( $page, $webName, $topic );
   1.106 +    $page = $session->renderer->getRenderedVersion($page, $webName, $topic );
   1.107 +
   1.108 +    $session->writeCompletePage( $page );
   1.109 +}
   1.110 +
   1.111 +1;