]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiForm.php
Eliminate MagicPhpWikiURL forms in favor of new WikiForm plugin.
[SourceForge/phpwiki.git] / lib / plugin / WikiForm.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiForm.php,v 1.1 2002-02-07 21:17:26 dairiki Exp $');
3 /**
4  * This is a replacement for MagicPhpWikiURL forms.
5  *
6  * 
7  */
8 class WikiPlugin_WikiForm
9 extends WikiPlugin
10 {
11     function getName () {
12         return _("WikiForm");
13     }
14
15     function getDefaultArguments() {
16         return array('action' => 'upload', // 'upload', 'loadfile', or 'dumpserial'
17                      'default' => false,
18                      'buttontext' => false);
19     }
20
21                                  
22     function run($dbi, $argstr, $request) {
23         extract($this->getArgs($argstr, $request));
24
25         $form = HTML::form(array('action' => USE_PATH_INFO ? WikiURL($request->getPage()) : SCRIPT_NAME,
26                                  'method' => 'post',
27                                  'class'  => 'wikiadmin',
28                                  'accept-charset' => CHARSET),
29                            HTML::input(array('type' => 'hidden',
30                                              'name' => 'action',
31                                              'value' => $action)));
32
33         $input = array('type' => 'text',
34                        'value' => $default,
35                        'size' => 50);
36
37         switch ($action) {
38         case 'loadfile':
39             $input['name'] = 'source';
40             if (!$default)
41                 $input['value'] = '/tmp/wikidump';
42             if (!$buttontext)
43                 $buttontext = _("Load File");
44             break;
45         case 'dumpserial':
46             $input['name'] = 'directory';
47             if (!$default)
48                 $input['value'] = '/tmp/wikidump';
49             if (!$buttontext)
50                 $buttontext = _("Dump Pages");
51             break;
52         case 'upload':
53             $form->setAttr('enctype', 'multipart/form-data');
54             $form->pushContent(HTML::input(array('name' => 'MAX_FILE_SIZE',
55                                                  'value' =>  MAX_UPLOAD_SIZE,
56                                                  'type'  => 'hidden')));
57             $input['name'] = 'file';
58             $input['type'] = 'file';
59             if (!$buttontext)
60                 $buttontext = _("Upload");
61             break;
62         default:
63             return HTML::p(fmt("WikiForm: %s: unknown action", $action));
64         }
65
66         
67         $input = HTML::input($input);
68         $input->addTooltip($buttontext);
69         $button = Button('submit:', $buttontext);
70
71         $form->pushContent(HTML::table(array('cellspacing' => 0,
72                                              'cellpadding' => 2,
73                                              'border' => 0),
74                                        HTML::tr(HTML::td($input),
75                                                 HTML::td($button))));
76
77         return $form;
78     }
79 };
80
81 // For emacs users
82 // Local Variables:
83 // mode: php
84 // tab-width: 8
85 // c-basic-offset: 4
86 // c-hanging-comment-ender-p: nil
87 // indent-tabs-mode: nil
88 // End:
89 ?>