<?php
/** \disctab.php
* \wikipedialike discussion tab for pmwiki
*
* see also http://www.pmwiki.org/wiki/Cookbook/DiscussionTab
* Provide a tabbed skin with the possibility to have an "discussion"-tab 
* and an "article"-tab as a kind of backlink to the Main Article.
*This one works for me but it's not well coded I think. I am not a programmer
* and I haven't the time to improve my small php knowledge to get it work better.
* Maybe someone find it usefull. If there is some help to improve this ifeel free to publish it.
* -----------------------------------------------------------------------------------------------
*/



/** This provides the action=discuss
*   the regexp was necessary because $Name didn't work for me in the function I wonder why ?? 
*/
SDV($HandleActions['discuss'], 'HandleDiscuss');
function HandleDiscuss($pagename) {
$string = $pagename;
$patterns = '/\./';
$replacements= '-Discuss-';
$disc = preg_replace($patterns, $replacements, $string);
redirect('Comments.'.$disc);
}
/* the next gives you a backlink variable/markup
* it is a modification of the comentpagelink recipe 
* http://pmwiki.org/wiki/Cookbook/CommentPageLink
*/
$string = $pagename;
$patterns[0] = '/Comments./';
$patterns[1] = '/-Discuss-/';
$replacements[0] = '';
$replacements[1] = '.';
$BaseName = preg_replace($patterns, $replacements, $string);
Markup('{$BaseName}', '>{$fmt}',
            '/{\\$BaseName}/',
preg_replace('/-Discuss-/', '.', FmtPageName('$Name', $pagename),     1));


?>