Skip to content

Commit

Permalink
Item15105: multiple improvements to MetaCommentPlugin
Browse files Browse the repository at this point in the history
   * add interface to render comments from a base translation
   * added =ismoderated= to only show approval controls if the topic actually is moderated
   * added new preference setting COMMENTNOTIFY (default on) to suppress change notifications when a topic is commented
   * rewrite of javascript code; blocking browser navigation when there are unsaved comments
   * improve usability of threaded commenting
   * enable wiki editor for commenting
   * use new api of JQDataTablesPlugin to register custom columns to dbcache and solr connectors
   * new solr fields =field_Comments_d= and =field_CommentDate_dt=
  • Loading branch information
MichaelDaum committed May 4, 2022
1 parent b32a68e commit ec7102e
Show file tree
Hide file tree
Showing 37 changed files with 3,990 additions and 1,648 deletions.
31 changes: 20 additions & 11 deletions data/System/MetaCommentPlugin.txt
@@ -1,15 +1,15 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1574759516" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1605804814" format="1.1" version="1"}%
---+!! MetaCommentPlugin
%FORMFIELD{"Description"}%

%TOC%

This is YACS (yet another comment system) which tries to

* (a) be easy to use,
* (b) scale up to lots of comments
* (c) provide different layouts and commenting requirements and
* (d) implement a moderation workflow for comments before they go live.
1 be easy to use,
1 scale up to lots of comments
1 provide different layouts and commenting requirements and
1 implement a moderation workflow for comments before they go live.

<nop>%TOPIC% allows to easily add commenting to any topic. Discussiosn can
either be displayed in linear or threaded mode. Different comment styles and
Expand Down Expand Up @@ -196,6 +196,7 @@ When rendering a comment, the following variables can be used in the =format= st
* $state: the state of this comment
* $count: the total number of comments
* $ismoderator: true/false if the current user is allowed to moderate the comments or not
* $ismoderated: true/false if the current topic is moderated or not
* $timestamp: the date when this comment was created; format in epoch seconds
* $date: the date when this comment was created in Foswiki's default time format
* $modified: the date this comment was last modified
Expand Down Expand Up @@ -265,6 +266,14 @@ The parameters =THEWEB=, =WHERE= and =LIMIT= are optional where

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 04 May 2022: | 7.00 - added interface to render comments from a base translation; \
improve usability of threaded commenting; \
better editor integration; \
use new api of JQDataTablesPlugin to register custom columns to dbcache and solr connectors; \
new solr fields =field_Comments_d= and =field_CommentDate_dt= |
| 17 Jun 2021: | 6.20 - added =ismoderated= to only show approval controls if the topic actually is moderated |
| 06 May 2021: | 6.10 - added new preference setting COMMENTNOTIFY (default on) to suppress change notifications when a topic is commented |
| 31 Mar 2021: | 6.00 - rewrite of javascript code; blocking browser navigation when there are unsaved comments |
| 26 Nov 2019: | 5.10 - added rev parameter to display comments of previous revisions of a topic; \
added "delete all", "approve all", "mark all" features to moderate comments in bunches; \
improved [[Foswiki:Extensions/SolrPlugin][SolrPlugin]] integration |
Expand Down Expand Up @@ -316,14 +325,14 @@ The parameters =THEWEB=, =WHERE= and =LIMIT= are optional where
fixed recoding of received data to the site's own charset; \
improved the way photos are gathered |

