lib/TWiki/UI/Changes.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
permissions -rw-r--r--
RELEASE 4.2.0 freetown
     1 # Module of TWiki Enterprise Collaboration Platform, http://TWiki.org/
     2 #
     3 # Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org
     4 # and TWiki Contributors. All Rights Reserved. TWiki Contributors
     5 # are listed in the AUTHORS file in the root of this distribution.
     6 # NOTE: Please extend that file, not this notice.
     7 #
     8 # Additional copyrights apply to some or all of the code in this
     9 # file as follows:
    10 # Based on parts of Ward Cunninghams original Wiki and JosWiki.
    11 # Copyright (C) 1998 Markus Peter - SPiN GmbH (warpi@spin.de)
    12 # Some changes by Dave Harris (drh@bhresearch.co.uk) incorporated
    13 #
    14 # This program is free software; you can redistribute it and/or
    15 # modify it under the terms of the GNU General Public License
    16 # as published by the Free Software Foundation; either version 2
    17 # of the License, or (at your option) any later version. For
    18 # more details read LICENSE in the root of this distribution.
    19 #
    20 # This program is distributed in the hope that it will be useful,
    21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    23 #
    24 # As per the GPL, removal of this notice is prohibited.
    25 
    26 package TWiki::UI::Changes;
    27 
    28 use strict;
    29 
    30 use Assert;
    31 use Error qw( :try );
    32 
    33 require TWiki;
    34 require TWiki::UI;
    35 require TWiki::Time;
    36 
    37 # Command handler for changes command
    38 sub changes {
    39     my $session = shift;
    40 
    41     my $query = $session->{cgiQuery};
    42     my $webName = $session->{webName};
    43     my $topic = $session->{topicName};
    44 
    45     TWiki::UI::checkWebExists( $session, $webName, $topic, 'find changes in' );
    46 
    47     my $skin = $session->getSkin();
    48 
    49     my $text = $session->templates->readTemplate( 'changes', $skin );
    50 
    51     my( $page, $eachChange, $after) = split( /%REPEAT%/, $text );
    52 
    53     my $showMinor = $query->param( 'minor' );
    54     unless( $showMinor ) {
    55         my $comment = CGI::b( 'Note: ' ).
    56           'This page is showing major changes only. '.
    57             CGI::a( { href => $query->url()."/$webName?minor=1",
    58                       rel => 'nofollow' }, 'View all changes' );
    59         $comment = CGI::div( { class => 'twikiHelp' }, $comment );
    60         $page .= $comment;
    61     }
    62     my %done = ();
    63 
    64     my $iterator = $session->{store}->eachChange( $webName, 0 );
    65 
    66     while( $iterator->hasNext() ) {
    67         my $change = $iterator->next();
    68         next if (!$showMinor && $change->{more} && $change->{more} =~ /minor/);
    69         next if $done{$change->{topic}};
    70         next unless $session->{store}->topicExists( $webName, $change->{topic} );
    71         try {
    72             my $summary = $session->renderer->summariseChanges(
    73                 $session->{user}, $webName, $change->{topic}, $change->{revision} );
    74             my $thisChange = $eachChange;
    75             $thisChange =~ s/%TOPICNAME%/$change->{topic}/go;
    76             my $wikiuser = $change->{user} ?
    77               $session->{users}->webDotWikiName($change->{user}) : '';
    78             $thisChange =~ s/%AUTHOR%/$wikiuser/go;
    79             my $time = TWiki::Time::formatTime( $change->{time} );
    80             $change->{revision} = 1 unless $change->{revision};
    81             my $srev = 'r' . $change->{revision};
    82             if( $change->{revision} == 1 ) {
    83                 $srev = CGI::span( { class => 'twikiNew' }, 'NEW' );
    84             }
    85             $thisChange =~ s/%TIME%/$time/g;
    86             $thisChange =~ s/%REVISION%/$srev/go;
    87             $thisChange = $session->renderer->getRenderedVersion
    88               ( $thisChange, $webName, $change->{topic} );
    89             $thisChange =~ s/%TEXTHEAD%/$summary/go;
    90             $page .= $thisChange;
    91         } catch TWiki::AccessControlException with {
    92             # ignore changes we can't see
    93         };
    94         $done{$change->{topic}} = 1;
    95     }
    96     if( $TWiki::cfg{Log}{changes} ) {
    97         # write log entry
    98         $session->writeLog( 'changes', $webName, '' );
    99     }
   100     $page .= $after;
   101 
   102     $page = $session->handleCommonTags( $page, $webName, $topic );
   103     $page = $session->renderer->getRenderedVersion($page, $webName, $topic );
   104 
   105     $session->writeCompletePage( $page );
   106 }
   107 
   108 1;