> * or <> * * Author: Reini Urban * * BUGS/COMMENTS: * Todo: fix with USE_PATH_INFO = false * * This plugin could probably result in a lot of confusion, especially when * redirecting to external sites. (Perhaps it can even be used for dastardly * purposes?) Maybe it should be disabled by default. */ class WikiPlugin_RedirectTo extends WikiPlugin { function getDescription() { return _("Redirect to another URL or page."); } function getDefaultArguments() { return array('href' => '', 'page' => false, ); } function run($dbi, $argstr, &$request, $basepage) { $args = ($this->getArgs($argstr, $request)); $href = $args['href']; $page = $args['page']; if ($href) { // If URL is urlencoded, decode it. if (strpos('%', $href) !== false) { $href = urldecode($href); } $url = strip_tags($href); if ($url != $href) { // URL contains tags return $this->disabled(_("Illegal characters in external URL.")); } $thispage = $request->getPage(); if (!$thispage->get('locked')) { return $this->disabled(_("Redirect to an external URL is only allowed in locked pages.")); } } elseif ($page) { $url = WikiURL($page, array('redirectfrom' => $request->getArg('pagename')), 'abs_path'); } else { return $this->error(_("'href' or 'page' parameter missing.")); } if ($page == $request->getArg('pagename')) { return $this->error(fmt("Recursive redirect to self: ā€œ%sā€", $url)); } if ($request->getArg('action') != 'browse') { return $this->disabled(_("Plugin not run: not in browse mode")); } $redirectfrom = $request->getArg('redirectfrom'); if ($redirectfrom !== false) { if ($redirectfrom) return $this->disabled(_("Double redirect not allowed.")); else { // Got here by following the "Redirected from ..." link // on a browse page. return $this->disabled(_("Viewing redirecting page.")); } } return $request->redirect($url); } } // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: