2 rcs_id('$Id: CreatePage.php,v 1.6 2004-09-06 08:35:32 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 * This allows you to create a page geting the new pagename from a
25 * forms-based interface, and optionally with the initial content from
26 * some template, plus expansion of some variables via %variable% statements
29 * Put it <?plugin-form CreatePage ?> at some page, browse this page,
30 * enter the name of the page to create, then click the button.
32 * Usage: <?plugin-form CreatePage template=SomeTemplatePage vars="year=2004&name=None" ?>
33 * @authors: Dan Frankowski, Reini Urban
35 class WikiPlugin_CreatePage
39 return _("CreatePage");
42 function getDescription() {
43 return _("Create a Wiki page by the provided name.");
46 function getVersion() {
47 return preg_replace("/[Revision: $]/", '',
51 function getDefaultArguments() {
52 return array('s' => false,
53 'initial_content' => '',
57 //'buttontext' => false,
62 function run($dbi, $argstr, &$request, $basepage) {
63 extract($this->getArgs($argstr, $request));
66 // Prevent spaces at the start and end of a page name
69 $param = array('action' => 'edit');
70 if ($template and $dbi->isWikiPage($template)) {
71 $param['template'] = $template;
72 } elseif (!empty($initial_content)) {
73 // Warning! Potential URI overflow here on the GET redirect. Better use template.
74 $param['initial_content'] = $initial_content;
76 // If the initial_content is too large, pre-save the content in the page
77 // and redirect without that argument.
79 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.1
80 $url = WikiURL($s, $param, 'absurl');
81 if (strlen($url) > 255
82 or preg_match('/%\w+%/',$initial_content)) // need variable expansion
84 unset($param['initial_content']);
85 $url = WikiURL($s, $param, 'absurl');
86 $page = $dbi->getPage($s);
87 $current = $page->getCurrentRevision();
88 $version = $current->getVersion();
89 if ($version and !$overwrite) {
90 return $this->error(fmt("%s already exists", WikiLink($s)));
92 $user = $request->getUser();
93 $meta = array('markup' => 2.0,
94 'author' => $user->getId());
95 if ($param['template'] and !$initial_content) {
96 $tmplpage = $dbi->getPage($template);
97 $currenttmpl = $tmplpage->getCurrentRevision();
98 $initial_content = $currenttmpl->getPackedContent();
99 $meta['markup'] = $currenttmpl->_data['markup'];
101 $meta['summary'] = _("Created by CreatePage");
102 // expand variables in $initial_content
103 if (preg_match('/%\w+%/', $initial_content)) {
106 foreach (split("&",$vars) as $pair) {
107 list($key,$val) = split("=",$pair);
111 if (empty($var['pagename']))
112 $var['pagename'] = $s;
113 if (empty($var['ctime']) and preg_match('/%ctime%/', $initial_content))
114 $var['ctime'] = $GLOBALS['WikiTheme']->formatDateTime(time());
115 if (empty($var['author']) and preg_match('/%author%/', $initial_content))
116 $var['author'] = $user->getId();
118 foreach ($var as $key => $val) {
119 $initial_content = preg_replace("/%$key%/",$val,$initial_content);
121 // need to destroy the template so that editpage doesn't overwrite it.
122 unset($param['template']);
123 $url = WikiURL($s, $param, 'absurl');
125 $page->save($initial_content, $version+1, $meta);
128 return HTML($request->redirect($url, true));
132 // $Log: not supported by cvs2svn $
133 // Revision 1.5 2004/07/08 20:30:07 rurban
134 // plugin->run consistency: request as reference, added basepage.
135 // encountered strange bug in AllPages (and the test) which destroys ->_dbi
137 // Revision 1.4 2004/04/21 16:14:50 zorloc
138 // Prevent spaces at the start and end of a created page name -- submitted by Dan Frankowski (dfrankow).
140 // Revision 1.3 2004/03/24 19:41:04 rurban
143 // Revision 1.2 2004/03/17 15:37:41 rurban
144 // properly support initial_content and template with URI length overflow workaround
146 // Revision 1.3 2004/03/16 16:25:05 dfrankow
147 // Support initial_content parameter
149 // Revision 1.2 2004/03/09 16:28:45 dfrankow
150 // Merge the RATING branch onto the main line
152 // Revision 1.1 2004/03/08 18:57:59 rurban
153 // Allow WikiForm overrides, such as method => POST, targetpage => [pagename]
154 // in the plugin definition.
155 // New simple CreatePage plugin by dfrankow.
157 // Revision 1.1.2.2 2004/02/23 21:22:29 dfrankow
160 // Revision 1.1.2.1 2004/02/21 15:29:19 dfrankow
161 // Allow a CreatePage edit box, as GUI syntactic sugar
163 // Revision 1.1.1.1 2004/01/29 14:30:28 dfrankow
164 // Right out of the 1.3.7 package
171 // c-hanging-comment-ender-p: nil
172 // indent-tabs-mode: nil