4 * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * This plugin allows user comments attached to a page, similar to WikiBlog.
25 * Based on WikiBlog, no summary.
28 * For admin user, put checkboxes beside comments to allow for bulk removal.
33 include_once 'lib/plugin/WikiBlog.php';
35 class WikiPlugin_AddComment
36 extends WikiPlugin_WikiBlog
38 function getDescription()
40 return sprintf(_("Show and add comments for %s."), '[pagename]');
45 // page - page where the comment is attached at (default current page)
47 // order - 'normal' - place in chronological order
48 // - 'reverse' - place in reverse chronological order
50 // mode - 'show' - only show old comments
51 // 'add' - only show entry box for new comment
52 // 'show,add' - show old comments, then entry box
53 // 'add,show' - show entry box followed by list of comments
54 // jshide - boolean - quick javascript expansion of the comments
57 function getDefaultArguments()
59 return array('pagename' => '[pagename]',
64 //'sortby' => '-pagename' // oldest first. reverse by order=reverse
68 function run($dbi, $argstr, &$request, $basepage)
70 $args = $this->getArgs($argstr, $request);
71 if (!$args['pagename']) {
72 return $this->error(sprintf(_("A required argument ā%sā is missing."), 'pagename'));
76 $comment = $request->getArg("comment");
77 $request->setArg('comment', false);
79 if ($request->isPost() and !empty($comment['addcomment'])) {
80 $this->add($request, $comment, 'comment'); // noreturn
83 // Now we display previous comments and/or provide entry box
86 if ($args['jshide']) {
87 $div = HTML::div(array('id' => 'comments', 'style' => 'display:none;'));
88 //$list->setAttr('style','display:none;');
89 $div->pushContent(Javascript("
90 function togglecomments(a) {
91 comments=document.getElementById('comments');
92 if (comments.style.display=='none') {
93 comments.style.display='block';
94 a.title='" . _("Click to hide the comments") . "';
96 comments.style.display='none';
97 a.title='" . _("Click to display all comments") . "';
100 $html->pushContent(HTML::h4(HTML::a(array('name' => 'comment-header',
101 'class' => 'wikiaction',
102 'title' => _("Click to display"),
103 'onclick' => "togglecomments(this)"),
106 $div = HTML::div(array('id' => 'comments'));
108 foreach (explode(',', $args['mode']) as $show) {
109 if (!empty($seen[$show]))
114 $show = $this->showAll($request, $args, 'comment');
115 //if ($args['jshide']) $show->setAttr('style','display:none;');
116 $div->pushContent($show);
120 if (!$WikiTheme->DUMP_MODE) {
121 $add = $this->showForm($request, $args, 'addcomment');
122 //if ($args['jshide']) $add->setAttr('style','display:none;');
123 $div->pushContent($add);
127 return $this->error(sprintf("Bad mode (ā%sā)", $show));
130 $html->pushContent($div);
140 // c-hanging-comment-ender-p: nil
141 // indent-tabs-mode: nil