--- loncom/publisher/lonpublisher.pm 2006/07/19 20:22:03 1.210
+++ loncom/publisher/lonpublisher.pm 2023/01/23 02:24:50 1.295.2.1.2.1
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.210 2006/07/19 20:22:03 albertel Exp $
+# $Id: lonpublisher.pm,v 1.295.2.1.2.1 2023/01/23 02:24:50 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -66,10 +66,10 @@ invocation by F:
=head1 OVERVIEW
-Authors can only write-access the C~authorname/> space. They can
-copy resources into the resource area through the publication step,
-and move them back through a recover step. Authors do not have direct
-write-access to their resource space.
+Authors can only write-access the C space.
+They can copy resources into the resource area through the
+publication step, and move them back through a recover step.
+Authors do not have direct write-access to their resource space.
During the publication step, several events will be
triggered. Metadata is gathered, where a wizard manages default
@@ -102,8 +102,6 @@ to publication space.
Many of the undocumented subroutines implement various magical
parsing shortcuts.
-=over 4
-
=cut
######################################################################
@@ -118,19 +116,20 @@ use Apache::File;
use File::Copy;
use Apache::Constants qw(:common :http :methods);
use HTML::LCParser;
+use HTML::Entities;
+use Encode::Encoder;
use Apache::lonxml;
-use Apache::loncacc;
use DBI;
use Apache::lonnet;
use Apache::loncommon();
+use Apache::lonhtmlcommon;
use Apache::lonmysql;
use Apache::lonlocal;
use Apache::loncfile;
use LONCAPA::lonmetadata;
use Apache::lonmsg;
use vars qw(%metadatafields %metadatakeys);
-use lib '/home/httpd/lib/perl/';
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
my %addid;
@@ -144,8 +143,12 @@ my $cudom;
my $registered_cleanup;
my $modified_urls;
+my $lock;
+
=pod
+=over 4
+
=item B
Evaluates a string that contains metadata. This subroutine
@@ -184,24 +187,25 @@ sub metaeval {
if ($token->[0] eq 'S') {
my $entry=$token->[1];
my $unikey=$entry;
+ next if ($entry =~ m/^(?:parameter|stores)_/);
if (defined($token->[2]->{'package'})) {
- $unikey.='_package_'.$token->[2]->{'package'};
+ $unikey.="\0package\0".$token->[2]->{'package'};
}
if (defined($token->[2]->{'part'})) {
- $unikey.='_'.$token->[2]->{'part'};
+ $unikey.="\0".$token->[2]->{'part'};
}
if (defined($token->[2]->{'id'})) {
- $unikey.='_'.$token->[2]->{'id'};
+ $unikey.="\0".$token->[2]->{'id'};
}
if (defined($token->[2]->{'name'})) {
- $unikey.='_'.$token->[2]->{'name'};
+ $unikey.="\0".$token->[2]->{'name'};
}
- foreach (@{$token->[3]}) {
- $metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
+ foreach my $item (@{$token->[3]}) {
+ $metadatafields{$unikey.'.'.$item}=$token->[2]->{$item};
if ($metadatakeys{$unikey}) {
- $metadatakeys{$unikey}.=','.$_;
+ $metadatakeys{$unikey}.=','.$item;
} else {
- $metadatakeys{$unikey}=$_;
+ $metadatakeys{$unikey}=$item;
}
}
my $newentry=$parser->get_text('/'.$entry);
@@ -261,8 +265,9 @@ sub metaread {
my ($logfile,$fn,$prefix)=@_;
unless (-e $fn) {
print($logfile 'No file '.$fn."\n");
- return ' '.&mt('No file').':'.
- &Apache::loncfile::display($fn).'';
+ return '
';
}
#########################################
@@ -281,15 +287,14 @@ sub metaread {
sub coursedependencies {
my $url=&Apache::lonnet::declutter(shift);
$url=~s/\.meta$//;
- my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
- my $regexp=$url;
- $regexp=~s/(\W)/\\$1/g;
+ my ($adomain,$aauthor)=($url=~ m{^($match_domain)/($match_username)/});
+ my $regexp=quotemeta($url);
$regexp='___'.$regexp.'___course';
my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
$aauthor,$regexp);
my %courses=();
- foreach (keys %evaldata) {
- if ($_=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
+ foreach my $item (keys(%evaldata)) {
+ if ($item=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
$courses{$1}=1;
}
}
@@ -313,8 +318,12 @@ string which presents the form field (fo
=item B
+=item B
+
=item B
+=item B
+
=item B
=back
@@ -324,30 +333,34 @@ string which presents the form field (fo
#########################################
#########################################
sub textfield {
- my ($title,$name,$value)=@_;
+ my ($title,$name,$value,$noline)=@_;
$value=~s/^\s+//gs;
$value=~s/\s+$//gs;
$value=~s/\s+/ /gs;
$title=&mt($title);
$env{'form.'.$name}=$value;
- return "\n
".
- &select_level_form($metadatafields{'highestgradelevel'},'highestgradelevel').
- &textfield('Standards','standards',$metadatafields{'standards'});
-
-
-
+ $intr_scrout.=&textfield('Standards','standards',$metadatafields{'standards'});
$intr_scrout.=&hiddenfield('mime',$1);
@@ -1278,15 +1502,21 @@ END
$intr_scrout.=&hiddenfield('lastrevisiondate',time);
-
+ my $pubowner_last;
+ if ($style eq 'prv') {
+ $pubowner_last = 1;
+ }
$intr_scrout.=&textfield('Publisher/Owner','owner',
- $metadatafields{'owner'});
+ $metadatafields{'owner'},$pubowner_last);
# ---------------------------------------------- Retrofix for unused copyright
if ($metadatafields{'copyright'} eq 'free') {
$metadatafields{'copyright'}='default';
$metadatafields{'sourceavail'}='open';
}
+ if ($metadatafields{'copyright'} eq 'priv') {
+ $metadatafields{'copyright'}='domain';
+ }
# ------------------------------------------------ Dial in reasonable defaults
my $defaultoption=$metadatafields{'copyright'};
unless ($defaultoption) { $defaultoption='default'; }
@@ -1303,33 +1533,32 @@ END
$intr_scrout.=&selectbox('Copyright/Distribution','copyright',
$defaultoption,
\&Apache::loncommon::copyrightdescription,
- (grep !/^public$/,(&Apache::loncommon::copyrightids)));
+ (grep !/^(public|priv)$/,(&Apache::loncommon::copyrightids)));
} else {
$intr_scrout.=&selectbox('Copyright/Distribution','copyright',
$defaultoption,
\&Apache::loncommon::copyrightdescription,
- (&Apache::loncommon::copyrightids));
+ (grep !/^priv$/,(&Apache::loncommon::copyrightids)));
}
my $copyright_help =
- Apache::loncommon::help_open_topic('Publishing_Copyright');
- $intr_scrout =~ s/Distribution:/'Distribution: ' . $copyright_help/ge;
- $intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights').$copyright_help;
+ &Apache::loncommon::help_open_topic('Publishing_Copyright');
+ my $replace=&mt('Copyright/Distribution:');
+ $intr_scrout =~ s/$replace/$replace.' '.$copyright_help/ge;
+
+ $intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights');
$intr_scrout.=&selectbox('Source Distribution','sourceavail',
$defaultsourceoption,
\&Apache::loncommon::source_copyrightdescription,
(&Apache::loncommon::source_copyrightids));
# $intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights');
my $uctitle=&mt('Obsolete');
- $intr_scrout.=
- "\n
$uctitle:".
- '
'.
- &text_with_browse_field('Suggested Replacement for Obsolete File',
+ my $obsolete_checked=($metadatafields{'obsolete'})?' checked="checked"':'';
+ $intr_scrout.="\n".&Apache::lonhtmlcommon::row_title($uctitle)
+ .''
+ .&Apache::lonhtmlcommon::row_closure(1);
+ $intr_scrout.=&text_with_browse_field('Suggested Replacement for Obsolete File',
'obsoletereplacement',
- $metadatafields{'obsoletereplacement'});
+ $metadatafields{'obsoletereplacement'},'',1);
} else {
$intr_scrout.=&hiddenfield('copyright','private');
}
@@ -1355,11 +1584,15 @@ END
&hiddenfield('obsolete',1).
&text_with_browse_field('Suggested Replacement for Obsolete File',
'obsoletereplacement',
- $metadatafields{'obsoletereplacement'});
+ $metadatafields{'obsoletereplacement'},'',1);
}
if (!$batch) {
- $scrout.=$intr_scrout.'';
+ $scrout.=$intr_scrout
+ .&Apache::lonhtmlcommon::end_pick_box()
+ .''
+ .'';
}
return($scrout,0);
}
@@ -1397,6 +1630,8 @@ Returns:
0: fail
1: success
+=back
+
=cut
#'stupid emacs
@@ -1412,17 +1647,17 @@ sub phasetwo {
#
unless ($env{'form.obsolete'}) {
if ($target=~/(\_\_\_|\&\&\&|\:\:\:)/) {
- $r->print(
- ''.&mt('Unsupported character combination').
- ' "'.$1.'" '.&mt('in filename, FAIL').'');
+ $r->print(''.
+ &mt('Unsupported character combination [_1] in filename, FAIL.',"'.$1.'").
+ '');
return 0;
}
unless ($target=~/\.(\w+)$/) {
- $r->print(''.&mt('No valid extension found in filename, FAIL').'');
+ $r->print(''.&mt('No valid extension found in filename, FAIL').'');
return 0;
}
if ($target=~/\.(\d+)\.(\w+)$/) {
- $r->print(''.&mt('Cannot publish versioned resource, FAIL').'');
+ $r->print(''.&mt('Filename of resource contains internal version number. Cannot publish such resources, FAIL').'');
return 0;
}
}
@@ -1434,18 +1669,49 @@ sub phasetwo {
my $logfile;
unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
$r->print(
- ''.
- &mt('No write permission to user directory, FAIL').'');
+ ''.
+ &mt('No write permission to user directory, FAIL').'');
return 0;
}
+
+ if ($source =~ /\.rights$/) {
+ $r->print('
'.&mt('Warning: It can take up to 1 hour for rights changes to fully propagate.').'
');
+ }
+
print $logfile
- "\n================= Publish ".localtime()." Phase Two ================\n".$env{'user.name'}.'@'.$env{'user.domain'}."\n";
+ "\n================= Publish ".localtime()." Phase Two ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";
%metadatafields=();
%metadatakeys=();
&metaeval(&unescape($env{'form.allmeta'}));
-
+
+ if ($batch) {
+ my %commonaccess;
+ map { $commonaccess{$_} = 1; } &Apache::loncommon::get_env_multiple('form.commonaccess');
+ if ($commonaccess{'dist'}) {
+ unless ($style eq 'prv') {
+ if ($env{'form.commondistselect'} eq 'custom') {
+ unless ($source =~ /\.rights$/) {
+ if ($env{'form.commoncustomrights'} =~ m{^/res/.+\.rights$}) {
+ $env{'form.customdistributionfile'} = $env{'form.commoncustomrights'};
+ $env{'form.copyright'} = $env{'form.commondistselect'};
+ }
+ }
+ } elsif ($env{'form.commondistselect'} =~ /^default|domain|public$/) {
+ $env{'form.copyright'} = $env{'form.commondistselect'};
+ }
+ }
+ }
+ unless ($style eq 'prv') {
+ if ($commonaccess{'source'}) {
+ if (($env{'form.commonsourceselect'} eq 'open') || ($env{'form.commonsourceselect'} eq 'closed')) {
+ $env{'form.sourceavail'} = $env{'form.commonsourceselect'};
+ }
+ }
+ }
+ }
+
$metadatafields{'title'}=$env{'form.title'};
$metadatafields{'author'}=$env{'form.author'};
$metadatafields{'subject'}=$env{'form.subject'};
@@ -1467,9 +1733,10 @@ sub phasetwo {
$metadatafields{'obsoletereplacement'}=
$env{'form.obsoletereplacement'};
$metadatafields{'dependencies'}=$env{'form.dependencies'};
- $metadatafields{'modifyinguser'}=$env{'user.name'}.'@'.
+ $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
$env{'user.domain'};
- $metadatafields{'authorspace'}=$cuname.'@'.$cudom;
+ $metadatafields{'authorspace'}=$cuname.':'.$cudom;
+ $metadatafields{'domain'}=$cudom;
my $allkeywords=$env{'form.addkey'};
if (exists($env{'form.keywords'})) {
@@ -1491,8 +1758,8 @@ sub phasetwo {
my $file=$metadatafields{'customdistributionfile'};
unless ($file=~/\.rights$/) {
$r->print(
- ''.&mt('No valid custom distribution rights file specified, FAIL').
- '');
+ ''.&mt('No valid custom distribution rights file specified, FAIL').
+ '');
return 0;
}
}
@@ -1501,21 +1768,21 @@ sub phasetwo {
my $mfh;
unless ($mfh=Apache::File->new('>'.$source.'.meta')) {
$r->print(
- ''.&mt('Could not write metadata, FAIL').
- '');
+ ''.&mt('Could not write metadata, FAIL').
+ '');
return 0;
}
- foreach (sort keys %metadatafields) {
- unless ($_=~/\./) {
- my $unikey=$_;
+ foreach my $field (sort(keys(%metadatafields))) {
+ unless ($field=~/\./) {
+ my $unikey=$field;
$unikey=~/^([A-Za-z]+)/;
my $tag=$1;
$tag=~tr/A-Z/a-z/;
print $mfh "\n\<$tag";
- foreach (split(/\,/,$metadatakeys{$unikey})) {
- my $value=$metadatafields{$unikey.'.'.$_};
+ foreach my $item (split(/\,/,$metadatakeys{$unikey})) {
+ my $value=$metadatafields{$unikey.'.'.$item};
$value=~s/\"/\'\'/g;
- print $mfh ' '.$_.'="'.$value.'"';
+ print $mfh ' '.$item.'="'.$value.'"';
}
print $mfh '>'.
&HTML::Entities::encode($metadatafields{$unikey},'<>&"')
@@ -1552,10 +1819,11 @@ sub phasetwo {
my $srcf=$2;
my $srct=$3;
my $srcd=$1;
- unless ($srcd=~/^\/home\/httpd\/html\/res/) {
+ my $docroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ unless ($srcd=~/^\Q$docroot\E\/res/) {
print $logfile "\nPANIC: Target dir is ".$srcd;
$r->print(
- "Invalid target directory, FAIL");
+ "".&mt('Invalid target directory, FAIL')."");
return 0;
}
opendir(DIR,$srcd);
@@ -1564,25 +1832,24 @@ sub phasetwo {
unlink($srcd.'/'.$filename);
unlink($srcd.'/'.$filename.'.meta');
} else {
- if ($filename=~/\Q$srcf\E\.(\d+)\.\Q$srct\E$/) {
+ if ($filename=~/^\Q$srcf\E\.(\d+)\.\Q$srct\E$/) {
$maxversion=($1>$maxversion)?$1:$maxversion;
}
}
}
closedir(DIR);
$maxversion++;
- $r->print('
Creating old version '.$maxversion.'
');
+ $r->print('
'.&mt('Creating old version [_1]',$maxversion).'
');
print $logfile "\nCreating old version ".$maxversion."\n";
my $copyfile=$srcd.'/'.$srcf.'.'.$maxversion.'.'.$srct;
if (copy($target,$copyfile)) {
print $logfile "Copied old target to ".$copyfile."\n";
- $r->print('
'.&mt('Copied old target file').'
');
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old target file')));
} else {
print $logfile "Unable to write ".$copyfile.':'.$!."\n";
- $r->print("".&mt('Failed to copy old target').
- ", $!, ".&mt('FAIL')."");
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Failed to copy old target').", $!",1));
return 0;
}
@@ -1592,13 +1859,12 @@ sub phasetwo {
if (copy($target.'.meta',$copyfile)) {
print $logfile "Copied old target metadata to ".$copyfile."\n";
- $r->print('
'.&mt('Copied old metadata').'
')
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Copied old metadata')));
} else {
print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
if (-e $target.'.meta') {
- $r->print(
- "".
-&mt('Failed to write old metadata copy').", $!, ".&mt('FAIL')."");
+ $r->print(&Apache::lonhtmlcommon::confirm_success(
+ &mt('Failed to write old metadata copy').", $!",1));
return 0;
}
}
@@ -1620,32 +1886,38 @@ sub phasetwo {
$path.="/$parts[$count]";
if ((-e $path)!=1) {
print $logfile "\nCreating directory ".$path;
- $r->print('
');
+
# ------------------------------------------------ Provide link to new resource
unless ($batch) {
- my $thissrc=$source;
- $thissrc=~s/^\/home\/(\w+)\/public_html/\/priv\/$1/;
-
+ my $thissrc=&Apache::loncfile::url($source);
my $thissrcdir=$thissrc;
$thissrcdir=~s/\/[^\/]+$/\//;
-
$r->print(
- ''.
- &mt('View Published Version').''.
- '