* 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 getVersion() { return preg_replace("/[Revision: $]/", '', "\$Revision: 1.7 $"); } 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->disabled(fmt(_("%s is only allowed in locked pages."), _("Redirect to an external url"))); } } else if ($page) { $url = $request->getURLtoSelf(array_merge(array('pagename' => $page, 'redirectfrom' => $request->getArg('pagename')), SplitQueryArgs($args['args']))); } else { return $this->error(fmt("%s or %s parameter missing", "'href'", "'page'")); } if ($page == $request->getArg('pagename')) { return $this->error(fmt("Recursive redirect to self: '%s'", $url)); } if ($request->getArg('action') != 'browse') return $this->disabled("(action != 'browse')"); $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); } }; // $Log: not supported by cvs2svn $ // Revision 1.6 2003/01/18 22:01:44 carstenklapp // Code cleanup: // Reformatting & tabs to spaces; // Added copyleft, getVersion, getDescription, rcs_id. // // 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: ?>