Skip to content

Commit

Permalink
Item14292: multiple improvements
Browse files Browse the repository at this point in the history
   * better handing of revision infos being attached to a h1
   * removed detection of old Internet Explorers as well as warning for unsupported browsers
   * better support for Foswiki:Extensions/DiffPlugin
   * hide "New" button based on web, not on topic access rights
  • Loading branch information
MichaelDaum committed Jan 23, 2017
1 parent c9daffc commit 584b9a7
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 190 deletions.
14 changes: 7 additions & 7 deletions .gitignore
@@ -1,8 +1,8 @@
*.swp
NatSkinPlugin.md5
NatSkinPlugin.sha1
NatSkinPlugin.tgz
NatSkinPlugin.txt
NatSkinPlugin.zip
NatSkinPlugin_installer
NatSkinPlugin_installer.pl
/NatSkinPlugin.md5
/NatSkinPlugin.sha1
/NatSkinPlugin.tgz
/NatSkinPlugin.txt
/NatSkinPlugin.zip
/NatSkinPlugin_installer
/NatSkinPlugin_installer.pl
16 changes: 7 additions & 9 deletions data/System/NatSkinPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1437155814" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1485176369" format="1.1" version="1"}%
---+!! The Natural Skin Plugin
%FORMFIELD{"Description"}%
%TOC%
Expand All @@ -20,7 +20,6 @@ returns the current topic revision

