Skip to content

Commit

Permalink
Item14448: fixed reporting outdated plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Jul 28, 2017
1 parent 3653b6f commit 9a1dc93
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
11 changes: 4 additions & 7 deletions UpdatesPlugin/data/System/UpdatesPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1493865930" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1501242886" format="1.1" version="1"}%
---+!! %TOPIC%
<img class="foswikiRight" src="%ATTACHURL%/logo.png">
%$SHORTDESCRIPTION%
Expand Down Expand Up @@ -66,6 +66,7 @@ to prevent disclosing them to the outside world.
This plugin was initially developed during a collaborative design and coding session at the 2011 Foswiki Camp.

| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 1.04 (28 Jul 2017) | Foswikitask:Item14448: fixed broken outdated plugins report |
| 1.03 (03 May 2017) | Foswikitask:Item13907: Report list of extensions needing update. |
| 1.02 (23 Jan 2017) | Foswikitask:Item14281: Cookie related changes. Inconsistent use of the domain and secure flags. |
| 1.01 (24 Jul 2015) | Foswikitask:Item13555: Compare VERSION not RELEASE strings.<br/>\
Expand All @@ -80,10 +81,6 @@ This plugin was initially developed during a collaborative design and coding ses
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/distro"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; Foswiki Contributors 2011-2017"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Home" title="Home" value="http://foswiki.org/Extensions/%25$ROOTMODULE%25"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%25$ROOTMODULE%25"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/%25$ROOTMODULE%25"}%
%META:FILEATTACHMENT{name="logo.png" attr="h" comment="" date="1493865930" size="53676" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="jquery.updates.js" attr="h" comment="" date="1493865930" size="2322" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="jquery.updates.js.gz" attr="h" comment="" date="1493865930" size="786" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="jquery.updates.uncompressed.js" attr="h" comment="" date="1493865930" size="4313" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Makefile" attr="h" comment="" date="1493865930" size="127" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="logo.png" attr="h" comment="" date="1501242886" size="53676" user="ProjectContributor" version="1"}%
4 changes: 2 additions & 2 deletions UpdatesPlugin/lib/Foswiki/Plugins/UpdatesPlugin.pm
Expand Up @@ -20,8 +20,8 @@ use warnings;

use Foswiki::Func ();

our $VERSION = '1.03';
our $RELEASE = '03 May 2017';
our $VERSION = '1.04';
our $RELEASE = '28 Jul 2017';
our $SHORTDESCRIPTION = 'Checks Foswiki.org for updates';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand Down
2 changes: 1 addition & 1 deletion UpdatesPlugin/lib/Foswiki/Plugins/UpdatesPlugin/build.pl
@@ -1,4 +1,4 @@
#!/usr/bin/perl -w
#!/usr/bin/env perl

# Standard preamble
use strict;
Expand Down
@@ -1,11 +1,12 @@
/*
* jquery.updates plugin 0.30
* jquery.updates plugin 1.04
*
* Copyright (c) 2011-2015 Foswiki Contributors http://foswiki.org
* Copyright (c) 2011-2017 Foswiki Contributors http://foswiki.org
*
* http://www.gnu.org/licenses/gpl.html
*
*/
"use strict";
(function($) {

// global defaults
Expand All @@ -28,14 +29,14 @@
self.options = $.extend({}, defaults, options);

if (self.options.debug) {
console.log("called new FoswikiUpdates");
console.log("called new FoswikiUpdates"); // eslint-disable-line no-console
}

self.init();
self.loadPluginInfo(0);

return self;
};
}

// init method
FoswikiUpdates.prototype.init = function() {
Expand All @@ -52,15 +53,15 @@

self.options.cookieName = foswiki.getPreference('COOKIENAMEPREFIX') + self.options.cookieNameSuffix;
self.options.cookieDomain = foswiki.getPreference('COOKIEREALM'); // Allow domain override
self.options.cookieSecure = foswiki.getPreference('URLHOST').startsWith('https://');
self.options.cookieSecure = foswiki.getPreference('URLHOST').indexOf('https://') === 0;

// events
$(document).bind("refresh.foswikiUpdates", function() {
$(document).on("refresh.foswikiUpdates", function() {
//console.log("BIND refresh.foswikiUpdates calling loadPluginInfo.");
self.loadPluginInfo(0);
});

$(document).bind("forceRefresh.foswikiUpdates", function() {
$(document).on("forceRefresh.foswikiUpdates", function() {
//console.log("BIND forceRefresh.foswikiUpdates calling loadPluginInfo.");
$.cookie(self.options.cookieName, null, {
expires: -1,
Expand All @@ -71,15 +72,15 @@
self.loadPluginInfo(1);
});

$(document).bind("display.foswikiUpdates", function() {
$(document).on("display.foswikiUpdates", function() {
//console.log("BIND display.foswikiUpdates calling loadPluginInfo.");
self.displayPluginInfo(0);
self.displayPluginInfo();
});

$(document).on("click", "#foswikiUpdatesIgnore", function() {
// setting the cookie to zero...means ignore and don't search again
//console.log("BIND click entered ");
$.cookie(self.options.cookieName, 0, {
$.cookie(self.options.cookieName, [], {
expires: self.options.cookieExpires,
path: "/",
domain:self.options.cookieDomain,
Expand All @@ -92,12 +93,12 @@

// pull info from f.o and refresh internal state
FoswikiUpdates.prototype.loadPluginInfo = function(forced) {
var self = this, key, version;
var self = this;

//console.log("called loadPluginInfo forced: " + forced );
self.numberOutdatedPlugins = $.cookie(self.options.cookieName);
self.outdatedPlugins = $.cookie(self.options.cookieName);

if (typeof(self.numberOutdatedPlugins) === 'undefined') {
if (typeof(self.outdatedPlugins) === 'undefined') {

// collect remote info
window.setTimeout(function() {
Expand All @@ -107,25 +108,24 @@
url: self.options.endpointUrl,
dataType: "json",
timeout: self.options.timeout,
success: function(data, status, xhr) {
success: function(data) {
//console.log("success: data=",data);
self.numberOutdatedPlugins = data.length;
self.pluginList = data.sort();
self.outdatedPlugins = data;
// remember findings: sets cookie to the number of outdated plugins. setting it to
// zero explicitly can either mean: everything up-to-date or ignore pending updates
$.cookie(self.options.cookieName, self.numberOutdatedPlugins, {
$.cookie(self.options.cookieName, self.outdatedPlugins, {
expires: self.options.cookieExpires,
path: "/",
domain:self.options.cookieDomain,
secure:self.options.cookieSecure
});

//console.log("Forced: " + forced);
if (self.numberOutdatedPlugins > 0 || forced) {
if (self.outdatedPlugins.length > 0 || forced) {
$(document).trigger("display.foswikiUpdates");
}
},
error: function(xhr, msg, status) {
error: function() {
//console.log("got an error: status=",status,"msg=",msg)
// remember the error state
$.cookie(self.options.cookieName, -1, {
Expand All @@ -137,22 +137,27 @@
}
});
}, self.options.delay);
} else if (self.numberOutdatedPlugins > 0) {
// we already know. so only trigger the display again
$(document).trigger("display.foswikiUpdates");
}
} else {
if (typeof(self.outdatedPlugins) === 'string' && self.outdatedPlugins.length > 0) {
self.outdatedPlugins = self.outdatedPlugins.split(/\s*,\s*/);
}
if (self.outdatedPlugins.length > 0) {
// we already know. so only trigger the display again
$(document).trigger("display.foswikiUpdates");
}
}
};

// displays internal state using a nice info box at the top of the page
FoswikiUpdates.prototype.displayPluginInfo = function() {
var self = this, elem;

$(".foswikiUpdateMessage").remove(); // ... the old one if there
$(".foswikiUpdatesMessage").remove(); // ... the old one if there

// ... and add a new one
elem = $("#foswikiUpdatesTmpl").render([{
nrPlugins:self.numberOutdatedPlugins,
pluginList:self.pluginList,
nrPlugins:self.outdatedPlugins.length,
outdatedPlugins:self.outdatedPlugins.sort().join(", "),
cookieExpires:self.options.cookieExpires,
configureUrl:self.options.configureUrl
}]);
Expand Down
12 changes: 6 additions & 6 deletions UpdatesPlugin/templates/updatesplugin.tmpl
@@ -1,16 +1,16 @@
%TMPL:DEF{"messagetmpl"}%<script id="foswikiUpdatesTmpl" type="text/x-jsrender">
<div class="foswikiBroadcastMessage foswikiUpdatesMessage">
%JQICON{"error"}%
%TMPL:P{"messagetmpl::icon"}%
%TMPL:P{"messagetmpl::text"}%
<a href="%SCRIPTURLPATH{configure}%">%JQICON{"tick"}% %MAKETEXT{"Upgrade"}%</a>
<a href="#" id="foswikiUpdatesIgnore">%JQICON{"cross"}% %MAKETEXT{"Ignore for 7 days"}%</a><br/>
%TMPL:P{"messagetmpl::list"}%
%TMPL:P{"messagetmpl::buttons"}%
%CLEAR%
</div>
</script>%TMPL:END%

%TMPL:DEF{"messagetmpl::text"}%%MAKETEXT{"Warning: Updates found for [_1] extension(s)." args="{{:nrPlugins}}"}%%TMPL:END%
%TMPL:DEF{"messagetmpl::list"}%({{:pluginList}})%TMPL:END%
%TMPL:DEF{"messagetmpl::icon"}%%JQICON{"error"}%%TMPL:END%
%TMPL:DEF{"messagetmpl::text"}%%MAKETEXT{"Warning: Updates found for [_1] extension(s): [_2]" arg1="{{:nrPlugins}}" arg2="{{:outdatedPlugins}}"}%%TMPL:END%
%TMPL:DEF{"messagetmpl::buttons"}%<a href="%SCRIPTURLPATH{configure}%">%JQICON{"tick"}% %MAKETEXT{"Upgrade"}%</a>
<a href="#" id="foswikiUpdatesIgnore">%JQICON{"cross"}% %MAKETEXT{"Ignore for 7 days"}%</a>%TMPL:END%

%TMPL:DEF{"css"}%<style type="text/css">
.foswikiBroadcastMessage.foswikiUpdatesMessage {
Expand Down

0 comments on commit 9a1dc93

Please sign in to comment.