2 rcs_id('$Id: AppendText.php,v 1.3 2004-11-25 13:56:23 rurban Exp $');
4 Copyright 2004 Pascal Giard <evilynux@gmail.com>
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
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Append text to an existing page.
26 * See http://sourceforge.net/mailarchive/forum.php?thread_id=6028698&forum_id=4517
27 * why not to use "text" as parameter. Nasty mozilla bug with mult. radio rows.
29 class WikiPlugin_AppendText
33 return _("AppendText");
36 function getDescription() {
37 return _("Append text to any page in this wiki.");
40 function getVersion() {
41 return preg_replace("/[Revision: $]/", '',
45 function getDefaultArguments() {
46 return array('page' => '[pagename]',
47 's' => '', // Text to append.
48 'before' => '', // Add before (ignores after if defined)
49 'after' => '', // Add after line beginning with this
53 function _fallback($addtext, $oldtext, $notfound, &$message) {
54 $message->pushContent(sprintf(_("%s not found. Appending at the end.\n"), $notfound));
55 return $oldtext . "\n" . $addtext;
58 function run($dbi, $argstr, &$request, $basepage) {
60 $args = $this->getArgs($argstr, $request);
61 $pagename = $args['page'];
63 if (empty($args['s']))
64 if ($request->isPost() and $pagename != _("AppendText"))
65 return HTML($request->redirect(WikiURL($pagename, false, 'absurl'), false));
69 $page = $dbi->getPage($pagename);
72 if (!$page->exists()) { // create it?
73 $message->pushContent(sprintf(_("Page could not be updated. %s doesn't exist!\n",
78 $current = $page->getCurrentRevision();
79 $oldtext = $current->getPackedContent();
82 // If a "before" or "after" is specified but not found, we simply append text to the end.
83 if (!empty($args['before'])) {
84 $before = preg_quote($args['before'], "/");
87 ( preg_match("/\n${before}/", $oldtext) ) ?
88 preg_replace("/(\n${before})/",
89 "\n" . preg_quote($text, "/") . "\\1",
91 $this->_fallback($text, $oldtext, $args['before'], &$message);
93 } elseif (!empty($args['after'])) {
95 $after = preg_quote($args['after'], "/");
97 ( preg_match("/\n${after}/", $oldtext) ) ?
98 preg_replace("/(\n${after})/",
99 "\\1\n" . preg_quote($text, "/"),
101 $this->_fallback($text, $oldtext, $args['after'], &$message);
105 $newtext = $oldtext .
109 require_once("lib/loadsave.php");
110 $meta = $current->_data;
111 $meta['summary'] = sprintf(_("AppendText to %s"), $pagename);
112 if ($page->save($newtext, $current->getVersion() + 1, $meta)) {
113 $message->pushContent(_("Page successfully updated."), HTML::br());
114 $message->pushContent(_("Go to "));
115 $message->pushContent(HTML::em(WikiLink($pagename)));
122 // $Log: not supported by cvs2svn $
123 // Revision 1.2 2004/11/25 08:29:43 rurban
124 // update from Pascal
126 // Revision 1.2 2004/11/24 11:22:30 Pascal Giard <evilynux@gmail.com>
127 // * Integrated rurban's modifications.
129 // Revision 1.1 2004/11/24 09:25:35 rurban
130 // simple plugin by Pascal Giard (QC/EMC)
132 // Revision 1.0 2004/11/23 09:43:35 epasgia
133 // * Initial version.
140 // c-hanging-comment-ender-p: nil
141 // indent-tabs-mode: nil