lib/TWiki/Plugins/CommentPlugin.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
child 1 e2915a7cbdfa
permissions -rw-r--r--
RELEASE 4.2.0 freetown
colas@0
     1
# Plugin for TWiki Enterprise Collaboration Platform, http://TWiki.org/
colas@0
     2
#
colas@0
     3
# Copyright (C) 2004 Crawford Currie
colas@0
     4
# Copyright (C) 2001-2006 TWiki Contributors. All Rights Reserved.
colas@0
     5
# TWiki Contributors
colas@0
     6
# are listed in the AUTHORS file in the root of this distribution.
colas@0
     7
# NOTE: Please extend that file, not this notice.
colas@0
     8
#
colas@0
     9
# This program is free software; you can redistribute it and/or
colas@0
    10
# modify it under the terms of the GNU General Public License
colas@0
    11
# as published by the Free Software Foundation; either version 2
colas@0
    12
# of the License, or (at your option) any later version. For
colas@0
    13
# more details read LICENSE in the root of this distribution.
colas@0
    14
#
colas@0
    15
# This program is distributed in the hope that it will be useful,
colas@0
    16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
colas@0
    17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
colas@0
    18
#
colas@0
    19
# For licensing info read LICENSE file in the TWiki root.
colas@0
    20
#
colas@0
    21
# See Plugin topic for history and plugin information
colas@0
    22
colas@0
    23
package TWiki::Plugins::CommentPlugin;
colas@0
    24
colas@0
    25
use strict;
colas@0
    26
colas@0
    27
require TWiki::Func;
colas@0
    28
require TWiki::Plugins;
colas@0
    29
colas@0
    30
use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION $NO_PREFS_IN_TOPIC );
colas@0
    31
colas@0
    32
# This should always be $Rev: 15776 (22 Jan 2008) $ so that TWiki can determine the checked-in
colas@0
    33
# status of the plugin. It is used by the build automation tools, so
colas@0
    34
# you should leave it alone.
colas@0
    35
$VERSION = '$Rev: 15776 (22 Jan 2008) $';
colas@0
    36
colas@0
    37
# This is a free-form string you can use to "name" your own plugin version.
colas@0
    38
# It is *not* used by the build automation tools, but is reported as part
colas@0
    39
# of the version number in PLUGINDESCRIPTIONS.
colas@0
    40
$RELEASE = 'TWiki-4';
colas@0
    41
colas@0
    42
$SHORTDESCRIPTION = 'Allows users to quickly post comments to a page without an edit/preview/save cycle';
colas@0
    43
colas@0
    44
sub initPlugin {
colas@0
    45
    #my ( $topic, $web, $user, $installWeb ) = @_;
colas@0
    46
colas@0
    47
    if( $TWiki::Plugins::VERSION < 1.026 ) {
colas@0
    48
        TWiki::Func::writeWarning( "CommentPlugin $VERSION requires TWiki::Plugins::VERSION >= 1.026, $TWiki::Plugins::VERSION found." );
colas@0
    49
        return 0;
colas@0
    50
    }
colas@0
    51
colas@0
    52
    return 1;
colas@0
    53
}
colas@0
    54
colas@0
    55
sub commonTagsHandler {
colas@0
    56
    my ( $text, $topic, $web, $meta ) = @_;
colas@0
    57
colas@0
    58
    require TWiki::Plugins::CommentPlugin::Comment;
colas@0
    59
colas@0
    60
    my $query = TWiki::Func::getCgiQuery();
colas@0
    61
    return unless( defined( $query ));
colas@0
    62
colas@0
    63
    return unless $_[0] =~ m/%COMMENT({.*?})?%/o;
colas@0
    64
colas@0
    65
    # SMELL: Nasty, tacky way to find out where we were invoked from
colas@0
    66
    my $scriptname = $ENV{'SCRIPT_NAME'} || '';
colas@0
    67
    # SMELL: unreliable
colas@0
    68
    my $previewing = ($scriptname =~ /\/(preview|gnusave|rdiff)/);
colas@0
    69
    TWiki::Plugins::CommentPlugin::Comment::prompt( $previewing,
colas@0
    70
                                                    $_[0], $web, $topic );
colas@0
    71
}
colas@0
    72
colas@0
    73
sub beforeSaveHandler {
colas@0
    74
    #my ( $text, $topic, $web ) = @_;
colas@0
    75
colas@0
    76
    require TWiki::Plugins::CommentPlugin::Comment;
colas@0
    77
colas@0
    78
    my $query = TWiki::Func::getCgiQuery();
colas@0
    79
    return unless $query;
colas@0
    80
colas@0
    81
    my $action = $query->param('comment_action');
colas@0
    82
colas@0
    83
    return unless( defined( $action ) && $action eq 'save' );
colas@0
    84
    TWiki::Plugins::CommentPlugin::Comment::save( @_ );
colas@0
    85
}
colas@0
    86
colas@0
    87
1;