2 rcs_id('$Id: AppendText.php,v 1.1 2004-11-24 09:25:35 rurban Exp $');
4 Copyright 2004 Pascal Giard (QC/EMC)
6 This file is not (yet) 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
25 * TODO: support for lbound and hbound.
27 class WikiPlugin_AppendText
31 return _("AppendText");
34 function getDescription() {
35 return _("Append text to any page in this wiki.");
38 function getVersion() {
39 return preg_replace("/[Revision: $]/", '',
43 function getDefaultArguments() {
44 return array('page' => '[pagename]',
45 'text' => '', // Text to append
46 'before' => '', // Add before (ignores after if defined)
47 'after' => '', // Add after line beginning with this
51 function run($dbi, $argstr, &$request, $basepage) {
53 $args = $this->getArgs($argstr, $request);
54 $pagename = $args['page'];
56 if (empty($args['text']))
57 if ($request->isPost() and $pagename != _("AppendText"))
58 return HTML($request->redirect(WikiURL($pagename, false, 'absurl'), false));
62 $page = $dbi->getPage($pagename);
65 if (!$page->exists()) { // create it?
66 $message->pushContent(sprintf(_("Page could not be updated. %s doesn't exist!\n",
71 $current = $page->getCurrentRevision();
72 $oldtext = $current->getPackedContent();
73 $text = $args['text'];
75 if (!empty($args['before'])) {
76 $before = preg_quote($args['before']);
77 if (preg_match("/\n${before}/", $oldtext)) {
78 $newtext = preg_replace("/(\n${before})/",
82 $message->pushContent(sprintf(_("%s not found. Appending at the end.\n",
84 $newtext = $oldtext . "\n" . $text;
86 } elseif (!empty($args['after'])) {
87 $after = preg_quote($args['after']);
88 if (preg_match("/\n${after}/", $oldtext)) {
89 $newtext = preg_replace("/(\n${after})/",
93 $message->pushContent(sprintf(_("%s not found. Appending at the end.\n",
95 $newtext = $oldtext . "\n" . $text;
102 require_once("lib/loadsave.php");
103 $meta = $current->_data;
104 $meta['summary'] = sprintf(_("AppendText to %s"), $pagename);
105 if ($page->save($newtext, $current->getVersion() + 1, $meta)) {
106 $message->pushContent(_("Page successfully updated."), HTML::br());
107 $message->pushContent(_("Go to "));
108 $message->pushContent(HTML::em(WikiLink($pagename)));
115 // $Log: not supported by cvs2svn $
116 // Revision 1.0 2004/11/23 09:43:35 epasgia
117 // * Initial version.
124 // c-hanging-comment-ender-p: nil
125 // indent-tabs-mode: nil