Tags:
create new tag
view all tags

New Feature: SCRIPTNAME Variable

Motivation

To show a meaningfull message to the user in LogoutAndLogin we need to distinguish between authenticated and non-authenticated access.

Description

New %SCRIPTNAME% variable showing the name of the current script, e.g. view or viewauth for topic view, rdiff for history etc. The suffix is included for sites that have one, e.g. view.cgi or viewauth.cgi.

Impact and Available Solutions

Documentation

#VarSCRIPTNAME
---+++ SCRIPTNAME -- name of current script
   * The name of the current script is shown, including script suffix, if any (for example =viewauth.cgi=)
   * Syntax: =%<nop>SCRIPTNAME%=
   * Expands to: =%SCRIPTNAME%=
   * Related: [[#VarSCRIPTSUFFIX][SCRIPTSUFFIX]], [[#VarSCRIPTURL][SCRIPTURL]], [[#VarSCRIPTURLPATH][SCRIPTURLPATH]]

The TWiki doc TWikiVariablesNtoZ is updated.

Examples

  • Syntax: %SCRIPTNAME%
  • Expands to: view

Implementation

This is the change for the latest MainBranch:

===================================================================
--- lib/TWiki.pm        (revision 3187)
+++ lib/TWiki.pm        (working copy)
@@ -2808,6 +2808,22 @@

 =pod

+---++ sub handleScriptName ( )
+
+Not yet documented.
+
+=cut
+
+sub handleScriptName
+{
+    my $value = $ENV{'SCRIPT_URL'} || ""; # e.g. '/cgi-bin/view.cgi/TWiki/WebHome'
+    $value =~ s|^$dispScriptUrlPath/?||;  # cut URL path to get 'view.cgi/TWiki/WebHome'
+    $value =~ s|/.*||;                    # cut extended path to get 'view.cgi'
+    return $value;
+}
+
+=pod
+
 ---++ sub handleEnvVariable (  $theVar  )

 Not yet documented.
@@ -2954,6 +2970,7 @@
     $_[0] =~ s/%WIKIHOMEURL%/$wikiHomeUrl/g;
     $_[0] =~ s/%SCRIPTURL%/$urlHost$dispScriptUrlPath/g;
     $_[0] =~ s/%SCRIPTURLPATH%/$dispScriptUrlPath/g;
+    $_[0] =~ s/%SCRIPTNAME%/&handleScriptName()/ge;
     $_[0] =~ s/%SCRIPTSUFFIX%/$scriptSuffix/g;
     $_[0] =~ s/%PUBURL%/$urlHost$pubUrlPath/g;
     $_[0] =~ s/%PUBURLPATH%/$pubUrlPath/g;

Crawford: Could you update the DevelopBranch. TWiki.pm got engineered a lot, it was not obvious to me at first sight where to put it!

TWiki.org is updated with this small enhancement.

-- PeterThoeny - 14 Feb 2005

Discussion:

OK. For future reference, all you do is add the tag name and method address to the table at the top and the handler body anywhere (observing the standard for the parameters, of course)

-- CrawfordCurrie - 14 Feb 2005

Merged across, and extended to use SCRIPT_FILENAME is SCRIPT_URL is not set (which it often isn't)

-- CrawfordCurrie - 16 Feb 2005

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2005-02-17 - CrawfordCurrie
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.