]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/CreatePage.php
plugin->run consistency: request as reference, added basepage.
[SourceForge/phpwiki.git] / lib / plugin / CreatePage.php
1 <?php // -*-php-*-
2 rcs_id('$Id: CreatePage.php,v 1.5 2004-07-08 20:30:07 rurban Exp $');
3 /**
4  Copyright 2004 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
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.
12
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.
17
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
21  */
22
23 /**
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.
27  *
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.
30  *
31  * Usage: <?plugin-form CreatePage ?>
32  * @author: Dan Frankowski
33  */
34 class WikiPlugin_CreatePage
35 extends WikiPlugin
36 {
37     function getName() {
38         return _("CreatePage");
39     }
40
41     function getDescription() {
42         return _("Create a Wiki page by the provided name.");
43     }
44
45     function getVersion() {
46         return preg_replace("/[Revision: $]/", '',
47                             "\$Revision: 1.5 $");
48     }
49
50     function getDefaultArguments() {
51         return array('s'            => false,
52                      'initial_content' => false,
53                      'template'     => false,
54                      //'method'     => 'POST'
55                      );
56     }
57
58     function run($dbi, $argstr, &$request, $basepage) {
59         extract($this->getArgs($argstr, $request));
60         if (!$s)
61             return '';
62             
63         // Prevent spaces at the start and end of a page name
64         $s = trim($s);
65
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;
72         }
73         // If the initial_content is too large, pre-save the content in the page 
74         // and redirect without that argument.
75         // URI length limit:
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));
85             } else {
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'];
94                 }
95                 $meta['summary'] = _("Created by CreatePage");
96                 $page->save($initial_content, 1, $meta);
97             }
98         }
99         return HTML($request->redirect($url, true));
100     }
101 };
102
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).
106 //
107 // Revision 1.3  2004/03/24 19:41:04  rurban
108 // fixed the name
109 //
110 // Revision 1.2  2004/03/17 15:37:41  rurban
111 // properly support initial_content and template with URI length overflow workaround
112 //
113 // Revision 1.3  2004/03/16 16:25:05  dfrankow
114 // Support initial_content parameter
115 //
116 // Revision 1.2  2004/03/09 16:28:45  dfrankow
117 // Merge the RATING branch onto the main line
118 //
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.
123 //
124 // Revision 1.1.2.2  2004/02/23 21:22:29  dfrankow
125 // Add a little doc
126 //
127 // Revision 1.1.2.1  2004/02/21 15:29:19  dfrankow
128 // Allow a CreatePage edit box, as GUI syntactic sugar
129 //
130 // Revision 1.1.1.1  2004/01/29 14:30:28  dfrankow
131 // Right out of the 1.3.7 package
132 //
133
134 // Local Variables:
135 // mode: php
136 // tab-width: 8
137 // c-basic-offset: 4
138 // c-hanging-comment-ender-p: nil
139 // indent-tabs-mode: nil
140 // End:
141 ?>