Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

CommentBox

Summary: Adds a simple form to post comments
Version: 2.0.19 (released 2007-10-31)
Status: Stable
Prerequisites: pmwiki 2.0 and above; 2.1 recommended
Maintainer: jr
Categories: Forms CMS Blog, Comments

Goal

Give authors a simple way to add a comment box to a wiki page.

Solution

  • commentbox.phpΔ (merges changes from commentbox2 and some of Mike's suggestions; now with division styling)

See also

  • CommentBoxPlus for a modified version with additional features.
  • CommentDb - an alternative solution, that stores comments in a database. For this price provides convenient comment pagination and RSS-feed of the comments.

Update: commentbox.phpΔ and commentboxplus.phpΔ are no longer allowing edit access to pages if no edit permission is present (a former security risk). - Jan 30, 2006.

Note: this uses the run-in head markup to lay out comments, so requires the MarkupExtensions to work correctly. However, the variables can also be redefined to work with a standard PmWiki install.

Installation

Put commentbox.php into the cookbook/ directory.

Add the following to local/config.php

include_once("cookbook/commentbox.php");

Usage

Following the (:searchbox:) directive naming convention, there are 2 new directives:

(:commentbox:) !!!!12 July 2005 !21:39 by '''[[~Pm]]'''!post again !21:39 by '''[[~Pm]]'''!Test comment posts comments latest first
(:commentboxchrono:) posts comments latest last

You can put (:commentbox:) in a GroupHeader -- all comments get posted at the top of the page.

You can put (:commentboxchrono:) in a GroupFooter -- all comments get posted at the bottom of the page.

If the page name ends in Journal or Diary (configurable), the script automatically inserts a comment box after the GroupHeader and before the text. You don't have to state e.g. (:commentbox:) anywhere for this feature (except loading in local/config.php of course)

Posting comments to other pages

This is a new feature.

The recipe also supports posting comments to different pages with the (:commentbox pagename:) option. As this is potentially a security risk, there are a number of controls in place using global variables that an administrator sets in local/config.php:

  • $EnablePostToAnyPage is false by default and cross-page commenting is disallowed; to enable cross-page comment posting, set to true
  • $EnableRedirectToCommentPage is false by default; to redirect the commenter to the comment page after posting, set to true
  • $AllowedPostToGroups is an empty array by default and comments are restricted to the current group; to enable cross-group posting, add the target group(s) to the array; for example, $AllowPostToGroups[] = 'Somegroup';

Format of comments

An administrator can control the format of comment entries using the following variables. See also samples in source.

ForVariableDefaultExample
Journal pages$JPDateFmt!!!!$Date!!!!!$Date
 $JPTimeFmtnn!$Time!nn'''$Time : '''
Diary pages$DPDateFmt!$Date!!!!!!$Daten
 $DPItemFmtnn: :n*
Message pages$MPDateFmt!!!!$Date!!!!!$Date
 $MPTimeFmtnn!$Time by '''$Author'''!nn'''$Time - ''$Author'' : '''
 $MPItemFmt(null string)n----

The $Date, $Time and $Author strings get str_replaced with the current values within the script. Note the $ for variables defined using " ... ". Administrators will want to test their use of "n" carefully -- the script author kept having too many or too few, leading to unexpected (and unwanted) results.

Addendum
The latest version of commentbox.phpΔ includes heading and division styling by default, with the following variable settings (these use the run-in head markup, but this can be changed). jr
Journal
     SDV($JPDateFmt,'!!!!$Date');
     SDV($JPTimeFmt,"\n\n>>journal<<\n!\$Time!");
     SDV($JPItemEndFmt,"\n>><<");
Diary
     SDV($DPDateFmt,">>diary<<\n!$Date!");
     SDV($DPItemFmt,"\n\n: :");
     SDV($DPItemEndFmt,"\n>><<");
Message
     SDV($MPDateFmt,'!!!!$Date');
     SDV($MPTimeFmt,"\n\n>>message<<\n!\$Time by \$Author!");
     SDV($MPItemFmt,'');
     SDV($MPItemEndFmt,"\n>><<");
     SDV($MPDateTimeFmt,
          ">>message<<\n!!!!\$Date at \$Time by \$Author\n\n");

The default styling is

  h4.journalhead, h4.messagehead { background:#ffb; border-top:1px dotted #999; }
  .message, .journal, .diary {
      padding:3px;
      border:1px dotted #999;
      background:#ffc;
  }
New feature
By default, $commentboxaccesscode is false. If set to true in local/config.php before loading commentbox.php, it prompts the poster to enter a randomly-generated 3 digit number. This may deter comment spamming robots. The code also limits the number of links allowed in a post to 1. The $MaxLinkCount variable controls this.

History

  • 31 Oct 2007 improve security of posting comments to other pages
  • 11 Aug 2006 tidy styles and add $commentboxaccesscode to deter spammers
  • 02 July 2006 add (:commentbox PageName:) option to post to a specified page
  • 28 March 2006 fix bug if pages contain backslash markup, add heading class
  • 31 Jan 2006 prevent ?action=comment from bring up the edit page form
  • 21 Sep 2005 add div around each comment (light version of Hans' extension)
  • 01 Sep 2005 support $Time and $Author in $MPItemFmt
  • 11 May 2005 changed BasicAuth to PmWikiAuth
  • 14 Mar 2005 set Author to 'anon' if author field is blank
  • 27 Feb 2005 remove "wrap='virtual'" from textareas
  • 10 Jan 2005 tidy the format (thanks to Mike)
  • 28 Nov 2004 fix <th>...</td> errors
  • 13 Nov 2004 set the format of comment entries using variables that an administrator can control
  • 29 Oct 2004 modify PmWiki 1 script to work with PmWiki 2

Contributors

jr

Comments

(older comments that have been covered in subsequent bug fixes have been removed) jr

  • 24-Feb-2005I found a small bug (using the commentbox.php): When the Wikitext contains "" (newline) it is changes to a single "" as soon a comment is entered. It look like something happens when the comment is stored. Klonk
    • 27-Feb-2005 I can't replicate this; however, I have removed the wrap='virtual', which may make a difference...
      • Sorry, does not make a difference. I'll check and see whether some other script interferes. Klonk - changed wiki markup a little bit (which helped) as I didn't find a solution.
  • How do I change the css so the comments are in smaller font?
    • make .message, .journal, .diary { font-size: smaller; }
      • This does not really address the issue, where are the <h1> and <strong> tags coming from? There's no reference to the actual HTML - and you can't force h1 to be small via CSS, I've tried and tried and tried. Please, could someone do a cleanup of this code? it's not commented well at all.
  • Is it possible to limit the number of entries displayed per page?
Here's what we might do... First, use a date markup yyyy-mm-dd that gets rendered as a long date. Then set an "omit postings older than $Today - $ExpiredCommentsAfterDays" options. For example (:commentbox 30:) would omit postings more than 30 days old. Finally, we'd need to add "show all" "hide all" "hide expired" links. Is this the kind of thing we want?
  • This is one of the worst recipes I ever used. It messes up with my pages having newlines, and it's not secure when used on a closed wiki. When you type "?action=comment", you can edit a page without having to type a password, and if you password protect the comment thing, you can't let your visitors leave comments, this is a pretty lousy recipe if it is used for a closed wiki.
Thanks for pointing out the security risk. I thought it was enough to hide the comment box, but you are right, it leaves the site open. I will see if this is fixable, meanwhile disable it on my site . What a shame. - HansB
I fixed commentboxstyled.phpΔ with additional security features to make it impossible to edit other pages on an edit protected site. - HansB January 08, 2006, at 09:39 AM
I think the following change fixes the problem. Add this line at the start of the HandleCommentPost function:
                  if (!@$_POST['post']) Redirect($pagename);
Is anything else required? This change is included in commentbox.phpΔ -- jr January 30, 2006, at 11:14 PM
thanks John! So much simpler than what I did! I used your solution now also in commentboxstyled.phpΔ. - On another note: I would love to tidy up this page, as lots of it is not relevant any longer, but I don't wan tto step on anyone's toes. ~HansB

Great recipe!
I'm having a small problem though. I put the (:commentbox:) directive at the bottom of a page below text for the visitor to comment on what he or she reads. However, when a comment is posted, some of my formatting changes, namely the \\ line break and \\\ paragraph lose all but one \.
Any reason this would occur?

thank you, GammaRay

Update: I found a workaround by using the [[<<]] instead. Nothing changes when a comment is posted now.

GammaRay

This was a bug caused by the subsequent pmwiki edit handler calling stripmagic and removing single backslashes. Fixed in version 2.0.13. jr
  • [31-Mar-2006] CommentBox is incompatible with the sectionedit recipe:
    Warning: array_merge() [function.array-merge]: Argument #2 is not an array
       in /www/pmwiki/cookbook/sectionedit.php on line 264
    Warning: array_unique() [function.array-unique]: The argument should be an array
       in /www/pmwiki/cookbook/sectionedit.php on line 266
    Warning: in_array() [function.in-array]: Wrong datatype for second argument
       in /www/pmwiki/cookbook/sectionedit.php on line 287
    Warning: in_array() [function.in-array]: Wrong datatype for second argument
       in /www/pmwiki/cookbook/sectionedit.php on line 287
    Warning: Cannot modify header information - headers already sent by (output started
       at /www/pmwiki/cookbook/sectionedit.php:264) in /www/pmwiki/pmwiki.php on line 857
    
    i don't know on which side the problem is...

This is Ridiculous.

Would it be possible to make the layout a little more difficult to modify? Otherwise, thanks for a solid recipe. UPDATE. You know what, I take it back. This recipe is totally unstable if modified in any way, even for layout changes. How about this: When I included it in a groupfooter it posts the comment above the rest of the page content, and this obvious bug is still in this recipe despite the authors recommendation that the commentbox markup be PUT in the groupfooter. This recipe sucks, and there is no alternative unless one wants to go into comment-pages or mySQL stuff. Which I don't. This problem is not local to this recipe. The sort of instability, dirty versioning and general mishmashing of code exemplified by this crappy code extension is just the sort of problem absolutely plagues PMWiki in it's entirety. the PMWiki philosophy is "leave the extensions out of the core code and let people install what they need to." this is a great philosophy and I am behind it. But the PMWiki strategy is then to take a Wikipedia approach to code: let everyone modify whatever they want, whenever they want, and release it as gospel to the general user public. THIS WORKS (sortof) FOR INFORMATION BUT NOT FOR CODE. I am sick of things half working. PMWiki could be an excellent piece of software, but PM has to exert a lot more authority. There are basic things people want, and they all have to work, and they have to work well together. A blog, a forum, a commentbox, etc. These are CORE EXTENSIONS. These need to be crisp, well-maintained and versioned, and singular - I am saying ONE endorsed extension for all the major components that people want in a website. There is a place for the arena-style development that is currently throttling the Cookbook. It is excellent to have lots of developers putting new stuff out there and improving (sometimes de-proving) on each other's work. But let me say it again my point is that there are about eight blog recipes and none of them are polished. This is basic functionality and PMWiki has still not got it figured out. Until PMWiki has this, it is going to remain a stew of code that is best used as a jumping off point for PHP developers to create their own wiki, because anything a basic user tries to do will be forever bugged. Personally? I'm going off to search for a program that has some idea of what it wants to be.

 - Disenchanted user Obi
Edit - History - Print - Recent Changes - Search
Page last modified on September 27, 2008, at 11:45 AM