Skip to content

Commit

Permalink
Item14378: Enhance buttons support, update docs, copyright
Browse files Browse the repository at this point in the history
Allow Immediate, or Normal notifications to be disabled in
bin/configure.

Add a VarNTF macro.

Make rendering of the Normal or Immediate buttons / checkboxes
conditional based on configuration.  Also disable the rest handler and
beforeSafeHandler, depending on whether their related features are
enabled.

Added a standard copyright. Bumped versions.
  • Loading branch information
gac410 committed Apr 28, 2017
1 parent 2fd4118 commit 23a13d0
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 58 deletions.
68 changes: 34 additions & 34 deletions data/System/NotificationPlugin.txt
Expand Up @@ -10,6 +10,27 @@ Allows you to specify to kinds of notifications - immediate and regular. Immedia

%TOC%

---++ Notification Types:
There are two types of notifications - Immediate and Normal.

---+++ Immediate notifications
This type of notifications is send immediatly after user change watched topic. This type of notification is send even if the user checks the (deprecated) 'Don't notify' checkbox.
This means that you can see ANY change which is made in selected topics or webs. But, on the other hand, this is also the best way to be spammed with many mails if you set immediate
notification on whole webs if topics in this web are often changed. You have to decide when to use this type of notification.

---+++ Regular notifications
This type of notifications is similar to the default Foswiki notification system, but it also ignores the "Don't notify" checkbox. This notificaiton type requires a cron-job to
run the mailnotify rest handler.

The site administrator can chose which types of notifications to allow, by
setting options in [[%SCRIPTURLPATH{"configure"}%]] in the Extensions ->
NotificationPlugin tab.

Current settings:

| ={Extensions}{NotificationPlugin}{EnableImmediateNotify}= | _%IF{"context NotificationPluginImmediate" then="Enabled" else="_Disabled_"}%_ |
| ={Extensions}{NotificationPlugin}{EnableNormalNotify}= | _%IF{"context NotificationPluginNormal" then="Enabled" else="_Disabled_"}%_ |

---++ Syntax Rules

You have to create topic *%Your_user_name%NotifyList* in *Main* web from template Main.NotificationPluginListTemplate. Fill it with desired topics, webs and regexps and enjoy...
Expand All @@ -22,24 +43,10 @@ You have to create topic *%Your_user_name%NotifyList* in *Main* web from templat
<div class="foswikiHelp">%T% The headings in the topic are important. If the headings are missing, the
notifications will not be performed.</div>

---+++ NTF variable
---+++ NTF Macro
For adding _fast switching_ to notifications you can use =%<nop>NTF{}%= variable:

There are two modes of use:
* As "immediate action" buttons. Click a button and the state toggles.
* Use to open a pop-up dialog with checkboxes for the types of notification.

You can use these attributes in =%<nop>NTF{}%= variable:
* =popup= - it displays button which opens new window with support of changing notifications. Default is off.

When "popup" is disabled (the default), then the following 4 buttons are
enabled by default:
* =tin= - displays button for changing 'Topic immediate notifications'
* =win= - displays button for changing 'Web immediate notifications'
* =tn= - displays button for changing 'Topic notifications'
* =wn= - displays button for changing 'Web notifications'

Default values for all these attributes are "on". You can set it "off" to hide buttons.
%INCLUDE{"VarNTF" section="ntf_attributes"}%

---++++ NTF examples
* =%<nop>NTF{}%= - displays all four buttons
Expand All @@ -49,18 +56,7 @@ Default values for all these attributes are "on". You can set it "off" to hide b
* =%<nop>NTF{popup="on"}%= - Displays a button to open the Update Notifications dialog.
* %NTF{popup="on"}%

---++ Description of <nop>NotifyList topics

There are two types of notifications - immediate and regular.

---+++ Immediate notifications
This type of notifications is send immediatly after user change watched topic. This type of notification is send even if the user checks the (deprecated) 'Don't notify' checkbox.
This means that you can see ANY change which is made in selected topics or webs. But, on the other hand, this is also the best way to be spammed with many mails if you set immediate
notification on whole webs if topics in this web are often changed. You have to decide when to use this type of notification.

---+++ Regular notifications (not currently functional)
This type of notifications is similar to the default Foswiki notification system, but it also ignores the "Don't notify" checkbox. This notificaiton type requires a cron-job to
run the mailnotify rest handler.
---+++ Description of <nop>NotifyList topics

