[LON-CAPA-cvs] cvs: loncom /publisher loncfile.pm
raeburn
raeburn at source.lon-capa.org
Tue Mar 5 21:31:17 EST 2019
raeburn Wed Mar 6 02:31:17 2019 EDT
Modified files:
/loncom/publisher loncfile.pm
Log:
- Include intermediate confirmation screen when changes were made automatically
to path, directory and/or filename proposed by user.
- Escape instead of encode entities in URLs being assigned to location.href in
javascript calls.
-------------- next part --------------
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.124 loncom/publisher/loncfile.pm:1.125
--- loncom/publisher/loncfile.pm:1.124 Sun May 22 01:09:54 2016
+++ loncom/publisher/loncfile.pm Wed Mar 6 02:31:16 2019
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.124 2016/05/22 01:09:54 raeburn Exp $
+# $Id: loncfile.pm,v 1.125 2019/03/06 02:31:16 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -109,13 +109,13 @@
}
sub done {
- my ($url) = @_;
+ my ($destfn) = @_;
return
'<p>'
.&Apache::lonhtmlcommon::confirm_success(&mt("Done"))
- .'<br /><a href="'.$url.'">'.&mt("Continue").'</a>'
+ .'<br /><a href="'.&url($destfn).'">'.&mt("Continue").'</a>'
.'<script type="text/javascript">'
- .'location.href="'.$url.'";'
+ .'location.href="'.&url($destfn,'js').'";'
.'</script>'
.'</p>';
}
@@ -167,11 +167,15 @@
}
sub url {
- my $fn=shift;
+ my ($fn,$context) = @_;
my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
$fn=~ s/^\Q$londocroot\E//;
$fn=~s{/\./}{/}g;
- $fn=&HTML::Entities::encode($fn,'<>"&');
+ if ($context eq 'js') {
+ &js_escape(\$fn);
+ } else {
+ $fn=&HTML::Entities::encode($fn,'\'<>"&');
+ }
return $fn;
}
@@ -350,9 +354,10 @@
}
sub cleanDest {
- my ($request,$dest,$subdir,$fn,$uname,$udom)=@_;
+ my ($dest,$subdir,$fn,$uname,$udom)=@_;
#remove bad characters
my $foundbad=0;
+ my $warnings;
my $error='';
if ($subdir && $dest =~/\./) {
$foundbad=1;
@@ -367,30 +372,29 @@
my ($newpath)=($dest=~m|(.*)/|);
($newpath,$error)=&relativeDest($fn,$newpath,$uname,$udom);
if (! -d "$newpath") {
- $request->print('<p class="LC_warning">'
- .&mt("You have requested to create file in directory [_1] which doesn't exist. The requested directory path has been removed from the requested filename."
- ,&display($newpath))
- .'</p>');
+ $warnings = '<p class="LC_warning">'
+ .&mt("You have requested to create file in directory [_1] which doesn't exist. The requested directory path has been removed from the requested filename."
+ ,&display($newpath))
+ .'</p>';
$dest=~s|.*/||;
}
}
- if ($dest =~ /\.(\d+)\.(\w+)$/){
- $request->print('<p class="LC_warning">'
- .&mt('Bad filename [_1]',&display($dest))
- .'<br />'
- .&mt('[_1](name).(number).(extension)[_2] not allowed.','<tt>','</tt>')
- .'<br />'
- .&mt('Removing the [_1].number.[_2] from requested filename.','<tt>','</tt>')
- .'</p>');
+ if ($dest =~ /\.(\d+)\.(\w+)$/) {
+ $warnings .= '<p class="LC_warning">'
+ .&mt('Bad filename [_1]',&display($dest))
+ .'<br />'
+ .&mt('[_1](name).(number).(extension)[_2] not allowed.','<tt>','</tt>')
+ .'<br />'
+ .&mt('Removing the [_1].number.[_2] from requested filename.','<tt>','</tt>')
+ .'</p>';
$dest =~ s/\.(\d+)(\.\w+)$/$2/;
}
if ($foundbad) {
- $request->print('<p class="LC_warning">'
- .&mt('Invalid characters in requested name have been removed.')
- .'</p>'
- );
+ $warnings .= '<p class="LC_warning">'
+ .&mt('Invalid characters in requested name have been removed.')
+ .'</p>';
}
- return ($dest,$error);
+ return ($dest,$error,$warnings);
}
sub relativeDest {
@@ -469,7 +473,7 @@
sub CloseForm2 {
my ($request, $user, $fn) = @_;
- $request->print(&done(&url($fn)));
+ $request->print(&done($fn));
}
=pod
@@ -840,6 +844,9 @@
=item $newfilename
- Name of the file to be created; no path information
+
+=item $warnings - Information about changes to filename made by cleanDest().
+
=back
Side Effects:
@@ -856,8 +863,8 @@
=cut
sub NewFile1 {
- my ($request, $user, $domain, $fn, $newfilename) = @_;
- return if (&filename_check($newfilename) ne 'ok');
+ my ($request, $user, $domain, $fn, $newfilename, $warnings) = @_;
+ return if (&filename_check($newfilename,$warnings) ne 'ok');
if ($env{'form.action'} =~ /new(.+)file/) {
my $extension=$1;
@@ -870,8 +877,8 @@
}
}
my ($type, $result)=&exists($user,$domain,$newfilename);
- $request->print($result);
if ($type eq 'error') {
+ $request->print($warnings.$result);
$request->print('</form>');
} else {
my $extension;
@@ -883,6 +890,7 @@
my @okexts = qw(xml html xhtml htm xhtm problem page sequence rights sty task library js css txt);
if (($extension eq '') || (!grep(/^\Q$extension\E/, at okexts))) {
my $validexts = '.'.join(', .', at okexts);
+ $request->print($warnings.$result);
$request->print('<p class="LC_warning">'.
&mt('Invalid filename: ').&display($newfilename).'</p><p>'.
&mt('The name of the new file needs to end with an appropriate file extension to indicate the type of file to create.').'<br />'.
@@ -895,14 +903,15 @@
'</span></form></p>'.
'<p><form action="'.&url($fn).
'" method="post"><p><input type="submit" value="'.&mt('Cancel').'" /></form></p>');
- } elsif ($type ne 'warning') {
+ } elsif (($type ne 'warning') && ($warnings eq '') && ($result eq '')) {
my $query = "";
$query .= "?mode=" . $env{'form.mode'} unless (!exists($env{'form.mode'}) || !length($env{'form.mode'}));
$request->print('
<script type="text/javascript">
- window.location = "'.&url($newfilename). $query .'";
+ window.location = "'.&url($newfilename,'js'). $query .'";
</script>');
} else {
+ $request->print($warnings.$result);
$request->print('<p>'.&mt('Make new file').' '.&display($newfilename).'?</p>');
$request->print('</form>');
$request->print('<form action="'.&url($newfilename).
@@ -965,8 +974,8 @@
my $doingdir=0;
if ($env{'form.action'} eq 'newdir') { $doingdir=1; }
- my ($newfilename,$error) =
- &cleanDest($r,$env{'form.newfilename'},$doingdir,$fn,$uname,$udom);
+ my ($newfilename,$error,$warnings) =
+ &cleanDest($env{'form.newfilename'},$doingdir,$fn,$uname,$udom);
unless ($error) {
($newfilename,$error)=&relativeDest($fn,$newfilename,$uname,$udom);
}
@@ -977,6 +986,9 @@
} else {
$dirlist=$fn;
}
+ if ($warnings) {
+ $r->print($warnings);
+ }
$r->print('<div class="LC_error">'.$error.'</div>'.
'<p><a href="'.&url($dirlist).'">'.&mt('Return to Directory').
'</a></p>');
@@ -986,49 +998,57 @@
'<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'.
'<input type="hidden" name="phase" value="two" />'.
'<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
-
- if ($env{'form.action'} eq 'rename') {
- &Rename1($r, $uname, $udom, $fn, $newfilename, 'rename');
- } elsif ($env{'form.action'} eq 'move') {
- &Rename1($r, $uname, $udom, $fn, $newfilename, 'move');
- } elsif ($env{'form.action'} eq 'delete') {
- &Delete1($r, $uname, $udom, $fn);
- } elsif ($env{'form.action'} eq 'decompress') {
- &Decompress1($r, $uname, $udom, $fn);
- } elsif ($env{'form.action'} eq 'copy') {
- if($newfilename) {
- &Copy1($r, $uname, $udom, $fn, $newfilename);
- } else {
- $r->print('<p class="LC_error">'
- .&mt('No new filename specified.')
- .'</p></form>'
- );
- }
- } elsif ($env{'form.action'} eq 'newdir') {
- my $mode = '';
- if (exists($env{'form.callingmode'}) ) {
- $mode = $env{'form.callingmode'};
- }
- &NewDir1($r, $uname, $udom, $fn, $newfilename, $mode);
- } elsif ($env{'form.action'} eq 'newfile' ||
- $env{'form.action'} eq 'newhtmlfile' ||
- $env{'form.action'} eq 'newproblemfile' ||
- $env{'form.action'} eq 'newpagefile' ||
- $env{'form.action'} eq 'newsequencefile' ||
- $env{'form.action'} eq 'newrightsfile' ||
- $env{'form.action'} eq 'newstyfile' ||
- $env{'form.action'} eq 'newtaskfile' ||
- $env{'form.action'} eq 'newlibraryfile' ||
- $env{'form.action'} eq 'Select Action') {
+
+ if ($env{'form.action'} eq 'newfile' ||
+ $env{'form.action'} eq 'newhtmlfile' ||
+ $env{'form.action'} eq 'newproblemfile' ||
+ $env{'form.action'} eq 'newpagefile' ||
+ $env{'form.action'} eq 'newsequencefile' ||
+ $env{'form.action'} eq 'newrightsfile' ||
+ $env{'form.action'} eq 'newstyfile' ||
+ $env{'form.action'} eq 'newtaskfile' ||
+ $env{'form.action'} eq 'newlibraryfile' ||
+ $env{'form.action'} eq 'Select Action') {
my $empty=&mt('Type Name Here');
- if (($newfilename!~/\/$/) && ($newfilename!~/$empty$/)) {
- &NewFile1($r, $uname, $udom, $fn, $newfilename);
- } else {
+ if (($newfilename!~/\/$/) && ($newfilename!~/$empty$/)) {
+ &NewFile1($r, $uname, $udom, $fn, $newfilename, $warnings);
+ } else {
+ if ($warnings) {
+ $r->print($warnings);
+ }
$r->print('<p class="LC_error">'
.&mt('No new filename specified.')
.'</p></form>'
);
- }
+ }
+ } else {
+ if ($warnings) {
+ $r->print($warnings);
+ }
+ if ($env{'form.action'} eq 'rename') {
+ &Rename1($r, $uname, $udom, $fn, $newfilename, 'rename');
+ } elsif ($env{'form.action'} eq 'move') {
+ &Rename1($r, $uname, $udom, $fn, $newfilename, 'move');
+ } elsif ($env{'form.action'} eq 'delete') {
+ &Delete1($r, $uname, $udom, $fn);
+ } elsif ($env{'form.action'} eq 'decompress') {
+ &Decompress1($r, $uname, $udom, $fn);
+ } elsif ($env{'form.action'} eq 'copy') {
+ if ($newfilename) {
+ &Copy1($r, $uname, $udom, $fn, $newfilename);
+ } else {
+ $r->print('<p class="LC_error">'
+ .&mt('No new filename specified.')
+ .'</p></form>'
+ );
+ }
+ } elsif ($env{'form.action'} eq 'newdir') {
+ my $mode = '';
+ if (exists($env{'form.callingmode'}) ) {
+ $mode = $env{'form.callingmode'};
+ }
+ &NewDir1($r, $uname, $udom, $fn, $newfilename, $mode);
+ }
}
}
@@ -1417,7 +1437,7 @@
['<a href="'.&url($dest).'">'.&mt('Return to Directory').'</a>',
'<a href="'.&url($dest_newname).'">'.$disp_newname.'</a>']));
} else {
- $r->print(&done(&url($dest)));
+ $r->print(&done($dest));
}
}
}
More information about the LON-CAPA-cvs
mailing list