--- loncom/publisher/loncfile.pm 2013/07/03 05:03:19 1.120 +++ loncom/publisher/loncfile.pm 2023/07/14 23:20:15 1.127 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.120 2013/07/03 05:03:19 raeburn Exp $ +# $Id: loncfile.pm,v 1.127 2023/07/14 23:20:15 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,13 +40,13 @@ Apache::loncfile - Authoring space file management. =head1 SYNOPSIS - - Content handler for buttons on the top frame of the construction space + + Content handler for buttons on the top frame of the construction space directory. =head1 INTRODUCTION - loncfile is invoked when buttons in the top frame of the construction + loncfile is invoked when buttons in the top frame of the construction space directory listing are clicked. All operations proceed in two phases. The first phase describes to the user exactly what will be done. If the user confirms the operation, the second phase commits the operation and indicates @@ -88,13 +88,13 @@ my $r; # Needs to be global for some Parameters: =over 4 - + =item $request - The current request operation. =item $message - The message to put in the log file. =back - + Returns: nothing. @@ -109,13 +109,13 @@ sub Debug { } sub done { - my ($url) = @_; + my ($destfn) = @_; return '
'
.&Apache::lonhtmlcommon::confirm_success(&mt("Done"))
- .'
'.&mt("Continue").''
+ .'
'.&mt("Continue").''
.''
.'
'.&mt('Error: destination for operation is an existing directory.').'
'); + return ('error',''.&mt('Error: destination for operation is an existing directory.').'
'); } if ( -e $published) { if ( -e $construct ) { $type = 'warning'; - $result.=''.&mt('Warning: target file exists, and has been published!').'
'; + $result.=''.&mt('Warning: target file exists, and has been published!').'
'; } else { my $published_type = (-d $published) ? 'directory' : 'file'; if ($published_type eq $creating) { $type = 'warning'; - $result.=''.&mt("Warning: a published $published_type of this name exists.").'
'; + $result.=''.&mt("Warning: a published $published_type of this name exists.").'
'; } else { $type = 'error'; - $result.=''.&mt("Error: a published $published_type of this name exists.").'
'; + $result.=''.&mt("Error: a published $published_type of this name exists.").'
'; } } } elsif ( -e $construct) { $type = 'warning'; - $result.=''.&mt('Warning: target file exists!').'
'; + $result.=''.&mt('Warning: target file exists!').'
'; } return ($type,$result); @@ -309,7 +313,7 @@ sub exists { =pod =item checksuffix($old, $new) - + Determine if a resource filename suffix (the stuff after the .) would change as a result of this operation. @@ -344,15 +348,16 @@ sub checksuffix { if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; } if (lc($oldsuffix) ne lc($newsuffix)) { $result.= - ''.&mt('Warning: change of MIME type!').'
'; + ''.&mt('Warning: change of MIME type!').'>
'; } return $result; } 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 @@ sub cleanDest { my ($newpath)=($dest=~m|(.*)/|); ($newpath,$error)=&relativeDest($fn,$newpath,$uname,$udom); if (! -d "$newpath") { - $request->print('' - .&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)) - .'
'); + $warnings = '' + .&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)) + .'
'; $dest=~s|.*/||; } } - if ($dest =~ /\.(\d+)\.(\w+)$/){ - $request->print(''
- .&mt('Bad filename [_1]',&display($dest))
- .'
'
- .&mt('[_1](name).(number).(extension)[_2] not allowed.','','')
- .'
'
- .&mt('Removing the [_1].number.[_2] from requested filename.','','')
- .'
'
+ .&mt('Bad filename [_1]',&display($dest))
+ .'
'
+ .&mt('[_1](name).(number).(extension)[_2] not allowed.','','')
+ .'
'
+ .&mt('Removing the [_1].number.[_2] from requested filename.','','')
+ .'
' - .&mt('Invalid characters in requested name have been removed.') - .'
' - ); + $warnings .= '' + .&mt('Invalid characters in requested name have been removed.') + .'
'; } - return ($dest,$error); + return ($dest,$error,$warnings); } sub relativeDest { @@ -459,7 +463,7 @@ Parameters: =item $user - string [in] - Name of the user that is initiating the request. -=item $directory - string [in] - Directory in which the operation is +=item $directory - string [in] - Directory in which the operation is being done relative to the top level construction space directory. @@ -469,20 +473,20 @@ Parameters: sub CloseForm2 { my ($request, $user, $fn) = @_; - $request->print(&done(&url($fn))); + $request->print(&done($fn)); } =pod =item Rename1($request, $filename, $user, $domain, $dir) - + Perform phase 1 processing of the file rename operation. Parameters: =over 4 -=item $request - Apache Request Object [in] The request object for the +=item $request - Apache Request Object [in] The request object for the current request. =item $filename - The filename relative to construction space. @@ -505,7 +509,7 @@ new filename relative to the current dir =back -=cut +=cut sub Rename1 { my ($request, $user, $domain, $fn, $newfilename, $style) = @_; @@ -583,7 +587,7 @@ sub Rename1 { ); return; } - + } =pod @@ -597,7 +601,7 @@ Parameters: =over 4 -=item $request - Apache Request Object [in] request object for the current +=item $request - Apache Request Object [in] request object for the current request. =item $user - string [in] Name of the user initiating the request. @@ -628,7 +632,7 @@ sub Delete1 { ); return; } - } else { + } else { unless (&obsolete_unpub($user,$domain,$fn)) { $request->print(''
.&mt('Cannot delete non-obsolete published file.')
@@ -665,7 +669,7 @@ Parameters:
=over 4
-=item $request - Apache Request Object [in] request object for the current
+=item $request - Apache Request Object [in] request object for the current
request.
=item $user - string [in] Name of the user initiating the request.
@@ -691,7 +695,7 @@ sub Copy1 {
if ($newfilename =~ m|/[^\.]+$|) {
#no extension add on original extension
if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { $newfilename.='.'.$1; }
- }
+ }
$newfilename=~s://+:/:g; # remove duplicate /
while ($newfilename=~m:/\.\./:) {
$newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
@@ -708,9 +712,8 @@ sub Copy1 {
my ($dir,$fname) = ($fn =~ m{^(.+/)([^/]+)$});
my $filesize = $fileinfo[7];
$filesize = int($filesize/1000); #expressed in kb
- my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$domain/$user";
- my $output = &Apache::loncommon::excess_filesize_authorspace($user,$domain,$authorspace,
- $fname,$filesize,'copy');
+ my $output = &Apache::loncommon::excess_filesize_warning($user,$domain,'author',
+ $fname,$filesize,'copy');
if ($output) {
$request->print($output.' '.
&mt('Invalid filename: ').&display($newfilename).' '.
&mt('The name of the new file needs to end with an appropriate file extension to indicate the type of file to create.').'
'.&mt('Cancel').'');
return;
@@ -737,7 +740,7 @@ sub Copy1 {
=pod
=item NewDir1
-
+
Does all phase 1 processing of directory creation:
Ensures that the user provides a new directory name,
and that the directory does not already exist.
@@ -755,7 +758,7 @@ Parameters:
=item $fn - source file.
-=item $newdir - Name of the directory to be created; path relative to the
+=item $newdir - Name of the directory to be created; path relative to the
top level of construction space.
=back
@@ -819,7 +822,7 @@ sub Decompress1 {
=pod
=item NewFile1
-
+
Does all phase 1 processing of file creation:
Ensures that the user provides a new filename, adds proper extension
if needed and that the file does not already exist, if it is a html,
@@ -841,6 +844,9 @@ Parameters:
=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:
@@ -857,8 +863,8 @@ button which returns you to the director
=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;
@@ -871,8 +877,8 @@ sub NewFile1 {
}
}
my ($type, $result)=&exists($user,$domain,$newfilename);
- $request->print($result);
if ($type eq 'error') {
+ $request->print($warnings.$result);
$request->print('');
} else {
my $extension;
@@ -884,6 +890,7 @@ sub NewFile1 {
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/,@okexts))) {
my $validexts = '.'.join(', .',@okexts);
+ $request->print($warnings.$result);
$request->print('
'.
@@ -896,16 +903,22 @@ sub NewFile1 {
'
'.&mt('Make new file').' '.&display($newfilename).'?
'); + $request->print(''); + $request->print(''); + $request->print(''); } - - $request->print(''.&mt('Make new file').' '.&display($newfilename).'?
'); - $request->print(''); - - $request->print(''); - $request->print(''); } return; } @@ -925,7 +938,7 @@ sub filename_check { ' '.&mt('Not Allowed').''); return; } - return 'ok'; + return 'ok'; } =pod @@ -936,7 +949,7 @@ sub filename_check { are returned if the request cannot be performed (e.g. attempts to manipulate files that are nonexistent). If the operation can be performed, what is about to be done will be presented to the user for confirmation. If the -user confirms the request, then phase two is executed, the action +user confirms the request, then phase two is executed, the action performed and reported to the user. Parameters: @@ -945,12 +958,12 @@ performed and reported to the user. =item $r - request object [in] - The Apache request being executed. -=item $fn = string [in] - The filename being manipulated by the +=item $fn = string [in] - The filename being manipulated by the request. =item $uname - string [in] Name of user logged in and doing this action. -=item $udom - string [in] Domain name under which the user logged in. +=item $udom - string [in] Domain name under which the user logged in. =back @@ -958,11 +971,11 @@ performed and reported to the user. sub phaseone { my ($r,$fn,$uname,$udom)=@_; - + 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); } @@ -971,7 +984,10 @@ sub phaseone { if ($fn=~m{^(.*/)[^/]+$}) { $dirlist=$1; } else { - $dirlist=$fn; + $dirlist=$fn; + } + if ($warnings) { + $r->print($warnings); } $r->print(''.&mt('Return to Directory').
@@ -982,49 +998,57 @@ sub phaseone {
''.
''.
'');
-
- 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(' '
- .&mt('No new filename specified.')
- .' '
.&mt('No new filename specified.')
.' '
+ .&mt('No new filename specified.')
+ .' '.&mt('Location').': '.&display($fn).' '
- .&mt('Co-Author [_1]',$uname.':'.$udom)
- .' '
+ .&mt('Co-Author [_1]',$uname.':'.$udom)
+ .' '
+ .&mt('Creation of a new file of type: [_1] is not permitted in Course Authoring Space',$newtype)
+ .' '
@@ -1566,7 +1624,7 @@ function writeDone() {
}
$r->print(&Apache::loncommon::end_page());
- return OK;
+ return OK;
}
1;
'.$action{$env{'form.action'}}.'
');
} else {
$r->print('