Skip to content

Commit

Permalink
Item12379:
Browse files Browse the repository at this point in the history
   * fixed error handling
   * hiding access to edit actions when not authorized anyway
   * fixed uploading files with special chars in their name
   * fixed initialization of flash backend
   * fixed reading foswiki preference settings



git-svn-id: http://svn.foswiki.org/trunk/TopicInteractionPlugin@16505 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Feb 1, 2013
1 parent c327cf3 commit 065e226
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 53 deletions.
5 changes: 5 additions & 0 deletions data/System/TopicInteractionPlugin.txt
Expand Up @@ -153,6 +153,11 @@ generates:
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 01 Feb 2013: | fixed error handling; \
hiding access to edit actions when not authorized anyway; \
fixed uploading files with special chars in their name; \
fixed initialization of flash backend; \
fixed reading foswiki preference settings |
| 31 Jan 2013: | using ATTACHLINKBOX to control the default state of the "create link" checkbox |
| 25 Jan 2013: | fixed auto-start feature; fixed registration of uploader component |
| 18 Jan 2013: | improved compatibility with !PatternSkin; \
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/TopicInteractionPlugin.pm
Expand Up @@ -18,8 +18,8 @@ package Foswiki::Plugins::TopicInteractionPlugin;
use strict;
use warnings;

our $VERSION = '3.23';
our $RELEASE = '3.23';
our $VERSION = '3.24';
our $RELEASE = '3.24';
our $SHORTDESCRIPTION = 'Improved interaction with attachments and !DataForms';
our $NO_PREFS_IN_TOPIC = 1;

