From: Reini U. <ru...@us...> - 2004-03-12 17:52:31
|
Update of /cvsroot/phpwiki/phpwiki/lib/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4955/lib/plugin Modified Files: WikiBlog.php Added Files: AddComment.php Log Message: new base class PageType_attach as base class for WikiBlog, Comment, and WikiForum. new plugin AddComment, which is a WikiBlog with different pagetype and template, based on WikiBlog. WikiForum comes later. --- NEW FILE: AddComment.php --- <?php // -*-php-*- rcs_id('$Id: AddComment.php,v 1.1 2004/03/12 17:32:41 rurban Exp $'); /* Copyright 2004 $ThePhpWikiProgrammingTeam This file is part of PhpWiki. PhpWiki is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. PhpWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with PhpWiki; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * This plugin allows user comments attached to a page, similar to WikiBlog. * based on WikiBlog, no summary. * * TODO: * For admin user, put checkboxes beside comments to allow for bulk removal. * * @author: ReiniUrban */ include_once("lib/plugin/WikiBlog.php"); class WikiPlugin_AddComment extends WikiPlugin_WikiBlog { function getName () { return _("AddComment"); } function getDescription () { return sprintf(_("Show and add comments for %s"),'[pagename]'); } function getVersion() { return preg_replace("/[Revision: $]/", '', "\$Revision: 1.1 $"); } // Arguments: // // page - page where the comment is attached at (default current page) // // order - 'normal' - place in chronological order // - 'reverse' - place in reverse chronological order // // mode - 'show' - only show old comments // 'add' - only show entry box for new comment // 'show,add' - show old comments then entry box // 'add,show' - show entry box followed by list of comments // jshide - boolean - quick javascript expansion of the addcomment box function getDefaultArguments() { return array('page' => '[pagename]', 'order' => 'normal', 'mode' => 'add,show', 'jshide' => '1', 'noheader' => false ); } function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (!$args['page']) return $this->error("No page specified"); // Get our form args. $comment = $request->getArg("comment"); $request->setArg('comment', false); if ($request->isPost() and !empty($comment['addcomment'])) { $this->add($request, $comment, 'comment'); // noreturn } // Now we display previous comments and/or provide entry box // for new comments $html = HTML(); foreach (explode(',', $args['mode']) as $show) { if (!empty($seen[$show])) continue; $seen[$show] = 1; switch ($show) { case 'show': $html->pushContent($this->showAll($request, $args, 'comment')); break; case 'add': $html->pushContent($this->showForm($request, $args, 'addcomment')); break; default: return $this->error(sprintf("Bad mode ('%s')", $show)); } } return $html; } }; // $Log: AddComment.php,v $ // Revision 1.1 2004/03/12 17:32:41 rurban // new base class PageType_attach as base class for WikiBlog, Comment, and WikiForum. // new plugin AddComment, which is a WikiBlog with different pagetype and template, // based on WikiBlog. WikiForum comes later. // // // For emacs users // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?> Index: WikiBlog.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/plugin/WikiBlog.php,v retrieving revision 1.9 retrieving revision 1.10 diff -u -2 -b -p -d -r1.9 -r1.10 --- WikiBlog.php 27 Feb 2004 02:10:50 -0000 1.9 +++ WikiBlog.php 12 Mar 2004 17:32:41 -0000 1.10 @@ -29,4 +29,6 @@ require_once('lib/TextSearchQuery.php'); * This plugin shows 'blogs' (comments/news) associated with a * particular page and provides an input form for adding a new blog. + * It is also the base class for all attachable pagetypes: + * wikiblog, comment and wikiforum * * HINTS/COMMENTS: @@ -124,5 +126,5 @@ extends WikiPlugin if ($request->isPost() and !empty($blog['addblog'])) { - $this->addBlog($request, $blog); // noreturn + $this->add($request, $blog); // noreturn } @@ -137,8 +139,8 @@ extends WikiPlugin switch ($show) { case 'show': - $html->pushContent($this->showBlogs($request, $args)); + $html->pushContent($this->showAll($request, $args)); break; case 'add': - $html->pushContent($this->showBlogForm($request, $args)); + $html->pushContent($this->showForm($request, $args)); break; default: @@ -149,8 +151,7 @@ extends WikiPlugin } - - function addBlog (&$request, $blog) { + function add (&$request, $blog, $type='wikiblog') { if (!($parent = $blog['page'])) - $request->finish("No page specified for blog."); + $request->finish(fmt("No page specified for %s",$type)); $user = $request->getUser(); @@ -160,4 +161,5 @@ extends WikiPlugin /* * Page^H^H^H^H Blog meta-data + * This method is reused for all attachable pagetypes: wikiblog, comment and wikiforum * * This is info that won't change for each revision. @@ -183,7 +185,9 @@ extends WikiPlugin 'summary' => $summary ? $summary : _("New comment."), 'mtime' => $now, - 'pagetype' => 'wikiblog', + 'pagetype' => $type, 'wikiblog' => $blog_meta, ); + if ($type == 'comment') + unset($version_meta['summary']); // Comment body. @@ -193,15 +197,17 @@ extends WikiPlugin while (!$saved) { // Generate the page name. For now, we use the format: - // Rootname/Blog-YYYYMMDDHHMMSS + // Rootname/Blog/2003-01-11/24:03:02 // This gives us natural chronological order when sorted // alphabetically. - // a unique name is found. - - // change to ISO formatted time? 2003-01-11T24:03:02 - // Yes, I think that's a good idea. -- JeffDairiki. - //$time = strftime ('%Y%m%d%H%M%S', $now); $time = Iso8601DateTime(); - $p = $dbi->getPage($parent . SUBPAGE_SEPARATOR . "Blog" . SUBPAGE_SEPARATOR . str_replace("T", SUBPAGE_SEPARATOR, "$time")); + if ($type == 'wikiblog') + $pagename = "Blog"; + elseif ($type == 'comment') + $pagename = "Comment"; + elseif ($type == 'wikiforum') + $pagename = "Topic"; + + $p = $dbi->getPage($parent . SUBPAGE_SEPARATOR . $pagename . SUBPAGE_SEPARATOR . str_replace("T", SUBPAGE_SEPARATOR, "$time")); $pr = $p->getCurrentRevision(); @@ -213,5 +219,4 @@ extends WikiPlugin } - // FIXME: there's a slight, but currently unimportant // race condition here. If someone else happens to @@ -237,5 +242,5 @@ extends WikiPlugin } - function showBlogs (&$request, $args) { + function showAll (&$request, $args, $type="wikiblog") { // FIXME: currently blogSearch uses WikiDB->titleSearch to // get results, so results are in alphabetical order. @@ -256,14 +261,13 @@ extends WikiPlugin if (!$args['noheader']) - $html->pushContent(HTML::h2(array('class' => 'wikiblog-heading'), + $html->pushContent(HTML::h4(array('class' => "$type-heading"), fmt("Comments on %s:", WikiLink($parent)))); foreach ($blogs as $rev) { - if (!$rev->get('wikiblog')) { + if (!$rev->get($type)) { // Ack! this is an old-style blog with data ctime in page meta-data. - $content = $this->_transformOldFormatBlog($rev); + $content = $this->_transformOldFormatBlog($rev,$type); } else - $content = $rev->getTransformedContent('wikiblog'); - + $content = $rev->getTransformedContent($type); $html->pushContent($content); } @@ -273,12 +277,12 @@ extends WikiPlugin } - function _transformOldFormatBlog($rev) { + function _transformOldFormatBlog($rev,$type='wikiblog') { $page = $rev->getPage(); foreach (array('ctime', 'creator', 'creator_id') as $key) - $blog_meta[$key] = $page->get($key); + $metadata[$key] = $page->get($key); $meta = $rev->getMetaData(); - $meta['wikiblog'] = $blog_meta; - return new TransformedText($page, $rev->getPackedContent(), $meta, 'wikiblog'); + $meta[$type] = $metadata; + return new TransformedText($page, $rev->getPackedContent(), $meta, $type); } @@ -313,7 +317,7 @@ extends WikiPlugin } - function showBlogForm (&$request, $args) { + function showForm (&$request, $args, $template='blogform') { // Show blog-entry form. - return new Template('blogform', $request, + return new Template($template, $request, array('PAGENAME' => $args['page'])); } @@ -321,4 +325,9 @@ extends WikiPlugin // $Log$ +// Revision 1.10 2004/03/12 17:32:41 rurban +// new base class PageType_attach as base class for WikiBlog, Comment, and WikiForum. +// new plugin AddComment, which is a WikiBlog with different pagetype and template, +// based on WikiBlog. WikiForum comes later. +// // Revision 1.9 2004/02/27 02:10:50 rurban // Patch #891133 by pablom517 |