---+++ Subtypes
The syntax of setting a notification is with bullet Foswiki list.
Expand All @@ -87,13 +83,17 @@ generated by the =%<nop>NTF{popup="on"}%= macro is pressed.
<input type="hidden" name="popup" value="1" />
<input type="hidden" name="topic" value="%URLPARAM{"notifyweb"}%.%URLPARAM{"notifytopic"}%" />
---++ <nop>%URLPARAM{"notifyweb"}%.%URLPARAM{"notifytopic"}%
%IF{"context NotificationPluginImmediate" then="
---+++ Immediate Notifications
<input type="checkbox" name="TIN" value="ON" %URLPARAM{"TIN"}% >changes to the Topic<br/>
<input type="checkbox" name="WIN" value="ON" %URLPARAM{"WIN"}% >changes to the Web<br/>
<input type='checkbox' name='TIN' value='ON' %URLPARAM{"TIN"}% >changes to the Topic<br/>
<input type='checkbox' name='WIN' value='ON' %URLPARAM{"WIN"}% >changes to the Web<br/>
"}%
%IF{"context NotificationPluginNormal" then="
---+++ Normal Notifications
<input type="checkbox" name="TN" value="ON" %URLPARAM{"TN"}% >changes to the Topic<br/>
<input type="checkbox" name="WN" value="ON" %URLPARAM{"WN"}% >changes to the web<br/>
<input type="hidden" value="Update" name="action"></form>
<input type='checkbox' name='TN' value='ON' %URLPARAM{"TN"}% >changes to the Topic<br/>
<input type='checkbox' name='WN' value='ON' %URLPARAM{"WN"}% >changes to the web<br/>
"}%
<input type='hidden' value='Update' name='action'></form>
<a class="jqUIDialogButton jqUIDialogSubmit jqUIDialogClose {icon:'ui-icon-circle-check'}" >%MAKETEXT{"Change"}%</a>
<a id='cancelLink' class="jqUIDialogButton jqUIDialogClose {icon:'ui-icon-cancel'}">%MAKETEXT{"Cancel"}%</a>
</div>
Expand All @@ -119,7 +119,7 @@ Original version sponsored by [[http://www.systinet.com][Systinet]] ;-)
Foswikitask:Item14326: Non-existing global variables are referenced. <br/>\
Foswikitask:Item11574: Notification buttons and popup are not working. <br/>\
Foswikitask:Item14378: mailnotify-NP script is not functional. |
| 12 Sep 2010 (1.16) | Foswikitask:Item8428: Lose SENDER |
| 12 Sep 2010 (1.20) | Foswikitask:Item8428: Lose SENDER |
| 21 May 2007 (1.15) | TWikibug:Item3969: 8bit email fix (Foswiki:Main.WillNorris) |
| 11 May 2004 (1.14) | Version 1.14 - popup support for changing notifications |
| 29 Apr 2004 (1.13) | Version 1.13 - mailnotify script bugfix |
Expand Down
21 changes: 21 additions & 0 deletions data/System/VarNTF.txt
@@ -0,0 +1,21 @@
%META:TOPICINFO{author="ProjectContributor" date="1434650530" format="1.1" version="1"}%
%META:TOPICPARENT{name="Macros"}%
---+ NTF -- Display the buttons for updating NotificationPlugin notification rules.
%STARTSECTION{"ntf_attributes"}%
---++ Parameters
* The following attributes are recognized:
%TABLE{sort="off"}%
| *Name* | *Description* | *Default* |
| =popup= | Renders a "Notifications" button, which invokes a popup menu for setting notificaions. | =off= |
| The following settings all default to =off= if =popup= is enabled ||
| =tin= | Renders a TIN button to toggle the Immediate Notify status of the topic. | %IF{"context NotificationPluginImmediate" then="=on=" else="__Disabled__"}% |
| =win= | Renders a WIN button to toggle the Immediate Notify status for the entire web. | %IF{"context NotificationPluginImmediate" then="=on=" else="__Disabled__"}% |
| =tn= | Renders a TN button to toggle the Normal Notify status of the topic. | %IF{"context NotificationPluginNormal" then="=on=" else="__Disabled__"}% |
| =wn= | Renders a WN button to toggle the Normal Notify status for the entire web. | %IF{"context NotificationPluginNormal" then="=on=" else="__Disabled__"}% |

%ENDSECTION{"ntf_attributes"}%
---++ Examples
* A =%<nop>NTF{tin="off"}%= display all buttons except for the Topic Immediate Notification (TIN) button.
%STOPINCLUDE%
---++ Related
NotificationPlugin, MailerContrib
95 changes: 71 additions & 24 deletions lib/Foswiki/Plugins/NotificationPlugin.pm
Expand Up @@ -7,8 +7,8 @@ use strict;
use Foswiki::Func;
use Foswiki::Time;

our $VERSION = '1.30';
our $RELEASE = '24 Feb 2017';
our $VERSION = '2.00';
our $RELEASE = '27 Apr 2017';
our $SHORTDESCRIPTION =
'Send fine grained notifications of topics you are interested in';
our $NO_PREFS_IN_TOPIC = 1;
Expand Down Expand Up @@ -45,13 +45,23 @@ sub initPlugin {
description => 'Modify NotificationPlugin subscriptions'
);

Foswiki::Func::registerRESTHandler(
'mailnotify', \&mailnotify_Handler,
authenticate => 1, # Set to 0 if handler should be useable by WikiGuest
validate => 1, # Set to 0 to disable StrikeOne CSRF protection
http_allow => 'POST', # Set to 'GET,POST' to allow use HTTP GET and POST
description => 'NotificationPlugin mail notificaions'
);
if ( $Foswiki::cfg{Extensions}{NotificationPlugin}{EnableNormalNotify} ) {
Foswiki::Func::getContext()->{NotificationPluginNormal} = 1;
Foswiki::Func::registerRESTHandler(
'mailnotify', \&mailnotify_Handler,
authenticate =>
1, # Set to 0 if handler should be useable by WikiGuest
validate => 1, # Set to 0 to disable StrikeOne CSRF protection
http_allow =>
'POST', # Set to 'GET,POST' to allow use HTTP GET and POST
description => 'NotificationPlugin mail notificaions'
);
}

if ( $Foswiki::cfg{Extensions}{NotificationPlugin}{EnableImmediateNotify} )
{
Foswiki::Func::getContext()->{NotificationPluginImmediate} = 1;
}

Foswiki::Func::registerTagHandler( 'NTF', \&_NTF );

Expand All @@ -71,6 +81,10 @@ sub _NTF {
sub beforeSaveHandler {
### my ( $text, $topic, $web ) = @_;

return
unless $Foswiki::cfg{Extensions}{NotificationPlugin}
{EnableImmediateNotify};

Foswiki::Func::writeDebug(
"- NotificatinoPlugin::beforeSaveHandler( $_[2].$_[1] )")
if $debug;
Expand Down Expand Up @@ -400,12 +414,13 @@ sub showNotifyButtons {
my ( $tin, $win, $tn, $wn, $popup ) = ( "on", "on", "on", "on", "off" );
my ( $tinOn, $winOn, $tnOn, $wnOn ) = ( "on", "on", "on", "on" );
my %tmp = ( "on" => "OFF", "off" => "ON" );
$popup = $params->{popup} || "off";
my $def = ( $popup eq 'on' ) ? 'off' : 'on';
$tin = $params->{tin} || $def;
$win = $params->{win} || $def;
$tn = $params->{tn} || $def;
$wn = $params->{wn} || $def;
$popup = Foswiki::Func::isTrue( $params->{popup} );
my $def = !$popup;

$tin = Foswiki::Func::isTrue( $params->{tin}, $def );
$win = Foswiki::Func::isTrue( $params->{win}, $def );
$tn = Foswiki::Func::isTrue( $params->{tn}, $def );
$wn = Foswiki::Func::isTrue( $params->{wn}, $def );

my $text = "";

Expand All @@ -423,7 +438,7 @@ sub showNotifyButtons {
if ( !isItemInSection( $curWikiName, "$web.$topic", 3 ) );
$wnOn = "off" if ( !isItemInSection( $curWikiName, "$web", 4 ) );

if ( $popup eq 'on' ) {
if ($popup) {
my $tinC = ( $tinOn eq 'on' ) ? 'checked' : '';
my $winC = ( $winOn eq 'on' ) ? 'checked' : '';
my $tnC = ( $tnOn eq 'on' ) ? 'checked' : '';
Expand All @@ -434,40 +449,48 @@ sub showNotifyButtons {
HERE
}

$text .= <<"HERE" if $tin eq 'on';
if (
$Foswiki::cfg{Extensions}{NotificationPlugin}{EnableImmediateNotify}
)
{
$text .= <<"HERE" if $tin;
<form id="TIN" action="$restURL" method="post">
<input type="hidden" name="what" value="TIN" />
<input type="hidden" name="topic" value="$web.$topic" />
<input type="hidden" name="action" value="$tmp{$tinOn}" />
<input type="submit" class="foswikiButton" value="TIN $tinOn" title="Topic immediate notifications! Click to set it $tmp{$tinOn}!" />
<input type="submit" value="TIN $tinOn" title="Topic immediate notifications! Click to set it $tmp{$tinOn}!" />
</form>
HERE
$text .= <<"HERE" if $win eq 'on';
$text .= <<"HERE" if $win;
<form id="WIN" action="$restURL" method="post">
<input type="hidden" name="what" value="WIN" />
<input type="hidden" name="topic" value="$web.$topic" />
<input type="hidden" name="action" value="$tmp{$winOn}" />
<input type="submit" class="foswikiButton" value="WIN $winOn" title="Topic immediate notifications! Click to set it $tmp{$winOn}!" />
<input type="submit" value="WIN $winOn" title="Topic immediate notifications! Click to set it $tmp{$winOn}!" />
</form>
HERE
}

$text .= <<"HERE" if $tn eq 'on';
if ( $Foswiki::cfg{Extensions}{NotificationPlugin}{EnableNormalNotify} )
{
$text .= <<"HERE" if $tn;
<form id="TN" action="$restURL" method="post">
<input type="hidden" name="what" value="TN" />
<input type="hidden" name="topic" value="$web.$topic" />
<input type="hidden" name="action" value="$tmp{$tnOn}" />
<input type="submit" class="foswikiButton" value="TN $tnOn" title="Topic immediate notifications! Click to set it $tmp{$tnOn}!" />
<input type="submit" value="TN $tnOn" title="Topic immediate notifications! Click to set it $tmp{$tnOn}!" />
</form>
HERE

$text .= <<"HERE" if $wn eq 'on';
$text .= <<"HERE" if $wn;
<form id="WN" action="$restURL" method="post">
<input type="hidden" name="what" value="WN" />
<input type="hidden" name="topic" value="$web.$topic" />
<input type="hidden" name="action" value="$tmp{$wnOn}" />
<input type="submit" class="foswikiButton" value="WN $wnOn" title="Topic immediate notifications! Click to set it $tmp{$wnOn}!" />
<input type="submit" value="WN $wnOn" title="Topic immediate notifications! Click to set it $tmp{$wnOn}!" />
</form>
HERE
}

}
return $text;
Expand Down Expand Up @@ -807,3 +830,27 @@ sub mailnotify_Handler {
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 2001-2006 TWiki Contributors. All Rights Reserved.
TWiki Contributors are listed in the AUTHORS file in the root
of this distribution. NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
12 changes: 12 additions & 0 deletions lib/Foswiki/Plugins/NotificationPlugin/Config.spec
Expand Up @@ -4,4 +4,16 @@
# Enable debugging (debug messages will be written to data/debug.txt)
$Foswiki::cfg{Plugins}{NotificationPlugin}{Debug} = '0';
#
# **BOOLEAN**
# Enables the "Immediate Notify" functionality. If disabled, the TIN and WIN
# buttons will not be displayed, and the beforeSafeHandler will be disabled.
# Note that the email processing in the beforeSafeHandler can slow down or
# block the save if the email server has issues.
$Foswiki::cfg{Extensions}{NotificationPlugin}{EnableImmediateNotify} = $TRUE;
#
# **BOOLEAN**
# Enables the "Normal Notify" functionality. If disabled, the TN and WN
# buttons will not be displayed. This function is disabled by default as the
# MailerContrib provides richer functionality.
$Foswiki::cfg{Extensions}{NotificationPlugin}{EnableNormalNotify} = $FALSE;
1;
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/NotificationPlugin/MANIFEST
@@ -1,5 +1,6 @@
data/Main/NotificationPluginListTemplate.txt 0644
data/System/NotificationPlugin.txt 0644
data/System/VarNTF.txt 0644
lib/Foswiki/Plugins/NotificationPlugin.pm 0644
lib/Foswiki/Plugins/NotificationPlugin/Config.spec 0755
lib/Foswiki/Plugins/NotificationPlugin/DEPENDENCIES 0644
Expand Down

0 comments on commit 23a13d0

Please sign in to comment.