2 rcs_id('$Id: WikiBlog.php,v 1.4 2003-01-11 22:23:00 carstenklapp Exp $');
4 * Author: MichaelVanDam
7 require_once('lib/TextSearchQuery.php');
8 //require_once('lib/plugin/IncludePage.php');
11 * This plugin shows 'blogs' (comments/news) associated with a
12 * particular page and provides an input form for adding a new blog.
16 * It also works as an action-page if you create a page called 'WikiBlog'
17 * containing this plugin. This allows adding comments to any page
18 * by linking "PageName?action=WikiBlog". Maybe a nice feature in
19 * lib/displaypage.php would be to automatically check if there are
20 * blogs for the given page, then provide a link to them somewhere on
21 * the page. Or maybe this just creates a huge mess...
23 * Maybe it would be a good idea to ENABLE blogging of only certain
24 * pages by setting metadata or something...? If a page is non-bloggable
25 * the plugin is ignored (perhaps with a warning message).
27 * Should blogs be by default filtered out of RecentChanges et al???
29 * Think of better name for this module: Blog? WikiLog? WebLog? WikiDot?
31 * Have other 'styles' for the plugin?... e.g. 'quiet'. Display only
32 * 'This page has 23 associated comments. Click here to view / add.'
34 * For admin user, put checkboxes beside comments to allow for bulk removal.
36 * Permissions for who can add blogs? Display entry box only if
37 * user meets these requirements...?
39 * Code cleanup: break into functions, use templates (or at least remove CSS)
44 class WikiPlugin_WikiBlog
51 function getDescription () {
52 return sprintf(_("Show and add blogs for %s"),'[pagename]');
55 function getVersion() {
56 return preg_replace("/[Revision: $]/", '',
62 // page - page which is blogged to (default current page)
64 // order - 'normal' - place in chronological order
65 // - 'reverse' - place in reverse chronological order
67 // mode - 'show' - only show old blogs
68 // 'add' - only show entry box for new blog
69 // 'show,add' - show old blogs then entry box
70 // 'add,show' - show entry box followed by old blogs
74 // - arguments to allow selection of time range to display
75 // - arguments to display only XX blogs per page (can this 'paging'
76 // co-exist with the wiki?? difficult)
77 // - arguments to allow comments outside this range to be
78 // display as e.g. June 2002 archive, July 2002 archive, etc..
79 // - captions for 'show' and 'add' sections
82 function getDefaultArguments() {
83 return array('page' => '[pagename]',
91 function run($dbi, $argstr, $request) {
92 $this->_args = $this->getArgs($argstr, $request);
93 extract($this->_args);
98 // Look at arguments to see if blog was submitted. If so,
99 // process this before displaying anything.
101 if ($request->getArg('addblog')) {
103 // TODO: change args to blog[page], blog[summary], blog[body] etc
105 $blog_page = $request->getArg('blog[page]');
108 // Generate the page name. For now, we use the format:
109 // Rootname/Blog-YYYYMMDDHHMMSS
110 // This gives us natural chronological order when sorted
112 // This is inside a loop because there is a small
113 // chance that another user could add a blog with
114 // the same timestamp. If such a conflict is
115 // detected, increment timestamp by 1 second until
116 // a unique name is found.
120 $p = false; // will store our page
121 $time = false; // will store our timestamp
126 //change to ISO formatted time? 2003-01-11T24:03:02
127 $time = strftime ('%Y%m%d%H%M%S', $now);
129 //add a subpage between, to allow one to create a page containing only all the blogs of the parent page
130 // $p = $dbi->getPage($blog_page . SUBPAGE_SEPARATOR . _("Comments") . SUBPAGE_SEPARATOR . "Blog-$time");
131 $p = $dbi->getPage($blog_page . SUBPAGE_SEPARATOR . "Blog-$time");
133 $pr = $p->getCurrentRevision();
135 // Version should be zero. If not, page already exists
136 // so increment timestamp and try again.
138 if ($pr->getVersion() > 0) $now ++;
144 // Generate meta-data for page
145 // This is info that won't change for each revision:
146 // ctime (time of creation), creator, and creator_id.
147 // Create-date is really the relevant date for a blog,
148 // not the last-modified date.
150 // FIXME: For now all blogs are locked. It would be
151 // nice to allow only the 'creator' to edit by default.
153 $user = $request->getUser();
154 $user_id = $user->getId();
155 $user_auth_id = $user->getAuthenticatedId();
157 $p->set ('ctime', $now);
158 $p->set ('creator', $user_id);
159 $p->set ('creator_id', $user_auth_id);
160 $p->set ('locked', true); // lock by default
161 $p->set ('pagetype', 'wikiblog');
163 // Generate meta-data for page revision
165 $meta = array('author' => $user_id,
166 'author_id' => $user_auth_id,
167 'markup' => 2.0, // assume new markup
168 'summary' => _("New comment."),
171 // FIXME: For now the page format is:
176 // This helps during editing (using standard editor)
177 // when the page/revision metadata is not available
178 // to the user. If we had a pagetype-specific editor
179 // then we could put the Summary into meta-data and
180 // still make it available for editing.
181 // Also, it helps for now during rendering because we
182 // don't need to create a new PageType class just yet...
184 // FIXME: move summary into the page's summary field
185 // PageType now displays the summary field when viewing
186 // an individual blog page
187 $summary = trim($request->getArg('blog[summary]'));
188 $body = trim($request->getArg('blog[body]'));
191 $meta['summary'] = $summary;
193 $pr = $p->createRevision($pr->getVersion()+1,
196 ExtractWikiPageLinks($body));
198 // FIXME: Detect if !$pr ?? How to handle errors?
200 // Save was successful. Unset all the arguments and
201 // redirect to page that user was viewing before.
202 // Unsetting arguments will prevent double-submitting
203 // problem and will clear out the text-boxes.
205 $request->setArg('addblog', false);
206 $request->setArg('blog[page]', false);
207 $request->setArg('blog[body]', false);
208 $request->setArg('blog[summary]', false);
210 $url = $request->getURLtoSelf();
211 $request->redirect($url);
213 // FIXME: when submit a comment from preview mode,
214 // adds the comment properly but jumps to browse mode.
215 // Any way to jump back to preview mode???
218 // The rest of the output will not be seen due to
222 // Now we display previous comments and/or provide entry box
226 $showblogform = true;
231 $showblogform = false;
240 // TODO: implement ordering show,add vs add,show !
248 $html->pushContent($this->showBlogs ($dbi, $request, $page, $order));
252 $html->pushContent($this->showBlogForm ($dbi, $request, $page));
260 function showBlogs ($dbi, $request, $page, $order) {
264 // FIXME: currently blogSearch uses WikiDB->titleSearch to
265 // get results, so results are in alphabetical order.
266 // When PageTypes fully implemented, could have smarter
267 // blogSearch implementation / naming scheme.
269 $pages = $dbi->blogSearch($page, $order);
271 $all_comments = HTML();
273 while ($p = $pages->next()) {
276 // Verify that it is a blog page. If not, go to next page.
277 // When we proper blogSearch implementation this will not
278 // be necessary. Non-blog pages will not be returned by
281 $name = $p->getName();
282 // If page contains '/', we must escape them
283 // FIXME: only works for '/' SUBPAGE_SEPARATOR
284 $escpage = preg_replace ("/\//", '\/', $page);
285 if (!preg_match("/^$escpage\/Blog-([[:digit:]]{14})$/", $name, $matches))
290 // TODO: ultimately have a function in PageType to handle
291 // display of blog entries...
293 // If we want to use IncludePage plugin to display blog:
294 // $i = new WikiPlugin_IncludePage;
295 // $html->pushContent($i->run($dbi, "page=$name", $request));
297 global $WikiNameRegexp;
300 $ctime = $p->get('ctime');
301 $ctime = $Theme->formatDateTime($ctime);
303 $creator = $p->get('creator');
304 $creator_id = $p->get('creator_id');
305 $creator_orig = $creator;
307 if (preg_match("/^$WikiNameRegexp\$/", $creator)
308 && $dbi->isWikiPage($creator))
309 $creator = WikiLink($creator);
311 $pr = $p->getCurrentRevision();
313 $modified = ($pr->getVersion() > 1);
315 $mtime = $pr->get('mtime');
316 $mtime = $Theme->formatDateTime($mtime);
318 $author = $pr->get('author');
319 $author_id = $pr->get('author_id');
320 $author_orig = $author;
322 $summary = $pr->get('summary');
324 if (preg_match("/^$WikiNameRegexp\$/", $author)
325 && $dbi->isWikiPage($author))
326 $authorlink = WikiLink($author);
328 $browseaction = WikiURL($name);
329 $editaction = WikiURL($name, array('action' => 'edit'));
330 $removeaction = WikiURL($name, array('action' => 'remove'));
332 $browselink = HTML::a(array('href' => $browseaction,
333 'class'=>'wiki'), $ctime);
334 $editlink = HTML::a(array('href' => $editaction,
335 'class' => 'wikiaction'), 'Edit');
336 $removelink = HTML::a(array('href' => $removeaction,
337 'class'=>'wikiadmin'), 'Delete');
339 // FIXME if necessary:
340 $creator_id_string = (strcmp($creator_orig, $creator_id) == 0) ? '' : ' (' . $creator_id . ')';
342 // FIXME if necessary:
343 $author_id_string = (strcmp($author_orig, $author_id) == 0) ? '' : ' (' . $author_id . ')';
345 // FIXME: for now we just show all links on all entries.
346 // This should be customizable.
348 @$blognumber++; //hackish fixme
349 $args['SHOWHEADER'] = (! $this->_args['noheader'])
350 && ($blognumber == 1);
351 $args['SHOWBLOGFORM'] = false;
352 $args['SHOWBLOG'] = true;
354 $args['PAGELINK'] = WikiLink($page);
355 $args['PAGENAME'] = $page;
356 $args['AUTHOR'] = $author;
358 // FIXME: use $request's api to get user
359 $isadmin = $request->_user->isadmin();
360 $isauthor = $request->_user->getId() == $author;
362 $args['EDITLINK'] = ($isadmin) || ($isauthor) ? $editlink : "";
363 $args['REMOVELINK'] = ($isadmin) ? $removelink : "";
364 $args['AUTHORLINK'] = $authorlink;
365 $args['SUMMARY'] = $summary;
366 $args['CONTENT'] = TransformInline($pr->getPackedContent());
367 $args['DATELINK'] = $browselink;
369 $args['datemodified'] = $modified ? $mtime : '';
370 $args['authormodified'] = $pr->get('author');
371 $blogformtemplate = new Template('blog', $request, $args);
372 $all_comments->pushContent($blogformtemplate);
374 return $all_comments;
377 function showBlogForm ($dbi, $request, $page) {
378 // Show blog-entry form.
379 $args['PAGENAME'] = $page;
380 $args['SHOWHEADER'] = false;
381 $args['SHOWBLOGFORM'] = true;
382 $args['SHOWBLOG'] = false;
383 $blogformtemplate = new Template('blog', $request, $args);
384 return $blogformtemplate;
388 // $Log: not supported by cvs2svn $
389 // Revision 1.3 2003/01/06 02:29:02 carstenklapp
390 // New: use blog.tmpl template to format output. Some cosmetic
391 // issues, it mostly works but code still needs cleanup. Added
392 // getVersion() for PluginManager.
400 // c-hanging-comment-ender-p: nil
401 // indent-tabs-mode: nil