Skip to content

Commit

Permalink
Item1523: Added debugging feature for preferences; subject to feature…
Browse files Browse the repository at this point in the history
… acceptance (see Development.DebugPreferenceSettings)

git-svn-id: http://svn.foswiki.org/trunk@3703 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Apr 25, 2009
1 parent 675f8ad commit 232335c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
9 changes: 9 additions & 0 deletions core/data/System/VarSHOWPREFERENCE.txt
@@ -0,0 +1,9 @@
%META:TOPICPARENT{name="Macros"}%
#VarSHOWPREFERENCE
---+++ SHOWPREFERENCE -- show where a preference/all preferences is/are defined.
* =%<nop>SHOWPREFERENCE%=
* Show all preferences
* =%<nop>SHOWPREFERENCE{"PREFERENCENAME"}%=
* Show just preference PREFERENCENAME.
For example, =%<nop>SHOWPREFERENCE{"ATTACHFILESIZELIMIT"}%= shows:
%SHOWPREFERENCE{"ATTACHFILESIZELIMIT"}%
6 changes: 6 additions & 0 deletions core/lib/Foswiki.pm
Expand Up @@ -214,6 +214,7 @@ BEGIN {
SEARCH => \&SEARCH,
SEP => \&SEP,
SERVERTIME => \&SERVERTIME,
SHOWPREFERENCE => \&SHOWPREFERENCE,
SPACEDTOPIC => \&SPACEDTOPIC_deprecated,
SPACEOUT => \&SPACEOUT,
'TMPL:P' => \&TMPLP,
Expand Down Expand Up @@ -4222,6 +4223,11 @@ sub GROUPS {
return '| *Group* | *Members* |' . "\n" . join( "\n", sort @table );
}

sub SHOWPREFERENCE {
my ( $this, $params ) = @_;
return $this->{prefs}->stringify( $params->{_DEFAULT} );
}

1;
__DATA__
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down
1 change: 1 addition & 0 deletions core/lib/Foswiki/Contrib/core/MANIFEST
Expand Up @@ -257,6 +257,7 @@ data/System/VarSERVERTIME.txt 0644
data/System/VarSESSIONID.txt 0644
data/System/VarSESSIONVAR.txt 0644
data/System/VarSESSIONVARIABLE.txt 0644
data/System/VarSHOWPREFERENCE.txt 0644
data/System/VarSILVER.txt 0644
data/System/VarSPACEDTOPIC.txt 0644
data/System/VarSPACEOUT.txt 0644
Expand Down
55 changes: 21 additions & 34 deletions core/lib/Foswiki/Prefs.pm
Expand Up @@ -27,8 +27,7 @@ Values in global and local scope are accessed using =getPreference=/
The final scope is _topic_ scope. In this scope, the value of the preference
is taken directly from the contents of the topic, and is not overridden by
wider scopes. Topic scope is used for access controls, and is accessed using
=getTopicPreference=.
wider scopes. Topic scope is used for access controls.
Because the highest cost in evaluating preferences is reading the individual
topics, preferences read from a topic are cached.
Expand Down Expand Up @@ -399,30 +398,7 @@ sub getPreference {
}
}

=begin TML
---++ ObjectMethod getTopicPreference( $topicObject, $key ) -> $value
* =$topicObject= - context of the request
* =$key= - key to look up
Returns the unfinalised topic preference value.
=cut

sub getTopicPreference {
my ( $this, $topicObject, $key ) = @_;
my ( $web, $topic ) = ( $topicObject->web, $topicObject->topic );
ASSERT($web) if DEBUG;
my $cache = $this->_getCache( $web, $topic );

# if ($key eq 'WEBBGCOLOR') {
# print STDERR $topicObject->getPath().": $key ";
# print STDERR $topicObject->getPath().": $key ".($cache->get( $key )||'undef');
# }
return undef unless $cache;
return $cache->get($key);
}

# Evaluate all the stacks to generate finalised preferences
sub _finalise {
my ( $this, $whereSet ) = @_;

Expand All @@ -436,11 +412,14 @@ sub _finalise {
foreach my $level (@levels) {
next unless $this->{stacks}->{$level};
next unless scalar( @{ $this->{stacks}->{$level} } );
# Examine values at each level in the stack
my $top = $this->{stacks}->{$level}->[-1];
while ( my ( $k, $v ) = each %{ $top->{values} } ) {
# If this key has not been finalised
unless ( $finalised{$k} ) {
$values{$k} = $v;
if ($whereSet) {
# Record where this value was set for debugging
$whereSet->{$k} =
( $top->{web} ? "$top->{web}.$top->{topic}" : $level );
}
Expand Down Expand Up @@ -475,30 +454,38 @@ sub _finalise {

=begin TML
---++ObjectMethod stringify() -> $text
---++ ObjectMethod stringify([$key]) -> $text
Generate a TML-formatted version of the current preferences
Generate TML-formatted information about the key (all keys if $key is undef)
=cut

sub stringify {
my $this = shift;
my ($this, $key) = @_;

# Refinalise to populate %whereSet
undef $this->{values};
my %whereSet;
$this->_finalise( \%whereSet );

my @keys = defined $key ? ( $key ) : sort keys %{ $this->{values} };
my @list;
foreach my $k ( sort keys %{ $this->{values} } ) {
foreach my $k ( @keys ) {
my $val = Foswiki::entityEncode( $this->{values}->{$k} );
push( @list,
" * " . "Set $k = \"$val\" " . ( $whereSet{$k} || 'unknown' ) );
push( @list, ' * Set '."$k = \"$val\"");
if (defined $whereSet{$k}) {
push( @list, " * $k was "
.($this->{finalised}->{$k} ? '*finalised*' : 'defined')
." in <nop>$whereSet{$k}");
}
}
foreach my $k ( sort keys %{ $this->{locals} } ) {
@keys = defined $key ? ( $key ) : sort keys %{ $this->{locals} };
foreach my $k ( @keys ) {
next unless defined $this->{locals}->{$k};
my $val = Foswiki::entityEncode( $this->{locals}->{$k} );
push( @list, " * " . "Local $k = \"$val\"" );
push( @list, ' * Local '."$k = \"$val\"" );
}

return join( "\n", @list ) . "\n";
}

Expand Down

0 comments on commit 232335c

Please sign in to comment.