see also:
[[#NATMAXREV][NATMAXREV]],
[[#NATREVISIONS][NATREVISIONS]]
[[#PREVREV][PREVREV]],

---+++ NATFORMBUTTON
Expand Down Expand Up @@ -71,12 +70,6 @@ paramters:
substitute for =%<nop>MAXREV%= which differes all too much on Beijing, Cairo
and Dakar. This version grants to behave the same.

---+++ NATREVISIONS
*Syntax*: =%<nop>NATREVISIONS%=

substitute for the =%<nop>REVISIONS%= tag which only works on
the <nop>PatternSkin.

---+++ NATWEBLOGO
*Syntax*: =%<nop>NATWEBLOGO{format="..."}%=

Expand Down Expand Up @@ -173,6 +166,11 @@ See NatSkin#Installation_Instructions
%$DEPENDENCIES%

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 23 Jan 2017: | better handing of revision infos being attached to a h1; \
removed detection of old Internet Explorers as well as warning for unsupported browsers; \
better support for Foswiki:Extensions/DiffPlugin; \
hide "New" button based on web, not on topic access rights |
| 25 Feb 2016: | improved support for pdf printouts; removed secure headers as that's a plugin of its own now |
| 17 Jul 2015: | better integration with Foswiki:Extensions/AutoTemplatePlugin; \
better detection of Internet Explorer versions; added edit_raw action; \
Expand All @@ -186,7 +184,7 @@ See NatSkin#Installation_Instructions

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Michael Daum"}%
%META:FIELD{name="Copyright" title="Copyright" value="2003-2016, Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Copyright" title="Copyright" value="2003-2017, Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/NatSkinPlugin"}%
%META:FIELD{name="License" title="License" value="GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]])"}%
Expand Down
62 changes: 25 additions & 37 deletions lib/Foswiki/Plugins/NatSkinPlugin.pm
@@ -1,7 +1,7 @@
###############################################################################
# NatSkinPlugin.pm - Plugin handler for the NatSkin.
#
# Copyright (C) 2003-2016 MichaelDaum http://michaeldaumconsulting.com
# Copyright (C) 2003-2017 MichaelDaum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -30,24 +30,17 @@ our $START = '(?:^|(?<=[\w\b\s]))';
our $STOP = '(?:$|(?=[\w\b\s\,\.\;\:\!\?\)\(]))';
our $doneInjectRevinfo = 0;

BEGIN {
#print STDERR "Perl Version $]\n";
}


###############################################################################
our $baseWeb;
our $baseTopic;

our $VERSION = '4.20';
our $RELEASE = '25 Feb 2016';
our $VERSION = '5.00';
our $RELEASE = '23 Jan 2017';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Support plugin for <nop>NatSkin';
our $themeEngine;

###############################################################################
sub initPlugin {
($baseTopic, $baseWeb) = @_;

#print STDERR "### Perl Version $]\n";

# theme engine macros
Foswiki::Func::registerTagHandler(
Expand Down Expand Up @@ -75,29 +68,27 @@ sub initPlugin {
Foswiki::Func::registerTagHandler(
'PREVREV',
sub {
return Foswiki::Plugins::NatSkinPlugin::Utils::getPrevRevision($baseWeb, $baseTopic, 1);
my ($session, $params, $topic, $web) = @_;
($web, $topic) = Foswiki::Func::normalizeWebTopicName($params->{web} || $session->{webName}, $params->{topic} || $session->{topicName});
return Foswiki::Plugins::NatSkinPlugin::Utils::getPrevRevision($web, $topic, 1);
}
);

Foswiki::Func::registerTagHandler(
'CURREV',
sub {
return Foswiki::Plugins::NatSkinPlugin::Utils::getCurRevision($baseWeb, $baseTopic);
my ($session, $params, $topic, $web) = @_;
($web, $topic) = Foswiki::Func::normalizeWebTopicName($params->{web} || $session->{webName}, $params->{topic} || $session->{topicName});
return Foswiki::Plugins::NatSkinPlugin::Utils::getCurRevision($web, $topic);
}
);

Foswiki::Func::registerTagHandler(
'NATMAXREV',
sub {
return Foswiki::Plugins::NatSkinPlugin::Utils::getMaxRevision($baseWeb, $baseTopic);
}
);

Foswiki::Func::registerTagHandler(
'NATREVISIONS',
sub {
require Foswiki::Plugins::NatSkinPlugin::Revisions;
return Foswiki::Plugins::NatSkinPlugin::Revisions::render(@_);
my ($session, $params, $topic, $web) = @_;
($web, $topic) = Foswiki::Func::normalizeWebTopicName($params->{web} || $session->{webName}, $params->{topic} || $session->{topicName});
return Foswiki::Plugins::NatSkinPlugin::Utils::getMaxRevision($web, $topic);
}
);

Expand Down Expand Up @@ -254,27 +245,24 @@ sub completePageHandler {

unless ($doneInjectRevinfo) {
my $flag = Foswiki::Func::isTrue(Foswiki::Func::getPreferencesValue("DISPLAYREVISIONINFO"), 1);
if ($flag && $_[0] =~ s/(<h1.*<\/h1>)/$1.&_insertRevInfo()/e) {
if ($flag && $_[0] =~ s/(<h1[^>]*>.*<\/h1>)/$1.&_insertRevInfo()/e) {
$doneInjectRevinfo = 1;
} else {
}
}
}

sub _insertRevInfo {

my $revinfo = Foswiki::Func::expandTemplate("revinfo");
$revinfo = Foswiki::Func::expandCommonVariables($revinfo);
return Foswiki::Func::renderText($revinfo, $baseWeb, $baseTopic);
}

###############################################################################
sub modifyHeaderHandler {
my ($headers, $query) = @_;

# force IE to the latest version; use chrome frame if available
my $xuaCompatible = $Foswiki::cfg{NatSkin}{XuaCompatible};
$xuaCompatible = 'ie=edge,chrome=1' unless defined $xuaCompatible;
$headers->{"X-UA-Compatible"} = $xuaCompatible if $xuaCompatible;
my $session = $Foswiki::Plugins::SESSION;
my $web = $session->{webName};
my $topic = $session->{topicName};

my $text = Foswiki::Func::expandTemplate("revinfo");
$text = Foswiki::Func::expandCommonVariables($text, $topic, $web);
$text = Foswiki::Func::renderText($text, $web, $topic);
$text =~ s/<!--[^\[<].*?-->//g;
return $text;
}

1;
Expand Down
37 changes: 3 additions & 34 deletions lib/Foswiki/Plugins/NatSkinPlugin/Config.spec
Expand Up @@ -32,48 +32,17 @@ $Foswiki::cfg{NatSkin}{SideBar} = 'right';
# **STRING**
# This is a list of actions that switch off the sidebar navigation automatically. Note, these are basically known cgi entry
# points to Foswiki.
$Foswiki::cfg{NatSkin}{NoSideBarActions} = 'edit, manage, login, logon, oops, register, compare, rdiff';
$Foswiki::cfg{NatSkin}{NoSideBarActions} = 'edit, manage, login, logon, oops, register, compare, rdiff, diff';

# ---+++ HTML post processing
# **BOOLEAN**
# If switched on, external links will be detected and styled accordingly to give the user visual feedback that this
# link is driving him off the site. This is a prerequisite to open external links in an extra borwser window/tab.
$Foswiki::cfg{NatSkin}{DetectExternalLinks} = 0;
$Foswiki::cfg{NatSkin}{DetectExternalLinks} = 1;

# **BOOLEAN**
# Enable this switch to perform some basic typographic fixes to the output text: support proper quotes, arrows and
# ellipsis.
$Foswiki::cfg{NatSkin}{FixTypograpghy} = 0;

# ---+++ Internet Explorer
# **STRING**
# Add an X-UA-Compatible entry to the HTTP headers. Use "ie=edge" to force any IE into the best mode supported. Add "chrome=1"
# to switch IE using Chrome-Frame if installed.
$Foswiki::cfg{NatSkin}{XuaCompatible} = 'ie=edge,chrome=1';

# **BOOLEAN**
# Enable this switch to display a browser warning when an IE6 has been detected.
$Foswiki::cfg{NatSkin}{DeprecateIE6} = 1;

# **BOOLEAN**
# Enable this switch to display a browser warning when an IE7 has been detected. WARNING: an IE8 in compatibility mode will report
# as an IE7 even though it has been forced back into IE8 standard mode using an appropriate X-UA-Compatible HTTP header.
$Foswiki::cfg{NatSkin}{DeprecateIE7} = 1;

# **BOOLEAN**
# Enable this switch to display a browser warning when an IE8 has been detected.
$Foswiki::cfg{NatSkin}{DeprecateIE8} = 1;

# **BOOLEAN**
# Enable this switch to display a browser warning when an IE9 has been detected.
$Foswiki::cfg{NatSkin}{DeprecateIE9} = 0;

# **BOOLEAN**
# Enable this switch to display a browser warning when an IE10 has been detected.
$Foswiki::cfg{NatSkin}{DeprecateIE10} = 0;

# **BOOLEAN**
# Enable this switch to display a browser warning when an IE11 has been detected.
$Foswiki::cfg{NatSkin}{DeprecateIE11} = 0;
$Foswiki::cfg{NatSkin}{FixTypograpghy} = 1;

1;
8 changes: 6 additions & 2 deletions lib/Foswiki/Plugins/NatSkinPlugin/DEPENDENCIES
@@ -1,5 +1,7 @@
Foswiki::Contrib::CopyContrib,>=2.0,perl,Required.
Foswiki::Plugins::DiffPlugin,>=1.0,perl,Required.
Foswiki::Contrib::FamFamFamContrib,>=2075,perl,Required.
Foswiki::Contrib::WebFontsContrib,>=1,perl,Required
Foswiki::Plugins::AutoTemplatePlugin,>=2.01,perl,Required
Foswiki::Plugins::BreadCrumbsPlugin,>=4318,perl,Required
Foswiki::Plugins::CaptchaPlugin,>=2.0.0,perl,Optional
Expand All @@ -9,13 +11,15 @@ Foswiki::Plugins::FlexWebListPlugin,>=3493,perl,Required
Foswiki::Plugins::GridLayoutPlugin,>=1.00,perl,Required
Foswiki::Plugins::ImagePlugin,>=2.40,perl,Required
Foswiki::Plugins::JQueryPlugin,>=7.00,perl,Required
Foswiki::Plugins::ListyPlugin,>=1,perl,Required
Foswiki::Plugins::MetaCommentPlugin,>=2.80,perl,Optional
Foswiki::Plugins::MimeIconPlugin,>=1,perl,Required
Foswiki::Plugins::MultiLingualPlugin,>=2.00,perl,Optional
Foswiki::Plugins::MultiLingualPlugin,>=2.00,perl,Required
Foswiki::Plugins::NatEditPlugin,>=8.00,perl,Required
Foswiki::Plugins::PageOptimizerPlugin,>=0.10,perl,Optional
Foswiki::Plugins::RedDotPlugin,>=1,perl,Required
Foswiki::Plugins::RenderPlugin,>=4.00,perl,Required
Foswiki::Plugins::SecurityHeadersPlugin,>=0.99,perl,Optional
Foswiki::Plugins::SecurityHeadersPlugin,>=2.00,perl,Optional
Foswiki::Plugins::TopicInteractionPlugin,>=1340,perl,Required
Foswiki::Plugins::WebLinkPlugin,>=1,perl,Required
ONLYIF ( $Foswiki::Plugins::VERSION < 2.1)
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/NatSkinPlugin/ExternalLink.pm
@@ -1,7 +1,7 @@
###############################################################################
# NatSkinPlugin.pm - Plugin handler for the NatSkin.
#
# Copyright (C) 2003-2016 MichaelDaum http://michaeldaumconsulting.com
# Copyright (C) 2003-2017 MichaelDaum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/NatSkinPlugin/HtmlTitle.pm
@@ -1,7 +1,7 @@
###############################################################################
# NatSkinPlugin.pm - Plugin handler for the NatSkin.
#
# Copyright (C) 2003-2016 MichaelDaum http://michaeldaumconsulting.com
# Copyright (C) 2003-2017 MichaelDaum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
4 changes: 3 additions & 1 deletion lib/Foswiki/Plugins/NatSkinPlugin/Revisions.pm
@@ -1,7 +1,7 @@
###############################################################################
# NatSkinPlugin.pm - Plugin handler for the NatSkin.
#
# Copyright (C) 2003-2016 MichaelDaum http://michaeldaumconsulting.com
# Copyright (C) 2003-2017 MichaelDaum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -16,6 +16,8 @@
#
###############################################################################

# SMELL: this is unused code

package Foswiki::Plugins::NatSkinPlugin::Revisions;
use strict;
use warnings;
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/NatSkinPlugin/Subscribe.pm
@@ -1,7 +1,7 @@
###############################################################################
# NatSkinPlugin.pm - Plugin handler for the NatSkin.
#
# Copyright (C) 2013-2016 MichaelDaum http://michaeldaumconsulting.com
# Copyright (C) 2013-2017 MichaelDaum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -28,7 +28,7 @@ sub render {
my ($session, $params, $theTopic, $theWeb) = @_;

Foswiki::Func::addToZone('skinjs', 'NATSKIN::SUBSCRIBE', <<'HERE', 'NATSKIN::JS, JQUERYPLUGIN::BLOCKUI');
<script src="%PUBURLPATH%/%SYSTEMWEB%/NatSkin/subscribe.js"></script>
<script type="text/javascript" src="%PUBURLPATH%/%SYSTEMWEB%/NatSkin/subscribe.js"></script>
HERE

my $webTopic = $params->{topic} || $theTopic;
Expand Down
51 changes: 4 additions & 47 deletions lib/Foswiki/Plugins/NatSkinPlugin/ThemeEngine.pm
@@ -1,7 +1,7 @@
###############################################################################
# NatSkinPlugin.pm - Plugin handler for the NatSkin.
#
# Copyright (C) 2003-2016 MichaelDaum http://michaeldaumconsulting.com
# Copyright (C) 2003-2017 MichaelDaum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -386,51 +386,6 @@ sub init {
$context->{$var} = 1;
}

# SMELL: these browser-based contexts should be core
if ($request) {
my $agent = $request->user_agent() || '';

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

# SMELL: better use Trident version to detect the physical version of the browser
$context->{msie6} = 1 if $agent =~ /MSIE 6/;
$context->{msie7} = 1 if $agent =~ /MSIE 7/;
$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 =~ /Trident\/7.0/;
} elsif ($agent =~ /Chrome/) {
$context->{chrome} = 1;
} elsif ($agent =~ /Firefox/) {
$context->{firefox} = 1;
} elsif ($agent =~ /Opera/) {
$context->{opera} = 1;
} elsif ($agent =~ /Konqueror/) {
$context->{konqueror} = 1;
} elsif ($agent =~ /Safari/) {
$context->{safari} = 1;
}

# flag unsupported browsers
$context->{UnsupportedBrowser} = 1 if $context->{msie6} && $Foswiki::cfg{NatSkin}{DeprecateIE6};
$context->{UnsupportedBrowser} = 1 if $context->{msie7} && $Foswiki::cfg{NatSkin}{DeprecateIE7};
$context->{UnsupportedBrowser} = 1 if $context->{msie8} && $Foswiki::cfg{NatSkin}{DeprecateIE8};
$context->{UnsupportedBrowser} = 1 if $context->{msie9} && $Foswiki::cfg{NatSkin}{DeprecateIE9};
$context->{UnsupportedBrowser} = 1 if $context->{msie10} && $Foswiki::cfg{NatSkin}{DeprecateIE10};
$context->{UnsupportedBrowser} = 1 if $context->{msie11} && $Foswiki::cfg{NatSkin}{DeprecateIE11};

my %deprecatedBrowsers = map { $_ => 1 } split(/\s*,\s*/, Foswiki::Func::getPreferencesValue('DEPRECATEDBROWSERS') || '');
$deprecatedBrowsers{msie6} = 1 if $Foswiki::cfg{NatSkin}{DeprecateIE6};
$deprecatedBrowsers{msie7} = 1 if $Foswiki::cfg{NatSkin}{DeprecateIE7};
$deprecatedBrowsers{msie8} = 1 if $Foswiki::cfg{NatSkin}{DeprecateIE8};
$deprecatedBrowsers{msie9} = 1 if $Foswiki::cfg{NatSkin}{DeprecateIE9};
$deprecatedBrowsers{msie10} = 1 if $Foswiki::cfg{NatSkin}{DeprecateIE10};
$deprecatedBrowsers{msie11} = 1 if $Foswiki::cfg{NatSkin}{DeprecateIE11};
Foswiki::Func::setPreferencesValue("DEPRECATEDBROWSERS", join(", ", sort keys %deprecatedBrowsers));
}

# SMELL: these misc helper contexts should be core
$context->{allow_loginname} = 1 if $Foswiki::cfg{Register}{AllowLoginName};

Expand All @@ -446,7 +401,7 @@ sub init {
Foswiki::Func::setPreferencesValue('FOSWIKI_COLORS_URL', '%NATSTYLEURL%');

Foswiki::Func::addToZone('skinjs', 'NATSKIN::JS', <<'HERE', 'NATSKIN, NATSKIN::PREFERENCES, JQUERYPLUGIN::FOSWIKI, JQUERYPLUGIN::SUPERFISH, JQUERYPLUGIN::UI');
<script src="%PUBURLPATH%/%SYSTEMWEB%/NatSkin/natskin.js"></script>
<script type='text/javascript' src="%PUBURLPATH%/%SYSTEMWEB%/NatSkin/natskin.js"></script>
HERE

Foswiki::Func::addToZone("skincss", 'NATSKIN', $this->renderSkinStyle(), 'TABLEPLUGIN_default, JQUERYPLUGIN::UI, JQUERYPLUGIN::THEME');
Expand Down Expand Up @@ -511,6 +466,8 @@ HERE
HERE
}

$text =~ s/^\s+|\s+$//g;

return $text;
}

Expand Down

0 comments on commit 584b9a7

Please sign in to comment.