%META:FILEATTACHMENT{name="MetaCommentSnap1.jpeg" attachment="MetaCommentSnap1.jpeg" attr="h" comment="" date="1574759516" path="MetaCommentSnap1.jpeg" size="51144" user="ProjectContributor" version="1"}%
%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Foswiki:Main/MichaelDaum"}%
%META:FIELD{name="Copyright" title="Copyright" value="2009-2019, Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}%
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="https://foswiki.org/Extensions/MetaCommentPlugin"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Release" title="Release" value="%$RELEASE%"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/MetaCommentPlugin"}%
%META:FIELD{name="Copyright" title="Copyright" value="2009-2022, Michael Daum"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Home" title="Home" value="https://foswiki.org/Extensions/MetaCommentPlugin"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/MetaCommentPlugin"}%
%META:FIELD{name="Version" title="Version" value="%$VERSION%"}%
%META:FILEATTACHMENT{name="MetaCommentSnap1.jpeg" attachment="MetaCommentSnap1.jpeg" attr="h" comment="" date="1574759516" path="MetaCommentSnap1.jpeg" size="51144" user="ProjectContributor" version="1"}%
40 changes: 37 additions & 3 deletions lib/Foswiki/Plugins/MetaCommentPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009-2019 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2022 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -18,9 +18,10 @@ use warnings;
use Foswiki::Func ();
use Foswiki::Plugins ();
use Foswiki::Contrib::JsonRpcContrib ();
use Foswiki::Plugins::JQueryPlugin ();

our $VERSION = '5.10';
our $RELEASE = '26 Nov 2019';
our $VERSION = '7.00';
our $RELEASE = '04 May 2022';
our $SHORTDESCRIPTION = 'An easy to use comment system';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand All @@ -31,6 +32,8 @@ sub initPlugin {
$core = undef;
@commentHandlers = ();

Foswiki::Plugins::JQueryPlugin::registerPlugin("MetaComment", 'Foswiki::Plugins::MetaCommentPlugin::JQuery');

Foswiki::Func::registerTagHandler('METACOMMENTS', sub {
return getCore(shift)->METACOMMENTS(@_);
});
Expand Down Expand Up @@ -92,6 +95,37 @@ sub initPlugin {
});
}

if ($Foswiki::cfg{Plugins}{JQDataTablesPlugin}{Enabled}) {
# register qmstate properties to JQDataTablesPlugin
require Foswiki::Plugins::JQDataTablesPlugin;

Foswiki::Plugins::JQDataTablesPlugin::describeColumn("dbcache", "comments", {
type => "number",
data => 'length(comments)',
search => 'length(comments)',
sort => 'length(comments)',
});
Foswiki::Plugins::JQDataTablesPlugin::describeColumn("dbcache", "commentdate", {
type => 'date',
data => 'commentdate',
search => 'lc(n2d(commentdate))',
sort => 'commentdate',
});

Foswiki::Plugins::JQDataTablesPlugin::describeColumn("solr", "comments", {
type => 'number',
data => 'field_Comments_d',
search => 'field_Comments_d',
sort => 'field_Comments_d',
});
Foswiki::Plugins::JQDataTablesPlugin::describeColumn("solr", "commentdate", {
type => 'date',
data => 'field_Comments_dt',
search => 'field_Comments_search',
sort => 'field_Comments_dt',
});
}

if ($Foswiki::Plugins::VERSION > 2.0) {
Foswiki::Meta::registerMETA("COMMENT", many=>1, alias=>"comment");
}
Expand Down
44 changes: 33 additions & 11 deletions lib/Foswiki/Plugins/MetaCommentPlugin/Core.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009-2019 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2021 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -41,6 +41,7 @@ sub new {
baseWeb => $session->{webName},
baseTopic => $session->{topicName},
anonCommenting => $Foswiki::cfg{MetaCommentPlugin}{AnonymousCommenting},
commentNotify => Foswiki::Func::isTrue(Foswiki::Func::getPreferencesValue("COMMENTNOTIFY"), 1),
wikiName => Foswiki::Func::getWikiName(),
};

Expand Down Expand Up @@ -142,7 +143,7 @@ sub jsonRpcSaveComment {
};

$meta->putKeyed('COMMENT', $comment);
Foswiki::Func::saveTopic($web, $topic, $meta, $text, {ignorepermissions=>1, minor=>1}) unless DRY;
Foswiki::Func::saveTopic($web, $topic, $meta, $text, {ignorepermissions=>1, minor => !$this->{commentNotify}}) unless DRY;
$this->triggerEvent("commentsave", $web, $topic, $comment);

