]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RedirectTo.php
Harmonize file footer
[SourceForge/phpwiki.git] / lib / plugin / RedirectTo.php
1 <?php // -*-php-*-
2 // rcs_id('$Id$');
3 /*
4  * Copyright 2002 $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  * Redirect to another page or external uri. Kind of PageAlias.
25  * Usage:
26  * <<RedirectTo href="http://www.internet-technology.de/fourwins_de.htm" >>
27  *      or  <<RedirectTo page=AnotherPage >>
28  *
29  * Author:  Reini Urban <rurban@x-ray.at>
30  *
31  * BUGS/COMMENTS:
32  * Todo: fix with USE_PATH_INFO = false
33  *
34  * This plugin could probably result in a lot of confusion, especially when
35  * redirecting to external sites.  (Perhaps it can even be used for dastardly
36  * purposes?)  Maybe it should be disabled by default.
37  */
38
39 class WikiPlugin_RedirectTo
40 extends WikiPlugin
41 {
42     function getName() {
43         return _("RedirectTo");
44     }
45
46     function getDescription() {
47         return _("Redirects to another URL or page.");
48     }
49
50     function getDefaultArguments() {
51         return array( 'href' => '',
52                       'page' => false,
53                       );
54     }
55
56     function run($dbi, $argstr, &$request, $basepage) {
57         $args = ($this->getArgs($argstr, $request));
58
59         $href = $args['href'];
60         $page = $args['page'];
61         if ($href) {
62             /*
63              * Use quotes on the href argument value, like:
64              *   <<RedirectTo href="http://funky.com/a b \" c.htm" ?>
65              *
66              * Do we want some checking on href to avoid malicious
67              * uses of the plugin? Like stripping tags or hexcode.
68              */
69             $url = preg_replace('/%\d\d/','',strip_tags($href));
70             $thispage = $request->getPage();
71             if (! $thispage->get('locked')) {
72                 return $this->disabled(_("Redirect to an external URL is only allowed in locked pages."));
73             }
74         }
75         else if ($page) {
76             $url = WikiURL($page,
77                            array('redirectfrom' => $request->getArg('pagename')),
78                            'abs_path');
79         }
80         else {
81             return $this->error(_("'href' or 'page' parameter missing."));
82         }
83
84         if ($page == $request->getArg('pagename')) {
85             return $this->error(fmt("Recursive redirect to self: '%s'", $url));
86         }
87
88         if ($request->getArg('action') != 'browse')
89             return $this->disabled("(action != 'browse')");
90
91         $redirectfrom = $request->getArg('redirectfrom');
92         if ($redirectfrom !== false) {
93             if ($redirectfrom)
94                 return $this->disabled(_("Double redirect not allowed."));
95             else {
96                 // Got here by following the "Redirected from ..." link
97                 // on a browse page.
98                 return $this->disabled(_("Viewing redirecting page."));
99             }
100         }
101
102         return $request->redirect($url);
103     }
104 };
105
106 // Local Variables:
107 // mode: php
108 // tab-width: 8
109 // c-basic-offset: 4
110 // c-hanging-comment-ender-p: nil
111 // indent-tabs-mode: nil
112 // End:
113 ?>