Skip to content

Commit

Permalink
Item13897: Remove Foswiki::cfg access from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed Oct 18, 2016
1 parent 9ea06bb commit c77e8e4
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 54 deletions.
9 changes: 5 additions & 4 deletions UnitTestContrib/test/unit/ViewFileScriptTests.pm
Expand Up @@ -529,17 +529,18 @@ sub test_nested_web_secured_topic_filename_param {

sub test_MIME_types {
my $this = shift;
my $app = $this->app;

$this->assert_equals(
'application/vnd.adobe.air-application-installer-package+zip',
Foswiki::UI::Viewfile::_suffixToMimeType('blah.air')
Foswiki::UI::Viewfile::_suffixToMimeType( $app, 'blah.air' )
);
$this->assert_equals( 'text/h323',
Foswiki::UI::Viewfile::_suffixToMimeType('blah.323') );
Foswiki::UI::Viewfile::_suffixToMimeType( $app, 'blah.323' ) );
$this->assert_equals( 'application/octet-stream',
Foswiki::UI::Viewfile::_suffixToMimeType('blah.w02') );
Foswiki::UI::Viewfile::_suffixToMimeType( $app, 'blah.w02' ) );
$this->assert_equals( 'text/plain',
Foswiki::UI::Viewfile::_suffixToMimeType('blah.wibble') );
Foswiki::UI::Viewfile::_suffixToMimeType( $app, 'blah.wibble' ) );

