Annotation of loncom/publisher/londiff.pm, revision 1.3
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: }
74: } else {
75: my $fn=
76: '/home/httpd/html//res/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/';
77: if ($ENV{'form.versionone'}) {
78: my ($main,$suffix)=($ENV{'form.filename'}=~/^(.+)\.(\w+)$/);
79: $fn.=$main.'.'.$ENV{'form.versionone'}.'.'.$suffix;
80: } else {
81: $fn.=$ENV{'form.filename'};
82: }
83: @f1=split(/\n/,&Apache::lonnet::getfile($fn));
84: }
85:
86:
87: if ($ENV{'form.versiontwo'} eq 'priv') {
88: my $fn='/home/'.$ENV{'user.name'}.'/public_html/'.$ENV{'form.filename'};
89: if (-e $fn) {
90: my $fh=Apache::File->new($fn);
91: my $line;
92: while($line=<$fh>) {
93: chomp($line);
94: $f2[$#f2+1]=$line;
95: }
96: }
97: } else {
98: my $fn=
99: '/home/httpd/html/res/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/';
100: if ($ENV{'form.versiontwo'}) {
101: my ($main,$suffix)=($ENV{'form.filename'}=~/^(.+)\.(\w+)$/);
102: $fn.=$main.'.'.$ENV{'form.versiontwo'}.'.'.$suffix;
103: } else {
104: $fn.=$ENV{'form.filename'};
105: }
106: @f2=split(/\n/,&Apache::lonnet::getfile($fn));
107: }
108:
109: # Run diff
110:
111: my $diffs = diff(\@f1, \@f2);
112:
113: # Start page output
114:
115: my $chunk;
116: my $line;
117:
1.3 ! www 118: $r->print('<pre>');
! 119:
1.1 www 120: foreach $chunk (@$diffs) {
1.3 ! www 121:
1.1 www 122: foreach $line (@$chunk) {
123: my ($sign, $lineno, $text) = @$line;
124: $text=~s/\</\<\;/g;
125: $text=~s/\>/\>\;/g;
1.3 ! www 126: $lineno=substr($lineno.' ',0,7);
! 127: $r->print('<font color='.(($sign eq '+')?'green':'red').'>'.
! 128: $sign.' '.$lineno.' '.$text."</font>\n");
1.1 www 129: }
1.3 ! www 130: $r->print("<hr>\n");
1.1 www 131: }
1.3 ! www 132: $r->print('</pre>');
1.1 www 133:
1.2 www 134: } else {
135: $r->print('<h1><font color=red>Binary File</font></h1>');
136: }
1.1 www 137: $r->print('</body></html>');
138: return OK;
139: }
140:
141:
142: 1;
143: __END__
1.2 www 144:
1.1 www 145:
146:
147:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>