Skip to content

Commit

Permalink
Item8014: Add ability to display Wikipedia like 'Redirected from...'
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/RedirectPlugin@925 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
AndrewJones authored and AndrewJones committed Nov 24, 2008
1 parent ff3a500 commit b5c430d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
5 changes: 4 additions & 1 deletion data/Sandbox/RedirectPluginDestination.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
%META:TOPICINFO{author="MeredithLesly" date="1150118041" format="1.1" version="1.1"}%
---+ %SYSTEMWEB%.RedirectPlugin Test Topic: destination

This is the destination of the !RedirectPlugin test topic. %BR%
You should end up here coming from <a href="%SCRIPTURL{view}%/%WEB%/RedirectPluginTest?noredirect=on">RedirectPluginTest</a>

The following demonstrates how to use the =redirectedfrom= parameter:

You have been redirected from: %URLPARAM{redirectedfrom}%
16 changes: 15 additions & 1 deletion data/TWiki/RedirectPlugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ To view the topic that contains a =REDIRECT=, pass parameter =noredirect=on= to
http://domain.com/twiki/bin/view/Main/WebHome?noredirect=on
</verbatim>

---++ Wikipedia like "Redirected from..."
A redirect now appends the =redirectedfrom= parameter to the url which contains the Web.Topic that the user has been redirected from. This allows us to display Wikipedia like "Redirected from ..." text on the destination topic. You can use the =%<nop>URLPARAM{redirectedfrom}%= variable to access the parameter and create the "Redirected from..." text.

Below is an example you can put in your template:

<verbatim>
%IF{ "$'URLPARAM{redirectedfrom}'" then="<span class='twikiGrayText'>(Redirected from <a href='%SCRIPTURLPATH{view}%/%URLPARAM{redirectedfrom}%?noredirect=on'>%URLPARAM{redirectedfrom}%</a>)</span>"}%
</verbatim>

Which will display the following on topics that have been redirected:

<span class="twikiGrayText">(Redirected from <a href="?noredirect=on">Web.Topic</a>)</span>

---++ Related Topics
* http://twiki.org/cgi-bin/view/Codev/RedirectPage
* http://twiki.org/cgi-bin/view/Codev/PageRedirectTag
Expand Down Expand Up @@ -56,8 +69,9 @@ __Note:__ You do not need to install anything on the browser to use this plugin.
---++ Plugin Info

| Plugin Author: | TWiki:Main/SteveMokris |
| Plugin Version: | 22 Apr 2006 |
| Plugin Version: | 24 Nov 2008 |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 24 Nov 2008: | Andrew Jones: Ability to display Wikipedia like "Redirected from..." |
| 22 Apr 2007: | Arthur Clemens: url parameters are now passed on. Adapted from TWiki:Main.JohnRouillard. |
| 21 Apr 2007: | Arthur Clemens: fixed redirect to non-wiki word topics; added =noredirect=on= parameter; added support for TWiki:Codev.ShorterURLs. |
| 10 Aug 2006: | Ability to redirect to URL restored by TWiki:Main/ThomasWeigert. Also added support for URL parameters. Fixed a few bugs. |
Expand Down
10 changes: 7 additions & 3 deletions lib/TWiki/Plugins/RedirectPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package TWiki::Plugins::RedirectPlugin;
use vars qw( $VERSION $RELEASE $debug $pluginName );
use strict;

$VERSION = '$Rev: 13491 $';
$VERSION = '$Rev: 17733 $';
$RELEASE = 'Dakar';
$pluginName = 'RedirectPlugin';

Expand Down Expand Up @@ -126,12 +126,16 @@ sub REDIRECT {
$queryString = $1;
}

$queryString = "?" . $queryString if $queryString;
# AndrewJones: allow us to use %<nop>URLPARAM{redirectfrom}%
# in destination topic to display Wikipedia like "Redirected
# from ..." text
my $q = "?redirectedfrom=$web.$topic";
$q .= "&" . $queryString if $queryString;

# topic exists
TWiki::Func::redirectCgiQuery( $query,
TWiki::Func::getViewUrl( $newWeb, $newTopic ) . $anchor
. $queryString );
. $q );

}

Expand Down

0 comments on commit b5c430d

Please sign in to comment.