Skip to content

Commit

Permalink
Item12952: Finish bootstrap of view w/ short urls
Browse files Browse the repository at this point in the history
The "installation instructions" to go along with this.
  - User installs foswiki
  - Configure apache with ApacheConfigGenerator
  - Visit the anticipated home url:
 ex: http://mysite.com/foswiki/Main/WebHome

  - The Bootstrap warning has link to configure.  Click configure and
    the view url is correctly bootstrapped.

I had to stash the initial view URL into a session variable because the
jsonrpc scripts need it, and they are invoked with POST.

The session variable code ... I think that could be moved to
ConfigurePlugin or the UI::Configure -  wasn't quite sure where to put
it,  but it works okay in Foswiki.pm

Also this changes the NOT_SET array to support multi-level parameters in
the bootstrap.
  • Loading branch information
gac410 committed Sep 3, 2014
1 parent fda7b8e commit a68c7cd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
32 changes: 30 additions & 2 deletions core/lib/Foswiki.pm
Expand Up @@ -405,7 +405,11 @@ BEGIN {
if (TRAUTO);
}

# Examine the CGI path
# Examine the CGI path. The 'view' script it typically removed from the
# URL when using "Short URLs. If this BEGIN block is being run by
# 'view', then $Foswiki::cfg{ScriptUrlPaths}{view} will be correctly
# bootstrapped. If run for any other script, it will be set to a
# reasonable though probably incorrect default.
if ( $ENV{SCRIPT_NAME} ) {
print STDERR "AUTOCONFIG: Found SCRIPT $ENV{SCRIPT_NAME} \n"
if (TRAUTO);
Expand Down Expand Up @@ -545,7 +549,7 @@ out by detecting the layout of the installation. Any requests made to this
Foswiki will be treated as requests made by an administrator with full rights
to make changes! You should either:
* correct any permissions problems with an existing !LocalSite.cfg (see the webserver error logs for details), or
* visit [[%SCRIPTURL{configure}%][configure]] as soon as possible to generate a new one.
* visit [[%SCRIPTURL{configure}%?VIEWPATH=$Foswiki::cfg{ScriptUrlPaths}{view}][configure]] as soon as possible to generate a new one.
BOOTS
}

Expand Down Expand Up @@ -2304,6 +2308,30 @@ sub new {
# Finish plugin initialization - register handlers
$this->{plugins}->enable();

# Bootstrap code. Capture the path for the "view" script from the URL
# and stash it into a session variable for use by jsonrpc commands.
# Or if it's not in the query, recover it from the session variable.
# (jsonrpc uses POSTs, so the URL param isn't there.
if ( $Foswiki::cfg{isBOOTSTRAPPING} && defined $query ) {
my $viewpath = $query->param('VIEWPATH');
if ( defined $viewpath ) {
$Foswiki::cfg{ScriptUrlPaths}{view} = $viewpath;
$Foswiki::Plugins::SESSION->getLoginManager()
->setSessionValue( 'VIEWPATH', $viewpath );
print STDERR "AUTOCONFIG: Applied viewpath $viewpath from URL\n";
}
else {
$viewpath =
$Foswiki::Plugins::SESSION->getLoginManager()
->getSessionValue('VIEWPATH');
if ( defined $viewpath ) {
$Foswiki::cfg{ScriptUrlPaths}{view} = $viewpath;
print STDERR
"AUTOCONFIG: Applied viewpath $viewpath from SESSION\n";
}
}
}

Monitor::MARK("Foswiki object created");

return $this;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki.spec
Expand Up @@ -113,7 +113,7 @@ $Foswiki::cfg{PathCheckLimit} = 7000;
# (so you'll have to leave this field empty if your wiki lives at the top level).
# <p></p>
# More information: <a href="http://foswiki.org/Support/ShorterUrlCookbook" target="_new">Shorter URL Cookbook</a>
$Foswiki::cfg{ScriptUrlPaths}{view} = '$Foswiki::cfg{ScriptUrlPath}/view$Foswiki::cfg{ScriptSuffix}';
#$Foswiki::cfg{ScriptUrlPaths}{view} = '$Foswiki::cfg{ScriptUrlPath}/view$Foswiki::cfg{ScriptSuffix}';

#! The following plugin must follow all other {ScriptUrlPaths} items
# *SCRIPTHASH*
Expand Down
15 changes: 5 additions & 10 deletions core/lib/Foswiki/Configure/Load.pm
Expand Up @@ -26,10 +26,9 @@ our $ITEMREGEX = qr/(?:\{(?:'(?:\\.|[^'])+'|"(?:\\.|[^"])+"|[A-Za-z0-9_]+)\})+/;
our $TRUE = 1;
our $FALSE = 0;

our @NOT_SET = qw( DataDir DefaultUrlHost PubUrlPath ToolsDir WorkingDir
PubDir TemplateDir ScriptDir ScriptUrlPath ScriptSuffix LocalesDir );

# {ScriptUrlPaths}{view} is also processed as NOT_SET
our @NOT_SET =
qw( {DataDir} {DefaultUrlHost} {PubUrlPath} {ToolsDir} {WorkingDir}
{PubDir} {TemplateDir} {ScriptDir} {ScriptUrlPath} {ScriptUrlPaths}{view} {ScriptSuffix} {LocalesDir} );

# Configuration items that have been deprecated and must be mapped to
# new configuration items. The value is mapped unchanged.
Expand Down Expand Up @@ -156,15 +155,11 @@ GOLLYGOSH
# a LocalSite.cfg, which we don't want
# die "$var must be defined in LocalSite.cfg"
# unless( defined $Foswiki::cfg{$var} );
unless ( defined $Foswiki::cfg{$var} ) {
$Foswiki::cfg{$var} = 'NOT SET';
unless ( eval("defined \$Foswiki::cfg$var") ) {
eval("\$Foswiki::cfg$var = 'NOT SET'");
$validLSC = 0;
}
}
unless ( defined $Foswiki::cfg{ScriptUrlPaths}{view} ) {
$Foswiki::cfg{ScriptUrlPaths}{view} = 'NOT SET';
$validLSC = 0;
}

# Patch deprecated config settings
if ( exists $Foswiki::cfg{StoreImpl} ) {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Configure/Wizards/Save.pm
Expand Up @@ -176,7 +176,7 @@ sub save {
if ( $Foswiki::cfg{isBOOTSTRAPPING} ) {
my %save;
foreach my $key (@Foswiki::Configure::Load::NOT_SET) {
$save{$key} = $Foswiki::cfg{$key};
eval("\$save$key = \$Foswiki::cfg$key ");
}

# Re-read LocalSite.cfg without expansions but with
Expand Down

0 comments on commit a68c7cd

Please sign in to comment.