DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:discussion

Discussion MediaWiki-Style

As I wanted to have a discussion-function such as Wikipedia provides, I mangled around with the source-code of lib/tpl/mytemplate/main.php, the file which usually is only about layouting your template.

It creates a link from yournamespace:pageX to discussion:yournamespace:pageX and backwards of course.

I tried hard to make the necessary changes to

  • conf/local.php: $conf['discuss']=1 - set 0 to disable discussion-feature
  • inc/common.php or inc/template.php (where?) to add function discuss
  • inc/lang/[en|de]/lang.php with the necessary 3 localization strings
  • inc/template.php to create actionlink and html_button for function discuss
  • lib/tpl/default/main.php to give an example place for button/link to discussion page

I failed. ;) What I got is a working function that I included directly to main.php. If you desperately waited for this feature, feel free to use it. If you think, this feature should be included to DokuWiki's next version, feel free to do so or if you aren't able (as I am not) at least leave a little comment to encourage others to do it.

See this feature at work: http://www.litwiki.de FIXME

So here comes the snippet directly out of my main.php, which bases on the g21-Media-DokuWiki-template and works with DW-release 2005-09-22:

discuss - directly @ main.php

	<div id="tabs">
		<?php tpl_actionlink('edit')?>		
		<?php tpl_actionlink('backlink')?>
 
<!-- Diskussion -->
 
<?php
 
/**
 * Discussion feature to DokuWiki
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Friederike Wenner <f [dot] wenner [at] gmx [dot] de>
 */
 
//  global $ID;
//  global $ACT;
 
  // @todo  adjust these strings for localization! Can later be placed in lang.php.
  $discussNS         = 'diskussion';
  $btn_discuss       = 'Diskussion';
  $btn_article       = 'Zurück zum Artikel';
 
 
  // check how $ID is separated
  if ($conf['useslash'] == '0') {
     $ns             = ':';
  }
  else {
     $ns             = '/';
}
 
  // prepare wikilink
  $wikipath          = wl(); 
 
  // check if we aren't already in discussionNS
  $idknack = explode($ns, $ID); 
  if (!($idknack[0] == $discussNS)) {
 
 	// determine the discussion file and link
	  $discussID       = $discussNS.$ns.$ID;
	  $discussLINK	  = "<a href='$wikipath$discussID' class='action discuss'>$btn_discuss</a>";
	  echo $discussLINK;
  }
  else {
	// determine the back-to-article link
    $articleID = substr($ID,strlen($discussNS)+1);
    $articleLINK = "<a href='$wikipath$articleID' class='action article'>$btn_article</a>";
	echo $articleLINK;
}
?>
 
<!-- Ende Diskussion -->
 
    </div>

Comments / Discussion

Feel free to gimme your opinion. — Freddy 2005-10-23 17:37

Alternative Way

I use a similar function in my ACH Template (the central approach is the same). The main difference is that I use more of the internal dokuwiki functions which results eg. in discussion links that show if a discussion page already exists or not (only if links are used and not - like in my template - if buttons are used). Another difference is: I haven't (yet) implemented anything with regard to the $conf['useslash'] option.

        $discussNS='discussion:';
        if(substr($ID,0,strlen($discussNS))==$discussNS) {
          $backID=substr(strstr($ID,':'),1);
          /*button: */print html_btn('back',$backID,'',array());
          /*link: tpl_pagelink(':'.$backID,$lang['btn_back']);*/
        } else {
          /*button: */print html_btn('discussion',$discussNS.$ID,'',array());
          /*link : tpl_pagelink($discussNS.$ID,$lang['btn_discussion']);*/
        }

The only thing that has to be added in ./inc/lang/en/lang.php and in the other languages respectively is

$lang['btn_discussion']   = 'Discussion';

IMHO, the best way to implement a discussion feature to a DokuWiki installation is to put things into main.php, because then it is easier to upgrade. If a discussion feature should be included into the DokuWiki core code, it should be done as you first intended to: with functions in inc/template.php and so on.

Anika Henke 2005-12-09 15:49