return;
Expand Down Expand Up @@ -260,7 +261,7 @@ sub jsonRpcUpdateComment {

$meta->putKeyed('COMMENT', $comment);

Foswiki::Func::saveTopic($web, $topic, $meta, $text, {ignorepermissions=>1, minor=>1}) unless DRY;
Foswiki::Func::saveTopic($web, $topic, $meta, $text, {ignorepermissions=>1, minor => !$this->{commentNotify}}) unless DRY;
$this->triggerEvent("commentupdate", $web, $topic, $comment);

return;
Expand Down Expand Up @@ -313,7 +314,7 @@ sub jsonRpcDeleteComment {
# remove this comment
$meta->remove('COMMENT', $id);

Foswiki::Func::saveTopic($web, $topic, $meta, $text, {ignorepermissions=>1, minor=>1}) unless DRY;
Foswiki::Func::saveTopic($web, $topic, $meta, $text, {ignorepermissions=>1, minor => !$this->{commentNotify}}) unless DRY;
$this->triggerEvent("commentdelete", $web, $topic, $comment);

return;
Expand Down Expand Up @@ -353,7 +354,7 @@ sub jsonRpcDeleteAllComments {
# remove all comments
$meta->remove('COMMENT');

Foswiki::Func::saveTopic($web, $topic, $meta, $text, {ignorepermissions=>1, minor=>1}) unless DRY;
Foswiki::Func::saveTopic($web, $topic, $meta, $text, {ignorepermissions=>1, minor => 1}) unless DRY;
$this->triggerEvent("commentdeleteall", $web, $topic);

return;
Expand Down Expand Up @@ -400,6 +401,7 @@ sub jsonRpcApproveAllComments {

return;
}

##############################################################################
sub jsonRpcMarkAllComments {
my ($this, $request) = @_;
Expand Down Expand Up @@ -500,7 +502,6 @@ sub isModerator {
my ($this, $web, $topic, $meta) = @_;

return 1 if Foswiki::Func::isAnAdmin();
return 0 unless $this->isModerated($web, $topic, $meta);
return 1 if Foswiki::Func::checkAccessPermission("MODERATE", $this->{wikiName}, undef, $topic, $web, $meta);
return 0;
}
Expand Down Expand Up @@ -581,7 +582,8 @@ sub METACOMMENTS {

$params->{count} = ($count > 1)?$params->{plural}:$params->{singular};
$params->{count} =~ s/\$count/$count/g;
$params->{ismoderator} = $this->isModerator($theWeb, $theTopic);
$params->{ismoderator} = $this->isModerator($theWeb, $theTopic, $meta);
$params->{ismoderated} = $this->isModerated($theWeb, $theTopic, $meta);

# format the results
my @topComments;
Expand All @@ -596,11 +598,13 @@ sub METACOMMENTS {
expandVariables($params->{header},
count=>$params->{count},
ismoderator=>$params->{ismoderator},
ismoderated=>$params->{ismoderated},
).
join(expandVariables($params->{separator}), @result).
expandVariables($params->{footer},
count=>$params->{count},
ismoderator=>$params->{ismoderator},
ismoderated=>$params->{ismoderated},
);

# oh well
Expand Down Expand Up @@ -810,10 +814,12 @@ sub formatComments {
count=>$params->{count},
index=>$indexString,
ismoderator=>$params->{ismoderator},
ismoderated=>$params->{ismoderated},
).$subComments.
expandVariables($params->{subfooter},
count=>$params->{count},
ismoderator=>$params->{ismoderator},
ismoderated=>$params->{ismoderated},
index=>$indexString)
};
}
Expand Down Expand Up @@ -841,6 +847,7 @@ sub formatComments {
state=>$comment->{state},
count=>$params->{count},
ismoderator=>$params->{ismoderator},
ismoderated=>$params->{ismoderated},
timestamp=>$comment->{date} || 0,
date=>Foswiki::Time::formatTime(($comment->{date}||0)),
modified=>Foswiki::Time::formatTime(($comment->{modified}||0)),
Expand Down Expand Up @@ -968,9 +975,8 @@ sub solrIndexTopicHandler {
# delete all previous comments of this topic
$indexer->deleteByQuery("type:comment web:$web topic:$topic");

my $commentDate = 0;
my @comments = $meta->find('COMMENT');
return unless @comments;

my @aclFields = $indexer->getAclFields($web, $topic, $meta);
my $isModerated = $this->isModerated($web, $topic, $meta);

Expand All @@ -980,7 +986,15 @@ sub solrIndexTopicHandler {

# set doc fields
my $createDate = Foswiki::Func::formatTime($comment->{date}, 'iso', 'gmtime');
my $date = defined($comment->{modified}) ? Foswiki::Func::formatTime($comment->{modified}, 'iso', 'gmtime') : $createDate;
my $createStr = Foswiki::Func::formatTime($comment->{date});
my $cmtDate = $comment->{modified} || $comment->{date};
my $date = Foswiki::Func::formatTime($cmtDate, 'iso', 'gmtime');
my $dateStr = Foswiki::Func::formatTime($cmtDate);

if ($cmtDate > $commentDate) {
$commentDate = $cmtDate;
}

my $webtopic = "$web.$topic";
$webtopic =~ s/\//./g;
my $id = $webtopic . '#' . $comment->{name};
Expand Down Expand Up @@ -1010,7 +1024,9 @@ sub solrIndexTopicHandler {
# 'author_url' => $comment->{author_url},
'contributor' => $comment->{author},
'date' => $date,
'date_s' => $dateStr,
'createdate' => $createDate,
'createdate_s' => $createStr,
'title' => $title,
'text' => $comment->{text},
'url' => $url,
Expand Down Expand Up @@ -1048,7 +1064,6 @@ sub solrIndexTopicHandler {
$doc->add_fields('catchall' => $title);
$doc->add_fields('catchall' => $comment->{text});


# add the document to the index
try {
$indexer->add($commentDoc);
Expand All @@ -1058,6 +1073,12 @@ sub solrIndexTopicHandler {
$indexer->log("ERROR: " . $e->{-text});
};
}

my $numComments = scalar(@comments);

$doc->add_fields(field_Comments_d => $numComments);
$doc->add_fields(field_CommentDate_dt => Foswiki::Func::formatTime($commentDate, 'iso', 'gmtime'))
if $commentDate;
}

##############################################################################
Expand All @@ -1068,6 +1089,7 @@ sub dbcacheIndexTopicHandler {
# cache comments
my $archivist = $db->getArchivist();
my @comments = $meta->find('COMMENT');

my $commentDate = 0;

my $cmts;
Expand Down
45 changes: 45 additions & 0 deletions lib/Foswiki/Plugins/MetaCommentPlugin/JQuery.pm
@@ -0,0 +1,45 @@
# Extension for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# JQuery Jitsi Meet is Copyright (C) 2021 Michael Daum
#
# 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.
#
# 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. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html

package Foswiki::Plugins::MetaCommentPlugin::JQuery;

use strict;
use warnings;

use Foswiki::Func ();
use Foswiki::Plugins::MetaCommentPlugin ();
use Foswiki::Plugins::JQueryPlugin::Plugin ();
our @ISA = qw( Foswiki::Plugins::JQueryPlugin::Plugin );

sub new {
my $class = shift;

my $this = bless(
$class->SUPER::new(
name => 'MetaCommentPlugin',
version => $Foswiki::Plugins::MetaCommentPlugin::VERSION,
author => 'Michael Daum',
homepage => 'https://foswiki.org/Extensions/MetaCommentPlugin',
javascript => ['naviblocker.js', 'metacomment.js'],
css => ['metacomment.css'],
puburl => '%PUBURLPATH%/%SYSTEMWEB%/MetaCommentPlugin',
dependencies => ['ui', 'form', 'jsonrpc', 'pnotify', 'scrollto'],
),
$class
);

return $this;
}

5 changes: 5 additions & 0 deletions lib/Foswiki/Plugins/MetaCommentPlugin/MANIFEST
Expand Up @@ -3,6 +3,7 @@ data/System/MetaCommentPlugin.txt 0644
lib/Foswiki/Plugins/MetaCommentPlugin/Config.spec 0644
lib/Foswiki/Plugins/MetaCommentPlugin/Core.pm 0644
lib/Foswiki/Plugins/MetaCommentPlugin/DEPENDENCIES 0644
lib/Foswiki/Plugins/MetaCommentPlugin/JQuery.pm 0644
lib/Foswiki/Plugins/MetaCommentPlugin.pm 0644
locale/MetaCommentPlugin/bg.po 0644
locale/MetaCommentPlugin/cs.po 0644
Expand Down Expand Up @@ -40,7 +41,11 @@ pub/System/MetaCommentPlugin/metacomment.pattern.uncompressed.css 0644
pub/System/MetaCommentPlugin/MetaCommentSnap1.jpeg 0644
pub/System/MetaCommentPlugin/metacomment.uncompressed.css 0644
pub/System/MetaCommentPlugin/metacomment.uncompressed.js 0644
pub/System/MetaCommentPlugin/naviblocker.js 0644
pub/System/MetaCommentPlugin/naviblocker.js.gz 0644
pub/System/MetaCommentPlugin/naviblocker.uncompressed.js 0644
pub/System/MetaCommentPlugin/nobody.gif 0644
pub/System/MetaCommentPlugin/nobody.png 0644
templates/metacomments.pattern.tmpl 0644
templates/metacommentsrss.tmpl 0644
templates/metacomments.tmpl 0644
Expand Down

0 comments on commit ec7102e

Please sign in to comment.