Skip to content

Commit

Permalink
Item13897: Convert Foswiki Macros to use $app->cfg->data
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed Oct 18, 2016
1 parent 5a62530 commit 9ea06bb
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 96 deletions.
5 changes: 3 additions & 2 deletions UnitTestContrib/test/unit/Fn_ICON.pm
Expand Up @@ -30,9 +30,10 @@ around set_up => sub {

my $it = Foswiki::Func::getPreferencesValue('ICONTOPIC');
$it =~ s/\./\//;
$this->reliconurl( $Foswiki::cfg{PubUrlPath} . '/'
$this->reliconurl( $this->app->cfg->data->{PubUrlPath} . '/'
. Foswiki::Func::expandCommonVariables($it) );
$this->absiconurl( $Foswiki::cfg{DefaultUrlHost} . $this->reliconurl );
$this->absiconurl(
$this->app->cfg->data->{DefaultUrlHost} . $this->reliconurl );

};

Expand Down
19 changes: 10 additions & 9 deletions core/lib/Foswiki/Macros/ENV.pm
Expand Up @@ -5,25 +5,26 @@ use strict;
use warnings;

sub ENV {
my ( $this, $params ) = @_;
my ( $app, $params ) = @_;

my $key = $params->{_DEFAULT};
my $key = $params->{_DEFAULT};
my $accessible = $app->cfg->data->{AccessibleENV};
return ''
unless $key
&& defined $Foswiki::cfg{AccessibleENV}
&& $key =~ m/$Foswiki::cfg{AccessibleENV}/;
&& defined $accessible
&& $key =~ m/$accessible/;
my $val;
if ( $key =~ m/^HTTPS?_(\w+)/ ) {
$val = $this->request->header($1);
$val = $app->request->header($1);
}
elsif ( $key eq 'REQUEST_METHOD' ) {
$val = $this->request->method;
$val = $app->request->method;
}
elsif ( $key eq 'REMOTE_USER' ) {
$val = $this->request->remoteUser;
$val = $app->request->remoteUser;
}
elsif ( $key eq 'REMOTE_ADDR' ) {
$val = $this->request->remoteAddress;
$val = $app->request->remoteAddress;
}
elsif ( $key eq 'PATH_INFO' ) {
$val = $ENV{$key};
Expand All @@ -47,7 +48,7 @@ sub ENV {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2009 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
48 changes: 24 additions & 24 deletions core/lib/Foswiki/Macros/GROUPINFO.pm
Expand Up @@ -5,7 +5,7 @@ use strict;
use warnings;

sub GROUPINFO {
my ( $this, $params ) = @_;
my ( $app, $params ) = @_;

my $group = $params->{_DEFAULT};
my $format = $params->{format};
Expand All @@ -32,48 +32,48 @@ sub GROUPINFO {
if ($group) {
if ( $group =~ m/[\.\/]/ ) { # Contains a web/topic separator
( my $web, $group ) =
Foswiki::Func::normalizeWebTopicName( $Foswiki::cfg{UsersWebName},
$group );
return '' unless ( $web eq $Foswiki::cfg{UsersWebName} );
Foswiki::Func::normalizeWebTopicName(
$app->cfg->data->{UsersWebName}, $group );
return '' unless ( $web eq $app->cfg->data->{UsersWebName} );
}

$it = $this->users->eachGroupMember( $group, { expand => $expand } );
$it = $app->users->eachGroupMember( $group, { expand => $expand } );
$format = '$wikiusername' unless defined $format;
}
else {
$it = $this->users->eachGroup();
$it = $app->users->eachGroup();
$format = '$name' unless defined $format;
}
while ( $it->hasNext() ) {
my $cUID = $it->next();
my $row = $format;
if ($group) {
next unless ( $this->users->groupAllowsView($cUID) );
my $change = $this->users->groupAllowsChange($cUID);
next unless ( $app->users->groupAllowsView($cUID) );
my $change = $app->users->groupAllowsChange($cUID);

#filter by show="" param
next if ( ( $show eq 'allowchange' ) and ( not $change ) );
next if ( ( $show eq 'denychange' ) and ($change) );
if ( $show =~ m/allowchange\((.*)\)/ ) {
next
if (
not $this->users->groupAllowsChange(
$group, $this->users->getCanonicalUserID($1)
not $app->users->groupAllowsChange(
$group, $app->users->getCanonicalUserID($1)
)
);
}
if ( $show =~ m/denychange\((.*)\)/ ) {
next
if (
$this->users->groupAllowsChange(
$group, $this->users->getCanonicalUserID($1)
$app->users->groupAllowsChange(
$group, $app->users->getCanonicalUserID($1)
)
);
}

my $wname = $this->users->getWikiName($cUID);
my $uname = $this->users->getLoginName($cUID) || $wname;
my $wuname = $this->users->webDotWikiName($cUID);
my $wname = $app->users->getWikiName($cUID);
my $uname = $app->users->getLoginName($cUID) || $wname;
my $wuname = $app->users->webDotWikiName($cUID);

$row =~ s/\$wikiname/$wname/ge;
$row =~ s/\$username/$uname/ge;
Expand All @@ -82,31 +82,31 @@ sub GROUPINFO {

#TODO: should return 0 if $1 is not a valid user?
$row =~
s/\$allowschange\((.*?)\)/$this->users->groupAllowsChange( $group , $this->users->getCanonicalUserID($1))/ges;
s/\$allowschange\((.*?)\)/$app->users->groupAllowsChange( $group , $app->users->getCanonicalUserID($1))/ges;
$row =~ s/\$allowschange/$change/ge;
}
else {

# all groups
next unless ( $this->users->groupAllowsView($cUID) );
my $change = $this->users->groupAllowsChange($cUID);
next unless ( $app->users->groupAllowsView($cUID) );
my $change = $app->users->groupAllowsChange($cUID);

#filter by show="" param
next if ( ( $show eq 'allowchange' ) and ( not $change ) );
next if ( ( $show eq 'denychange' ) and ($change) );
if ( $show =~ m/allowchange\((.*)\)/ ) {
next
if (
not $this->users->groupAllowsChange(
$cUID, $this->users->getCanonicalUserID($1)
not $app->users->groupAllowsChange(
$cUID, $app->users->getCanonicalUserID($1)
)
);
}
if ( $show =~ m/denychange\((.*)\)/ ) {
next
if (
$this->users->groupAllowsChange(
$cUID, $this->users->getCanonicalUserID($1)
$app->users->groupAllowsChange(
$cUID, $app->users->getCanonicalUserID($1)
)
);
}
Expand All @@ -115,7 +115,7 @@ s/\$allowschange\((.*?)\)/$this->users->groupAllowsChange( $group , $this->users

#TODO: should return 0 if $1 is not a valid user?
$row =~
s/\$allowschange\((.*?)\)/$this->users->groupAllowsChange( $cUID , $this->users->getCanonicalUserID($1))/ges;
s/\$allowschange\((.*?)\)/$app->users->groupAllowsChange( $cUID , $app->users->getCanonicalUserID($1))/ges;
$row =~ s/\$allowschange/$change/ge;
}
push( @rows, $row );
Expand All @@ -137,7 +137,7 @@ s/\$allowschange\((.*?)\)/$this->users->groupAllowsChange( $cUID , $this->users-
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2009 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
22 changes: 12 additions & 10 deletions core/lib/Foswiki/Macros/GROUPS.pm
Expand Up @@ -6,28 +6,30 @@ use warnings;

# Legacy
sub GROUPS {
my ( $this, $params ) = @_;
my ( $app, $params ) = @_;

my $groups = $this->users->eachGroup;
my $groups = $app->users->eachGroup;
my @table;
while ( $groups->hasNext() ) {
my $group = $groups->next();
next unless ( $this->users->groupAllowsView($group) );
next unless ( $app->users->groupAllowsView($group) );

# Nop it to prevent wikiname expansion unless the topic exists.
my $groupLink = "<nop>$group";
$groupLink = '[[' . $Foswiki::cfg{UsersWebName} . ".$group][$group]]"
$groupLink =
'[[' . $app->cfg->data->{UsersWebName} . ".$group][$group]]"
if (
$this->store->topicExists( $Foswiki::cfg{UsersWebName}, $group ) );
$app->store->topicExists( $app->cfg->data->{UsersWebName}, $group )
);
my $descr = "| $groupLink |";
my $it = $this->users->eachGroupMember($group);
my $it = $app->users->eachGroupMember($group);
my $limit_output = 32;
while ( $it->hasNext() ) {
my $user = $it->next();
next unless ( $this->users->groupAllowsView($user) );
next unless ( $app->users->groupAllowsView($user) );
$descr .= ' [['
. $this->users->webDotWikiName($user) . ']['
. $this->users->getWikiName($user) . ']]';
. $app->users->webDotWikiName($user) . ']['
. $app->users->getWikiName($user) . ']]';
if ( $limit_output == 0 ) {
$descr .= '<div>%MAKETEXT{"user list truncated"}%</div>';
last;
Expand All @@ -44,7 +46,7 @@ sub GROUPS {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2009 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/Macros/HTTP.pm
Expand Up @@ -7,9 +7,9 @@ use warnings;
# $https flag set when HTTPS macro is requested.

sub HTTP {
my ( $this, $params, $topicObject ) = @_;
my ( $app, $params, $topicObject ) = @_;
my $res;
my $req = _validateRequest( $params->{_DEFAULT} );
my $req = _validateRequest( $app, $params->{_DEFAULT} );

my $https = ( substr( ( caller() )[1], -8 ) eq "HTTPS.pm" );

Expand All @@ -19,29 +19,31 @@ sub HTTP {
!defined $req # Requesting secure flag
|| length($req) # or requesting a specific header
);
$res = $this->request->https($req);
$res = $app->request->https($req);
}
else {
return ''
unless (
defined $req # Specifc header requested
&& length($req) # and passed validation
);
$res = $this->request->http($req);
$res = $app->request->http($req);
}
$res = '' unless defined($res);
return $res;
}

sub _validateRequest {

my $app = shift;

# Permit undef - used by HTTPS variant
return $_[0] unless defined $_[0];

# Nothing allowed if AccessibleHeaders is not defined
return '' unless ( scalar @{ $Foswiki::cfg{AccessibleHeaders} } );
return '' unless ( scalar @{ $app->cfg->data->{AccessibleHeaders} } );

foreach my $hdr ( @{ $Foswiki::cfg{AccessibleHeaders} } ) {
foreach my $hdr ( @{ $app->cfg->data->{AccessibleHeaders} } ) {
return $hdr if ( lc( $_[0] ) eq lc($hdr) );
}

Expand All @@ -53,7 +55,7 @@ sub _validateRequest {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2015 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/Macros/ICON.pm
Expand Up @@ -168,7 +168,7 @@ sub _getIconURL {
my $a = $1;
my $app = $this->app;
my ( $w, $t ) =
$app->request->normalizeWebTopicName( $Foswiki::cfg{SystemWebName},
$app->request->normalizeWebTopicName( $app->cfg->data->{SystemWebName},
$path );
return $app->cfg->getPubURL( $w, $t, $a, %$params );
}
Expand Down Expand Up @@ -223,7 +223,7 @@ sub expand {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2009-2014 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2009-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
9 changes: 5 additions & 4 deletions core/lib/Foswiki/Macros/INCLUDE.pm
Expand Up @@ -290,7 +290,7 @@ sub _includeTopic {

# prevent dirty areas in included topics from being parsed
$text = Foswiki::takeOutBlocks( $text, 'dirtyarea', $dirtyAreas )
if $Foswiki::cfg{Cache}{Enabled};
if $app->cfg->data->{Cache}{Enabled};

# handle sections
my ( $ntext, $sections ) = $app->macros->parseSections($text);
Expand Down Expand Up @@ -430,7 +430,7 @@ sub _includeTopic {

# restoring dirty areas
Foswiki::putBackBlocks( \$text, $dirtyAreas, 'dirtyarea' )
if $Foswiki::cfg{Cache}{Enabled};
if $app->cfg->data->{Cache}{Enabled};

my @context = $app->prefs->popTopicContext();
$req->web( $context[0] );
Expand Down Expand Up @@ -472,7 +472,8 @@ sub expand {
}

# Filter out '..' from path to prevent includes of '../../file'
elsif ( $Foswiki::cfg{DenyDotDotInclude} && $control{_DEFAULT} =~ m/\.\./ )
elsif ($app->cfg->data->{DenyDotDotInclude}
&& $control{_DEFAULT} =~ m/\.\./ )
{
$text =
$this->_includeWarning( $control{warn}, 'bad_include_path',
Expand Down Expand Up @@ -519,7 +520,7 @@ sub expand {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2009 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/Macros/MAKETEXT.pm
Expand Up @@ -7,7 +7,7 @@ use warnings;
use Locale::Maketext;

sub MAKETEXT {
my ( $this, $params ) = @_;
my ( $app, $params ) = @_;

my $str = $params->{_DEFAULT} || $params->{string} || "";
return "" unless $str;
Expand Down Expand Up @@ -35,7 +35,7 @@ s/~\[(\*,\_(\d+),[^,]+(,([^,]+))?)~\]/ _validate($1, $2, $max, $min, $param_erro

# Escape any escapes.
$str =~ s#\\#\\\\#g
if ( $Foswiki::cfg{UserInterfaceInternationalisation}
if ( $app->cfg->data->{UserInterfaceInternationalisation}
&& $Locale::Maketext::VERSION
&& $Locale::Maketext::VERSION < 1.23 ); # escape any escapes

Expand All @@ -56,7 +56,7 @@ s/~\[(\*,\_(\d+),[^,]+(,([^,]+))?)~\]/ _validate($1, $2, $max, $min, $param_erro
}

# do the magic:
my $result = $this->i18n->maketext( $str, @args );
my $result = $app->i18n->maketext( $str, @args );

# replace accesskeys:
$result =~
Expand Down Expand Up @@ -92,7 +92,7 @@ sub _validate {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2009 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 9ea06bb

Please sign in to comment.