]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiForm.php
New FSF address
[SourceForge/phpwiki.git] / lib / plugin / WikiForm.php
1 <?php // -*-php-*-
2 // $Id$
3 /**
4  * Copyright 1999, 2000, 2001, 2002, 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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /**
24  * This is a replacement for MagicPhpWikiURL forms.
25  * Just a few old actions are supported, which where previously
26  * encoded with the phpwiki: syntax.
27  *
28  * See WikiFormMore for the more generic version.
29  */
30 class WikiPlugin_WikiForm
31 extends WikiPlugin
32 {
33     function getName () {
34         return _("WikiForm");
35     }
36
37     function getDescription () {
38         return _("Provide generic WikiForm input buttons");
39     }
40
41     function getDefaultArguments() {
42         return array('action' => 'upload', // 'upload', 'loadfile', or
43                                            // 'dumpserial'
44                      'default' => false,
45                      'buttontext' => false,
46                      'overwrite' => false,
47                      'size' => 50);
48     }
49
50     function run($dbi, $argstr, &$request, $basepage) {
51         extract($this->getArgs($argstr, $request));
52         $form = HTML::form(array('action' => $request->getPostURL(),
53                                  'method' => 'post',
54                                  'class'  => 'wikiadmin',
55                                  'accept-charset' => $GLOBALS['charset']),
56                            HiddenInputs(array('action' => $action,
57                                               'pagename' => $basepage)));
58         $input = array('type' => 'text',
59                        'value' => $default,
60                        'size' => $size);
61
62         switch ($action) {
63         case 'loadfile':
64             $input['name'] = 'source';
65             if (!$default)
66                 $input['value'] = DEFAULT_DUMP_DIR;
67             if (!$buttontext)
68                 $buttontext = _("Load File");
69             $class = false;
70             break;
71         case 'login':
72             $input['name'] = 'source';
73             if (!$buttontext)
74                 $buttontext = _("Login");
75             $class = 'wikiadmin';
76             break;
77         case 'dumpserial':
78             $input['name'] = 'directory';
79             if (!$default)
80                 $input['value'] = DEFAULT_DUMP_DIR;
81             if (!$buttontext)
82                 $buttontext = _("Dump Pages");
83             $class = 'wikiadmin';
84             break;
85         case 'dumphtml':
86             $input['name'] = 'directory';
87             if (!$default)
88                 $input['value'] = HTML_DUMP_DIR;
89             if (!$buttontext)
90                 $buttontext = _("Dump Pages as XHTML");
91             $class = 'wikiadmin';
92             break;
93         case 'upload':
94             $form->setAttr('enctype', 'multipart/form-data');
95             $form->pushContent(HTML::input(array('name' => 'MAX_FILE_SIZE',
96                                                  'value' =>  MAX_UPLOAD_SIZE,
97                                                  'type'  => 'hidden')));
98             $input['name'] = 'file';
99             $input['type'] = 'file';
100             if (!$buttontext)
101                 $buttontext = _("Upload");
102             $class = false; // local OS function, so use native OS button
103             break;
104         default:
105             return HTML::p(fmt("WikiForm: %s: unknown action", $action));
106         }
107
108
109         $input = HTML::input($input);
110         $input->addTooltip($buttontext);
111         $button = Button('submit:', $buttontext, $class);
112         if ($request->getArg('start_debug'))
113             $form->pushContent(HTML::input(array('name' => 'start_debug',
114                                                  'value' =>  $request->getArg('start_debug'),
115                                                  'type'  => 'hidden')));
116         $form->pushContent(HTML::span(array('class' => $class),
117                                       $input, $button));
118
119         return $form;
120     }
121 };
122
123 // Local Variables:
124 // mode: php
125 // tab-width: 8
126 // c-basic-offset: 4
127 // c-hanging-comment-ender-p: nil
128 // indent-tabs-mode: nil
129 // End:
130 ?>