Expand Down
8 changes: 4 additions & 4 deletions lib/Foswiki/Plugins/TopicInteractionPlugin/Attachments.pm
Expand Up @@ -180,7 +180,7 @@ sub handle {
my $iconUrl = '%ICONURL{"' . $info->{name} . '" alt="else"}%';
my $icon = '%ICON{"' . $info->{name} . '" alt="else"}%';

my $encName = urlEncode($info->{name});
my $encName = urlEncode($info, 'name');

# actions
my $thisWebDavUrl = $webDavUrl;
Expand Down Expand Up @@ -248,7 +248,7 @@ sub handle {
$text =~ s/\$oldversions\b/$oldVersions/g;
$text =~ s/\$web\b/$thisWeb/g;
$text =~ s/\$topic\b/$thisTopic/g;
$text =~ s/\$encode\((.*?)\)/urlEncode($1)/ges;
$text =~ s/\$encode\((.*?)\)/urlEncode($info, $1)/ges;

push @result, $text if $text;
}
Expand All @@ -270,10 +270,10 @@ sub handle {
}

##############################################################################
# slightly different version as Foswiki::urlEncode: also encodes single quotes
sub urlEncode {
my $text = shift;
my ($infoOrText, $property) = @_;

my $text = defined($property)?$infoOrText->{$property}:$infoOrText;
$text =~ s/([^0-9a-zA-Z-_.:~!*\/])/'%'.sprintf('%02X',ord($1))/ge;

return $text;
Expand Down
37 changes: 20 additions & 17 deletions lib/Foswiki/Plugins/TopicInteractionPlugin/Uploader.pm
Expand Up @@ -42,19 +42,22 @@ Constructor
sub new {
my $class = shift;

my $this = bless($class->SUPER::new(
$Foswiki::Plugins::SESSION,
name => 'Uploader',
version => '1.2.1',
author => 'Michael Daum',
homepage => 'http://foswiki.org/Externsions/TopicInteractionPlugin',
puburl => '%PUBURLPATH%/%SYSTEMWEB%/TopicInteractionPlugin',
documentation => "$Foswiki::cfg{SystemWebName}.TopicInteractionPlugin",
javascript => ['jquery.uploader.js'],
css => ['jquery.uploader.css'],
dependencies => ['blockui', 'scrollto', 'button', 'livequery', 'metadata', 'ui::dialog', 'form', 'JavaScriptFiles/foswikiPref', 'JQUERYPLUGIN::UPLOADER::ENGINES'],
@_
), $class);
my $this = bless(
$class->SUPER::new(
$Foswiki::Plugins::SESSION,
name => 'Uploader',
version => '1.3.0',
author => 'Michael Daum',
homepage => 'http://foswiki.org/Externsions/TopicInteractionPlugin',
puburl => '%PUBURLPATH%/%SYSTEMWEB%/TopicInteractionPlugin',
documentation => "$Foswiki::cfg{SystemWebName}.TopicInteractionPlugin",
javascript => ['jquery.uploader.js'],
css => ['jquery.uploader.css'],
dependencies => ['blockui', 'scrollto', 'button', 'livequery', 'metadata', 'ui::dialog', 'pnotify', 'form', 'JavaScriptFiles/foswikiPref', 'JQUERYPLUGIN::UPLOADER::ENGINES'],
@_
),
$class
);

return $this;
}
Expand All @@ -80,15 +83,15 @@ sub init {
# export configuration to javascript
my %meta = ();

$meta{"foswiki.TopicInteractionPlugin.attachFileSizeLimit"} = Foswiki::Func::getPreferencesValue("ATTACHFILESIZELIMIT") || 0;
$meta{"foswiki.TopicInteractionPlugin.Runtimes"} = $engines;
$meta{"TopicInteractionPlugin.attachFileSizeLimit"} = Foswiki::Func::getPreferencesValue("ATTACHFILESIZELIMIT") || 0;
$meta{"TopicInteractionPlugin.Runtimes"} = $engines;

# add flash config
$meta{"foswiki.TopicInteractionPlugin.flashUrl"} = "%PUBURLPATH%/%SYSTEMWEB%/TopicInteractionPlugin/plupload.flash.swf"
$meta{"TopicInteractionPlugin.flashUrl"} = "%PUBURLPATH%/%SYSTEMWEB%/TopicInteractionPlugin/plupload.flash.swf"
if $enabled{flash};

# add silverlight config
$meta{"foswiki.TopicInteractionPlugin.silverlightUrl"} = "%PUBURLPATH%/%SYSTEMWEB%/TopicInteractionPlugin/plupload.silverlight.xap"
$meta{"TopicInteractionPlugin.silverlightUrl"} = "%PUBURLPATH%/%SYSTEMWEB%/TopicInteractionPlugin/plupload.silverlight.xap"
if $enabled{silverlight};

my $content = "<script type='text/javascript'>\njQuery.extend(foswiki.preferences, ".JSON::to_json(\%meta, {pretty=>1}) .");\n</script>";
Expand Down
2 changes: 2 additions & 0 deletions pub/System/TopicInteractionPlugin/Makefile
Expand Up @@ -19,6 +19,8 @@ SUBDIRS=i18n

-include $(FOSWIKI_ROOT)/pub/System/JQueryPlugin/Makefile.include

DEBUG=false

to-git:
cp plupload.browserplus.uncompressed.js git/src/javascript/plupload.browserplus.js
cp plupload.flash.swf git/bin/plupload.flash.swf
Expand Down
50 changes: 40 additions & 10 deletions pub/System/TopicInteractionPlugin/jquery.uploader.uncompressed.js
Expand Up @@ -328,11 +328,24 @@

/*********************************************************************/
uploader.bind("Error", function(up, err) {
var file = err.file,
msg = err.message.replace(/\.$/, "");
var file = err.file, msg, response;

if (err.details) {
msg += ", "+err.details;
if (err.response) {
try {
response = $.parseJSON(err.response);
if (typeof(response.error) !== 'undefined') {
msg = response.error.message;
}
} catch (e) {
alert("can't parse json response from backend");
}
}

if (typeof(msg) === 'undefined') {
msg = err.message.replace(/\.$/, "");
if (err.details) {
msg += ", "+err.details;
}
}

if (file) {
Expand Down Expand Up @@ -424,15 +437,32 @@
parseError = true;
}

// patch in renamed files
if (!parseError) {
$.each(uploader.files, function(i, file) {
if (typeof(response.result[file.name]) != 'undefined') {
file.name = response.result[file.name];
}
if (parseError) {
up.trigger('Error', {
code : plupload.HTTP_ERROR,
message : "can't parse json response from backend",
response: args.response,
file : file
});
return false;
}

if (typeof(response.error) !== 'undefined') {
up.trigger('Error', {
code : plupload.HTTP_ERROR,
message : response.error.message,
file : file
});
return false;
}

// patch in renamed files
$.each(uploader.files, function(i, file) {
if (typeof(response.result[file.name]) != 'undefined') {
file.name = response.result[file.name];
}
});

updateFileProgress(file);
updateMessage();
});
Expand Down
Expand Up @@ -24,7 +24,7 @@
padding:1em;
}
.foswikiMetaDataNotAllowed .foswikiMetaDataEdit {
display:none;
display:none !important;
}

/* attachments */
Expand Down
30 changes: 20 additions & 10 deletions pub/System/TopicInteractionPlugin/metadata.uncompressed.js
Expand Up @@ -483,7 +483,11 @@ jQuery(function($) {
error: function(xhr, msg) {
var data = $.parseJSON(xhr.responseText);
$.unblockUI();
$attachment.find(".foswikiAttachmentContainer").append("<div class='foswikiErrorMessage'>Error: "+data.error.message+"</div>");
$.pnotify({
title: 'Edit failed',
text: data.error.message,
type: 'error'
});
}
});
});
Expand All @@ -497,7 +501,6 @@ jQuery(function($) {

$.log("METADATA: clicked edit attachment");

$attachment.find(".foswikiErrorMessage").remove();
loadDialog({
id:"#foswikiAttachmentEditor",
template:"attachments::editor",
Expand Down Expand Up @@ -548,7 +551,11 @@ jQuery(function($) {
error: function(xhr, msg) {
var data = $.parseJSON(xhr.responseText);
$.unblockUI();
$attachment.find(".foswikiAttachmentContainer").append("<div class='foswikiErrorMessage'>Error: "+data.error.message+"</div>");
$.pnotify({
title: 'Failed to delete '+filename,
text: data.error.message,
type: 'error'
});
}
});
});
Expand All @@ -561,7 +568,6 @@ jQuery(function($) {
attachmentOpts = $.extend({}, $attachment.metadata()),
thumbnail = $attachment.find(".foswikiThumbnail").clone(true).removeClass("foswikiLeft");

$attachment.find(".foswikiErrorMessage").remove();
loadDialog({
id:"#foswikiAttachmentConfirmDelete",
template:"attachments::confirmdelete",
Expand Down Expand Up @@ -601,7 +607,11 @@ jQuery(function($) {
error: function(xhr, msg) {
var data = $.parseJSON(xhr.responseText);
$.unblockUI();
$attachment.find(".foswikiAttachmentContainer").append("<div class='foswikiErrorMessage'>Error: "+data.error.message+"</div>");
$.pnotify({
title: 'Move failed',
text: data.error.message,
type: 'error'
});
}
});
});
Expand All @@ -613,8 +623,6 @@ jQuery(function($) {
attachmentOpts = $.extend({}, $attachment.metadata()),
thumbnail = $attachment.find(".foswikiThumbnail").clone(true).removeClass("foswikiLeft");

$attachment.find(".foswikiErrorMessage").remove();

loadDialog({
id: "#foswikiAttachmentMove",
template: "attachments::moveattachment",
Expand Down Expand Up @@ -677,7 +685,11 @@ jQuery(function($) {
error: function(xhr, msg) {
var data = $.parseJSON(xhr.responseText);
$.unblockUI();
$attachment.find(".foswikiAttachmentContainer").append("<div class='foswikiErrorMessage'>Error: "+data.error.message+"</div>");
$.pnotify({
title: 'Error during "'+action+'"',
text: data.error.message,
type: 'error'
});
}
});
});
Expand Down Expand Up @@ -714,8 +726,6 @@ jQuery(function($) {
return;
}

$this.find(".foswikiErrorMessage").remove();

if (action != "move") {
loadDialog({
id: "#foswikiAttachmentConfirmBulk",
Expand Down
Expand Up @@ -555,6 +555,7 @@
up.trigger('Error', {
code : plupload.HTTP_ERROR,
message : plupload.translate('HTTP Error.'),
response : xhr.responseText,
file : file,
status : httpStatus
});
Expand Down
18 changes: 9 additions & 9 deletions templates/metadata.tmpl
Expand Up @@ -254,7 +254,7 @@
header="<div class='foswikiAttachmentsPager foswikiAttachmentsPagerTop {count:$count}'>$pager</div>
<div class=\"foswikiAttachmentsContainer %TMPL:P{"metadata::lightbox::parameter"}% \">"
footer="%CLEAR%<div class='foswikiAttachmentsPager foswikiAttachmentsPagerBottom'>$pager</div></div>"
format="<div class='foswikiAttachment {filename:\"$encode($name)\", filecomment:\"$encode($comment)\", fileattr:\"$attr\"}' id='$encode($name)'>
format="<div class='foswikiAttachment {filename:\"$encode(name)\", filecomment:\"$encode(comment)\", fileattr:\"$attr\"}' id='$encode(name)'>
<div class='foswikiAttachmentContainer'>
<div class='foswikiThumbnail foswikiLeft'>
$percntIF{
Expand All @@ -263,7 +263,7 @@
else=\"<a href='$url'>$percntMIMEICON{\"$name\" size=\"48\"}$percnt</a>\"
}$percnt
</div>
<div class=\"foswikiAttachmentControl foswikiRight \">
<div class=\"foswikiAttachmentControl foswikiRight foswikiMetaDataEdit\">
<a href='#' class='foswikiAttachmentEditButton' title='%MAKETEXT{"Edit properties of this attachment"}%' rel='nofollow'>%JQICON{"pencil"}%</a>
$percntIF{\"(context FlexPaperPluginEnabled and '$name'=~'\.pdf$') or '$name'=~'flv|swf|mp3'\"
then=\"<a href='#' class='foswikiAttachmentPreviewButton' title='%MAKETEXT{"Preview this attachment"}%' rel='nofollow'>%JQICON{"eye"}%</a>\"
Expand Down Expand Up @@ -303,16 +303,16 @@
<td>
<select class="foswikiSelect" name="bulkaction">
<option class="foswikiOption" value="">%MAKETEXT{"Bulk action"}%</option>
<option class="foswikiOption" value="createlink">%MAKETEXT{"Insert links"}%</option>
<option class="foswikiOption foswikiMetaDataEdit" value="createlink">%MAKETEXT{"Insert links"}%</option>
%IF{"context ImageGalleryPluginEnabled"
then=" <option class='foswikiOption' value='createimagegallery'>%MAKETEXT{"Create image gallery"}%</option>"
then=" <option class='foswikiOption foswikiMetaDataEdit' value='createimagegallery'>%MAKETEXT{"Create image gallery"}%</option>"
else="<!-- -->"
}%
<option class="foswikiOption" value="download">%MAKETEXT{"Download"}%</option>
<option class="foswikiOption" value="hide">%MAKETEXT{"Hide"}%</option>
<option class="foswikiOption" value="unhide">%MAKETEXT{"Unhide"}%</option>
<option class="foswikiOption" value="move">%MAKETEXT{"Move"}%</option>
<option class="foswikiOption" value="delete">%MAKETEXT{"Delete"}%</option>
<option class="foswikiOption foswikiMetaDataEdit" value="hide">%MAKETEXT{"Hide"}%</option>
<option class="foswikiOption foswikiMetaDataEdit" value="unhide">%MAKETEXT{"Unhide"}%</option>
<option class="foswikiOption foswikiMetaDataEdit" value="move">%MAKETEXT{"Move"}%</option>
<option class="foswikiOption foswikiMetaDataEdit" value="delete">%MAKETEXT{"Delete"}%</option>
</select>
</td>
<td>
Expand Down Expand Up @@ -350,7 +350,7 @@
format="$percntFORMATLIST{\"$oldversions\"
split=\"$n\"
pattern=\"(.*);(.*);(.*);(.*)\"
format=\"%MAKETEXT{"<a href='[_1]'>Version [_2]</a> uploaded by [_3] on [_4]" args="%SCRIPTURL{"viewfile"}%/%WEB%/%TOPIC%?filename=$encode($name);rev=$3,$3,$dollarpercntSPACEOUT{$2}$dollarpercnt,$1"}%\"
format=\"%MAKETEXT{"<a href='[_1]'>Version [_2]</a> uploaded by [_3] on [_4]" args="%SCRIPTURL{"viewfile"}%/%WEB%/%TOPIC%?filename=$encode(name);rev=$3,$3,$dollarpercntSPACEOUT{$2}$dollarpercnt,$1"}%\"
separator=\"%BR%$n\"
}$percnt"
}%
Expand Down

0 comments on commit 065e226

Please sign in to comment.