2 rcs_id('$Id: CreatePage.php,v 1.10 2007-01-25 07:42:16 rurban Exp $');
4 Copyright 2004,2007 $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 getting 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 <?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
36 include_once("lib/plugin/Template.php");
38 class WikiPlugin_CreatePage
39 extends WikiPlugin_Template
42 return _("CreatePage");
45 function getDescription() {
46 return _("Create a Wiki page by the provided name.");
49 function getVersion() {
50 return preg_replace("/[Revision: $]/", '',
51 "\$Revision: 1.10 $");
54 function getDefaultArguments() {
55 return array('s' => false,
56 'initial_content' => '',
60 //'buttontext' => false,
65 function run($dbi, $argstr, &$request, $basepage) {
66 extract($this->getArgs($argstr, $request));
69 // Prevent spaces at the start and end of a page name
72 $param = array('action' => 'edit');
73 if ($template and $dbi->isWikiPage($template)) {
74 $param['template'] = $template;
75 } elseif (!empty($initial_content)) {
76 // Warning! Potential URI overflow here on the GET redirect. Better use template.
77 $param['initial_content'] = $initial_content;
79 // If the initial_content is too large, pre-save the content in the page
80 // and redirect without that argument.
82 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.1
83 $url = WikiURL($s, $param, 'absurl');
84 // FIXME: expand vars in templates here.
85 if (strlen($url) > 255
86 or ($param['template'])
87 or preg_match('/%%\w+%%/', $initial_content)) // need variable expansion
89 unset($param['initial_content']);
90 $url = WikiURL($s, $param, 'absurl');
91 $page = $dbi->getPage($s);
92 $current = $page->getCurrentRevision();
93 $version = $current->getVersion();
94 if ($version and !$overwrite) {
95 return $this->error(fmt("%s already exists", WikiLink($s)));
97 $user = $request->getUser();
98 $meta = array('markup' => 2.0,
99 'author' => $user->getId());
100 if (!empty($param['template']) and !$initial_content) {
101 $tmplpage = $dbi->getPage($template);
102 $currenttmpl = $tmplpage->getCurrentRevision();
103 $initial_content = $currenttmpl->getPackedContent();
104 $meta['markup'] = $currenttmpl->_data['markup'];
106 if (preg_match('/<noinclude>.+<\/noinclude>/s', $initial_content)) {
107 $initial_content = preg_replace("/<noinclude>.+?<\/noinclude>/s", "",
111 $meta['summary'] = _("Created by CreatePage");
112 $content = $this->doVariableExpansion($initial_content, $vars, $s, $request);
114 if ($content !== $initial_content) {
115 // need to destroy the template so that editpage doesn't overwrite it.
116 unset($param['template']);
117 $url = WikiURL($s, $param, 'absurl');
120 $page->save($content, $version+1, $meta);
123 return HTML($request->redirect($url, true));
127 // $Log: not supported by cvs2svn $
128 // Revision 1.9 2007/01/04 16:42:23 rurban
129 // Expand even if no vars are given. They may be defaults, i.e %%pagename%%
131 // Revision 1.8 2007/01/03 21:23:32 rurban
132 // Derive from Template. Use same variable expansion. Support <noinclude> as in Template.
134 // Revision 1.7 2004/09/06 10:22:15 rurban
135 // oops, forgot global request
137 // Revision 1.6 2004/09/06 08:35:32 rurban
138 // support template variables (not yet working)
140 // Revision 1.5 2004/07/08 20:30:07 rurban
141 // plugin->run consistency: request as reference, added basepage.
142 // encountered strange bug in AllPages (and the test) which destroys ->_dbi
144 // Revision 1.4 2004/04/21 16:14:50 zorloc
145 // Prevent spaces at the start and end of a created page name -- submitted by Dan Frankowski (dfrankow).
147 // Revision 1.3 2004/03/24 19:41:04 rurban
150 // Revision 1.2 2004/03/17 15:37:41 rurban
151 // properly support initial_content and template with URI length overflow workaround
153 // Revision 1.3 2004/03/16 16:25:05 dfrankow
154 // Support initial_content parameter
156 // Revision 1.2 2004/03/09 16:28:45 dfrankow
157 // Merge the RATING branch onto the main line
159 // Revision 1.1 2004/03/08 18:57:59 rurban
160 // Allow WikiForm overrides, such as method => POST, targetpage => [pagename]
161 // in the plugin definition.
162 // New simple CreatePage plugin by dfrankow.
164 // Revision 1.1.2.2 2004/02/23 21:22:29 dfrankow
167 // Revision 1.1.2.1 2004/02/21 15:29:19 dfrankow
168 // Allow a CreatePage edit box, as GUI syntactic sugar
170 // Revision 1.1.1.1 2004/01/29 14:30:28 dfrankow
171 // Right out of the 1.3.7 package
178 // c-hanging-comment-ender-p: nil
179 // indent-tabs-mode: nil