Annotation of loncom/publisher/londiff.pm, revision 1.5
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to show differences between file versions
3: #
4: # (Handler to retrieve an old version of a file
5: #
6: # (Publication Handler
7: #
8: # (TeX Content Handler
9: #
10: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
11: #
12: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
13: # 03/23 Guy Albertelli
14: # 03/24,03/29 Gerd Kortemeyer)
15: #
16: # 03/31,04/03 Gerd Kortemeyer)
17: #
1.5 ! www 18: # 05/02/01,05/09 Gerd Kortemeyer
1.1 www 19:
20: package Apache::londiff;
21:
22: use strict;
23: use Apache::File;
24: use File::Copy;
25: use Algorithm::Diff qw(diff);
26: use Apache::Constants qw(:common :http :methods);
1.5 ! www 27: use Apache::loncacc;
1.1 www 28:
29: sub handler {
30:
31: my $r=shift;
32:
33: # Get query string for limited number of parameters
34:
35: map {
36: my ($name, $value) = split(/=/,$_);
37: $value =~ tr/+/ /;
38: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
39: if (($name eq 'filename') || ($name eq 'versiontwo') ||
40: ($name eq 'versionone')) {
41: unless ($ENV{'form.'.$name}) {
42: $ENV{'form.'.$name}=$value;
43: }
44: }
45: } (split(/&/,$ENV{'QUERY_STRING'}));
46:
47: # Get the files
48:
1.5 ! www 49: my $cuname=$ENV{'user.name'};
! 50: my $cudom=$ENV{'user.domain'};
! 51:
! 52: unless (($cuname,$cudom)=
! 53: &Apache::loncacc::constructaccess($ENV{'form.filename'},
! 54: $r->dir_config('lonDefDomain'))) {
! 55: $r->log_reason($cuname.' at '.$cudom.
! 56: ' trying to get diffs file '.$ENV{'form.filename'}.
! 57: ' - not authorized',
! 58: $r->filename);
! 59: return HTTP_NOT_ACCEPTABLE;
! 60: }
! 61:
! 62: my $efn=$ENV{'form.filename'};
! 63:
! 64: $efn=~s/\/\~(\w+)//g;
! 65:
1.1 www 66: my @f1=();
67: my @f2=();
68:
1.2 www 69: $r->content_type('text/html');
70: $r->send_http_header;
71:
72: $r->print('<html><head><title>LON-CAPA Construction Diffs</title></head>');
73:
74: $r->print('<body bgcolor="#FFFFFF">');
75:
76:
1.5 ! www 77: $r->print('<h1>Compare versions of <tt>'.$efn.'</tt></h1>');
! 78:
! 79: if (($cuname ne $ENV{'user.name'}) || ($cudom ne $ENV{'user.domain'})) {
! 80: $r->print('<h3><font color=red>Co-Author: '.$cuname.' at '.$cudom.
! 81: '</font></h3>');
! 82: }
! 83:
1.2 www 84:
1.5 ! www 85: if (&Apache::lonnet::fileembstyle(($efn=~/\.(\w+)$/)) eq
1.2 www 86: 'ssi') {
1.1 www 87: if ($ENV{'form.versionone'} eq 'priv') {
1.5 ! www 88: my $fn='/home/'.$cuname.'/public_html/'.$efn;
1.1 www 89: if (-e $fn) {
90: my $fh=Apache::File->new($fn);
91: my $line;
92: while($line=<$fh>) {
93: chomp($line);
94: $f1[$#f1+1]=$line;
95: }
96: }
1.4 www 97: $r->print('<h3>Construction Space Version</h3>');
1.1 www 98: } else {
99: my $fn=
1.5 ! www 100: '/home/httpd/html//res/'.$cudom.'/'.$cuname.'/';
1.1 www 101: if ($ENV{'form.versionone'}) {
1.5 ! www 102: my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
1.1 www 103: $fn.=$main.'.'.$ENV{'form.versionone'}.'.'.$suffix;
1.4 www 104: $r->print('<h3>Version '.$ENV{'form.versionone'}.'</h3>');
1.1 www 105: } else {
1.5 ! www 106: $fn.=$efn;
1.4 www 107: $r->print('<h3>Current Version</h3>');
1.1 www 108: }
109: @f1=split(/\n/,&Apache::lonnet::getfile($fn));
110: }
111:
1.4 www 112: $r->print('versus');
1.1 www 113:
114: if ($ENV{'form.versiontwo'} eq 'priv') {
1.5 ! www 115: my $fn='/home/'.$cuname.'/public_html/'.$efn;
1.1 www 116: if (-e $fn) {
117: my $fh=Apache::File->new($fn);
118: my $line;
119: while($line=<$fh>) {
120: chomp($line);
121: $f2[$#f2+1]=$line;
122: }
123: }
1.4 www 124: $r->print('<h3>Construction Space Version</h3>');
1.1 www 125: } else {
126: my $fn=
1.5 ! www 127: '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
1.1 www 128: if ($ENV{'form.versiontwo'}) {
1.5 ! www 129: my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
1.1 www 130: $fn.=$main.'.'.$ENV{'form.versiontwo'}.'.'.$suffix;
1.4 www 131: $r->print('<h3>Version '.$ENV{'form.versiontwo'}.'</h3>');
1.1 www 132: } else {
1.5 ! www 133: $fn.=$efn;
1.4 www 134: $r->print('<h3>Current Version</h3>');
1.1 www 135: }
136: @f2=split(/\n/,&Apache::lonnet::getfile($fn));
137: }
138:
139: # Run diff
140:
141: my $diffs = diff(\@f1, \@f2);
142:
143: # Start page output
144:
145: my $chunk;
146: my $line;
147:
1.3 www 148: $r->print('<pre>');
149:
1.1 www 150: foreach $chunk (@$diffs) {
1.3 www 151:
1.1 www 152: foreach $line (@$chunk) {
153: my ($sign, $lineno, $text) = @$line;
154: $text=~s/\</\<\;/g;
155: $text=~s/\>/\>\;/g;
1.3 www 156: $lineno=substr($lineno.' ',0,7);
157: $r->print('<font color='.(($sign eq '+')?'green':'red').'>'.
158: $sign.' '.$lineno.' '.$text."</font>\n");
1.1 www 159: }
1.3 www 160: $r->print("<hr>\n");
1.1 www 161: }
1.3 www 162: $r->print('</pre>');
1.1 www 163:
1.2 www 164: } else {
165: $r->print('<h1><font color=red>Binary File</font></h1>');
166: }
1.1 www 167: $r->print('</body></html>');
168: return OK;
169: }
170:
171:
172: 1;
173: __END__
1.2 www 174:
1.1 www 175:
176:
177:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>