return;
}
Expand Down
12 changes: 6 additions & 6 deletions core/lib/Foswiki/UI.pm
Expand Up @@ -52,8 +52,8 @@ sub logon {
my $app = $this->app;
my $req = $app->request;

if ( defined $Foswiki::cfg{LoginManager}
&& $Foswiki::cfg{LoginManager} eq 'none' )
if ( defined $app->cfg->data->{LoginManager}
&& $app->cfg->data->{LoginManager} eq 'none' )
{
throw Foswiki::OopsException(
app => $app,
Expand Down Expand Up @@ -99,7 +99,7 @@ sub checkWebExists {
status => 404,
def => 'bad_web_name',
web => $webName,
topic => $Foswiki::cfg{WebPrefsTopicName},
topic => $app->cfg->data->{WebPrefsTopicName},
params => [ $op, $app->request->invalidWeb ]
);
}
Expand All @@ -110,7 +110,7 @@ sub checkWebExists {
status => 404,
def => 'bad_web_name',
web => $webName,
topic => $Foswiki::cfg{WebPrefsTopicName},
topic => $app->cfg->data->{WebPrefsTopicName},
params => [$op]
);
}
Expand All @@ -122,7 +122,7 @@ sub checkWebExists {
status => 404,
def => 'no_such_web',
web => $webName,
topic => $Foswiki::cfg{WebPrefsTopicName},
topic => $app->cfg->data->{WebPrefsTopicName},
params => [$op]
);
}
Expand Down Expand Up @@ -255,7 +255,7 @@ sub checkValidationKey {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
10 changes: 5 additions & 5 deletions core/lib/Foswiki/UI/Configure.pm
Expand Up @@ -47,7 +47,7 @@ sub configure {

Foswiki::Configure::Auth::checkAccess($app);

unless ( $Foswiki::cfg{Plugins}{ConfigurePlugin}{Enabled} ) {
unless ( $app->cfg->data->{Plugins}{ConfigurePlugin}{Enabled} ) {
$tmplData =
CGI::start_html()
. CGI::h1( {}, 'Error' )
Expand All @@ -74,14 +74,14 @@ MESSAGE

my $meta = $this->create(
'Foswiki::Meta',
web => $Foswiki::cfg{SystemWebName},
topic => $Foswiki::cfg{SitePrefsTopicName}
web => $app->cfg->data->{SystemWebName},
topic => $app->cfg->data->{SitePrefsTopicName}
);

$tmplData = $meta->expandMacros($tmplData);

# Expand JS bootsrap flag
my $bs = $Foswiki::cfg{isBOOTSTRAPPING} ? 'true' : 'false';
my $bs = $app->cfg->data->{isBOOTSTRAPPING} ? 'true' : 'false';
$tmplData =~ s/%BOOTSTRAPPED%/$bs/gs;

$app->writeCompletePage($tmplData);
Expand All @@ -91,7 +91,7 @@ MESSAGE
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2014 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2014-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
10 changes: 5 additions & 5 deletions core/lib/Foswiki/UI/Edit.pm
Expand Up @@ -117,9 +117,9 @@ sub init_edit {

# The lease has expired, but see if we are still
# expected to issue a "less forceful' warning
if ( $Foswiki::cfg{LeaseLengthLessForceful} < 0
if ( $app->cfg->data->{LeaseLengthLessForceful} < 0
|| $t < $lease->{expires} +
$Foswiki::cfg{LeaseLengthLessForceful} )
$app->cfg->data->{LeaseLengthLessForceful} )
{
$def = 'lease_old';
$past =
Expand Down Expand Up @@ -270,7 +270,7 @@ sub init_edit {
if ( !$store->topicExists( $templateWeb, $templateTopic ) ) {

# System default template
$templateWeb = $Foswiki::cfg{SystemWebName};
$templateWeb = $app->cfg->data->{SystemWebName};
}
}
if ( $store->topicExists( $templateWeb, $templateTopic ) ) {
Expand Down Expand Up @@ -528,7 +528,7 @@ sub finalize_edit {
$text = Foswiki::entityEncode($text);
$tmpl =~ s/%TEXT%/$text/g;

$topicObject->setLease( $Foswiki::cfg{LeaseLength} );
$topicObject->setLease( $app->cfg->data->{LeaseLength} );

$app->writeCompletePage( $tmpl, 'edit', $cgiAppType );
}
Expand All @@ -537,7 +537,7 @@ sub finalize_edit {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
8 changes: 4 additions & 4 deletions core/lib/Foswiki/UI/Manage.pm
Expand Up @@ -419,9 +419,9 @@ sub _action_editSettings {

# The lease has expired, but see if we are still
# expected to issue a "less forceful' warning
if ( $Foswiki::cfg{LeaseLengthLessForceful} < 0
if ( $app->cfg->data->{LeaseLengthLessForceful} < 0
|| $t < $lease->{expires} +
$Foswiki::cfg{LeaseLengthLessForceful} )
$app->cfg->data->{LeaseLengthLessForceful} )
{
$def = 'lease_old';
$past =
Expand Down Expand Up @@ -460,7 +460,7 @@ sub _action_editSettings {
}

my $settings = "";
$topicObject->setLease( $Foswiki::cfg{LeaseLength} );
$topicObject->setLease( $app->cfg->data->{LeaseLength} );

my @fields = $topicObject->find('PREFERENCE');
foreach my $field (@fields) {
Expand Down Expand Up @@ -680,7 +680,7 @@ sub _action_restoreRevision {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/UI/Oops.pm
Expand Up @@ -137,7 +137,7 @@ MESSAGE
# a null or bogus web name!
my $topicObject = $this->create(
'Foswiki::Meta',
web => $web || $Foswiki::cfg{SystemWebName},
web => $web || $app->cfg->data->{SystemWebName},
topic => $topic
);
$tmplData = $topicObject->expandMacros($tmplData);
Expand All @@ -163,7 +163,7 @@ MESSAGE
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
16 changes: 9 additions & 7 deletions core/lib/Foswiki/UI/RDiff.pm
Expand Up @@ -531,7 +531,8 @@ sub diff {

# Limit the total number of diffs to avoid DoS
my $step =
int( ( $olderi - $neweri ) / $Foswiki::cfg{MaxRevisionsInADiff} + 0.5 );
int(
( $olderi - $neweri ) / $app->cfg->data->{MaxRevisionsInADiff} + 0.5 );
$step = 1 if $step < 1;

$before =~ s/%REVTITLE1%/$revTitleHigh/g;
Expand All @@ -554,11 +555,11 @@ sub diff {

# If we are applying control to the raw view:
if ( $renderStyle eq 'debug'
&& defined $Foswiki::cfg{FeatureAccess}{AllowRaw}
&& $Foswiki::cfg{FeatureAccess}{AllowRaw} ne 'all' )
&& defined $app->cfg->data->{FeatureAccess}{AllowRaw}
&& $app->cfg->data->{FeatureAccess}{AllowRaw} ne 'all' )
{

if ( $Foswiki::cfg{FeatureAccess}{AllowRaw} eq 'authenticated' ) {
if ( $app->cfg->data->{FeatureAccess}{AllowRaw} eq 'authenticated' ) {
Foswiki::AccessControlException->throw(
mode => 'authenticated',
user => $app->user,
Expand All @@ -574,11 +575,12 @@ sub diff {
}

# If we are applying control to the revisions:
if ( defined $Foswiki::cfg{FeatureAccess}{AllowHistory}
&& $Foswiki::cfg{FeatureAccess}{AllowHistory} ne 'all' )
if ( defined $app->cfg->data->{FeatureAccess}{AllowHistory}
&& $app->cfg->data->{FeatureAccess}{AllowHistory} ne 'all' )
{

if ( $Foswiki::cfg{FeatureAccess}{AllowHistory} eq 'authenticated' ) {
if ( $app->cfg->data->{FeatureAccess}{AllowHistory} eq 'authenticated' )
{
Foswiki::AccessControlException->throw(
mode => 'authenticated',
user => $app->user,
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/UI/Rest.pm
Expand Up @@ -195,7 +195,7 @@ sub rest {
|| !defined $record->{validate} )
{
my $msg;
if ( $Foswiki::cfg{LegacyRESTSecurity} ) {
if ( $app->cfg->data->{LegacyRESTSecurity} ) {
$msg =
'WARNING: This REST handler does not specify http_allow, validate and/or authenticate. LegacyRESTSecurity is enabled. This handler may be insecure and should be examined:';
}
Expand Down Expand Up @@ -240,7 +240,7 @@ sub rest {

# no need to exempt cli. LoginManager sets authenticated correctly.
unless ( $app->inContext('authenticated')
|| $Foswiki::cfg{LoginManager} eq 'none' )
|| $app->cfg->data->{LoginManager} eq 'none' )
{
$res->header( -type => 'text/html', -status => '401' );
$err =
Expand Down Expand Up @@ -269,7 +269,7 @@ sub rest {
# an XHR. Also, the common routine throws a ValidationException
# and we want a simple engine exception here.
if ( $record->{validate}
&& $Foswiki::cfg{Validation}{Method} ne 'none'
&& $app->cfg->data->{Validation}{Method} ne 'none'
&& !$app->inContext('command_line')
&& uc( $req->method() eq 'POST' ) )
{
Expand Down
30 changes: 16 additions & 14 deletions core/lib/Foswiki/UI/View.pm
Expand Up @@ -132,11 +132,12 @@ sub view {

# If we are applying control to the raw view:
if ( $raw
&& defined $Foswiki::cfg{FeatureAccess}{AllowRaw}
&& $Foswiki::cfg{FeatureAccess}{AllowRaw} ne 'all' )
&& defined $app->cfg->data->{FeatureAccess}{AllowRaw}
&& $app->cfg->data->{FeatureAccess}{AllowRaw} ne 'all' )
{

if ( $Foswiki::cfg{FeatureAccess}{AllowRaw} eq 'authenticated' ) {
if ( $app->cfg->data->{FeatureAccess}{AllowRaw} eq 'authenticated' )
{
Foswiki::AccessControlException->throw(
mode => 'raw',
user => $app->user,
Expand All @@ -153,11 +154,12 @@ sub view {

# If we are applying control to the revisions:
if ( $requestedRev
&& defined $Foswiki::cfg{FeatureAccess}{AllowHistory}
&& $Foswiki::cfg{FeatureAccess}{AllowHistory} ne 'all' )
&& defined $app->cfg->data->{FeatureAccess}{AllowHistory}
&& $app->cfg->data->{FeatureAccess}{AllowHistory} ne 'all' )
{

if ( $Foswiki::cfg{FeatureAccess}{AllowHistory} eq 'authenticated' )
if ( $app->cfg->data->{FeatureAccess}{AllowHistory} eq
'authenticated' )
{
Foswiki::AccessControlException->throw(
mode => 'history',
Expand Down Expand Up @@ -315,7 +317,7 @@ sub view {
$tmpl =~ s/%REVARG%/$revArg/g;

if ( $indexableView
&& $Foswiki::cfg{AntiSpam}{RobotsAreWelcome}
&& $app->cfg->data->{AntiSpam}{RobotsAreWelcome}
&& !$query->param() )
{

Expand Down Expand Up @@ -523,29 +525,29 @@ sub revisionsAround {

my $app = $this->app;

my $revsToShow = $Foswiki::cfg{NumberOfRevisions} + 1;
my $revsToShow = $app->cfg->data->{NumberOfRevisions} + 1;

# Soak up the revision iterator
my $revIt = $topicObject->getRevisionHistory();
my @revs = $revIt->all();
my $maxRevDisjoint = 0;

if ( $Foswiki::cfg{NumberOfRevisions} ) {
if ( $app->cfg->data->{NumberOfRevisions} ) {

# Locate the preferred rev in the array
my $showIndex = $#revs;
my $left = 0;
my $right = $Foswiki::cfg{NumberOfRevisions};
my $right = $app->cfg->data->{NumberOfRevisions};
if ( $requestedRev && $showIndex >= 0 ) {
while ( $showIndex && $revs[$showIndex] != $showRev ) {
$showIndex--;
}
$right = $showIndex + $Foswiki::cfg{NumberOfRevisions} - 1;
$right = $showIndex + $app->cfg->data->{NumberOfRevisions} - 1;
$right = scalar(@revs) if $right > scalar(@revs);
$left = $right - $Foswiki::cfg{NumberOfRevisions};
$left = $right - $app->cfg->data->{NumberOfRevisions};
if ( $left < 0 ) {
$left = 0;
$right = $Foswiki::cfg{NumberOfRevisions};
$right = $app->cfg->data->{NumberOfRevisions};
}
}
splice( @revs, $right ) if ( $right < scalar(@revs) );
Expand Down Expand Up @@ -604,7 +606,7 @@ sub revisionsAround {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
8 changes: 4 additions & 4 deletions core/lib/Foswiki/UI/Viewfile.pm
Expand Up @@ -107,7 +107,7 @@ sub viewfile {

my $fh = $topicObject->openAttachment( $fileName, '<', version => $rev );

my $type = _suffixToMimeType($fileName);
my $type = _suffixToMimeType( $app, $fileName );

#re-set to 200, in case this was a 404 or other redirect
$app->response->status(200);
Expand All @@ -129,12 +129,12 @@ sub viewfile {
}

sub _suffixToMimeType {
my ($attachment) = @_;
my ( $app, $attachment ) = @_;

my $mimeType = 'text/plain';
if ( $attachment && $attachment =~ m/\.([^.]+)$/ ) {
my $suffix = $1;
if ( open( my $fh, '<', $Foswiki::cfg{MimeTypesFileName} ) ) {
if ( open( my $fh, '<', $app->cfg->data->{MimeTypesFileName} ) ) {
local $/ = undef;
my $types = <$fh>;
close($fh);
Expand All @@ -153,7 +153,7 @@ sub _suffixToMimeType {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down

0 comments on commit c77e8e4

Please sign in to comment.