]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/GoTo.php
function run: @return mixed
[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     /**
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         $request->setArg('action', false);
56         $args = $this->getArgs($argstr, $request);
57         extract($args);
58
59         if ($goto = $request->getArg('goto')) {
60             // The user has pressed 'Go'; process request
61             $request->setArg('goto', false);
62             $target = $goto['target'];
63             if ($dbi->isWikiPage($target))
64                 $url = WikiURL($target, array(), 1);
65             else
66                 $url = WikiURL($target, array('action' => 'edit'), 1);
67
68             $request->redirect($url);
69             // User should see nothing after redirect
70             return '';
71         }
72
73         $action = $request->getURLtoSelf();
74         $form = HTML::form(array('action' => $action,
75             'method' => 'post'
76         ));
77
78         $form->pushContent(HiddenInputs($request->getArgs()));
79
80         $textfield = HTML::input(array('type' => 'text',
81             'size' => $size,
82             'name' => 'goto[target]'));
83
84         $button = Button('submit:goto[go]', _("Go"), false);
85
86         $form->pushContent($textfield, $button);
87
88         return $form;
89
90     }
91 }
92
93 // Local Variables:
94 // mode: php
95 // tab-width: 8
96 // c-basic-offset: 4
97 // c-hanging-comment-ender-p: nil
98 // indent-tabs-mode: nil
99 // End: