2 rcs_id('$Id: AppendText.php,v 1.4 2004-11-25 17:20:52 rurban Exp $');
4 Copyright 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
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 * @Author: Pascal Giard <evilynux@gmail.com>
28 * See http://sourceforge.net/mailarchive/message.php?msg_id=10141823
29 * why not to use "text" as parameter. Nasty mozilla bug with mult. radio rows.
31 class WikiPlugin_AppendText
35 return _("AppendText");
38 function getDescription() {
39 return _("Append text to any page in this wiki.");
42 function getVersion() {
43 return preg_replace("/[Revision: $]/", '',
47 function getDefaultArguments() {
48 return array('page' => '[pagename]',
49 's' => '', // Text to append.
50 'before' => '', // Add before (ignores after if defined)
51 'after' => '', // Add after line beginning with this
55 function _fallback($addtext, $oldtext, $notfound, &$message) {
56 $message->pushContent(sprintf(_("%s not found. Appending at the end.\n"), $notfound));
57 return $oldtext . "\n" . $addtext;
60 function run($dbi, $argstr, &$request, $basepage) {
62 $args = $this->getArgs($argstr, $request);
63 $pagename = $args['page'];
65 if (empty($args['s'])) {
66 if ($request->isPost()) {
67 if ($pagename != _("AppendText"))
68 return HTML($request->redirect(WikiURL($pagename, false, 'absurl'), false));
73 $page = $dbi->getPage($pagename);
76 if (!$page->exists()) { // create it?
77 $message->pushContent(sprintf(_("Page could not be updated. %s doesn't exist!\n",
82 $current = $page->getCurrentRevision();
83 $oldtext = $current->getPackedContent();
86 // If a "before" or "after" is specified but not found, we simply append text to the end.
87 if (!empty($args['before'])) {
88 $before = preg_quote($args['before'], "/");
90 $newtext = preg_match("/\n${before}/", $oldtext)
91 ? preg_replace("/(\n${before})/",
92 "\n" . preg_quote($text, "/") . "\\1",
94 : $this->_fallback($text, $oldtext, $args['before'], &$message);
95 } elseif (!empty($args['after'])) {
97 $after = preg_quote($args['after'], "/");
98 $newtext = preg_match("/\n${after}/", $oldtext)
99 ? preg_replace("/(\n${after})/",
100 "\\1\n" . preg_quote($text, "/"),
102 : $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 // if ($basepage == pagename) $errmsg = _("AppendText");
114 $message->pushContent(_("Page successfully updated."), HTML::br());
115 $message->pushContent(_("Go to "));
116 $message->pushContent(HTML::em(WikiLink($pagename)));
123 // $Log: not supported by cvs2svn $
124 // Revision 1.3 2004/11/25 13:56:23 rurban
125 // renamed text to s because of nasty mozilla radio button bug
127 // Revision 1.2 2004/11/25 08:29:43 rurban
128 // update from Pascal
130 // Revision 1.2 2004/11/24 11:22:30 Pascal Giard <evilynux@gmail.com>
131 // * Integrated rurban's modifications.
133 // Revision 1.1 2004/11/24 09:25:35 rurban
134 // simple plugin by Pascal Giard (QC/EMC)
136 // Revision 1.0 2004/11/23 09:43:35 epasgia
137 // * Initial version.
144 // c-hanging-comment-ender-p: nil
145 // indent-tabs-mode: nil