Skip to content

Commit

Permalink
Item13483: added support for Foswiki-2.0
Browse files Browse the repository at this point in the history
also:
- better integration with Foswiki:Extensions/AutoTemplatePlugin
- better detection of Internet Explorer versions; added edit_raw action
- properly searching for WebComponents in the web holding the local SitePreferences ... which not necessarily is the user web
  • Loading branch information
MichaelDaum committed Jul 17, 2015
1 parent d7fd209 commit b080402
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 15 deletions.
6 changes: 5 additions & 1 deletion data/System/NatSkinPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="save topic" date="1363520449" format="1.1" version="7"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1437155814" format="1.1" version="1"}%
---+!! The Natural Skin Plugin
%TOC%

Expand Down Expand Up @@ -181,6 +181,10 @@ See NatSkin#Installation_Instructions
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 17 Jul 2015: | better integration with Foswiki:Extensions/AutoTemplatePlugin; \
better detection of Internet Explorer versions; added edit_raw action; \
added support for Foswiki-2.0; \
properly searching for !WebComponents in the web holding the local !SitePreferences ... which not necessarily is the user web |
| 27 Feb 2015: | finally 4.00 |
| 29 Aug 2014: | third beta |
| 28 Mar 2013: | second beta |
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/NatSkinPlugin.pm
Expand Up @@ -39,8 +39,8 @@ BEGIN {
our $baseWeb;
our $baseTopic;

our $VERSION = '4.00';
our $RELEASE = '27 Feb 2015';
our $VERSION = '4.10';
our $RELEASE = '17 Jul 2015';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Support plugin for <nop>NatSkin';
our $themeEngine;
Expand Down
4 changes: 3 additions & 1 deletion lib/Foswiki/Plugins/NatSkinPlugin/DEPENDENCIES
Expand Up @@ -6,11 +6,13 @@ Foswiki::Plugins::CaptchaPlugin,>=2.0.0,perl,Optional
Foswiki::Plugins::DBCachePlugin,>=1,perl,Required
Foswiki::Plugins::FilterPlugin,>=3491,perl,Required
Foswiki::Plugins::FlexWebListPlugin,>=3493,perl,Required
Foswiki::Plugins::GridLayoutPlugin,>=1.00,perl,Required
Foswiki::Plugins::ImagePlugin,>=2.40,perl,Required
Foswiki::Plugins::JQueryPlugin,>=5.00,perl,Required
Foswiki::Plugins::MetaCommentPlugin,>=2.80,perl,Optional
Foswiki::Plugins::MimeIconPlugin,>=1,perl,Required
Foswiki::Plugins::MultiLingualPlugin,>=2.00,perl,Optional
Foswiki::Plugins::NatEditPlugin,>=8.00,perl,Required
Foswiki::Contrib::NatSkin,>=3.99_004,perl,Required
Foswiki::Plugins::PageOptimizerPlugin,>=0.10,perl,Optional
Foswiki::Plugins::RenderPlugin,>=3644,perl,Required
Foswiki::Plugins::TopicInteractionPlugin,>=1340,perl,Required
Expand Down
11 changes: 9 additions & 2 deletions lib/Foswiki/Plugins/NatSkinPlugin/ThemeEngine.pm
Expand Up @@ -357,11 +357,18 @@ sub init {
my $viewTemplate = $request->param('template')
|| Foswiki::Func::getPreferencesValue('VIEW_TEMPLATE');

if (!$viewTemplate && $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Enabled}) {
require Foswiki::Plugins::AutoTemplatePlugin;
my $session = $Foswiki::Plugins::SESSION;
$viewTemplate = Foswiki::Plugins::AutoTemplatePlugin::getTemplateName($session->{webName}, $session->{topicName});
}

Foswiki::Func::loadTemplate($viewTemplate)
if $viewTemplate;

# check if 'sidebar' is empty. if so then switch it off in the skinState
my $sidebar = Foswiki::Func::expandTemplate('sidebar');

$this->{skinState}{'sidebar'} = 'off' unless $sidebar;
}
}
Expand All @@ -384,7 +391,7 @@ sub init {
my $agent = $request->user_agent() || '';

#print STDERR "agent=$agent\n";
if ($agent =~ /MSIE/) {
if ($agent =~ /MSIE|Trident/) {
$context->{msie} = 1;

# SMELL: better use Trident version to detect the physical version of the browser
Expand All @@ -393,7 +400,7 @@ sub init {
$context->{msie8} = 1 if $agent =~ /MSIE 8/;
$context->{msie9} = 1 if $agent =~ /MSIE 9/;
$context->{msie10} = 1 if $agent =~ /MSIE 10/;
$context->{msie11} = 1 if $agent =~ /MSIE 11/;
$context->{msie11} = 1 if $agent =~ /Trident\/7.0/;
} elsif ($agent =~ /Chrome/) {
$context->{chrome} = 1;
} elsif ($agent =~ /Firefox/) {
Expand Down
49 changes: 42 additions & 7 deletions lib/Foswiki/Plugins/NatSkinPlugin/UserActions.pm
Expand Up @@ -77,12 +77,11 @@ sub render {
$actionParams->{menu_footer} = $params->{menu_footer};
$actionParams->{hiderestricted} = Foswiki::Func::isTrue($params->{hiderestricted}, 0);
$actionParams->{mode} = $params->{mode} || 'short';
$actionParams->{sep} = $params->{sep} || $params->{separator};
$actionParams->{sep} = '<span class="natSep"> | </span>' unless defined $actionParams->{sep};
$actionParams->{sep} = $params->{sep} || $params->{separator} || '';

# get restrictions
my $restrictedActions = $params->{restrictedactions};
$restrictedActions = 'edit, attach, move, delete, diff, more, raw'
$restrictedActions = 'edit, edit_raw, attach, move, delete, diff, more, raw'
unless defined $restrictedActions;
%{$actionParams->{isRestrictedAction}} = map { $_ => 1 } split(/\s*,\s*/, $restrictedActions);

Expand All @@ -93,6 +92,7 @@ sub render {

# list all actions that need edit rights
if ($actionParams->{isRestrictedAction}{'edit'}) {
$actionParams->{isRestrictedAction}{'edit_raw'} = 1;
$actionParams->{isRestrictedAction}{'attach'} = 1;
$actionParams->{isRestrictedAction}{'delete'} = 1;
$actionParams->{isRestrictedAction}{'editform'} = 1;
Expand Down Expand Up @@ -145,6 +145,7 @@ sub formatResult {
$text =~ s/\$(?:editform\b|action\(editform(?:,\s*(.*?))?\))/renderEditForm($params, $1, $mode)/ge;
$text =~ s/\$(?:account\b|action\(account(?:,\s*(.*?))?\))/renderAccount($params, $1, $mode)/ge;
$text =~ s/\$(?:diff\b|action\(diff(?:,\s*(.*?))?\))/renderDiff($params, $1, $mode)/ge;
$text =~ s/\$(?:edit_raw\b|action\(edit_raw(?:,\s*(.*?))?\))/renderEditRaw($params, $1, $mode)/ge;
$text =~ s/\$(?:edit\b|action\(edit(?:,\s*(.*?))?\))/renderEdit($params, $1, $mode)/ge;
$text =~ s/\$(?:view\b|action\(view(?:,\s*(.*?))?\))/renderView($params, $1, $mode)/ge;
$text =~ s/\$(?:first\b|action\(first(?:,\s*(.*?))?\))/renderFirst($params, $1, $mode)/ge;
Expand All @@ -156,7 +157,7 @@ sub formatResult {
$text =~ s/(\$sep)?\$(?:logout\b|action\(logout(?:,\s*(.*?))?\))/renderLogout($params, $1, $2, $mode)/ge;

# normal actions / backwards compatibility
$text =~ s/\$(attach|copytopic|delete|editsettings|edittext|help|history|more|move|new|pdf|print|register|restore|users)\b/renderAction($1, $params, undef, undef, undef, $mode)/ge;
$text =~ s/\$(attach|copytopic|delete|editsettings|edittext|help|history|more|move|new|pdf|print|register|restore|users|share)\b/renderAction($1, $params, undef, undef, undef, $mode)/ge;

# generic actions
$text =~ s/\$action\((.*?)(?:,\s*(.*?))?\)/renderAction($1, $params, undef, undef, $2, $mode)/ge;
Expand Down Expand Up @@ -241,6 +242,40 @@ sub renderEdit {
return $result;
}

###############################################################################
sub renderEditRaw {
my ($params, $context, $mode) = @_;

return '' if (defined($context) && !Foswiki::Func::getContext()->{$context});

my $result = '';
my $label;
my $themeEngine = Foswiki::Plugins::NatSkinPlugin::getThemeEngine();

if ($params->{isRestrictedAction}{'edit_raw'}) {
return '' if $params->{hiderestricted};
if ($themeEngine->{skinState}{"history"}) {
$result = Foswiki::Func::expandTemplate('RESTORE_ACTION_RESTRICTED');
$label = getLabelForAction("RESTORE", $mode);
} else {
$result = Foswiki::Func::expandTemplate('EDIT_RAW_ACTION_RESTRICTED');
$label = getLabelForAction("EDIT_RAW", $mode);
}
} else {
if ($themeEngine->{skinState}{"history"}) {
$result = Foswiki::Func::expandTemplate('RESTORE_ACTION');
$label = getLabelForAction("RESTORE", $mode);
} else {
$result = Foswiki::Func::expandTemplate('EDIT_RAW_ACTION');
$label = getLabelForAction("EDIT_RAW", $mode);
}
}

$result =~ s/\$label/$label/g;

return $result;
}

###############################################################################
sub renderView {
my ($params, $context, $mode) = @_;
Expand Down Expand Up @@ -400,13 +435,13 @@ sub renderEditForm {
if ($topicObj && $topicObj->getFormName) {
if ($params->{isRestrictedAction}{'editform'}) {
return '' if $params->{hiderestricted};
$result = Foswiki::Func::expandTemplate("EDITFORM_ACTION_RESTRICTED");
$result = Foswiki::Func::expandTemplate("EDIT_FORM_ACTION_RESTRICTED");
}
$result = Foswiki::Func::expandTemplate("EDITFORM_ACTION");
$result = Foswiki::Func::expandTemplate("EDIT_FORM_ACTION");

}

my $label = getLabelForAction("EDITFORM", $mode);
my $label = getLabelForAction("EDIT_FORM", $mode);
$result =~ s/\$label/$label/g;

return $result;
Expand Down
2 changes: 2 additions & 0 deletions lib/Foswiki/Plugins/NatSkinPlugin/Utils.pm
Expand Up @@ -23,6 +23,7 @@ use warnings;
use Foswiki::Func ();
use Foswiki::Plugins ();
use Foswiki::Plugins::NatSkinPlugin ();
use Encode();

our %maxRevs = (); # cache for getMaxRevision()

Expand Down Expand Up @@ -60,6 +61,7 @@ sub makeParams {
sub urlEncode {
my $text = shift;

$text = Encode::encode_utf8($text) if $Foswiki::UNICODE;
$text =~ s/([^0-9a-zA-Z-_.:~!*'\/])/'%'.sprintf('%02x',ord($1))/ge;

return $text;
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/NatSkinPlugin/WebComponent.pm
Expand Up @@ -95,7 +95,7 @@ sub getWebComponent {
# get component for web
my $text = '';
my $meta = '';
my $usersWeb = $Foswiki::cfg{UsersWebName};
my ($configWeb) = Foswiki::Func::normalizeWebTopicName(undef, $Foswiki::cfg{LocalSitePreferences});
my $systemWeb = $Foswiki::cfg{SystemWebName};

my $theWeb = $web;
Expand All @@ -110,7 +110,7 @@ sub getWebComponent {
# current
($meta, $text) = Foswiki::Func::readTopic($theWeb, $theComponent);
} else {
$theWeb = $usersWeb;
$theWeb = $configWeb;
$theComponent = 'Site' . $component;

if ( Foswiki::Func::topicExists($theWeb, $theComponent)
Expand Down

0 comments on commit b080402

Please sign in to comment.