diff --git a/core/lib/Foswiki/Configure/Checkers/LANGUAGE.pm b/core/lib/Foswiki/Configure/Checkers/LANGUAGE.pm index 2509f2e350..58428c9572 100644 --- a/core/lib/Foswiki/Configure/Checkers/LANGUAGE.pm +++ b/core/lib/Foswiki/Configure/Checkers/LANGUAGE.pm @@ -84,11 +84,25 @@ sub check_current_value { } } -sub refresh_cache { - my ( $this, $string, $reporter ) = @_; +=begin TML + +---++ ObjectMethod onSave() + +This routine is called during the Save wizard, for any key that being +saved, regardless of whether or not it has actually changed. This +is enabled by including the ONSAVE key in the Spec. (In this case it is +automatically enabled by the =Pluggable/LANGUAGES.pm= + +This will remove the languages.cache file from the WorkingDir, so that +the cache can be regenerated. + +=cut + +sub onSave { + my ( $this, $reporter, $key, $val ) = @_; if ( $Foswiki::cfg{UserInterfaceInternationalisation} ) { - my $dir = $Foswiki::cfg{LocalesDir}; + my $dir = $Foswiki::cfg{WorkingDir}; if ( -f "$dir/languages.cache" ) { if ( unlink("$dir/languages.cache") ) { diff --git a/core/lib/Foswiki/Configure/Pluggables/LANGUAGES.pm b/core/lib/Foswiki/Configure/Pluggables/LANGUAGES.pm index 11e770c9b8..11157b6ddf 100755 --- a/core/lib/Foswiki/Configure/Pluggables/LANGUAGES.pm +++ b/core/lib/Foswiki/Configure/Pluggables/LANGUAGES.pm @@ -73,6 +73,7 @@ sub construct { CHECKER => 'LANGUAGE', DISPLAY_IF => "{UserInterfaceInternationalisation}", opts => 'CHECK="undefok emptyok"', + ONSAVE => 1, ); $langs{$label} = $value; diff --git a/core/lib/Foswiki/Configure/Value.pm b/core/lib/Foswiki/Configure/Value.pm index a41c5cbcd3..cbdc880ff5 100755 --- a/core/lib/Foswiki/Configure/Value.pm +++ b/core/lib/Foswiki/Configure/Value.pm @@ -77,6 +77,7 @@ use constant ATTRSPEC => { MULTIPLE => {}, # Allow multiple select SPELLCHECK => {}, LABEL => {}, + ONSAVE => {}, # Call Checker->onSave() when set. # Rename single character options (legacy) H => 'HIDDEN', diff --git a/core/lib/Foswiki/Configure/Wizards/Save.pm b/core/lib/Foswiki/Configure/Wizards/Save.pm index 04ddec7ac7..dc821aaa93 100644 --- a/core/lib/Foswiki/Configure/Wizards/Save.pm +++ b/core/lib/Foswiki/Configure/Wizards/Save.pm @@ -20,6 +20,7 @@ use Fcntl; use File::Spec (); use Foswiki::Configure::Load (); use Foswiki::Configure::LoadSpec (); +use Foswiki::Configure::Checker (); use Foswiki::Configure::FileUtil (); use Foswiki::Configure::Wizard (); @@ -230,6 +231,19 @@ sub save { if ( $this->param('set') ) { while ( my ( $k, $v ) = each %{ $this->param('set') } ) { my $spec = $root->getValueObject($k); + + # If ONSAVE checking is specified, call the checker's onSave() + # routine. This could provide "cleanup" processing for example, + # when a configuration value is saved. It can modify the value + # being saved, such as to hash a password, but never modify other + # values. + if ( $spec && $spec->{ONSAVE} ) { + my $checker = Foswiki::Configure::Checker::loadChecker($spec); + if ( $checker && $checker->can('onSave') ) { + $checker->onSave( $reporter, $k, $v ); + } + } + if ( defined $v ) { $v =~ m/^(.*)$/s; $v = $1; # untaint