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
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Redirect to another page or external uri. Kind of PageAlias.
26 * <?plugin RedirectTo href="http://www.internet-technology.de/fourwins_de.htm" ?>
27 * or <?plugin RedirectTo page=AnotherPage ?>
28 * at the VERY FIRST LINE in the content! Otherwise it will be ignored.
30 * Author: Reini Urban <rurban@x-ray.at>
33 * Todo: fix with USE_PATH_INFO = false
35 * This plugin could probably result in a lot of confusion, especially when
36 * redirecting to external sites. (Perhaps it can even be used for dastardly
37 * purposes?) Maybe it should be disabled by default.
39 * It would be nice, when redirecting to another wiki page, to (as
40 * UseModWiki does) add a note to the top of the target page saying
41 * something like "(Redirected from SomeRedirectingPage)".
43 class WikiPlugin_RedirectTo
47 return _("RedirectTo");
50 function getDescription() {
51 return _("Redirects to another url or page.");
54 function getVersion() {
55 return preg_replace("/[Revision: $]/", '',
59 function getDefaultArguments() {
60 return array( 'href' => '',
61 // 'type' => 'Temp' // or 'Permanent' // so far ignored
66 function run($dbi, $argstr, &$request, $basepage) {
67 $args = ($this->getArgs($argstr, $request));
69 $href = $args['href'];
70 $page = $args['page'];
73 * Use quotes on the href argument value, like:
74 * <?plugin RedirectTo href="http://funky.com/a b \" c.htm" ?>
76 * Do we want some checking on href to avoid malicious
77 * uses of the plugin? Like stripping tags or hexcode.
79 $url = preg_replace('/%\d\d/','',strip_tags($href));
80 $thispage = $request->getPage();
81 if (! $thispage->get('locked')) {
82 return $this->disabled(fmt("%s is only allowed in locked pages.",
83 _("Redirect to an external url")));
88 array('redirectfrom' => $request->getArg('pagename')),
92 return $this->error(fmt("%s or %s parameter missing",
96 if ($page == $request->getArg('pagename')) {
97 return $this->error(fmt("Recursive redirect to self: '%s'", $url));
100 if ($request->getArg('action') != 'browse')
101 return $this->disabled("(action != 'browse')");
103 $redirectfrom = $request->getArg('redirectfrom');
104 if ($redirectfrom !== false) {
106 return $this->disabled(_("Double redirect not allowed."));
108 // Got here by following the "Redirected from ..." link
110 return $this->disabled(_("Viewing redirecting page."));
114 return $request->redirect($url);
123 // c-hanging-comment-ender-p: nil
124 // indent-tabs-mode: nil