]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RedirectTo.php
access-restrictions are not implemented
[SourceForge/phpwiki.git] / lib / plugin / RedirectTo.php
1 <?php
2
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 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  * 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     {
44         return _("RedirectTo");
45     }
46
47     function getDescription()
48     {
49         return _("Redirect to another URL or page.");
50     }
51
52     function getDefaultArguments()
53     {
54         return array('href' => '',
55             'page' => false,
56         );
57     }
58
59     function run($dbi, $argstr, &$request, $basepage)
60     {
61         $args = ($this->getArgs($argstr, $request));
62
63         $href = $args['href'];
64         $page = $args['page'];
65         if ($href) {
66             // If URL is urlencoded, decode it.
67             if (strpos('%', $href) !== false) {
68                 $href = urldecode($href);
69             }
70             $url = strip_tags($href);
71             if ($url != $href) { // URL contains tags
72                 return $this->disabled(_("Illegal characters in external URL."));
73             }
74             $thispage = $request->getPage();
75             if (!$thispage->get('locked')) {
76                 return $this->disabled(_("Redirect to an external URL is only allowed in locked pages."));
77             }
78         } elseif ($page) {
79             $url = WikiURL($page,
80                 array('redirectfrom' => $request->getArg('pagename')),
81                 'abs_path');
82         } else {
83             return $this->error(_("'href' or 'page' parameter missing."));
84         }
85
86         if ($page == $request->getArg('pagename')) {
87             return $this->error(fmt("Recursive redirect to self: ā€œ%sā€", $url));
88         }
89
90         if ($request->getArg('action') != 'browse') {
91             return $this->disabled(_("Plugin not run: not in browse mode"));
92         }
93
94         $redirectfrom = $request->getArg('redirectfrom');
95         if ($redirectfrom !== false) {
96             if ($redirectfrom)
97                 return $this->disabled(_("Double redirect not allowed."));
98             else {
99                 // Got here by following the "Redirected from ..." link
100                 // on a browse page.
101                 return $this->disabled(_("Viewing redirecting page."));
102             }
103         }
104
105         return $request->redirect($url);
106     }
107 }
108
109 // Local Variables:
110 // mode: php
111 // tab-width: 8
112 // c-basic-offset: 4
113 // c-hanging-comment-ender-p: nil
114 // indent-tabs-mode: nil
115 // End: