File:
[LON-CAPA] /
loncom /
publisher /
londiff.pm
Revision
1.17:
download - view:
text,
annotated -
select for diffs
Sun May 29 01:46:16 2005 UTC (19 years, 2 months ago) by
www
Branches:
MAIN
CVS tags:
version_2_1_X,
version_2_1_3,
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1,
version_1_99_0,
HEAD
Cleanup handler
1: # The LearningOnline Network with CAPA
2: # Handler to show differences between file versions
3: #
4: # $Id: londiff.pm,v 1.17 2005/05/29 01:46:16 www Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: package Apache::londiff;
31:
32: use strict;
33: use Apache::File;
34: use File::Copy;
35: use Algorithm::Diff qw(diff);
36: use Apache::Constants qw(:common :http :methods);
37: use Apache::loncacc;
38: use Apache::lonnet;
39: use Apache::loncommon();
40: use Apache::lonlocal;
41:
42:
43: sub get_split_file {
44: my ($fn,$style)=@_;
45: my $f1;
46: my @f1;
47: if ($style='local') {
48: if (-e $fn) {
49: my $fh=Apache::File->new($fn);
50: my $line;
51: while($line=<$fh>) {
52: $f1.=$line;
53: }
54: }
55: } elsif ($style eq 'remote') {
56: my $f1=&Apache::lonnet::getfile($fn);
57: }
58: if ($f1=~/\r/) {
59: @f1=split(/\r/,&Apache::lonnet::getfile($fn));
60: foreach my $line (@f1) {
61: $line=~s/\n//g;
62: }
63: } else {
64: @f1=split(/\n/,&Apache::lonnet::getfile($fn));
65: }
66: return @f1;
67: }
68:
69: sub handler {
70:
71: my $r=shift;
72:
73: # Get query string for limited number of parameters
74:
75: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
76: ['filename','versiontwo','versionone','filetwo']);
77: # Get the files
78:
79: my $cuname=$env{'user.name'};
80: my $cudom=$env{'user.domain'};
81:
82: if ($env{'form.filename'}=~/^\/res\//) {
83: ($cudom,$cuname,$env{'form.filename'})=
84: ($env{'form.filename'}=~/^\/res\/(\w+)\/(\w+)\/(.*)$/);
85: } else {
86: unless (($cuname,$cudom)=
87: &Apache::loncacc::constructaccess($env{'form.filename'},
88: $r->dir_config('lonDefDomain'))) {
89: $r->log_reason($cuname.' at '.$cudom.
90: ' trying to get diffs file '.$env{'form.filename'}.
91: ' - not authorized',
92: $r->filename);
93: return HTTP_NOT_ACCEPTABLE;
94: }
95: }
96:
97: my $efn=$env{'form.filename'};
98:
99: $efn=~s/\/\~(\w+)//g;
100:
101: my @f1=();
102: my @f2=();
103:
104: &Apache::loncommon::content_type($r,'text/html');
105: $r->send_http_header;
106:
107: $r->print('<html><head><title>LON-CAPA Construction Diffs</title></head>');
108:
109: $r->print(&Apache::loncommon::bodytag('Resource Differences'));
110:
111:
112: $r->print('<h1>'.($env{'form.filetwo'}?'':&mt('Compare versions of')).
113: ' <tt>'.$efn.'</tt></h1>');
114:
115: if (($cuname ne $env{'user.name'}) || ($cudom ne $env{'user.domain'})) {
116: $r->print('<h3><font color=red>Co-Author: '.$cuname.' at '.$cudom.
117: '</font></h3>');
118: }
119:
120:
121: if (&Apache::loncommon::fileembstyle(($efn=~/\.(\w+)$/)) eq 'ssi') {
122: $r->print('<p><font color="red">');
123: if ($env{'form.versionone'} eq 'priv') {
124: my $fn='/home/'.$cuname.'/public_html/'.$efn;
125: @f1=&get_split_file($fn,'local');
126: $r->print('<b>'.&mt('Construction Space Version').'</b>');
127: } else {
128: my $fn=
129: '/home/httpd/html//res/'.$cudom.'/'.$cuname.'/';
130: if ($env{'form.versionone'}) {
131: my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
132: $fn.=$main.'.'.$env{'form.versionone'}.'.'.$suffix;
133: $r->print('<b>'.&mt('Version').' '.$env{'form.versionone'}.'</b>');
134: } else {
135: $fn.=$efn;
136: $r->print('<b>'.&mt('Current Version').'</b>');
137: }
138: @f1=&get_split_file($fn,'remote');
139: }
140:
141: $r->print('</font><br />'.&mt('versus').'<br /><font color="green">');
142:
143: if ($env{'form.filetwo'}) {
144: my $efn2=$env{'form.filetwo'};
145: $efn2=~s/\/\~(\w+)//g;
146: my $fn='/home/'.$cuname.'/public_html/'.$efn2;
147: @f2=&get_split_file($fn,'local');
148: $r->print('<tt>'.$efn2.'</tt>');
149: } elsif ($env{'form.versiontwo'} eq 'priv') {
150: my $fn='/home/'.$cuname.'/public_html/'.$efn;
151: @f2=&get_split_file($fn,'local');
152: $r->print('<b>'.&mt('Construction Space Version').'</b>');
153: } else {
154: my $fn=
155: '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
156: if ($env{'form.versiontwo'}) {
157: my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
158: $fn.=$main.'.'.$env{'form.versiontwo'}.'.'.$suffix;
159: $r->print('<b>'.&mt('Version').' '.$env{'form.versiontwo'}.'</b>');
160: } else {
161: $fn.=$efn;
162: $r->print('<b>'.&mt('Current Version').'</b>');
163: }
164: @f2=&get_split_file($fn,'remote');
165: }
166: $r->print('</font></p>');
167: # Run diff
168:
169: my $diffs = diff(\@f1, \@f2);
170:
171: # Start page output
172:
173: my $chunk;
174: my $line;
175:
176: $r->print('<pre>');
177:
178: foreach $chunk (@$diffs) {
179:
180: foreach $line (@$chunk) {
181: my ($sign, $lineno, $text) = @$line;
182: $text=~s/\</\<\;/g;
183: $text=~s/\>/\>\;/g;
184: $lineno=substr($lineno.' ',0,7);
185: $r->print('<font color='.(($sign eq '+')?'green':'red').'>'.
186: $sign.' '.$lineno.' '.$text."</font>\n");
187: }
188: $r->print("<hr>\n");
189: }
190: $r->print('</pre>');
191:
192: } else {
193: $r->print('<h1><font color=red>'.&mt('Binary File').'</font></h1>');
194: }
195: $r->print('<center><a href="javascript:window.close();">'.&mt('Close This Window').'</a></center></body></html>');
196: return OK;
197: }
198:
199:
200: 1;
201: __END__
202:
203:
204:
205:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>