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