]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/GoTo.php
php_closing_tag [PSR-2] The closing ?> tag MUST be omitted from files containing...
[SourceForge/phpwiki.git] / lib / plugin / GoTo.php
1 <?php // -*-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 getName () {
37         return _("GoTo");
38     }
39
40     function getDescription () {
41         return _("Go to or create page.");
42     }
43
44     function getDefaultArguments() {
45         return array('size' => 32);
46     }
47
48     function run($dbi, $argstr, &$request, $basepage) {
49         $request->setArg('action',false);
50         $args = $this->getArgs($argstr, $request);
51         extract($args);
52
53         if ($goto = $request->getArg('goto')) {
54             // The user has pressed 'Go'; process request
55             $request->setArg('goto', false);
56             $target = $goto['target'];
57             if ($dbi->isWikiPage($target))
58                 $url = WikiURL($target,0,1);
59             else
60                 $url = WikiURL($target, array('action'=>'edit'),1);
61
62             $request->redirect($url);
63             // User should see nothing after redirect
64             return '';
65         }
66
67         $action = $request->getURLtoSelf();
68         $form = HTML::form(array('action'=>$action,
69                                  'method'=>'post'
70                           ));
71
72         $form->pushContent(HiddenInputs($request->getArgs()));
73
74         $textfield = HTML::input(array('type' => 'text',
75                                        'size' => $size,
76                                        'name' => 'goto[target]'));
77
78         $button = Button('submit:goto[go]', _("Go"), false);
79
80         $form->pushContent($textfield, $button);
81
82         return $form;
83
84     }
85 };
86
87 // Local Variables:
88 // mode: php
89 // tab-width: 8
90 // c-basic-offset: 4
91 // c-hanging-comment-ender-p: nil
92 // indent-tabs-mode: nil
93 // End: