Changeset 1221
- Timestamp:
- 12/09/08 18:16:48 (3 years ago)
- Location:
- trunk/core
- Files:
-
- 13 edited
-
data/System/CommandAndCGIScripts.txt (modified) (1 diff)
-
data/System/DevelopingPlugins.txt (modified) (5 diffs)
-
lib/Foswiki.pm (modified) (10 diffs)
-
lib/Foswiki/Func.pm (modified) (6 diffs)
-
lib/Foswiki/LoginManager/ApacheLogin.pm (modified) (1 diff)
-
lib/Foswiki/LoginManager/TemplateLogin.pm (modified) (2 diffs)
-
lib/Foswiki/OopsException.pm (modified) (2 diffs)
-
lib/Foswiki/Render.pm (modified) (1 diff)
-
lib/Foswiki/UI/Manage.pm (modified) (3 diffs)
-
lib/Foswiki/UI/Register.pm (modified) (1 diff)
-
lib/Foswiki/UI/Rest.pm (modified) (8 diffs)
-
lib/Foswiki/UI/Save.pm (modified) (6 diffs)
-
lib/Foswiki/UI/Upload.pm (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/data/System/CommandAndCGIScripts.txt
r1163 r1221 322 322 | =createlink= | if defined, will create a link to file at end of topic | | 323 323 | =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. 326 339 327 340 ---+++ =view= -
trunk/core/data/System/DevelopingPlugins.txt
r1041 r1221 1 1 ---+ Developing Plugins 2 2 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.3 Foswiki 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. 4 4 5 5 To address this problem Foswiki provides a number of Application Program Interfaces (APIs) that allow you to extend Foswiki in a robust way. … … 7 7 The 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=. 8 8 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.9 To 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. 10 10 * =[[%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. 11 11 * =[[%SCRIPTURL{view}%/%SYSTEMWEB%/PerlDoc?module=Foswiki::Func][Foswiki::Func]]= - bridge to core functions. This is the package you will use most. … … 19 19 * =$Foswiki::Plugins::SESSION= - reference to =Foswiki= singleton object 20 20 * =$Foswiki::cfg= - reference to configuration hash 21 * =$Foswiki::regex - see 'Standard Regular Expressions', below 21 22 * =$Foswiki::sandbox= - reference to the static sandbox object (type =Foswiki::Sandbox=), used for calling external programs. 22 23 %I% Foswiki:Development.GettingStarted is the starting point for more comprehensive documentation on developing for Foswiki. 23 24 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. 27 This will only be a problem if you are writing an extension that doesn't 28 use the standard initialisation sequence. 29 30 ---+++ Standard Regular Expressions 31 A 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 33 following are guaranteed to be present. Others may exist, but their use 34 is unsupported and they may be removed in future Foswiki versions. 35 36 In the table below, the expression marked type 'String' are intended for 37 use within character classes (i.e. for use within square brackets inside 38 a regular expression), for example: 39 <verbatim> 40 my $isCapitalizedWord = 41 ( $s =~ /[$Foswiki::regex{upperAlpha}][$Foswiki::regex{mixedAlpha}]+/ ); 42 </verbatim> 43 Those 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 66 Plugins '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 68 Foswiki:Development.StepByStepRenderingOrder helps you decide which rendering handler to use. See [[EmptyPlugin]] for a full list of the handlers that are defined. 29 69 30 70 #FastPluginHints … … 44 84 45 85 * All plugin packages require a =$VERSION= variable. This should be an integer, or a subversion version id. 46 47 86 * The =initPlugin= handler should check all dependencies and return 1 if the initialization is OK or 0 if something went wrong. 48 87 * The plugin initialization code does not register a plugin that returns 0 (or that has no =initPlugin= handler). 49 50 88 * =$Foswiki::Plugins::VERSION= in the =Foswiki::Plugins= module contains the Foswiki plugin API version, currently *%PLUGINVERSION{}%*. 51 89 * You can also use the =[[VarPLUGINVERSION][%<nop>PLUGINVERSION{}%]]= macro to query the plugin API version or the version of installed plugins. … … 53 91 ---+++ Security 54 92 55 * Badly written plugins can open hugesecurity 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. 57 95 * [[#ConfigSpec][Integrating with <code>configure</code>]] describes the steps 58 96 * Foswiki:Extensions.MailInContrib has an example 59 97 * 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//. 61 101 * 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. 62 102 -
trunk/core/lib/Foswiki.pm
r1206 r1221 407 407 $regex{anchorRegex} = qr/\#[$regex{mixedAlphaNum}_]+/o; 408 408 $regex{abbrevRegex} = qr/[$regex{upperAlpha}]{3,}s?\b/o; 409 409 $regex{topicNameRegex} = 410 qr/(?:(?:$regex{wikiWordRegex})|(?:$regex{abbrevRegex}))/o; 410 411 # Simplistic email regex, e.g. for WebNotify processing - no i18n 411 412 # characters allowed … … 724 725 } 725 726 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 729 sub _isRedirectSafe { 735 730 my $redirect = shift; 736 731 … … 758 753 } 759 754 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 758 Gets a redirect url from CGI parameter 'redirectto', if present on the query. 759 760 If the redirectto CGI parameter specifies a valid redirection target it is 761 returned; otherwise the original URL passed in the parameter is returned. 762 763 Conditions 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 771 sub redirectto { 772 my ($this, $url) = @_; 773 ASSERT($url); 774 775 my $redirecturl = $this->{request}->param('redirectto'); 776 return $url unless $redirecturl; 771 777 772 778 if ( $redirecturl =~ m#^$regex{linkProtocolPattern}://#o ) { 773 779 774 780 # assuming URL 775 if ( isRedirectSafe($redirecturl) ) {781 if ( _isRedirectSafe($redirecturl) ) { 776 782 return $redirecturl; 777 783 } 778 784 else { 779 return '';785 return $url; 780 786 } 781 787 } … … 783 789 # assuming 'web.topic' or 'topic' 784 790 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 ) 793 798 794 799 * $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) 798 802 799 803 Redirects the request to =$url=, *unless* 800 804 1 It is overridden by a plugin declaring a =redirectCgiQueryHandler=. 801 805 1 =$session->{request}= is =undef= or 802 1 $query->param('noredirect') is set to a true value.803 806 Thus a redirect is only generated when in a CGI context. 804 807 … … 820 823 821 824 sub redirect { 822 my ( $this, $url, $passthru, $action_redirectto ) = @_; 825 my ( $this, $url, $passthru ) = @_; 826 ASSERT(defined $url); 823 827 824 828 my $query = $this->{request}; … … 826 830 # if we got here without a query, there's not much more we can do 827 831 return unless $query; 828 829 # SMELL: if noredirect is set, don't generate the redirect, throw an830 # 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 }841 832 842 833 if ( $passthru && defined $query->method() ) { … … 872 863 # do this check as late as possible to catch _any_ last minute hacks 873 864 # TODO: this should really use URI 874 if ( ! isRedirectSafe($url) ) {865 if ( !_isRedirectSafe($url) ) { 875 866 876 867 # goto oops if URL is trying to take us somewhere dangerous … … 962 953 my ($name) = @_; 963 954 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 ); 978 956 } 979 957 … … 1148 1126 while ( my $p = shift @args ) { 1149 1127 if ( $p eq '#' ) { 1150 $anchor .= '#' . shift(@args);1128 $anchor .= '#' . urlEncode( shift(@args) ); 1151 1129 } 1152 1130 else { … … 3859 3837 # Issues multi-valued parameters as separate hiddens 3860 3838 my $value = $this->{request}->param($name); 3839 $value = '' unless defined $value; 3861 3840 $name = _encode( $encoding, $name ); 3862 3841 $value = _encode( $encoding, $value ); -
trunk/core/lib/Foswiki/Func.pm
r1050 r1221 1278 1278 =begin TML 1279 1279 1280 ---+++ saveTopic( $web, $topic, $meta, $text, $options ) -> $error1280 ---+++ saveTopic( $web, $topic, $meta, $text, $options ) 1281 1281 1282 1282 * =$web= - web for the topic … … 1289 1289 | =forcenewrevision= | force the save to increment the revision counter | 1290 1290 | =minor= | True if this is a minor change, and is not to be notified | 1291 Return: error message or undef.1292 1291 1293 1292 For example, … … 1300 1299 __Note:__ Plugins handlers ( e.g. =beforeSaveHandler= ) will be called as 1301 1300 appropriate. 1301 1302 In the event of an error an exception will be thrown. Callers can elect 1303 to trap the exceptions thrown, or allow them to propagate to the calling 1304 environment. May throw Foswiki::OopsException, Foswiki::AccessControlException or Error::Simple. 1302 1305 1303 1306 =cut … … 2320 2323 =begin TML 2321 2324 2322 ---+++ getRegularExpression( $name ) -> $expr2323 2324 Retrieves a Foswiki predefined regular expression or character class.2325 * =$name= - Name of the expression to retrieve. See notes below2326 Return: String or precompiled regular expression matching as described below.2327 2328 __Note:__ Foswiki internally precompiles several regular expressions to2329 represent various string entities in an <nop>I18N-compatible manner. Plugins2330 authors are encouraged to use these in matching where appropriate. The2331 following are guaranteed to be present. Others may exist, but their use2332 is unsupported and they may be removed in future Foswiki versions.2333 2334 In the table below, the expression marked type 'String' are intended for2335 use within character classes (i.e. for use within square brackets inside2336 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 =cut2364 2365 sub getRegularExpression {2366 my ($regexName) = @_;2367 return $Foswiki::regex{$regexName};2368 }2369 2370 =begin TML2371 2372 2325 ---+++ normalizeWebTopicName($web, $topic) -> ($web, $topic) 2373 2326 … … 2509 2462 =begin TML 2510 2463 2464 ---+++ isValidWebName( $name, $system ) -> $boolean 2465 2466 Check for a valid web name. If $system is true, then 2467 system web names are considered valid (names starting with _) 2468 otherwise only user web names are valid 2469 2470 If $Foswiki::cfg{EnableHierarchicalWebs} is off, it will also return false 2471 when a nested web name is passed to it. 2472 2473 =cut 2474 2475 sub isValidWebName { 2476 return Foswiki::isValidWebName(@_); 2477 } 2478 2479 =begin TML 2480 2481 ---++ StaticMethod isValidTopicName( $name ) -> $boolean 2482 2483 Check for a valid topic name. 2484 2485 =cut 2486 2487 sub isValidTopicName { 2488 return Foswiki::isValidTopicName(@_); 2489 } 2490 2491 =begin TML 2492 2511 2493 ---+++ extractParameters($attr ) -> %params 2512 2494 … … 2581 2563 The following functions are retained for compatibility only. You should 2582 2564 stop 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 2573 equivalent. 2574 2575 See System.DevelopingPlugins for more information 2576 2577 =cut 2578 2579 sub getRegularExpression { 2580 my ($regexName) = @_; 2581 return $Foswiki::regex{$regexName}; 2582 } 2583 2584 =begin TML 2583 2585 2584 2586 ---+++ getScriptUrlPath( ) -> $path -
trunk/core/lib/Foswiki/LoginManager/ApacheLogin.pm
r1050 r1221 120 120 $url .= ( ';' . $query->query_string() ) if $query->query_string(); 121 121 122 $session->redirect( $url, 1 ); 122 $session->redirect( $url, 1 ); # with passthrough 123 123 } 124 124 -
trunk/core/lib/Foswiki/LoginManager/TemplateLogin.pm
r1195 r1221 64 64 my $url = $session->getScriptUrl( 0, 'login', $web, $topic ); 65 65 $query->param( -name => 'origurl', -value => $session->{request}->uri ); 66 $session->redirect( $url, 1 ); 66 $session->redirect( $url, 1 ); # with passthrough 67 67 return 1; 68 68 } … … 162 162 ; #remove the sudo param - its only to tell TemplateLogin that we're using BaseMapper.. 163 163 # Redirect with passthrough 164 $sessionSession->redirect( $origurl, 1 ); 164 $sessionSession->redirect( $origurl, 1 ); # with passthrough 165 165 return; 166 166 } -
trunk/core/lib/Foswiki/OopsException.pm
r1127 r1221 87 87 my $this = $class->SUPER::new(); 88 88 $this->{template} = $template; 89 $this->{status} = 500; # default server error 89 90 ASSERT( scalar(@_) % 2 == 0, join( ";", map { $_ || 'undef' } @_ ) ) 90 91 if DEBUG; … … 177 178 178 179 my @p = $this->_prepareResponse( $session ); 179 $session->{response}->status( $this->{status} || 500);180 $session->{response}->status( $this->{status} ); 180 181 require Foswiki::UI::Oops; 181 182 Foswiki::UI::Oops::oops($session, $this->{web}, $this->{topic}, -
trunk/core/lib/Foswiki/Render.pm
r1206 r1221 467 467 } 468 468 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 ); 472 473 } 473 474 -
trunk/core/lib/Foswiki/UI/Manage.pm
r1206 r1221 263 263 | =currentwebonly= | if defined, searches current web only for links to this topic | 264 264 | =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}=). | 265 266 266 267 =cut … … 462 463 } 463 464 464 # follow redirectto=465 $session->redirect( $ new_url, undef, 1);465 # follow redirectto 466 $session->redirect( $session->redirectto( $new_url ) ); 466 467 } 467 468 … … 1587 1588 }; 1588 1589 my $viewURL = $session->getScriptUrl( 0, 'view', $web, $topic ); 1589 $session->redirect( $viewURL, undef, 1 ); 1590 return; 1591 1590 $session->redirect( $session->redirectto($viewURL) ); 1592 1591 } 1593 1592 -
trunk/core/lib/Foswiki/UI/Register.pm
r1127 r1221 200 200 $session->leaveContext('absolute_urls'); 201 201 202 $session->redirect( $session->getScriptUrl( 1, 'view', $web, $logTopic ) ); 202 my $nurl = $session->getScriptUrl( 1, 'view', $web, $logTopic ); 203 $session->redirect( $nurl ); 203 204 } 204 205 -
trunk/core/lib/Foswiki/UI/Rest.pm
r1078 r1221 16 16 17 17 sub rest { 18 my ( $ twiki, %initialContext ) = @_;18 my ( $session, %initialContext ) = @_; 19 19 20 my $query = $ twiki->{request};20 my $query = $session->{request}; 21 21 my $login = $query->param('username'); 22 22 my $pass = $query->param('password'); … … 28 28 if ($topic) { 29 29 unless ( $topic =~ /((?:.*[\.\/])+)(.*)/ ) { 30 my $res = $ twiki->{response};30 my $res = $session->{response}; 31 31 $res->header( 32 32 -type => 'text/html', … … 42 42 43 43 # 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}; 46 46 } 47 47 48 48 if ($login) { 49 my $validation = $ twiki->{users}->checkPassword( $login, $pass );49 my $validation = $session->{users}->checkPassword( $login, $pass ); 50 50 unless ($validation) { 51 my $res = $ twiki->{response};51 my $res = $session->{response}; 52 52 $res->header( 53 53 -type => 'text/html', … … 59 59 } 60 60 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 ); 64 64 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; 67 67 } 68 68 69 69 try { 70 $ twiki->{users}->{loginManager}->checkAccess();70 $session->{users}->{loginManager}->checkAccess(); 71 71 } 72 72 catch Error with { 73 73 my $e = shift; 74 my $res = $ twiki->{response};74 my $res = $session->{response}; 75 75 $res->header( 76 76 -type => 'text/html', … … 87 87 # Foswiki rest invocations are defined as having a subject (pluginName) 88 88 # and verb (restHandler in that plugin) 89 my $res = $ twiki->{response};89 my $res = $session->{response}; 90 90 $res->header( 91 91 -type => 'text/html', … … 99 99 100 100 unless ( Foswiki::isValidWikiWord($subject) ) { 101 my $res = $ twiki->{response};101 my $res = $session->{response}; 102 102 $res->header( 103 103 -type => 'text/html', … … 111 111 my $function = $Foswiki::restDispatch{$subject}{$verb}; 112 112 unless ($function) { 113 my $res = $ twiki->{response};113 my $res = $session->{response}; 114 114 $res->header( 115 115 -type => 'text/html', … … 122 122 123 123 no strict 'refs'; 124 my $result = &$function( $ twiki, $subject, $verb, $twiki->{response} );124 my $result = &$function( $session, $subject, $verb, $session->{response} ); 125 125 use strict 'refs'; 126 126 my $endPoint = $query->param('endPoint'); 127 127 if ( defined($endPoint) ) { 128 $twiki->redirect( $twiki->getScriptUrl( 1, 'view', '', $endPoint ) ); 128 my $nurl = $session->getScriptUrl( 1, 'view', '', $endPoint ); 129 $session->redirect( $nurl ); 129 130 } 130 131 else { 131 $ twiki->writeCompletePage($result) if $result;132 $session->writeCompletePage($result) if $result; 132 133 } 133 134 } -
trunk/core/lib/Foswiki/UI/Save.pm
r1127 r1221 441 441 } 442 442 my $viewURL = $session->getScriptUrl( 1, 'view', $w, $t ); 443 $session->redirect( $ viewURL, undef, 1);443 $session->redirect( $session->redirectto($viewURL) ); 444 444 445 445 return; … … 498 498 499 499 # 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); 500 507 } 501 508 … … 530 537 531 538 #success - redirect to topic view (unless its a checkpoint save) 532 $redirecturl ||= $session->getScriptUrl( 1, 'view', $web, $topic );533 539 534 540 if ( $saveCmd eq 'delRev' ) { … … 548 554 }; 549 555 550 $session->redirect( $redirecturl , undef, 1);556 $session->redirect( $redirecturl ); 551 557 return; 552 558 } … … 577 583 }; 578 584 579 $session->redirect( $redirecturl, undef, 580 ( $saveaction ne 'checkpoint' ) ); 585 $session->redirect( $redirecturl); 581 586 return; 582 587 } … … 620 625 } 621 626 622 $session->redirect( $redirecturl , undef, ( $saveaction ne 'checkpoint' ));627 $session->redirect( $redirecturl ); 623 628 } 624 629 -
trunk/core/lib/Foswiki/UI/Upload.pm
r1127 r1221 119 119 CGI parameters, passed in $query: 120 120 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. 121 Does 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. 133 139 134 140 =cut 135 141 136 142 sub 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 180 sub _upload { 137 181 my $session = shift; 138 182 … … 159 203 $filePath =~ s/\s*$//o; 160 204 161 Foswiki::UI::checkWebExists( $session, $webName, $topic, 'attach files to' ); 205 Foswiki::UI::checkWebExists( 206 $session, $webName, $topic, 'attach files to' ); 162 207 Foswiki::UI::checkTopicExists( $session, $webName, $topic, 163 'attach files to' );208 'attach files to' ); 164 209 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 ); 166 212 167 213 my $origName = $fileName; … … 174 220 try { 175 221 $tmpFilePath = $query->tmpFileName($fh); 176 } 177 catch Error::Simple with { 222 } catch Error::Simple with { 178 223 179 224 # Item5130, Item5133 - Illegal file name, bad path, … … 185 230 topic => $topic, 186 231 params => [ ( $filePath || '""' ) ] 187 );232 ); 188 233 }; 189 234 … … 205 250 topic => $topic, 206 251 params => [ ( $filePath || '""' ) ] 207 );252 ); 208 253 } 209 254 … … 219 264 topic => $topic, 220 265 params => [ $fileName, $maxSize ] 221 );266 ); 222 267 } 223 268 } … … 238 283 tmpFilename => $tmpFilePath, 239 284 } 240 ); 241 } 242 catch Error::Simple with { 285 ); 286 } catch Error::Simple with { 243 287 throw Foswiki::OopsException( 244 288 'attention', … … 247 291 topic => $topic, 248 292 params => [ shift->{-text} ] 249 );293 ); 250 294 }; 251 295 close($stream) if $stream; 252 296 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 ) { 259 298 throw Foswiki::OopsException( 260 299 'attention', … … 264 303 topic => $topic, 265 304 params => [ $origName, $fileName ] 266 );267 } 268 269 # generate a message useful for those calling this script from the command line270 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"; 273 312 } 274 313
Note: See TracChangeset
for help on using the changeset viewer.