I've been playing with this alternative method and I have come up with a solution to the buttons not being able to show if the discussion page exists. I do a check for if the file exists, and if it doesn't the button text reads “Start a Discussion.” If the discussion page does exist, it says “Discuss this page.” I'm also toying around with having the wiki autogenerate the discussion pages with ====== Discussion of pagetitle ====== at the top followed by some comments (using one of the comment plugins) that ask users to scroll to the bottom of the edit window and put their discussion at the bottom of the page. What do you think?

I'll post more details when I get back to my computer at home.

carl [dot] thorpe [at] gmail [dot] com 2006-01-30 12:57 pm CDT


I was able to get buttons when using the first example by making this change in the last if-block:

  // check if we aren't already in discussionNS
  $idknack = explode($ns, $ID); 
  if (!($idknack[0] == $discussNS)) {
 
 	// determine the discussion file and link
	  $discussID       = $discussNS.$ns.$ID;
          print html_btn('disc',$ID,'',array('id' => "$discussID")) // Replace the two lines with this one
  }
  else {
	// determine the back-to-article link
    $articleID = substr($ID,strlen($discussNS)+1);
    print html_btn('article',$ID,'',array('id' => "$articleID")); // Replace the two lines with this one
}

Then you can add the languages part in inc/lang/en/lang.php

$lang['btn_disc']      = 'Discussion';
$lang['btn_article']   = 'Return to Article';

I might have gotten something wrong with the $ID part, but it seems to work fine in my wiki. You can see this in action in my wiki at http://www.inwetrust.org. - Chris Wellons (mosquitopsu – gmail com)


Here is another implementation. I wrote it myself, then improved upon it once I found this page. This one changes the background color when on the talk page and specifies hotkeys. It also processes the $ID carefully, so that multiple namespaces work properly (for example wiki:playground → talk:wiki:playground).

Modifications to lib/tpl/default/main.php:

Replace <body> with (current color is #bcd, change as desired):

<body<?php
       $sep = ($conf['useslash'] == '0') ? ':' : '/';
       $idparts = explode($sep, $ID);
       $pn = array_pop($idparts);
       $top_ns = array_shift($idparts);
       $is_talk = ($top_ns == 'talk');
       if ($top_ns != '') {
         $top_ns = $top_ns . $sep;
       }
       $ns = implode($sep, $idparts);
       if ($ns != '') {
         $ns = $ns . $sep;
       }
       if ($is_talk) {
         echo ' style = "background-color: #bcd;"';
       }
     ?>>

Find the word history, add this as a new line after it:

        <?php
           if ($is_talk) {
             $talkID = $ns . $pn;
             print html_btn('article', $talkID, 'a', array('do' => 'show'));
          } else {
            $talkID = 'talk' . $sep . $top_ns . $ns . $pn;
             print html_btn('talk', $talkID, 'c', array('do' => 'show'));
          }
        ?>

Find the word history again, add this as a new line after it:

        <?php
          if ($is_talk) {
            print html_btn('article', $talkID, 'a', array('do' => 'show'));
          } else {
            print html_btn('talk', $talkID, 'c', array('do' => 'show'));
          }
        ?>

Modifications to inc/lang/en/lang.php:

Add these lines:

$lang['btn_talk']   = 'Comments';
$lang['btn_article'] = 'Article';

See it at http://kidsquid.com/.

Jeffry Johnston 2006-02-20 05:55


I like this approach Jeffry. I adapted it to also show a message when someone edits a comments page, i.e. a page in the 'talk' namespace. It adds a notice that the page is for discussing the page itself, rather than the topic, if you see what I mean.

Here's what I did:

in inc/html.php, find

 if(!$DATE) $DATE = $INFO['lastmod'];
?>

And after it, add:

<?php
       $sep = ($conf['useslash'] == '0') ? ':' : '/';
       $idparts = explode($sep, $ID);
       $pn = array_pop($idparts);
       $top_ns = array_shift($idparts);
       $is_talk = ($top_ns == 'talk');
       if ($top_ns != '') {
         $top_ns = $top_ns . $sep;
       }
       $ns = implode($sep, $idparts);
       if ($ns != '') {
         $ns = $ns . $sep;
       }
?>
 
<?php
    if ($is_talk) {
   print '<p>N.B. This page is for discussing the <b>wiki page</b>, not the topic itself.</p>';
  }
?>

Ben Pollinger 2006-06-15

tips/discussion.txt · Last modified: 2017-09-25 13:43 by bactram

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki