4 * Copyright 2002 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
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.
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.
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.
24 * Redirect to another page or external uri. Kind of PageAlias.
26 * <<RedirectTo href="http://www.internet-technology.de/fourwins_de.htm" >>
27 * or <<RedirectTo page=AnotherPage >>
29 * Author: Reini Urban <rurban@x-ray.at>
32 * Todo: fix with USE_PATH_INFO = false
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.
39 class WikiPlugin_RedirectTo
42 function getDescription()
44 return _("Redirect to another URL or page.");
47 function getDefaultArguments()
49 return array('href' => '',
54 function run($dbi, $argstr, &$request, $basepage)
56 $args = ($this->getArgs($argstr, $request));
58 $href = $args['href'];
59 $page = $args['page'];
61 // If URL is urlencoded, decode it.
62 if (strpos('%', $href) !== false) {
63 $href = urldecode($href);
65 $url = strip_tags($href);
66 if ($url != $href) { // URL contains tags
67 return $this->disabled(_("Illegal characters in external URL."));
69 $thispage = $request->getPage();
70 if (!$thispage->get('locked')) {
71 return $this->disabled(_("Redirect to an external URL is only allowed in locked pages."));
75 array('redirectfrom' => $request->getArg('pagename')),
78 return $this->error(_("'href' or 'page' parameter missing."));
81 if ($page == $request->getArg('pagename')) {
82 return $this->error(fmt("Recursive redirect to self: ā%sā", $url));
85 if ($request->getArg('action') != 'browse') {
86 return $this->disabled(_("Plugin not run: not in browse mode"));
89 $redirectfrom = $request->getArg('redirectfrom');
90 if ($redirectfrom !== false) {
92 return $this->disabled(_("Double redirect not allowed."));
94 // Got here by following the "Redirected from ..." link
96 return $this->disabled(_("Viewing redirecting page."));
100 return $request->redirect($url);
108 // c-hanging-comment-ender-p: nil
109 // indent-tabs-mode: nil