2 rcs_id('$Id: CreatePage.php,v 1.5 2004-07-08 20:30:07 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
28 * Put it <?plugin-form CreatePage ?> at some page, browse this page,
29 * enter the name of the page to create, then click the button.
31 * Usage: <?plugin-form CreatePage ?>
32 * @author: Dan Frankowski
34 class WikiPlugin_CreatePage
38 return _("CreatePage");
41 function getDescription() {
42 return _("Create a Wiki page by the provided name.");
45 function getVersion() {
46 return preg_replace("/[Revision: $]/", '',
50 function getDefaultArguments() {
51 return array('s' => false,
52 'initial_content' => false,
58 function run($dbi, $argstr, &$request, $basepage) {
59 extract($this->getArgs($argstr, $request));
63 // Prevent spaces at the start and end of a page name
66 $param = array('action' => 'edit');
67 if ($template and $dbi->isWikiPage($template)) {
68 $param['template'] = $template;
69 } elseif ($initial_content) {
70 // Warning! Potential URI overflow here on the GET redirect. Better use template.
71 $param['initial_content'] = $initial_content;
73 // If the initial_content is too large, pre-save the content in the page
74 // and redirect without that argument.
76 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.1
77 $url = WikiURL($s, $param, 'absurl');
78 if (strlen($url) > 255) {
79 unset($param['initial_content']);
80 $url = WikiURL($s, $param, 'absurl');
81 $page = $dbi->getPage($s);
82 $current = $page->getCurrentRevision();
83 if ($current->getVersion()) {
84 return $this->error(fmt("%s already exists",$s));
86 $user = $request->getUser();
87 $meta = array('markup' => 2.0,
88 'author' => $user->getId());
89 if ($param['template'] and !$initial_content) {
90 $tmplpage = $dbi->getPage($template);
91 $currenttmpl = $tmplpage->getCurrentRevision();
92 $initial_content = $currenttmpl->getPackedContent();
93 $meta['markup'] = $currenttmpl->_data['markup'];
95 $meta['summary'] = _("Created by CreatePage");
96 $page->save($initial_content, 1, $meta);
99 return HTML($request->redirect($url, true));
103 // $Log: not supported by cvs2svn $
104 // Revision 1.4 2004/04/21 16:14:50 zorloc
105 // Prevent spaces at the start and end of a created page name -- submitted by Dan Frankowski (dfrankow).
107 // Revision 1.3 2004/03/24 19:41:04 rurban
110 // Revision 1.2 2004/03/17 15:37:41 rurban
111 // properly support initial_content and template with URI length overflow workaround
113 // Revision 1.3 2004/03/16 16:25:05 dfrankow
114 // Support initial_content parameter
116 // Revision 1.2 2004/03/09 16:28:45 dfrankow
117 // Merge the RATING branch onto the main line
119 // Revision 1.1 2004/03/08 18:57:59 rurban
120 // Allow WikiForm overrides, such as method => POST, targetpage => [pagename]
121 // in the plugin definition.
122 // New simple CreatePage plugin by dfrankow.
124 // Revision 1.1.2.2 2004/02/23 21:22:29 dfrankow
127 // Revision 1.1.2.1 2004/02/21 15:29:19 dfrankow
128 // Allow a CreatePage edit box, as GUI syntactic sugar
130 // Revision 1.1.1.1 2004/01/29 14:30:28 dfrankow
131 // Right out of the 1.3.7 package
138 // c-hanging-comment-ender-p: nil
139 // indent-tabs-mode: nil