]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiForm.php
Add HTML 5 required
[SourceForge/phpwiki.git] / lib / plugin / WikiForm.php
1 <?php
2
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 class WikiPlugin_WikiForm
29     extends WikiPlugin
30 {
31     function getDescription()
32     {
33         return _("Provide generic WikiForm input buttons.");
34     }
35
36     function getDefaultArguments()
37     {
38         return array('action' => 'upload', // 'upload', 'loadfile',
39             // 'dumphtml' or 'dumpserial'
40             'default' => false,
41             'buttontext' => false,
42             'overwrite' => false,
43             'size' => 50);
44     }
45
46     /**
47      * @param WikiDB $dbi
48      * @param string $argstr
49      * @param WikiRequest $request
50      * @param string $basepage
51      * @return mixed
52      */
53     function run($dbi, $argstr, &$request, $basepage)
54     {
55         extract($this->getArgs($argstr, $request));
56         $form = HTML::form(array('action' => $request->getPostURL(),
57                 'method' => 'post',
58                 'class' => 'wikiadmin',
59                 'accept-charset' => 'UTF-8'),
60             HiddenInputs(array('action' => $action,
61                 'overwrite' => $overwrite,
62                 'pagename' => $basepage)));
63         $input = array('type' => 'text',
64             'value' => $default,
65             'size' => $size);
66
67         switch ($action) {
68             case 'loadfile':
69                 $input['name'] = 'source';
70                 $input['required'] = 'required';
71                 if (!$default)
72                     $input['value'] = DEFAULT_DUMP_DIR;
73                 if (!$buttontext)
74                     $buttontext = _("Load File");
75                 $class = false;
76                 break;
77             case 'dumpserial':
78                 $input['name'] = 'directory';
79                 $input['required'] = 'required';
80                 if (!$default)
81                     $input['value'] = DEFAULT_DUMP_DIR;
82                 if (!$buttontext)
83                     $buttontext = _("Dump Pages");
84                 $class = 'wikiadmin';
85                 break;
86             case 'dumphtml':
87                 $input['name'] = 'directory';
88                 $input['required'] = 'required';
89                 if (!$default)
90                     $input['value'] = HTML_DUMP_DIR;
91                 if (!$buttontext)
92                     $buttontext = _("Dump Pages as XHTML");
93                 $class = 'wikiadmin';
94                 break;
95             case 'upload':
96                 $form->setAttr('enctype', 'multipart/form-data');
97                 $form->pushContent(HTML::input(array('name' => 'MAX_FILE_SIZE',
98                     'value' => MAX_UPLOAD_SIZE,
99                     'type' => 'hidden')));
100                 $input['name'] = 'file';
101                 $input['type'] = 'file';
102                 $input['required'] = 'required';
103                 if (!$buttontext)
104                     $buttontext = _("Upload");
105                 $class = false; // local OS function, so use native OS button
106                 break;
107             default:
108                 return HTML::div(array('class' => "error"), fmt("WikiForm: %s: unknown action", $action));
109         }
110
111         $input = HTML::input($input);
112         $input->addTooltip($buttontext);
113         $button = Button('submit:', $buttontext, $class);
114         if ($request->getArg('start_debug'))
115             $form->pushContent(HTML::input(array('name' => 'start_debug',
116                 'value' => $request->getArg('start_debug'),
117                 'type' => 'hidden')));
118         $form->pushContent(HTML::span(array('class' => $class),
119             $input, $button));
120
121         return $form;
122     }
123 }
124
125 // Local Variables:
126 // mode: php
127 // tab-width: 8
128 // c-basic-offset: 4
129 // c-hanging-comment-ender-p: nil
130 // indent-tabs-mode: nil
131 // End: