[LON-CAPA-cvs] cvs: loncom /publisher loncleanup.pm londiff.pm lonpubdir.pm
www
lon-capa-cvs@mail.lon-capa.org
Sun, 29 May 2005 01:46:18 -0000
This is a MIME encoded message
--www1117331178
Content-Type: text/plain
www Sat May 28 21:46:18 2005 EDT
Modified files:
/loncom/publisher loncleanup.pm londiff.pm lonpubdir.pm
Log:
Cleanup handler
--www1117331178
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20050528214618.txt"
Index: loncom/publisher/loncleanup.pm
diff -u loncom/publisher/loncleanup.pm:1.3 loncom/publisher/loncleanup.pm:1.4
--- loncom/publisher/loncleanup.pm:1.3 Sat May 28 14:53:50 2005
+++ loncom/publisher/loncleanup.pm Sat May 28 21:46:16 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to cleanup XML files
#
-# $Id: loncleanup.pm,v 1.3 2005/05/28 18:53:50 albertel Exp $
+# $Id: loncleanup.pm,v 1.4 2005/05/29 01:46:16 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -244,21 +244,85 @@
sub phaseone {
my ($r,$fn,$uname,$udom)=@_;
+ $r->print(&mt('Select actions to attempt:').
+ '<br /><input type="checkbox" name="linefeed" checked="checked" /> '.
+ &mt('Linefeeds, formfeeds, and carriage returns').
+ '<br /><input type="checkbox" name="empty" checked="checked" /> '.
+ &mt('Empty tags').
+ '<br /><input type="checkbox" name="lower" checked="checked" /> '.
+ &mt('Lower casing').
+ '<br /><input type="checkbox" name="symbol"checked="checked" /> '.
+ &mt('Symbol font').
+ '<input type="hidden" name="phase" value="two" />'.
+ '<p><input type="submit" value="'.&mt('Cleanup').'" /></p>');
}
sub phasetwo {
my ($r,$fn,$uname,$udom)=@_;
+ open(IN,'/home/'.$uname.'/public_html/'.$fn);
+ my $text='';
+ while (my $line=<IN>) {
+ $text.=$line;
+ }
+ close(IN);
+ my $uri='/~'.$uname.$fn;
+ my $result=&Apache::lonnet::ssi_body($uri,
+ ('grade_target'=>'web',
+ 'return_only_error_and_warning_counts' => 1));
+ my ($errorcount,$warningcount)=split(':',$result);
+ $r->print(&mt('Original file').': '.
+ $errorcount.' '.&mt('error(s)').', '.
+ $warningcount.' '.&mt('warning(s)'));
+ $text=&htmlclean($text,1,
+ ($env{'form.linefeed'} ne 'on'),
+ ($env{'form.empty'} ne 'on'),
+ ($env{'form.lower'} ne 'on'),
+ ($env{'form.symbol'} ne 'on'));
+ my ($main,$ext)=($fn=~/^(.*)\.(\w+)/);
+ my $newfn=$main.'_Auto_Cleaned_Up.'.$ext;
+ open(OUT,'>/home/'.$uname.'/public_html'.$newfn);
+ print OUT $text;
+ close(OUT);
+ my $newuri='/~'.$uname.$newfn;
+ $result=&Apache::lonnet::ssi_body($newuri,
+ ('grade_target'=>'web',
+ 'return_only_error_and_warning_counts' => 1));
+ ($errorcount,$warningcount)=split(':',$result);
+ $r->print('<br />'.&mt('Cleaned up file').': '.
+ $errorcount.' '.&mt('error(s)').', '.
+ $warningcount.' '.&mt('warning(s)').
+ '<br /><a href="'.$newuri.'" target="prev">'.
+ &mt('Open (and edit) cleaned up file in new window').'</a>'.
+ '<br /><a href="/adm/diff?filename='.&Apache::lonnet::escape($uri).
+ '&versionone=priv&filetwo='.
+ &Apache::lonnet::escape($newuri).'" target="prev">'.
+ &mt('Show diffs in new window').'</a><br />'.
+ '<input type="hidden" name="phase" value="three" />'.
+ '<input type="submit" name="accept" value="'.&mt('Accept Result').'" />'.
+ '<input type="submit" name="reject" value="'.&mt('Reject Result').'" />'
+ );
}
sub phasethree {
my ($r,$fn,$uname,$udom)=@_;
+ my $old='/home/'.$uname.'/public_html/'.$fn;
+ my ($main,$ext)=($fn=~/^(.*)\.(\w+)/);
+ my $newfn=$main.'_Auto_Cleaned_Up.'.$ext;
+ my $new='/home/'.$uname.'/public_html'.$newfn;
+ if ($env{'form.accept'}) {
+ $r->print(&mt('Accepting changes'));
+ move($new,$old);
+ } else {
+ $r->print(&mt('Rejeting changes'));
+ unlink($new);
+ }
}
# ---------------------------------------------------------------- Main Handler
sub handler {
my $r=shift;
-
+ my $fn='';
# Get query string for limited number of parameters
@@ -302,16 +366,26 @@
$r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
$r->print(&Apache::loncommon::bodytag('Cleanup XML Document'));
-
- if ($env{'form.phase'} eq 'three') {
- &phasethree($r,$fn,$uname,$udom);
- } elsif ($env{'form.phase'} eq 'two') {
- &phasetwo($r,$fn,$uname,$udom);
+ $r->print('<h2>'.$fn.'</h2>'.
+ '<form action="/adm/cleanup" method="post">'.
+ '<input type="hidden" name="filename" value="'.$env{'form.filename'}.'" />');
+ unless ($fn=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
+ $r->print(&mt('Cannot cleanup this filetype'));
} else {
- &phaseone($r,$fn,$uname,$udom);
+ if ($env{'form.phase'} eq 'three') {
+ &phasethree($r,$fn,$uname,$udom);
+ } elsif ($env{'form.phase'} eq 'two') {
+ &phasetwo($r,$fn,$uname,$udom);
+ } else {
+ &phaseone($r,$fn,$uname,$udom);
+ }
}
-
- $r->print('</body></html>');
+ my $dir=$fn;
+ $dir=~s/\/[^\/]+$/\//;
+ $r->print('</form>'.
+ '<br /><a href="/priv/'.$uname.'/'.$fn.'">'.&mt('Back to Source File').'</a>'.
+ '<br /><a href="/priv/'.$uname.'/'.$dir.'">'.&mt('Back to Source Directory').'</a>'.
+ '</body></html>');
return OK;
}
Index: loncom/publisher/londiff.pm
diff -u loncom/publisher/londiff.pm:1.16 loncom/publisher/londiff.pm:1.17
--- loncom/publisher/londiff.pm:1.16 Thu Apr 7 02:56:26 2005
+++ loncom/publisher/londiff.pm Sat May 28 21:46:16 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to show differences between file versions
#
-# $Id: londiff.pm,v 1.16 2005/04/07 06:56:26 albertel Exp $
+# $Id: londiff.pm,v 1.17 2005/05/29 01:46:16 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,23 +25,6 @@
#
# http://www.lon-capa.org/
#
-#
-# (Handler to retrieve an old version of a file
-#
-# (Publication Handler
-#
-# (TeX Content Handler
-#
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
-#
-# 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
-# 03/23 Guy Albertelli
-# 03/24,03/29 Gerd Kortemeyer)
-#
-# 03/31,04/03 Gerd Kortemeyer)
-#
-# 05/02/01,05/09 Gerd Kortemeyer
-#
###
package Apache::londiff;
@@ -90,7 +73,7 @@
# Get query string for limited number of parameters
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['filename','versiontwo','versionone']);
+ ['filename','versiontwo','versionone','filetwo']);
# Get the files
my $cuname=$env{'user.name'};
@@ -98,19 +81,19 @@
if ($env{'form.filename'}=~/^\/res\//) {
($cudom,$cuname,$env{'form.filename'})=
- ($env{'form.filename'}=~/^\/res\/(\w+)\/(\w+)\/(.*)$/);
+ ($env{'form.filename'}=~/^\/res\/(\w+)\/(\w+)\/(.*)$/);
} else {
- unless (($cuname,$cudom)=
- &Apache::loncacc::constructaccess($env{'form.filename'},
- $r->dir_config('lonDefDomain'))) {
- $r->log_reason($cuname.' at '.$cudom.
- ' trying to get diffs file '.$env{'form.filename'}.
- ' - not authorized',
- $r->filename);
- return HTTP_NOT_ACCEPTABLE;
- }
+ unless (($cuname,$cudom)=
+ &Apache::loncacc::constructaccess($env{'form.filename'},
+ $r->dir_config('lonDefDomain'))) {
+ $r->log_reason($cuname.' at '.$cudom.
+ ' trying to get diffs file '.$env{'form.filename'}.
+ ' - not authorized',
+ $r->filename);
+ return HTTP_NOT_ACCEPTABLE;
+ }
}
-
+
my $efn=$env{'form.filename'};
$efn=~s/\/\~(\w+)//g;
@@ -126,7 +109,8 @@
$r->print(&Apache::loncommon::bodytag('Resource Differences'));
- $r->print('<h1>'.&mt('Compare versions of').' <tt>'.$efn.'</tt></h1>');
+ $r->print('<h1>'.($env{'form.filetwo'}?'':&mt('Compare versions of')).
+ ' <tt>'.$efn.'</tt></h1>');
if (($cuname ne $env{'user.name'}) || ($cudom ne $env{'user.domain'})) {
$r->print('<h3><font color=red>Co-Author: '.$cuname.' at '.$cudom.
@@ -134,75 +118,80 @@
}
- if (&Apache::loncommon::fileembstyle(($efn=~/\.(\w+)$/)) eq
- 'ssi') {
- $r->print('<p><font color="red">');
- if ($env{'form.versionone'} eq 'priv') {
- my $fn='/home/'.$cuname.'/public_html/'.$efn;
- @f1=&get_split_file($fn,'local');
- $r->print('<b>'.&mt('Construction Space Version').'</b>');
- } else {
- my $fn=
- '/home/httpd/html//res/'.$cudom.'/'.$cuname.'/';
- if ($env{'form.versionone'}) {
- my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
- $fn.=$main.'.'.$env{'form.versionone'}.'.'.$suffix;
- $r->print('<b>'.&mt('Version').' '.$env{'form.versionone'}.'</b>');
- } else {
- $fn.=$efn;
- $r->print('<b>'.&mt('Current Version').'</b>');
- }
- @f1=&get_split_file($fn,'remote');
- }
-
- $r->print('</font><br />'.&mt('versus').'<br /><font color="green">');
-
- if ($env{'form.versiontwo'} eq 'priv') {
- my $fn='/home/'.$cuname.'/public_html/'.$efn;
- @f2=&get_split_file($fn,'local');
- $r->print('<b>'.&mt('Construction Space Version').'</b>');
- } else {
- my $fn=
- '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
- if ($env{'form.versiontwo'}) {
- my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
- $fn.=$main.'.'.$env{'form.versiontwo'}.'.'.$suffix;
- $r->print('<b>'.&mt('Version').' '.$env{'form.versiontwo'}.'</b>');
- } else {
- $fn.=$efn;
- $r->print('<b>'.&mt('Current Version').'</b>');
- }
- @f2=&get_split_file($fn,'remote');
- }
- $r->print('</font></p>');
+ if (&Apache::loncommon::fileembstyle(($efn=~/\.(\w+)$/)) eq 'ssi') {
+ $r->print('<p><font color="red">');
+ if ($env{'form.versionone'} eq 'priv') {
+ my $fn='/home/'.$cuname.'/public_html/'.$efn;
+ @f1=&get_split_file($fn,'local');
+ $r->print('<b>'.&mt('Construction Space Version').'</b>');
+ } else {
+ my $fn=
+ '/home/httpd/html//res/'.$cudom.'/'.$cuname.'/';
+ if ($env{'form.versionone'}) {
+ my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
+ $fn.=$main.'.'.$env{'form.versionone'}.'.'.$suffix;
+ $r->print('<b>'.&mt('Version').' '.$env{'form.versionone'}.'</b>');
+ } else {
+ $fn.=$efn;
+ $r->print('<b>'.&mt('Current Version').'</b>');
+ }
+ @f1=&get_split_file($fn,'remote');
+ }
+
+ $r->print('</font><br />'.&mt('versus').'<br /><font color="green">');
+
+ if ($env{'form.filetwo'}) {
+ my $efn2=$env{'form.filetwo'};
+ $efn2=~s/\/\~(\w+)//g;
+ my $fn='/home/'.$cuname.'/public_html/'.$efn2;
+ @f2=&get_split_file($fn,'local');
+ $r->print('<tt>'.$efn2.'</tt>');
+ } elsif ($env{'form.versiontwo'} eq 'priv') {
+ my $fn='/home/'.$cuname.'/public_html/'.$efn;
+ @f2=&get_split_file($fn,'local');
+ $r->print('<b>'.&mt('Construction Space Version').'</b>');
+ } else {
+ my $fn=
+ '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
+ if ($env{'form.versiontwo'}) {
+ my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
+ $fn.=$main.'.'.$env{'form.versiontwo'}.'.'.$suffix;
+ $r->print('<b>'.&mt('Version').' '.$env{'form.versiontwo'}.'</b>');
+ } else {
+ $fn.=$efn;
+ $r->print('<b>'.&mt('Current Version').'</b>');
+ }
+ @f2=&get_split_file($fn,'remote');
+ }
+ $r->print('</font></p>');
# Run diff
- my $diffs = diff(\@f1, \@f2);
+ my $diffs = diff(\@f1, \@f2);
# Start page output
- my $chunk;
- my $line;
+ my $chunk;
+ my $line;
- $r->print('<pre>');
+ $r->print('<pre>');
- foreach $chunk (@$diffs) {
-
- foreach $line (@$chunk) {
- my ($sign, $lineno, $text) = @$line;
- $text=~s/\</\<\;/g;
- $text=~s/\>/\>\;/g;
- $lineno=substr($lineno.' ',0,7);
- $r->print('<font color='.(($sign eq '+')?'green':'red').'>'.
- $sign.' '.$lineno.' '.$text."</font>\n");
- }
- $r->print("<hr>\n");
- }
- $r->print('</pre>');
-
-} else {
- $r->print('<h1><font color=red>'.&mt('Binary File').'</font></h1>');
-}
+ foreach $chunk (@$diffs) {
+
+ foreach $line (@$chunk) {
+ my ($sign, $lineno, $text) = @$line;
+ $text=~s/\</\<\;/g;
+ $text=~s/\>/\>\;/g;
+ $lineno=substr($lineno.' ',0,7);
+ $r->print('<font color='.(($sign eq '+')?'green':'red').'>'.
+ $sign.' '.$lineno.' '.$text."</font>\n");
+ }
+ $r->print("<hr>\n");
+ }
+ $r->print('</pre>');
+
+ } else {
+ $r->print('<h1><font color=red>'.&mt('Binary File').'</font></h1>');
+ }
$r->print('<center><a href="javascript:window.close();">'.&mt('Close This Window').'</a></center></body></html>');
return OK;
}
Index: loncom/publisher/lonpubdir.pm
diff -u loncom/publisher/lonpubdir.pm:1.82 loncom/publisher/lonpubdir.pm:1.83
--- loncom/publisher/lonpubdir.pm:1.82 Fri May 27 22:18:03 2005
+++ loncom/publisher/lonpubdir.pm Sat May 28 21:46:16 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Construction Space Directory Lister
#
-# $Id: lonpubdir.pm,v 1.82 2005/05/28 02:18:03 www Exp $
+# $Id: lonpubdir.pm,v 1.83 2005/05/29 01:46:16 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -578,8 +578,8 @@
$editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceColoredit=1" target="_parent">'.&mt('Edit').'</a>)';
}
if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
- $editlink.='<a href="/adm/cleanup?filename=/~'.$uname.
- $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Clean Up').'</a>';
+ $editlink.=' (<a href="/adm/cleanup?filename=/~'.$uname.
+ $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Clean Up').')</a>';
}
if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
$editlink=' (<a target="_parent" href="/adm/cfile?decompress=/~'.
--www1117331178--