]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiForm.php
Tuning/fixing of POST action URLs and hidden inputs.
[SourceForge/phpwiki.git] / lib / plugin / WikiForm.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiForm.php,v 1.9 2003-02-26 01:56:52 dairiki Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $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 is a replacement for MagicPhpWikiURL forms.
25  *
26  *
27  */
28 class WikiPlugin_WikiForm
29 extends WikiPlugin
30 {
31     function getName () {
32         return _("WikiForm");
33     }
34
35     function getVersion() {
36         return preg_replace("/[Revision: $]/", '',
37                             "\$Revision: 1.9 $");
38     }
39
40     function getDefaultArguments() {
41         return array('action' => 'upload', // 'upload', 'loadfile', or
42                                            // 'dumpserial'
43                      'default' => false,
44                      'buttontext' => false,
45                      'size' => 50);
46     }
47
48
49     function run($dbi, $argstr, &$request, $basepage) {
50         extract($this->getArgs($argstr, $request));
51         $form = HTML::form(array('action' => $request->getPostURL(),
52                                  'method' => 'post',
53                                  'class'  => 'wikiadmin',
54                                  'accept-charset' => CHARSET),
55                            HiddenInputs(array('action' => $action,
56                                               'pagename' => $basepage)));
57                 $input = array('type' => 'text',
58                        'value' => $default,
59                        'size' => $size);
60
61         switch ($action) {
62         case 'loadfile':
63             $input['name'] = 'source';
64             if (!$default)
65                 $input['value'] = '/tmp/wikidump';
66             if (!$buttontext)
67                 $buttontext = _("Load File");
68             $class = false;
69             break;
70         case 'login':
71             $input['name'] = 'source';
72             if (!$buttontext)
73                 $buttontext = _("Login");
74             $class = 'wikiadmin';
75             break;
76         case 'dumpserial':
77             $input['name'] = 'directory';
78             if (!$default)
79                 $input['value'] = '/tmp/wikidump';
80             if (!$buttontext)
81                 $buttontext = _("Dump Pages");
82             $class = 'wikiadmin';
83             break;
84         case 'dumphtml':
85             $input['name'] = 'directory';
86             if (!$default)
87                 $input['value'] = '/tmp/wikidumphtml';
88             if (!$buttontext)
89                 $buttontext = _("Dump Pages as XHTML");
90             $class = 'wikiadmin';
91             break;
92         case 'upload':
93             $form->setAttr('enctype', 'multipart/form-data');
94             $form->pushContent(HTML::input(array('name' => 'MAX_FILE_SIZE',
95                                                  'value' =>  MAX_UPLOAD_SIZE,
96                                                  'type'  => 'hidden')));
97             $input['name'] = 'file';
98             $input['type'] = 'file';
99             if (!$buttontext)
100                 $buttontext = _("Upload");
101             $class = false; // local OS function, so use native OS button
102             break;
103         default:
104             return HTML::p(fmt("WikiForm: %s: unknown action", $action));
105         }
106
107
108         $input = HTML::input($input);
109         $input->addTooltip($buttontext);
110         $button = Button('submit:', $buttontext, $class);
111
112         $form->pushContent(HTML::span(array('class' => $class),
113                                       $input, $button));
114
115         return $form;
116     }
117 };
118
119 // $Log: not supported by cvs2svn $
120 // Revision 1.8  2003/01/18 22:14:30  carstenklapp
121 // Code cleanup:
122 // Reformatting & tabs to spaces;
123 // Added copyleft, getVersion, getDescription, rcs_id.
124 //
125
126 // For emacs users
127 // Local Variables:
128 // mode: php
129 // tab-width: 8
130 // c-basic-offset: 4
131 // c-hanging-comment-ender-p: nil
132 // indent-tabs-mode: nil
133 // End:
134 ?>