~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/UI/Changes.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

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