CommentPageLink

Summary: How to create a comment page
Version:
Prerequisites: This recipe should work with any PmWiki version; last tested on PmWiki version:2.0b40
Status:
Maintainer:

Questions

Is there an easy way to create a "comment page", "discussion page", or "talk page"? Just what the heck is a "comment page" or "talk page"?

Answers

Suppose you have an edit-protected page called "Arizona" on your wiki. Users cannot leave comments on the page or discuss its contents. A "comment page", "discussion page", or "talk page" would provide a consistent place for such comments to appear. Some people suggest creating a new page called "Arizona_Talk" or "Arizona-comments" and placing a link on the Arizona page.

An even slicker solution is to place this link on the Arizona page:

[[{$Name}-comments | Comments]]

Or, if you wanted to have a comments group for all comments pages, you could use:

[[GroupName.{$Name}-comments | Click here to leave comments]]

Advanced students will recognize that this little markup snippet could be placed into a group header or footer, which would then create automatic links in each page in the group. In this scenario, you probably do want to put the comments in a different group - otherwise you will end up with pages called Arizona-comments-comments-comments.

Preventing "-comments" recursion

By including a bit of conditional markup, you can prevent comment links from appearing in pages that end with "-comments".

(:if ! match -comments$ :) [[{$Name}-comments | Comments]] (:if:)rest of the page

The first "if" says "if the page name does not end with "-comments" ", then generate the comments link. The second "if" just closes off the first one.

It has also been suggested that the markup snippet could be placed into the page template - but that may also lead to the recursion shown above.

Using a dedicated Comments group

If you don't like the idea of having pages called Main.Arizona and Main.Arizona-comments or if you just want to gather all comments into their own group, use this markup:

[[Comments.{$Group}-{$Name} | Comments]]

This creates a link that points to a page in the Comments group (use any name you like for the group) and automatically names the comments page with the group and page name of the source page. So in the example above, the comments link for Main.Arizona would point to Comments.Main-Arizona.

Backlinks

To create a backlink from a comments page in a dedicated comments group, put these lines in your config.php:

Markup('{$BaseName}', '>{$fmt}', '/{\\$BaseName}/', preg_replace('/-/', '.', FmtPageName('$Name', $pagename), 1));

This does not work for PmWiki 2.1beta15 and later. Use this instead:

$FmtPV['$BaseName'] = 'str_replace("-", ".", $name)';

Klonk

and then use [[{$BaseName}]] for a link back to the original page.

This will take the name of the comments page (e.g. Comments.Main-Arizona) and convert it into [[Main.Arizona]].

Or better yet just use this:
$BaseNamePatterns['/-Comments$/'] = '';
Then you can use {$BaseName} to refer to the part before the -Comments. (Your link would be [[{$BaseName}]] Peter Bowers

Automating the whole thing

Rather than placing copies of this markup on each page, you can put a single copy of the markup into a group header or group footer. For example, put the comments markup in Main.GroupHeader and every page in the Main group will display a link to a unique comments page. Put the backlinks markup in Comments.GroupHeader, and every Comments page will have an automatic backlink to its source page.

Or, you could put the markup into a wiki page menu (PageFootMenu, PageTopMenu, etc.) so that it automatically appears (with a skin like FixFlow?) on each page along with edit, history, etc.

Another very easy possibility to add a discussion tab to skin monospace is to adjust the PageAction setting.

  • Change the global definition of "Site" or your "Group":
    pmwiki.php?n=Site.PageActions?action=edit
    to:
* %item class=browse accesskey=$[ak_view]%[[{$FullName} | $[View] ]] 
* %item class=discuss accesskey=$[ak_edit]%[[[[Comments.{$Group}-{$Name}?action=view | $[Discussion] ]] 
* %item class=edit accesskey=$[ak_edit]%[[{$FullName}?action=edit | $[Edit] ]] 
(:if false:) 
* %item class=diff accesskey=$[ak_history]%[[{$FullName}?action=diff | $[History] ]] 
(:if:) 
(:if auth upload:) 
* %item class=upload accesskey=$[ak_attach]%[[{$FullName}?action=upload | $[Attach] ]] 
(:if:) 
* %item class=print accesskey=$[ak_print]%[[{$FullName}?action=print | $[Print] ]]
  • To avoid comments of comments replace the discussion tab with a backward tab for the group 'Comments'.
    pmwiki.php?n=Comments.PageActions?action=edit
    to:
* %item class=browse accesskey=$[ak_view]%[[{$FullName} | $[Discussion] ]] 
* %item class=back accesskey=$[ak_back]%[[@3@{$Name}@3@}?action=view | $[Document] ]] 
* %item class=edit accesskey=$[ak_edit]%[[{$FullName}?action=edit | $[Edit] ]] 
(:if false:) 
* %item class=diff accesskey=$[ak_history]%[[{$FullName}?action=diff | $[History] ]] 
(:if:) 
(:if auth upload:) 
* %item class=upload accesskey=$[ak_attach]%[[{$FullName}?action=upload | $[Attach] ]] 
(:if:) 
* %item class=print accesskey=$[ak_print]%[[{$FullName}?action=print | $[Print] ]]
  • Add the following line to control.php or config.php to perform the replacement for the backward link.
    Markup("@3@", "inline", "/@3@(.*?)@3@/e", 'str_replace("-",".","$1")');

That should work, C.Gruber (Tested with pmwiki-2.0.13).


Discussion page using SubgroupMarkup

I implemented a slightly different version using the [[,subpage]] notation of SubgroupMarkup. My PageActions contains

(:if match $[,Discuss$] :)
* %item class=discuss%[[[[{$BaseName}?action=view | $[Article] ]] 
(:elseif exists {$FullName},Discuss :)
* %item class=discuss%[[[[{$FullName},Discuss?action=view | $[Discuss] ]] 
(:else:)
* %item red class=discuss%[[[[{$FullName},Discuss?action=edit | $[Discuss] ]]<sup>?</sup>
(:ifend:)

Will show "Discuss" action (or Discuss? if the page hasn't been created yet) which points to the {$FullName},Discuss subpage. On the discussion page itself, the same action is now "Article" pointing to the parent page. Also need to add {$BaseName} in local/config.php

$FmtPV['$BaseName'] = 'substr($name,0,strrpos($name,","))';
Note: SubgroupMarkup isn't essential for this purpose. It enables the use of "," in the page name. Using "-" or "_" should still work without SubgroupMarkup.

Tested on pmwiki-2.2.0-beta42. ~moe April 25, 2007

Simple Discuss-link solution

Moved to its own recipe page: Cookbook:SimpleDiscussLink .

Notes and Comments

See Also

Cookbook.CommentBox - adds a comment box to a page
Cookbook.Comments - adds a global commenting capability to PmWiki

For an example in action see: https://hambone.ca/index.php/Archived-CSM2018/HomePage

Contributors

  • NeilHerber June 21, 2005, at 09:16 AM
  • JonHaupt - original suggestion on PmWiki-users
  • BenjaminWilson - template suggestion on PmWiki-users
  • Ian MacGregor - Testing and documentation

Comments

See discussion at CommentPageLink-Talk