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