Skip to content

Commit

Permalink
Item8679: Adds dontCheck so you can redirect to pages that don't exist
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/RedirectPlugin@6676 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MartinCleaver authored and MartinCleaver committed Mar 7, 2010
1 parent 536eceb commit faec776
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 16 additions & 0 deletions data/System/RedirectPlugin.txt
Expand Up @@ -41,6 +41,21 @@ Which will display the following on topics that have been redirected:

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

---++ Don't check that the target topic exists

If you pass the dontcheck=1 parameter then Foswiki will let you redirect to a topic that doesn't exist. This is very useful as a way to wrap up data form creators for applications.

e.g. !RoleCreator:

<verbatim>
%REDIRECT{newtopic="%SCRIPTURLPATH{"edit"}%/%BASEWEB%/UnnamedRoleAUTOINC1?topicparent=RoleList;templatetopic=RoleTemplate;t=%SERVERTIME{"$day$hour$min$sec"}%" dontCheck="1"}%
</verbatim>

Now, for instance in WebLeftBar you can just use:
<pre>
* [[RoleCreator][Create Role]]
</pre>

---++ Test topics
If installed:
* Sandbox.RedirectPluginTest - this topic should redirect to landing page:
Expand All @@ -63,6 +78,7 @@ If installed:
| Plugin Release: | %$RELEASE% |
| Plugin Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 07 Mar 2010: | Added facility to dontCheck destination topic exists - Foswiki:Main.MartinCleaver |
| 09 Apr 2009: | Ported to Foswiki as 1.0; Update documentation - Foswiki:Main.AndrewJones |
| 24 Nov 2008: | Ability to display Wikipedia like "Redirected from..." - Foswiki:Main.AndrewJones |
| 22 Apr 2007: | Arthur Clemens: url parameters are now passed on. Adapted from TWiki:Main.JohnRouillard. |
Expand Down
11 changes: 7 additions & 4 deletions lib/Foswiki/Plugins/RedirectPlugin.pm
Expand Up @@ -54,6 +54,7 @@ sub REDIRECT {
my $anchor = '';
my $queryString = '';
my $dest = $params->{'newtopic'} || $params->{_DEFAULT};
my $dontCheckDestinationExists = $params->{'dontCheck'} || 0;

my $webNameRegex = Foswiki::Func::getRegularExpression('webNameRegex');
my $wikiWordRegex = Foswiki::Func::getRegularExpression('wikiWordRegex');
Expand Down Expand Up @@ -102,10 +103,12 @@ sub REDIRECT {
$topicLocation = "$newWeb.$newTopic";
}

if ( !Foswiki::Func::topicExists( undef, $topicLocation ) ) {
return
"%RED% Could not redirect to topic $topicLocation (the topic does not seem to exist) %ENDCOLOR%";
}
unless ($dontCheckDestinationExists) {
if ( !Foswiki::Func::topicExists( undef, $topicLocation ) ) {
return
"%RED% Could not redirect to topic $topicLocation (the topic does not seem to exist) %ENDCOLOR%";
}
}

if ( $dest =~ /($anchorRegex)/ ) {
$anchor = $1;
Expand Down

0 comments on commit faec776

Please sign in to comment.