Annotation of loncom/publisher/londiff.pm, revision 1.4
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: #
18: # 05/02/01 Gerd Kortemeyer
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);
27:
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:
49: my @f1=();
50: my @f2=();
51:
1.2 www 52: $r->content_type('text/html');
53: $r->send_http_header;
54:
55: $r->print('<html><head><title>LON-CAPA Construction Diffs</title></head>');
56:
57: $r->print('<body bgcolor="#FFFFFF">');
58:
59:
60: $r->print('<h1>Compare versions of <tt>'.$ENV{'form.filename'}.'</tt></h1>');
61:
62: if (&Apache::lonnet::fileembstyle(($ENV{'form.filename'}=~/\.(\w+)$/)) eq
63: 'ssi') {
1.1 www 64: if ($ENV{'form.versionone'} eq 'priv') {
65: my $fn='/home/'.$ENV{'user.name'}.'/public_html/'.$ENV{'form.filename'};
66: if (-e $fn) {
67: my $fh=Apache::File->new($fn);
68: my $line;
69: while($line=<$fh>) {
70: chomp($line);
71: $f1[$#f1+1]=$line;
72: }
73: }
1.4 ! www 74: $r->print('<h3>Construction Space Version</h3>');
1.1 www 75: } else {
76: my $fn=
77: '/home/httpd/html//res/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/';
78: if ($ENV{'form.versionone'}) {
79: my ($main,$suffix)=($ENV{'form.filename'}=~/^(.+)\.(\w+)$/);
80: $fn.=$main.'.'.$ENV{'form.versionone'}.'.'.$suffix;
1.4 ! www 81: $r->print('<h3>Version '.$ENV{'form.versionone'}.'</h3>');
1.1 www 82: } else {
83: $fn.=$ENV{'form.filename'};
1.4 ! www 84: $r->print('<h3>Current Version</h3>');
1.1 www 85: }
86: @f1=split(/\n/,&Apache::lonnet::getfile($fn));
87: }
88:
1.4 ! www 89: $r->print('versus');
1.1 www 90:
91: if ($ENV{'form.versiontwo'} eq 'priv') {
92: my $fn='/home/'.$ENV{'user.name'}.'/public_html/'.$ENV{'form.filename'};
93: if (-e $fn) {
94: my $fh=Apache::File->new($fn);
95: my $line;
96: while($line=<$fh>) {
97: chomp($line);
98: $f2[$#f2+1]=$line;
99: }
100: }
1.4 ! www 101: $r->print('<h3>Construction Space Version</h3>');
1.1 www 102: } else {
103: my $fn=
104: '/home/httpd/html/res/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/';
105: if ($ENV{'form.versiontwo'}) {
106: my ($main,$suffix)=($ENV{'form.filename'}=~/^(.+)\.(\w+)$/);
107: $fn.=$main.'.'.$ENV{'form.versiontwo'}.'.'.$suffix;
1.4 ! www 108: $r->print('<h3>Version '.$ENV{'form.versiontwo'}.'</h3>');
1.1 www 109: } else {
110: $fn.=$ENV{'form.filename'};
1.4 ! www 111: $r->print('<h3>Current Version</h3>');
1.1 www 112: }
113: @f2=split(/\n/,&Apache::lonnet::getfile($fn));
114: }
115:
116: # Run diff
117:
118: my $diffs = diff(\@f1, \@f2);
119:
120: # Start page output
121:
122: my $chunk;
123: my $line;
124:
1.3 www 125: $r->print('<pre>');
126:
1.1 www 127: foreach $chunk (@$diffs) {
1.3 www 128:
1.1 www 129: foreach $line (@$chunk) {
130: my ($sign, $lineno, $text) = @$line;
131: $text=~s/\</\<\;/g;
132: $text=~s/\>/\>\;/g;
1.3 www 133: $lineno=substr($lineno.' ',0,7);
134: $r->print('<font color='.(($sign eq '+')?'green':'red').'>'.
135: $sign.' '.$lineno.' '.$text."</font>\n");
1.1 www 136: }
1.3 www 137: $r->print("<hr>\n");
1.1 www 138: }
1.3 www 139: $r->print('</pre>');
1.1 www 140:
1.2 www 141: } else {
142: $r->print('<h1><font color=red>Binary File</font></h1>');
143: }
1.1 www 144: $r->print('</body></html>');
145: return OK;
146: }
147:
148:
149: 1;
150: __END__
1.2 www 151:
1.1 www 152:
153:
154:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>