Loading...
 
Skip to main content

Allow redirect plugin to use fragment identifiers (section/anchor ids) (patch included)

Status
Open
Subject
Allow redirect plugin to use fragment identifiers (section/anchor ids) (patch included)
Version
1.9.x
2.x
3.x
Category
  • Feature request
  • Patch
Feature
Wiki Plugin (extends basic syntax)
Search engine optimization (SEO)
Submitted by
lbmaian
Lastmod by
Marc Laporte
Rating
(0)
Description
The redirect plugin currently lacks the ability to include fragment identifiers, e.g. {REDIRECT(page=Foo#some_id)/} does not work; the resulting URL is tiki-index.php?page=Foo#some_id&redirectpage=this_page instead of tiki-index.php?page=Foo&redirectpage=this_page#some_id.
Solution

This patch provides a new parameter called "section" which can be set to the anchor id (not including the "#"). I decided to add this new parameter instead of better parsing of the "page" parameter to be consistent with the fragment syntax for internal links ( ((Foo|#bar)) - note how it's not ((Foo#bar)))

--- wikiplugin_redirect.php.old	2009-04-29 07:02:08.000000000 -0500
+++ wikiplugin_redirect.php	2009-05-20 12:22:21.028250000 -0500
@@ -6,7 +6,7 @@
 // @author damian aka damosoft 30 March 2004
 
 function wikiplugin_redirect_help() {
-        return tra("Redirects you to another wiki page").":<br />{REDIRECT(page=pagename [,url=http://foobar])/}";
+	return tra("Redirects you to another wiki page").":<br />{REDIRECT(page=pagename [,section=section_id] [,url=http://foobar])/}";
 }
 
 function wikiplugin_redirect_info() {
@@ -22,6 +22,11 @@
 				'name' => tra('Page Name'),
 				'description' => tra('Wiki page name to redirect to.'),
 			),
+            'section' => array(
+                'required' => false,
+                'name' => tra('Section/anchor id'),
+                'description' => tra('Id of section/anchor within wiki page to redirect to (see id attribute of <a> elements in HTML source of wiki page).'),
+            ),
 			'url' => array(
 				'required' => false,
 				'name' => tra('url'),
@@ -43,11 +48,15 @@
 	} else {
 		/* SEO: Redirect with HTTP status 301 - Moved Permanently than default 302 - Found */
 		if (isset($page)) {
-			header("Location: tiki-index.php?page=$page&redirectpage=".$_REQUEST['page'], true, 301);
+			if (isset($section))
+				$section = '#'.$section;
+			else
+				$section = '';
+			header('Location: tiki-index.php?page='.urlencode($page).'&redirectpage='.$_REQUEST['page'].$section, true, 301);
 			exit;
 		}
 		if (isset($url)) {
-			header("Location: $url");
+			header("Location: $url", true, 301);
 			exit;
 		}
 	}
Priority
25
Demonstrate Bug on Tiki 19+
Demonstrate Bug (older Tiki versions)
Ticket ID
2516
Created
Wednesday 20 May, 2009 17:34:34 UTC
by Unknown
LastModif
Sunday 07 June, 2009 16:15:30 UTC


Show PHP error messages