]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/GoTo.php
getName should not translate
[SourceForge/phpwiki.git] / lib / plugin / GoTo.php
1 <?php
2
3 /*
4  * Copyright (C) 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  *  Display a form with text entry box and 'Go' button.
25  *  The user enters a page name... if it exists, browse
26  *  that page; if not, edit (create) that page.
27  *  Note: pagenames are absolute, not relative to the actual subpage.
28  *
29  *  Usage: <<GoTo >>
30  * @author: Michael van Dam
31  */
32
33 class WikiPlugin_GoTo
34     extends WikiPlugin
35 {
36     function getDescription()
37     {
38         return _("Go to or create page.");
39     }
40
41     function getDefaultArguments()
42     {
43         return array('size' => 32);
44     }
45
46     function run($dbi, $argstr, &$request, $basepage)
47     {
48         $request->setArg('action', false);
49         $args = $this->getArgs($argstr, $request);
50         extract($args);
51
52         if ($goto = $request->getArg('goto')) {
53             // The user has pressed 'Go'; process request
54             $request->setArg('goto', false);
55             $target = $goto['target'];
56             if ($dbi->isWikiPage($target))
57                 $url = WikiURL($target, 0, 1);
58             else
59                 $url = WikiURL($target, array('action' => 'edit'), 1);
60
61             $request->redirect($url);
62             // User should see nothing after redirect
63             return '';
64         }
65
66         $action = $request->getURLtoSelf();
67         $form = HTML::form(array('action' => $action,
68             'method' => 'post'
69         ));
70
71         $form->pushContent(HiddenInputs($request->getArgs()));
72
73         $textfield = HTML::input(array('type' => 'text',
74             'size' => $size,
75             'name' => 'goto[target]'));
76
77         $button = Button('submit:goto[go]', _("Go"), false);
78
79         $form->pushContent($textfield, $button);
80
81         return $form;
82
83     }
84 }
85
86 // Local Variables:
87 // mode: php
88 // tab-width: 8
89 // c-basic-offset: 4
90 // c-hanging-comment-ender-p: nil
91 // indent-tabs-mode: nil
92 // End: