]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/GoTo.php
Normalize header
[SourceForge/phpwiki.git] / lib / plugin / GoTo.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
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
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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: <?plugin 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 getVersion() {
45         return preg_replace("/[Revision: $]/", '',
46                             "\$Revision$");
47     }
48
49     function getDefaultArguments() {
50         return array('size' => 32);
51     }
52
53     function run($dbi, $argstr, &$request, $basepage) {
54         $request->setArg('action',false);
55         $args = $this->getArgs($argstr, $request);
56         extract($args);
57
58         if ($goto = $request->getArg('goto')) {
59             // The user has pressed 'Go'; process request
60             $request->setArg('goto', false);
61             $target = $goto['target'];
62             if ($dbi->isWikiPage($target))
63                 $url = WikiURL($target,0,1);
64             else
65                 $url = WikiURL($target, array('action'=>'edit'),1);
66
67             $request->redirect($url);
68             // User should see nothing after redirect
69             return '';
70         } 
71
72         $action = $request->getURLtoSelf();
73         $form = HTML::form(array('action'=>$action,
74                                  'method'=>'post'
75                           ));
76  
77         $form->pushContent(HiddenInputs($request->getArgs()));
78
79         $textfield = HTML::input(array('type' => 'text',
80                                        'size' => $size,
81                                        'name' => 'goto[target]'));
82
83         $button = Button('submit:goto[go]', _("Go"), false);
84
85         $form->pushContent($textfield, $button);
86
87         return $form;
88
89     }
90 };
91
92 // Local Variables:
93 // mode: php
94 // tab-width: 8
95 // c-basic-offset: 4
96 // c-hanging-comment-ender-p: nil
97 // indent-tabs-mode: nil
98 // End:   
99 ?>