Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

CommentsSplit

Summary: A simple way to have publically-editable comments section at the bottom of your pages
Version:
Prerequisites:
Status:
Maintainer:
Categories: Comments

Description

This is a simple way to have a publically-editable 'comments' section at the bottom of your pages

The goal is to split pages in two, with the bottom half publically-editable, like this

  +------------------------------------------+
  | the normal text of the page              |
  | (which might not be publically editable) |
  +------------------------------------------+
  | COMMENTS:                                |
  | and then a comments section              |
  | (which is publically editable)           |
  +------------------------------------------+

To achieve this, actually use two pages. The top half is as normal. The bottom half is in the Comments group. We'll adopt the following naming convention:

  Main/HomePage  ...  Comments/Main-HomePage
  Group/Name     ...  Comments/Group-Name

Each top half will (:include:) its respective comments-page.

You might, for instance, protect the top half so that only you can edit them. And leave the "Comments" half publically editable.

Instructions

1. Make the "Comments" group publically editable

  • Navigate to ...mywiki.../Comments/GroupAttributes?action=attr
  • Set the edit password to @nopass

2. Set up redirection

  • Add the following to local/config.php
  $pagename2 = preg_replace('/^Comments[\/\.](.*?)-(.*)$/','${1}/${2}',$pagename);
  if ($action=='browse' && $pagename != $pagename2)
  { Redirect($pagename2); exit;
  }

The idea is this: we don't really want anyone to be *looking* at the comments page on its own. We only want them to be looking at the main page, which includes its respective comments page.

PmWiki by default has several places which take the user direct to the comments page. The user will go there after editing comments, for instance. And when clicking on a link in an RSS feed or on Site.AllRecentChanges.

The redirection code here will trap all of these cases, and redirect all of them to the main page.

3. Include the comments

The top half of our pages will include the following text.

  ----
  [[Comments/{$Group}-{$Name}?action=edit|(edit)]]

  (:include Comments/{$Group}-{$Name}:)
  ----

The question is, where does that text go? There are three scenarios:

  1. You might want comments only for one of your pages only. In this case, just edit the page as normal and put that text at the bottom.
  2. You might want comments for every page in a group, for instance the Main group. So, navigate to Main/GroupFooter?action=edit and put in the text above. If you want the comments to be printed, you'll also have to navigate to Main/GroupPrintFooter?action=edit and put the text there as well.
  3. You might want comments for every page on your site. In this case, go to local/config.php and put in the following. It will apply to every group. (and for printing, also set $GroupPrintFooterFmt )
  $GroupFooterFmt =
    '(:nl:)(:include $Group.GroupFooter:)'.
    '(:nl:)---- [[Comments.{$Group}-{$Name}?action=edit|(edit)]](:nl:)'.
    '(:include Comments.{$Group}-{$Name}:) (:nl:)----';

Notes

As always, if you have publically editable pages, you have to be careful of vandalism and link-spam. Some users of PmWiki suggest that just having a publically-knowable password is helpful! In Step (2) I actually set the password to "comment", and in Step (3) I tell people what the password is:

  ----
  [[Comments/{$Group}-{$Name}?action=edit|(edit)]] [- (use the password "comments") -]

  (:include Comments/{$Group}-{$Name}:)
  ----

Also, make sure to read UrlApprovals.

Also, I personally use some powerful markup in my local/config.php which lets me embed arbitrary html code. Anyone would also be able to use the markup in the publically-editable contents area. This could be a security risk: they could include malicious javascript, for instance. Read the EnableHTML cookbook to see how $ROSPatterns can be used to allow only people with "admin" privilages to embed html.

Comments

Nicer View of Comments using History Simonx, 18. April 2008
I aimed to show Comments (for all pages) in a chronological order, marked with author, etc. (I use AuthForm to determine the Author) Using the History of the Comment.-Page instead of the Page itself, I solved this problem partially by changing the Footer you include in config.php to:

$GroupFooterFmt =
    '(:nl:)(:include $Group.GroupFooter:)'.
    '(:nl:)---- %target=_blank% [[Comments.{$Group}-{$Name}?action=edit|Write Comment...]](:nl:)'.
    '%target=_blank% [[Comments.{$Group}-{$Name}?action=diff|Read Comments...]] (:nl:)----';

The Problem: This only creates a LINK to the History of the Discussion - where we want an inclusion (split)! However, History is not a wiki-page and neither can one use http-inclusion (e.g. cascaded sidebar). Any Idea?

In case the actual wiki group name contains hyphens, like [[Blog-Trip-2008/2008-01-04]], the redirection will not work properly. --Petko January 06, 2008, at 12:18 PM

See Also

Cookbook:Comments

Contributors

Lucian Wischik. Based on ideas by Hans and PM.

Edit - History - Print - Recent Changes - Search
Page last modified on September 10, 2011, at 11:42 AM