* or * at the VERY FIRST LINE in the content! Otherwise it will be ignored. * Author: Reini Urban * * BUGS/COMMENTS: * * 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. * * It would be nice, when redirecting to another wiki page, to (as * UseModWiki does) add a note to the top of the target page saying * something like "(Redirected from SomeRedirectingPage)". */ class WikiPlugin_RedirectTo extends WikiPlugin { function getName() { return _("RedirectTo"); } function getDescription() { return _("Redirects to another url or page."); } function getDefaultArguments() { return array( 'href' => '', // 'type' => 'Temp' // or 'Permanent' // so far ignored 'page' => false, 'args' => false, // pass more args to the page. TestMe! ); } function run($dbi, $argstr, $request) { $args = ($this->getArgs($argstr, $request)); $href = $args['href']; $page = $args['page']; if ($href) { /* * Use quotes on the href argument value, like: * * * Do we want some checking on href to avoid malicious * uses of the plugin? Like stripping tags or hexcode. */ $url = preg_replace('/%\d\d/','',strip_tags($href)); $thispage = $request->getPage(); if (! $thispage->get('locked')) { return $this->error(HTML(fmt(_("%s is only allowed in locked pages."), _("Redirect to an external url")), HTML::br(), fmt("url=\"%s\"", $url))); } } else if ($page) { $url = $request->getURLtoSelf(array_merge(array('pagename' => $page, 'redirectfrom' => $request->getArg('pagename')), SplitQueryArgs($args['args']))); } else return $this->error(sprintf(_("%s or %s parameter missing"), "'href'", "'page'")); if ($page == $request->getArg('pagename')) { return $this->error(sprintf(_("Recursive redirect to self: '%s'"), $url)); } return $request->redirect($url); } }; // For emacs users // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>