Changeset 1221


Ignore:
Timestamp:
12/09/08 18:16:48 (3 years ago)
Author:
CrawfordCurrie
Message:

Item253: remove TWikiDrawPlugin hack; analyse, rationalise and document usage of redirectto; Item5926: added encodings that were proposed to make chinese work (they don't break anything AFAICT). Deprecate Foswiki::Func::getRegularExpression (the regex array is published)

Location:
trunk/core
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/data/System/CommandAndCGIScripts.txt

    r1163 r1221  
    322322| =createlink= | if defined, will create a link to file at end of topic | | 
    323323| =changeproperties= | if defined, this is a property change operation *only* - no file will be uploaded. | null | 
    324  
    325 You can use a tool like =curl= to upload files from the command line using this script. 
     324| =redirectto= | URL to redirect to after upload. ={AllowRedirectUrl}= \ 
     325     must be enabled in =configure=. The parameter value can be a \ 
     326     =TopicName=, a =Web.TopicName=, or a URL. Redirect to a URL only works \ 
     327     if it is enabled in =configure=, and is ignored if =noredirect= is \ 
     328     specified.%BR% __Note:__ Redirect to a URL only works if it is enabled \ 
     329     in =configure= (Miscellaneous ={AllowRedirectUrl}=). | 
     330| =noredirect= | Normally it will redirect to 'view' when the upload is \ 
     331     complete, but also designed to be useable for REST-style calling using \ 
     332     the 'noredirect' parameter. If this parameter is set it will return an \ 
     333     appropriate HTTP status code and print a message to STDOUT, starting \ 
     334     with 'OK' on success and 'ERROR' on failure. | 
     335 
     336__Tips__ 
     337   * You can use a tool like =curl= to upload files from the command line using this script. 
     338   * You can call upload easily from !XmlHttpRequest in Javascript. 
    326339 
    327340---+++ =view= 
  • trunk/core/data/System/DevelopingPlugins.txt

    r1041 r1221  
    11---+ Developing Plugins 
    22 
    3 Foswiki has a large number of internal (perl code) interfaces that give access to all the internal functionality. However in general it's a bad idea to use these interfaces to extend Foswiki, because that would result in your code breaking every time the core changes. 
     3Foswiki has a large number of internal (perl code) interfaces. However in general it's a bad idea to use these interfaces to extend Foswiki, because that would result in your code breaking every time the core changes. 
    44 
    55To address this problem Foswiki provides a number of Application Program Interfaces (APIs) that allow you to extend Foswiki in a robust way. 
     
    77The usual way Foswiki is extended is by writing a _Plugin_. Plugins extend Foswiki by providing functions that 'listen' to events in the Foswiki core, and handling these events. These functions are called "Plugin Handlers" and they are described in depth in %SYSTEMWEB%.EmptyPlugin and =lib/Foswiki/Plugins/EmptyPlugin.pm=. 
    88 
    9 To be robust plugins must avoid using any unpublished functionality from the Foswiki core. Functionality that is available to plugins consists of the following perl packages. Click on the name of the packge to see the full documentation. 
     9To be robust extensions must avoid using any unpublished functionality from the Foswiki core. The following perl packages give access to features for extension authors. These APIs are not just for Plugins, they can be used in any type of extension. Click on the name of the package to see the full documentation. 
    1010   * =[[%SCRIPTURL{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::Plugins::EmptyPlugin][Foswiki::Plugins::EmptyPlugin]]= - template plugin for you to use as a starting point for your own plugins. 
    1111   * =[[%SCRIPTURL{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::Func][Foswiki::Func]]= - bridge to core functions. This is the package you will use most. 
     
    1919   * =$Foswiki::Plugins::SESSION= - reference to =Foswiki= singleton object 
    2020   * =$Foswiki::cfg= - reference to configuration hash 
     21   * =$Foswiki::regex - see 'Standard Regular Expressions', below 
    2122   * =$Foswiki::sandbox= - reference to the static sandbox object (type =Foswiki::Sandbox=), used for calling external programs. 
    2223%I% Foswiki:Development.GettingStarted  is the starting point for more comprehensive documentation on developing for Foswiki. 
    2324 
    24 ---+++ Predefined Hooks 
    25  
    26 Plugins 'listen' to events happening in the core by registering an interest in those events. They do this using 'plugin handlers'. these are simply functions with a particular name that, if they exist in your plugin, will be called by the core. 
    27  
    28 Foswiki:Development.StepByStepRenderingOrder helps you decide which rendering handler to use. See EmptyPlugin for a full list of the handlers that are defined. 
     25__Note__ the APIs are available to all extensions, but rely on a 
     26=Foswiki= singleton object having been created before the APIs can be used. 
     27This will only be a problem if you are writing an extension that doesn't 
     28use the standard initialisation sequence. 
     29 
     30---+++ Standard Regular Expressions 
     31A number of standard regular expressions are available for use in extensions, in the =$Foswiki::regex= hash. these regular expressions are precompiled in an 
     32<nop>I18N-compatible manner. The 
     33following are guaranteed to be present. Others may exist, but their use 
     34is unsupported and they may be removed in future Foswiki versions. 
     35 
     36In the table below, the expression marked type 'String' are intended for 
     37use within character classes (i.e. for use within square brackets inside 
     38a regular expression), for example: 
     39<verbatim> 
     40   my $isCapitalizedWord = 
     41     ( $s =~ /[$Foswiki::regex{upperAlpha}][$Foswiki::regex{mixedAlpha}]+/ ); 
     42</verbatim> 
     43Those expressions marked type 'RE' are precompiled regular expressions that can be used outside square brackets. For example: 
     44<verbatim> 
     45   my $isWebName = ( $s =~ m/$Foswiki::regex{webNameRegex}/ ); 
     46</verbatim> 
     47 
     48| *Name*         | *Matches*                        | *Type* | 
     49| upperAlpha     | Upper case characters            | String | 
     50| upperAlphaNum  | Upper case characters and digits | String | 
     51| lowerAlpha     | Lower case characters            | String | 
     52| lowerAlphaNum  | Lower case characters and digits | String | 
     53| numeric        | Digits                           | String | 
     54| mixedAlpha     | Alphabetic characters            | String | 
     55| mixedAlphaNum  | Alphanumeric characters          | String | 
     56| wikiWordRegex  | WikiWords                        | RE | 
     57| webNameRegex   | User web names                   | RE | 
     58| topicNameRegex | Topic names                      | RE | 
     59| anchorRegex    | #AnchorNames                     | RE | 
     60| abbrevRegex    | Abbreviations/Acronyms e.g. GOV, IRS | RE | 
     61| emailAddrRegex | email@address.com                | RE | 
     62| tagNameRegex   | Standard macro names e.g. %<nop>THIS_BIT% (THIS_BIT only) | RE | 
     63 
     64---+++ Predefined Hooks for Plugins 
     65 
     66Plugins 'listen' to events happening in the core by registering an interest in those events. They do this by declaring 'plugin handlers'. These are simply functions with a particular name that, if they exist in your plugin, will be called by the core. 
     67 
     68Foswiki:Development.StepByStepRenderingOrder helps you decide which rendering handler to use. See [[EmptyPlugin]] for a full list of the handlers that are defined. 
    2969 
    3070#FastPluginHints 
     
    4484 
    4585   * All plugin packages require a =$VERSION= variable. This should be an integer, or a subversion version id. 
    46  
    4786   * The =initPlugin= handler should check all dependencies and return 1 if the initialization is OK or 0 if something went wrong. 
    4887      * The plugin initialization code does not register a plugin that returns 0 (or that has no =initPlugin= handler). 
    49  
    5088   * =$Foswiki::Plugins::VERSION= in the =Foswiki::Plugins= module contains the Foswiki plugin API version, currently *%PLUGINVERSION{}%*. 
    5189      * You can also use the =[[VarPLUGINVERSION][%<nop>PLUGINVERSION{}%]]= macro to query the plugin API version or the version of installed plugins. 
     
    5391---+++ Security 
    5492 
    55    * Badly written plugins can open huge security holes in Foswiki. This is especially true if care isn't taken to prevent execution of arbitrary commands on the server. 
    56    * Don't allow sensitive configuration data to be edited by users. it is better to add sensitive configuration options to the =%Foswiki::cfg= hash than adding it as preferences in the plugin topic. 
     93   * Badly written plugins can open security holes in Foswiki. This is especially true if care isn't taken to prevent execution of arbitrary commands on the server. 
     94   * Don't allow sensitive configuration data to be edited by users. Use the =%Foswiki::cfg= hash for configuration options. Don't ask installers to edit topics in the System web. 
    5795      * [[#ConfigSpec][Integrating with <code>configure</code>]] describes the steps 
    5896      * Foswiki:Extensions.MailInContrib has an example 
    5997      * Foswiki:Extensions.BuildContrib can help you with this 
    60    * Always use the Foswiki::Sandbox to execute commands. 
     98   * Make sure that all user input is checked and validated. Be especially careful to filter characters that might be used in perl string interpolation. 
     99   * Avoid =eval=, and if you must use it make sure you sanitise parameters 
     100   * Always use the Foswiki::sandbox to execute commands. Never use backtick or qx//. 
    61101   * Always audit the plugins you install, and make sure you are happy with the level of security provided. While every effort is made to monitor plugin authors activities, at the end of the day they are uncontrolled user contributions. 
    62102 
  • trunk/core/lib/Foswiki.pm

    r1206 r1221  
    407407    $regex{anchorRegex}         = qr/\#[$regex{mixedAlphaNum}_]+/o; 
    408408    $regex{abbrevRegex}         = qr/[$regex{upperAlpha}]{3,}s?\b/o; 
    409  
     409    $regex{topicNameRegex}      = 
     410      qr/(?:(?:$regex{wikiWordRegex})|(?:$regex{abbrevRegex}))/o; 
    410411    # Simplistic email regex, e.g. for WebNotify processing - no i18n 
    411412    # characters allowed 
     
    724725} 
    725726 
    726 =begin TML 
    727  
    728 ---++ StaticMethod isRedirectSafe($redirect) => $ok 
    729  
    730 tests if the $redirect is an external URL, returning false if AllowRedirectUrl is denied 
    731  
    732 =cut 
    733  
    734 sub isRedirectSafe { 
     727# Tests if the $redirect is an external URL, returning false if 
     728# AllowRedirectUrl is denied 
     729sub _isRedirectSafe { 
    735730    my $redirect = shift; 
    736731 
     
    758753} 
    759754 
    760 # _getRedirectUrl() => redirectURL set from the parameter 
    761 # Reads a redirect url from CGI parameter 'redirectto'. 
    762 # This function is used to get and test the 'redirectto' cgi parameter, 
    763 # and then the calling function can set its own reporting if there is a 
    764 # problem. 
    765 sub _getRedirectUrl { 
    766     my $session = shift; 
    767  
    768     my $query       = $session->{request}; 
    769     my $redirecturl = $query->param('redirectto'); 
    770     return '' unless $redirecturl; 
     755=begin TML 
     756 
     757---++ ObjectMethod redirectto($url) -> $url 
     758Gets a redirect url from CGI parameter 'redirectto', if present on the query. 
     759 
     760If the redirectto CGI parameter specifies a valid redirection target it is 
     761returned; otherwise the original URL passed in the parameter is returned. 
     762 
     763Conditions for a valid redirection target are: 
     764   * The target matches the linkProtocolPattern regex, and redirection 
     765     to the url _isRedirectSafe 
     766   * The target specified a topic, or a Web.Topic (redirect will be to 
     767     'view') 
     768 
     769=cut 
     770 
     771sub redirectto { 
     772    my ($this, $url) = @_; 
     773    ASSERT($url); 
     774 
     775    my $redirecturl = $this->{request}->param('redirectto'); 
     776    return $url unless $redirecturl; 
    771777 
    772778    if ( $redirecturl =~ m#^$regex{linkProtocolPattern}://#o ) { 
    773779 
    774780        # assuming URL 
    775         if ( isRedirectSafe($redirecturl) ) { 
     781        if ( _isRedirectSafe($redirecturl) ) { 
    776782            return $redirecturl; 
    777783        } 
    778784        else { 
    779             return ''; 
     785            return $url; 
    780786        } 
    781787    } 
     
    783789    # assuming 'web.topic' or 'topic' 
    784790    my ( $w, $t ) = 
    785       $session->normalizeWebTopicName( $session->{webName}, $redirecturl ); 
    786     $redirecturl = $session->getScriptUrl( 1, 'view', $w, $t ); 
    787     return $redirecturl; 
    788 } 
    789  
    790 =begin TML 
    791  
    792 ---++ ObjectMethod redirect( $url, $passthrough, $action_redirectto ) 
     791      $this->normalizeWebTopicName( $this->{webName}, $redirecturl ); 
     792    return $this->getScriptUrl( 1, 'view', $w, $t ); 
     793} 
     794 
     795=begin TML 
     796 
     797---++ ObjectMethod redirect( $url, $passthrough ) 
    793798 
    794799   * $url - url or topic to redirect to 
    795    * $passthrough - (optional) parameter to **FILLMEIN** 
    796    * $action_redirectto - (optional) redirect to where ?redirectto= 
    797      points to (if it's valid) 
     800   * $passthrough - (optional) parameter to pass through current query 
     801     parameters (see below) 
    798802 
    799803Redirects the request to =$url=, *unless* 
    800804   1 It is overridden by a plugin declaring a =redirectCgiQueryHandler=. 
    801805   1 =$session->{request}= is =undef= or 
    802    1 $query->param('noredirect') is set to a true value. 
    803806Thus a redirect is only generated when in a CGI context. 
    804807 
     
    820823 
    821824sub redirect { 
    822     my ( $this, $url, $passthru, $action_redirectto ) = @_; 
     825    my ( $this, $url, $passthru ) = @_; 
     826    ASSERT(defined $url); 
    823827 
    824828    my $query = $this->{request}; 
     
    826830    # if we got here without a query, there's not much more we can do 
    827831    return unless $query; 
    828  
    829     # SMELL: if noredirect is set, don't generate the redirect, throw an 
    830     # exception instead. This is a HACK used to support TWikiDrawPlugin. 
    831     # It is deprecated and must be replaced by REST handlers in the plugin. 
    832     if ( $query->param('noredirect') ) { 
    833         die "ERROR: $url"; 
    834         return; 
    835     } 
    836  
    837     if ($action_redirectto) { 
    838         my $redir = _getRedirectUrl($this); 
    839         $url = $redir if ($redir); 
    840     } 
    841832 
    842833    if ( $passthru && defined $query->method() ) { 
     
    872863    # do this check as late as possible to catch _any_ last minute hacks 
    873864    # TODO: this should really use URI 
    874     if ( !isRedirectSafe($url) ) { 
     865    if ( !_isRedirectSafe($url) ) { 
    875866 
    876867        # goto oops if URL is trying to take us somewhere dangerous 
     
    962953    my ($name) = @_; 
    963954 
    964     return isValidWikiWord(@_) || isValidAbbrev(@_); 
    965 } 
    966  
    967 =begin TML 
    968  
    969 ---++ StaticMethod isValidAbbrev( $name ) -> $boolean 
    970  
    971 Check for a valid ABBREV (acronym) 
    972  
    973 =cut 
    974  
    975 sub isValidAbbrev { 
    976     my $name = shift || ''; 
    977     return ( $name =~ m/^$regex{abbrevRegex}$/o ); 
     955    return ( $name =~ m/^$regex{topicNameRegex}$/o ); 
    978956} 
    979957 
     
    11481126    while ( my $p = shift @args ) { 
    11491127        if ( $p eq '#' ) { 
    1150             $anchor .= '#' . shift(@args); 
     1128            $anchor .= '#' . urlEncode( shift(@args) ); 
    11511129        } 
    11521130        else { 
     
    38593837        # Issues multi-valued parameters as separate hiddens 
    38603838        my $value = $this->{request}->param($name); 
     3839        $value = '' unless defined $value; 
    38613840        $name = _encode( $encoding, $name ); 
    38623841        $value = _encode( $encoding, $value ); 
  • trunk/core/lib/Foswiki/Func.pm

    r1050 r1221  
    12781278=begin TML 
    12791279 
    1280 ---+++ saveTopic( $web, $topic, $meta, $text, $options ) -> $error 
     1280---+++ saveTopic( $web, $topic, $meta, $text, $options ) 
    12811281 
    12821282   * =$web= - web for the topic 
     
    12891289     | =forcenewrevision= | force the save to increment the revision counter | 
    12901290     | =minor= | True if this is a minor change, and is not to be notified | 
    1291 Return: error message or undef. 
    12921291 
    12931292For example, 
     
    13001299__Note:__ Plugins handlers ( e.g. =beforeSaveHandler= ) will be called as 
    13011300appropriate. 
     1301 
     1302In the event of an error an exception will be thrown. Callers can elect 
     1303to trap the exceptions thrown, or allow them to propagate to the calling 
     1304environment. May throw Foswiki::OopsException, Foswiki::AccessControlException or Error::Simple. 
    13021305 
    13031306=cut 
     
    23202323=begin TML 
    23212324 
    2322 ---+++ getRegularExpression( $name ) -> $expr 
    2323  
    2324 Retrieves a Foswiki predefined regular expression or character class. 
    2325    * =$name= - Name of the expression to retrieve.  See notes below 
    2326 Return: String or precompiled regular expression matching as described below. 
    2327  
    2328 __Note:__ Foswiki internally precompiles several regular expressions to 
    2329 represent various string entities in an <nop>I18N-compatible manner. Plugins 
    2330 authors are encouraged to use these in matching where appropriate. The 
    2331 following are guaranteed to be present. Others may exist, but their use 
    2332 is unsupported and they may be removed in future Foswiki versions. 
    2333  
    2334 In the table below, the expression marked type 'String' are intended for 
    2335 use within character classes (i.e. for use within square brackets inside 
    2336 a regular expression), for example: 
    2337 <verbatim> 
    2338    my $upper = Foswiki::Func::getRegularExpression('upperAlpha'); 
    2339    my $alpha = Foswiki::Func::getRegularExpression('mixedAlpha'); 
    2340    my $capitalized = qr/[$upper][$alpha]+/; 
    2341 </verbatim> 
    2342 Those expressions marked type 'RE' are precompiled regular expressions that can be used outside square brackets. For example: 
    2343 <verbatim> 
    2344    my $webRE = Foswiki::Func::getRegularExpression('webNameRegex'); 
    2345    my $isWebName = ( $s =~ m/$webRE/ ); 
    2346 </verbatim> 
    2347  
    2348 | *Name*         | *Matches*                        | *Type* | 
    2349 | upperAlpha     | Upper case characters            | String | 
    2350 | upperAlphaNum  | Upper case characters and digits | String | 
    2351 | lowerAlpha     | Lower case characters            | String | 
    2352 | lowerAlphaNum  | Lower case characters and digits | String | 
    2353 | numeric        | Digits                           | String | 
    2354 | mixedAlpha     | Alphabetic characters            | String | 
    2355 | mixedAlphaNum  | Alphanumeric characters          | String | 
    2356 | wikiWordRegex  | WikiWords                        | RE | 
    2357 | webNameRegex   | User web names                   | RE | 
    2358 | anchorRegex    | #AnchorNames                     | RE | 
    2359 | abbrevRegex    | Abbreviations e.g. GOV, IRS      | RE | 
    2360 | emailAddrRegex | email@address.com                | RE | 
    2361 | tagNameRegex   | Standard variable names e.g. %<nop>THIS_BIT% (THIS_BIT only) | RE | 
    2362  
    2363 =cut 
    2364  
    2365 sub getRegularExpression { 
    2366     my ($regexName) = @_; 
    2367     return $Foswiki::regex{$regexName}; 
    2368 } 
    2369  
    2370 =begin TML 
    2371  
    23722325---+++ normalizeWebTopicName($web, $topic) -> ($web, $topic) 
    23732326 
     
    25092462=begin TML 
    25102463 
     2464---+++ isValidWebName( $name, $system ) -> $boolean 
     2465 
     2466Check for a valid web name. If $system is true, then 
     2467system web names are considered valid (names starting with _) 
     2468otherwise only user web names are valid 
     2469 
     2470If $Foswiki::cfg{EnableHierarchicalWebs} is off, it will also return false 
     2471when a nested web name is passed to it. 
     2472 
     2473=cut 
     2474 
     2475sub isValidWebName { 
     2476    return Foswiki::isValidWebName(@_); 
     2477} 
     2478 
     2479=begin TML 
     2480 
     2481---++ StaticMethod isValidTopicName( $name ) -> $boolean 
     2482 
     2483Check for a valid topic name. 
     2484 
     2485=cut 
     2486 
     2487sub isValidTopicName { 
     2488    return Foswiki::isValidTopicName(@_); 
     2489} 
     2490 
     2491=begin TML 
     2492 
    25112493---+++ extractParameters($attr ) -> %params 
    25122494 
     
    25812563The following functions are retained for compatibility only. You should 
    25822564stop using them as soon as possible. 
     2565 
     2566=cut 
     2567 
     2568=begin TML 
     2569 
     2570---+++ getRegularExpression( $name ) -> $expr 
     2571 
     2572*Deprecated* 28 Nov 2008 - use =$Foswiki::regex{...}= instead, it is directly 
     2573equivalent. 
     2574 
     2575See System.DevelopingPlugins for more information 
     2576 
     2577=cut 
     2578 
     2579sub getRegularExpression { 
     2580    my ($regexName) = @_; 
     2581    return $Foswiki::regex{$regexName}; 
     2582} 
     2583 
     2584=begin TML 
    25832585 
    25842586---+++ getScriptUrlPath( ) -> $path 
  • trunk/core/lib/Foswiki/LoginManager/ApacheLogin.pm

    r1050 r1221  
    120120    $url .= ( ';' . $query->query_string() ) if $query->query_string(); 
    121121 
    122     $session->redirect( $url, 1 ); 
     122    $session->redirect( $url, 1 ); # with passthrough 
    123123} 
    124124 
  • trunk/core/lib/Foswiki/LoginManager/TemplateLogin.pm

    r1195 r1221  
    6464        my $url   = $session->getScriptUrl( 0, 'login', $web, $topic ); 
    6565        $query->param( -name => 'origurl', -value => $session->{request}->uri ); 
    66         $session->redirect( $url, 1 ); 
     66        $session->redirect( $url, 1 ); # with passthrough 
    6767        return 1; 
    6868    } 
     
    162162              ; #remove the sudo param - its only to tell TemplateLogin that we're using BaseMapper.. 
    163163                # Redirect with passthrough 
    164             $sessionSession->redirect( $origurl, 1 ); 
     164            $sessionSession->redirect( $origurl, 1 ); # with passthrough 
    165165            return; 
    166166        } 
  • trunk/core/lib/Foswiki/OopsException.pm

    r1127 r1221  
    8787    my $this     = $class->SUPER::new(); 
    8888    $this->{template} = $template; 
     89    $this->{status} = 500; # default server error 
    8990    ASSERT( scalar(@_) % 2 == 0, join( ";", map { $_ || 'undef' } @_ ) ) 
    9091      if DEBUG; 
     
    177178 
    178179    my @p = $this->_prepareResponse( $session ); 
    179     $session->{response}->status( $this->{status} || 500 ); 
     180    $session->{response}->status( $this->{status} ); 
    180181    require Foswiki::UI::Oops; 
    181182    Foswiki::UI::Oops::oops($session, $this->{web}, $this->{topic}, 
  • trunk/core/lib/Foswiki/Render.pm

    r1206 r1221  
    467467    } 
    468468 
    469     # No need to encode 8-bit characters in anchor due to UTF-8 URL support 
    470  
    471     return $anchorName; 
     469    # There should be no need to encode 8-bit characters in anchor 
     470    # due to UTF-8 URL support. However encoding apparently cures Item5962 
     471 
     472    return Foswiki::urlEncode( $anchorName ); 
    472473} 
    473474 
  • trunk/core/lib/Foswiki/UI/Manage.pm

    r1206 r1221  
    263263| =currentwebonly= | if defined, searches current web only for links to this topic | 
    264264| =nonwikiword= | if defined, a non-wikiword is acceptable for the new topic name | 
     265| =redirectto= | If the rename process is successful, rename will redirect to this topic or URL. The parameter value can be a =TopicName=, a =Web.TopicName=, or a URL.%BR% __Note:__ Redirect to a URL only works if it is enabled in =configure= (Miscellaneous ={AllowRedirectUrl}=). | 
    265266 
    266267=cut 
     
    462463    } 
    463464 
    464     #follow redirectto= 
    465     $session->redirect( $new_url, undef, 1 ); 
     465    # follow redirectto 
     466    $session->redirect( $session->redirectto( $new_url ) ); 
    466467} 
    467468 
     
    15871588    }; 
    15881589    my $viewURL = $session->getScriptUrl( 0, 'view', $web, $topic ); 
    1589     $session->redirect( $viewURL, undef, 1 ); 
    1590     return; 
    1591  
     1590    $session->redirect( $session->redirectto($viewURL) ); 
    15921591} 
    15931592 
  • trunk/core/lib/Foswiki/UI/Register.pm

    r1127 r1221  
    200200    $session->leaveContext('absolute_urls'); 
    201201 
    202     $session->redirect( $session->getScriptUrl( 1, 'view', $web, $logTopic ) ); 
     202    my $nurl = $session->getScriptUrl( 1, 'view', $web, $logTopic ); 
     203    $session->redirect( $nurl ); 
    203204} 
    204205 
  • trunk/core/lib/Foswiki/UI/Rest.pm

    r1078 r1221  
    1616 
    1717sub rest { 
    18     my ( $twiki, %initialContext ) = @_; 
     18    my ( $session, %initialContext ) = @_; 
    1919 
    20     my $query = $twiki->{request}; 
     20    my $query = $session->{request}; 
    2121    my $login = $query->param('username'); 
    2222    my $pass  = $query->param('password'); 
     
    2828    if ($topic) { 
    2929        unless ( $topic =~ /((?:.*[\.\/])+)(.*)/ ) { 
    30             my $res = $twiki->{response}; 
     30            my $res = $session->{response}; 
    3131            $res->header( 
    3232                -type   => 'text/html', 
     
    4242 
    4343        # Point it somewhere innocent 
    44         $twiki->{webName}   = $Foswiki::cfg{UsersWebName}; 
    45         $twiki->{topicName} = $Foswiki::cfg{HomeTopicName}; 
     44        $session->{webName}   = $Foswiki::cfg{UsersWebName}; 
     45        $session->{topicName} = $Foswiki::cfg{HomeTopicName}; 
    4646    } 
    4747 
    4848    if ($login) { 
    49         my $validation = $twiki->{users}->checkPassword( $login, $pass ); 
     49        my $validation = $session->{users}->checkPassword( $login, $pass ); 
    5050        unless ($validation) { 
    51             my $res = $twiki->{response}; 
     51            my $res = $session->{response}; 
    5252            $res->header( 
    5353                -type   => 'text/html', 
     
    5959        } 
    6060 
    61         my $cUID     = $twiki->{users}->getCanonicalUserID($login); 
    62         my $WikiName = $twiki->{users}->getWikiName($cUID); 
    63         $twiki->{users}->{loginManager}->userLoggedIn( $login, $WikiName ); 
     61        my $cUID     = $session->{users}->getCanonicalUserID($login); 
     62        my $WikiName = $session->{users}->getWikiName($cUID); 
     63        $session->{users}->{loginManager}->userLoggedIn( $login, $WikiName ); 
    6464 
    65 #TODO: its a bit odd that $twiki->{user} has to be manually set (expected userLoggedIn would do it) 
    66         $twiki->{user} = $cUID; 
     65#TODO: its a bit odd that $session->{user} has to be manually set (expected userLoggedIn would do it) 
     66        $session->{user} = $cUID; 
    6767    } 
    6868 
    6969    try { 
    70         $twiki->{users}->{loginManager}->checkAccess(); 
     70        $session->{users}->{loginManager}->checkAccess(); 
    7171    } 
    7272    catch Error with { 
    7373        my $e   = shift; 
    74         my $res = $twiki->{response}; 
     74        my $res = $session->{response}; 
    7575        $res->header( 
    7676            -type   => 'text/html', 
     
    8787        # Foswiki rest invocations are defined as having a subject (pluginName) 
    8888        # and verb (restHandler in that plugin) 
    89         my $res = $twiki->{response}; 
     89        my $res = $session->{response}; 
    9090        $res->header( 
    9191            -type   => 'text/html', 
     
    9999 
    100100    unless ( Foswiki::isValidWikiWord($subject) ) { 
    101         my $res = $twiki->{response}; 
     101        my $res = $session->{response}; 
    102102        $res->header( 
    103103            -type   => 'text/html', 
     
    111111    my $function = $Foswiki::restDispatch{$subject}{$verb}; 
    112112    unless ($function) { 
    113         my $res = $twiki->{response}; 
     113        my $res = $session->{response}; 
    114114        $res->header( 
    115115            -type   => 'text/html', 
     
    122122 
    123123    no strict 'refs'; 
    124     my $result = &$function( $twiki, $subject, $verb, $twiki->{response} ); 
     124    my $result = &$function( $session, $subject, $verb, $session->{response} ); 
    125125    use strict 'refs'; 
    126126    my $endPoint = $query->param('endPoint'); 
    127127    if ( defined($endPoint) ) { 
    128         $twiki->redirect( $twiki->getScriptUrl( 1, 'view', '', $endPoint ) ); 
     128        my $nurl = $session->getScriptUrl( 1, 'view', '', $endPoint ); 
     129        $session->redirect( $nurl ); 
    129130    } 
    130131    else { 
    131         $twiki->writeCompletePage($result) if $result; 
     132        $session->writeCompletePage($result) if $result; 
    132133    } 
    133134} 
  • trunk/core/lib/Foswiki/UI/Save.pm

    r1127 r1221  
    441441        } 
    442442        my $viewURL = $session->getScriptUrl( 1, 'view', $w, $t ); 
    443         $session->redirect( $viewURL, undef, 1 ); 
     443        $session->redirect( $session->redirectto($viewURL) ); 
    444444 
    445445        return; 
     
    498498 
    499499        # drop through 
     500    } else { 
     501         $redirecturl = $session->getScriptUrl( 1, 'view', $web, $topic ); 
     502     } 
     503 
     504    # Do we have ?redirectto= 
     505    if ($saveaction ne 'checkpoint') { 
     506        $redirecturl = $session->redirectto($redirecturl); 
    500507    } 
    501508 
     
    530537 
    531538    #success - redirect to topic view (unless its a checkpoint save) 
    532     $redirecturl ||= $session->getScriptUrl( 1, 'view', $web, $topic ); 
    533539 
    534540    if ( $saveCmd eq 'delRev' ) { 
     
    548554        }; 
    549555 
    550         $session->redirect( $redirecturl, undef, 1 ); 
     556        $session->redirect( $redirecturl ); 
    551557        return; 
    552558    } 
     
    577583        }; 
    578584 
    579         $session->redirect( $redirecturl, undef, 
    580             ( $saveaction ne 'checkpoint' ) ); 
     585        $session->redirect( $redirecturl); 
    581586        return; 
    582587    } 
     
    620625    } 
    621626 
    622     $session->redirect( $redirecturl, undef, ( $saveaction ne 'checkpoint' ) ); 
     627    $session->redirect( $redirecturl ); 
    623628} 
    624629 
  • trunk/core/lib/Foswiki/UI/Upload.pm

    r1127 r1221  
    119119CGI parameters, passed in $query: 
    120120 
    121 | =hidefile= | if defined, will not show file in attachment table | 
    122 | =filepath= | | 
    123 | =filename= | | 
    124 | =filecomment= | comment to associate with file in attachment table | 
    125 | =createlink= | if defined, will create a link to file at end of topic | 
    126 | =changeproperties= | | 
    127 | =redirectto= | URL to redirect to after upload. ={AllowRedirectUrl}= must be enabled in =configure=. The parameter value can be a =TopicName=, a =Web.TopicName=, or a URL. Redirect to a URL only works if it is enabled in =configure=. | 
    128  
    129 Does the work of uploading a file to a topic. Designed to be useable for 
    130 a crude RPC (it will redirect to the 'view' script unless the 
    131 'noredirect' parameter is specified, in which case it will print a message to 
    132 STDOUT, starting with 'OK' on success and 'ERROR' on failure. 
     121Does the work of uploading an attachment to a topic. 
     122 
     123   * =hidefile= - if defined, will not show file in attachment table 
     124   * =filepath= - 
     125   * =filename= - 
     126   * =filecomment= - comment to associate with file in attachment table 
     127   * =createlink= - if defined, will create a link to file at end of topic 
     128   * =changeproperties= - 
     129   * =redirectto= - URL to redirect to after upload. ={AllowRedirectUrl}= 
     130     must be enabled in =configure=. The parameter value can be a 
     131     =TopicName=, a =Web.TopicName=, or a URL. Redirect to a URL only works 
     132     if it is enabled in =configure=, and is ignored if =noredirect= is 
     133     specified. 
     134   * =noredirect= - Normally it will redirect to 'view' when the upload is 
     135     complete, but also designed to be useable for REST-style calling using 
     136     the 'noredirect' parameter. If this parameter is set it will return an 
     137     appropriate HTTP status code and print a message to STDOUT, starting 
     138     with 'OK' on success and 'ERROR' on failure. 
    133139 
    134140=cut 
    135141 
    136142sub upload { 
     143    my $session = shift; 
     144 
     145    my $query   = $session->{request}; 
     146    if ($query->param('noredirect')) { 
     147        my $message; 
     148        my $status = 200; 
     149        try { 
     150            $message = _upload($session); 
     151        } catch Foswiki::OopsException with { 
     152            my $e = shift; 
     153            $status = $e->{status}; 
     154            if ($status >= 400) { 
     155                $message = 'ERROR: '.$e->stringify(); 
     156            } 
     157        } catch Foswiki::AccessControlException with { 
     158            my $e = shift; 
     159            $status = 403; 
     160            $message = 'ERROR: '.$e->stringify(); 
     161        }; 
     162        if ($status < 400) { 
     163            $message = 'OK '.$message; 
     164        }; 
     165        $session->{response}->header( 
     166            -status => $status, 
     167            -type => 'text/plain'); 
     168        $session->{response}->print($message); 
     169    } else { 
     170        # allow exceptions to propagate 
     171        _upload($session); 
     172 
     173        my $nurl = $session->getScriptUrl( 
     174            1, 'view', $session->{webName}, $session->{topicName} ); 
     175        $session->redirect( $session->redirectto( $nurl )); 
     176    }; 
     177} 
     178 
     179# Real work of upload 
     180sub _upload { 
    137181    my $session = shift; 
    138182 
     
    159203    $filePath    =~ s/\s*$//o; 
    160204 
    161     Foswiki::UI::checkWebExists( $session, $webName, $topic, 'attach files to' ); 
     205    Foswiki::UI::checkWebExists( 
     206        $session, $webName, $topic, 'attach files to' ); 
    162207    Foswiki::UI::checkTopicExists( $session, $webName, $topic, 
    163         'attach files to' ); 
     208                                   'attach files to' ); 
    164209    Foswiki::UI::checkMirror( $session, $webName, $topic ); 
    165     Foswiki::UI::checkAccess( $session, $webName, $topic, 'CHANGE', $user ); 
     210    Foswiki::UI::checkAccess( 
     211        $session, $webName, $topic, 'CHANGE', $user ); 
    166212 
    167213    my $origName = $fileName; 
     
    174220        try { 
    175221            $tmpFilePath = $query->tmpFileName($fh); 
    176         } 
    177         catch Error::Simple with { 
     222        } catch Error::Simple with { 
    178223 
    179224            # Item5130, Item5133 - Illegal file name, bad path, 
     
    185230                topic  => $topic, 
    186231                params => [ ( $filePath || '""' ) ] 
    187             ); 
     232               ); 
    188233        }; 
    189234 
     
    205250                topic  => $topic, 
    206251                params => [ ( $filePath || '""' ) ] 
    207             ); 
     252               ); 
    208253        } 
    209254 
     
    219264                topic  => $topic, 
    220265                params => [ $fileName, $maxSize ] 
    221             ); 
     266               ); 
    222267        } 
    223268    } 
     
    238283                tmpFilename => $tmpFilePath, 
    239284            } 
    240         ); 
    241     } 
    242     catch Error::Simple with { 
     285           ); 
     286    } catch Error::Simple with { 
    243287        throw Foswiki::OopsException( 
    244288            'attention', 
     
    247291            topic  => $topic, 
    248292            params => [ shift->{-text} ] 
    249         ); 
     293           ); 
    250294    }; 
    251295    close($stream) if $stream; 
    252296 
    253     if ( $fileName eq $origName ) { 
    254         $session->redirect( 
    255             $session->getScriptUrl( 1, 'view', $webName, $topic ), 
    256             undef, 1 ); 
    257     } 
    258     else { 
     297    if ( $fileName ne $origName ) { 
    259298        throw Foswiki::OopsException( 
    260299            'attention', 
     
    264303            topic  => $topic, 
    265304            params => [ $origName, $fileName ] 
    266         ); 
    267     } 
    268  
    269  # generate a message useful for those calling this script from the command line 
    270     my $message = ($doPropsOnly) ? 'properties changed' : "$fileName uploaded"; 
    271  
    272     print 'OK ', $message, "\n" if $session->inContext('command_line'); 
     305           ); 
     306    } 
     307 
     308    # generate a message useful for those calling this script 
     309    # from the command line 
     310    return ($doPropsOnly) ? 'properties changed' : 
     311      "$fileName uploaded"; 
    273312} 
    274313 
Note: See TracChangeset for help on using the changeset viewer.