Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

Comments

Summary: Comment addon - comments in separate files
Version: 14 April 2005
Prerequisites:
Status:
Maintainer: Ilya Zverev
Discussion: Comments-Talk

This is not a page to leave comments to all cookbooks!! It is the page for the recipe "Comments"!

This recipe may be obsolete: It uses the deprecated mailposts script, and the maintainer has not been available for assistance. It also had some serious drawbacks, even when it was current. You may do better to look at other recipes in the Comments category.


This is a backup from Google Cache 2007-02-10, because the history of this version of the page wasn't available.

Description

This module enables comment functionality on all pages in the wiki. It doesn't mess page content, because comments are stored in separate files. Users have ability to alter their comments right after posting. Wiki markup is supported. Installation

To install the software, unpack the zip file and copy its contents to your pmwiki directory.

Add the following line into your local/config.php file:

    include_once('cookbook/comments.php');

Then, to display comments you should call PmWiki with action=comments. For example you may add the following line in your pmwiki.tmpl template file, if you're using standard template:

<a href='$PageUrl?action=comments#comments'> $[Comment] (<!--function:DisplayCommentsCount -->) </a>

If you want comments always to be displayed in pages, Add the following line into your local/config.php file after including comments.php:

  PatchCommentBrowseFmt();

To be able to remove comments you also need to set the default password for this action:

    $DefaultPasswords['removecomment'] = crypt('yourpassword');

See also Passwords and PasswordsAdmin for information on using passwords in PmWiki. Usage

To display comments call pmwiki.php script with action=comments. Or simply open any page, if the comments are shown by default. Under the page text there will be a bunch of already written comments (if any) and the form to enter new comment. It looks like:

    Enter your comment:
    [                                             ]
    [                                             ]
    [                                             ]
    [                                             ]
    [                                             ]
    [                                             ]
    Author: [          ]  [Submit]

After entering comment text and author name (if not entered, it's substituted by author's ip address) and submitting the form buttons are replaced by those:

    Author: [          ]  [Update] [Delete] [Reset]

User can now edit his recently posted comment and submit changes by pressing Update button. If the text is completely deleted and posted, the recent comment is deleted. The same effect can be reached by pressing Delete. To add a completely new comment, Reset button should be pressed to clear all the hidden fields.

The behaviour seems a bit hard to understand, but it's useful and easy when one's got used to it. As for beginners, they could probably need some advice, and it should be written in the PmWiki.CommentsFooter page. For example, it may contain the following text:

The meaning of buttons:

    * Submit — submits a new comment;
    * Update — updates recently submitted comment's text;
    * Delete — removes last comment;
    * Reset — clears text and hidden fields allowing to enter a new comment. 

The one useful feature is that wiki markup is supported in the comment text. Configuration

In the script there are two functions that set default values for the styling variables. The first one, InitComments(), uses plain wiki markup to style comments. If you are not afraid of using CSS markup, you may leave a call to InitCommentsStyled() uncommented.

Variables

$CommentStartFmt

Defines comment list header.

$NoCommentsFmt

Defines text that is displayed when there's no comments for the page. By default it looks like $CommentStartFmt, but saying 'No comments'.

$CommentFmt

Defines how the comment is displayed. Has following variables that are substituted: $Author — author's name or ip; $Time — date and time of the comment (formatted with $TimeFmt); $Text — the comment itself.

$CommentEditFmt

Contains the comment edit form excepting buttons. Before changing this variable you must learn how it works by examining the default value.

$NewCommentButtonsFmt

Contains Submit button, which sends the new comment data.

$EditCommentButtonsFmt

Contains Update, Delete and Reset buttons used to alter posted comment.

$CommentsFooterFmt

By default displays PmWiki.CommentsFooter page under the edit form. Is referred in the $CommentEditFmt.

$RecentComments vList pages where notifications about recently added comments are stored, just as $RecentChanges array. By default contains Main.AllRecentComments and $Group.RecentComments. $CommentsFileName

The name of the function which takes page name as parameter and return the file name where page comments are stored. Default function returns "$WikiDir/$pagename.Comments".

Internationalization

Several strings in default values are made i18nable, and some of those strings interfere with the standard ones. I think this is not critical because the meaning is the same. The strings are:

    * Comments (in $CommentStartFmt)
    * No comments (in $NoCommentsFmt)
    * Enter your comment
    * Author
    * Submit
    * Update
    * Delete
    * Reset
    * Set new comment removing password: 

Storage

Comments are stored in $WikiDir along with wiki pages. The name of comments file for the page in constructed by adding .Comments extension to the page file name. For example, for Main.HomePage comments file will be named Main.HomePage.Comments. If you want to override this behaviour (for example, store comments in a separate directory), write your own comment-file-name-constructing function and specify its name in the $CommentsFileName variable.

Each comment occupies exactly one line in the file. The line has the following format:

    UID|IP|Author|Time|Text

The meaning of fields is:

  • UID — the unique id of the comment allowing its author to alter it right after posting. Probably it will allow changing all comments by the author in the future;
  • IP — the ip address of the comment author;
  • Author — the author's name;
  • Time — the unix-timestamp of the comment, is converted to normal time using $TimeFmt when the comment is displayed;
  • Text — the comment text itself. All newlines are replaced with the $Newline symbol. Note that $Newline is not stored along with comments, so it will be a disaster when you change it.

History

Apr 14, 2005

  • commentsmailed.php version added

Dec 8, 2004

  • Updated to work in PmWiki 2.0.beta6

Oct 29, 2004

  • Handling \r chars in input.
  • CommentsCount() function caused warnings.
  • Now allows authorized users to delete comments.
  • Added forgotten fclose() in HandlePostComment{}.

Sep 29, 2004

  • original version.

Revision: Commentsmailed.php

I decided to modify Ilya's original script so that I could receive e-mail notifications about comments through the MailPosts script. To use this, simply replace

    include_once('cookbook/comments.php');

in config.php with

    include_once('cookbook/commentsmailed.php');

Aside from integrating with MailPosts, the only other change I made was to prettify the links placed in the RecentComments pages, so that they show the name of the page, rather than the naked hyperlink. I still can't figure out how to place them in reverse chronological order; even though Ilya's code is identical to that used to create the RecentChanges pages, the order is reversed. Weird... - David A Spitzley

Author

I'm Ilya Zverev, you can mail to zverik at int.spb.ru if you are experiencing problems with this script. I'm also subscribed to Pmwiki-users list: use it if you think that the question (and the answer) may be interesting to others.

Script was updated for PmWiki 2.0.beta6 by Jeffrey Barke (jbarke@milwaukeedept.org).

Comments

See discussion at Comments-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on September 02, 2012, at 09:21 PM