File:
[LON-CAPA] /
loncom /
publisher /
londiff.pm
Revision
1.19:
download - view:
text,
annotated -
select for diffs
Wed May 17 13:41:45 2006 UTC (18 years, 2 months ago) by
www
Branches:
MAIN
CVS tags:
version_2_2_X,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
HEAD
Bug #1431: if the file did not change, maintain the publication status
1: # The LearningOnline Network with CAPA
2: # Handler to show differences between file versions
3: #
4: # $Id: londiff.pm,v 1.19 2006/05/17 13:41:45 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 File::Compare;
36: use Algorithm::Diff qw(diff);
37: use Apache::Constants qw(:common :http :methods);
38: use Apache::loncacc;
39: use Apache::lonnet;
40: use Apache::loncommon();
41: use Apache::lonlocal;
42:
43:
44: sub get_split_file {
45: my ($fn,$style)=@_;
46: my $f1;
47: my @f1;
48: if ($style eq 'local') {
49: if (-e $fn) {
50: my $fh=Apache::File->new($fn);
51: my $line;
52: while($line=<$fh>) {
53: $f1.=$line;
54: }
55: }
56: } elsif ($style eq 'remote') {
57: my $f1=&Apache::lonnet::getfile($fn);
58: }
59: if ($f1=~/\r/) {
60: @f1=split(/\r/,&Apache::lonnet::getfile($fn));
61: foreach my $line (@f1) {
62: $line=~s/\n//g;
63: }
64: } else {
65: @f1=split(/\n/,&Apache::lonnet::getfile($fn));
66: }
67: return @f1;
68: }
69:
70: sub are_different_files {
71: my ($fileone,$filetwo)=@_;
72: return &compare($fileone,$filetwo);
73: }
74:
75: sub handler {
76:
77: my $r=shift;
78:
79: # Get query string for limited number of parameters
80:
81: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
82: ['filename','versiontwo','versionone','filetwo']);
83: # Get the files
84:
85: my $cuname=$env{'user.name'};
86: my $cudom=$env{'user.domain'};
87:
88: if ($env{'form.filename'}=~/^\/res\//) {
89: ($cudom,$cuname,$env{'form.filename'})=
90: ($env{'form.filename'}=~/^\/res\/(\w+)\/(\w+)\/(.*)$/);
91: } else {
92: unless (($cuname,$cudom)=
93: &Apache::loncacc::constructaccess($env{'form.filename'},
94: $r->dir_config('lonDefDomain'))) {
95: $r->log_reason($cuname.' at '.$cudom.
96: ' trying to get diffs file '.$env{'form.filename'}.
97: ' - not authorized',
98: $r->filename);
99: return HTTP_NOT_ACCEPTABLE;
100: }
101: }
102:
103: my $efn=$env{'form.filename'};
104:
105: $efn=~s/\/\~(\w+)//g;
106:
107: my @f1=();
108: my @f2=();
109:
110: &Apache::loncommon::content_type($r,'text/html');
111: $r->send_http_header;
112:
113: $r->print(&Apache::loncommon::start_page('Resource Differences'));
114:
115:
116: $r->print('<h1>'.($env{'form.filetwo'}?'':&mt('Compare versions of')).
117: ' <tt>'.$efn.'</tt></h1>');
118:
119: if (($cuname ne $env{'user.name'}) || ($cudom ne $env{'user.domain'})) {
120: $r->print('<h3><font color=red>Co-Author: '.$cuname.' at '.$cudom.
121: '</font></h3>');
122: }
123:
124:
125: if (&Apache::loncommon::fileembstyle(($efn=~/\.(\w+)$/)) eq 'ssi') {
126: $r->print('<p><font color="red">');
127: if ($env{'form.versionone'} eq 'priv') {
128: my $fn='/home/'.$cuname.'/public_html/'.$efn;
129: @f1=&get_split_file($fn,'local');
130: $r->print('<b>'.&mt('Construction Space Version').'</b>');
131: } else {
132: my $fn=
133: '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
134: if ($env{'form.versionone'}) {
135: my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
136: $fn.=$main.'.'.$env{'form.versionone'}.'.'.$suffix;
137: $r->print('<b>'.&mt('Version').' '.$env{'form.versionone'}.'</b>');
138: } else {
139: $fn.=$efn;
140: $r->print('<b>'.&mt('Current Version').'</b>');
141: }
142: @f1=&get_split_file($fn,'remote');
143: }
144:
145: $r->print('</font><br />'.&mt('versus').'<br /><font color="green">');
146:
147: if ($env{'form.filetwo'}) {
148: my $efn2=$env{'form.filetwo'};
149: $efn2=~s/\/\~(\w+)//g;
150: my $fn='/home/'.$cuname.'/public_html/'.$efn2;
151: @f2=&get_split_file($fn,'local');
152: $r->print('<tt>'.$efn2.'</tt>');
153: } elsif ($env{'form.versiontwo'} eq 'priv') {
154: my $fn='/home/'.$cuname.'/public_html/'.$efn;
155: @f2=&get_split_file($fn,'local');
156: $r->print('<b>'.&mt('Construction Space Version').'</b>');
157: } else {
158: my $fn=
159: '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
160: if ($env{'form.versiontwo'}) {
161: my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
162: $fn.=$main.'.'.$env{'form.versiontwo'}.'.'.$suffix;
163: $r->print('<b>'.&mt('Version').' '.$env{'form.versiontwo'}.'</b>');
164: } else {
165: $fn.=$efn;
166: $r->print('<b>'.&mt('Current Version').'</b>');
167: }
168: @f2=&get_split_file($fn,'remote');
169: }
170: $r->print('</font></p>');
171: # Run diff
172:
173: my $diffs = diff(\@f1, \@f2);
174:
175: # Start page output
176:
177: my $chunk;
178: my $line;
179:
180: $r->print('<pre>');
181:
182: foreach $chunk (@$diffs) {
183:
184: foreach $line (@$chunk) {
185: my ($sign, $lineno, $text) = @$line;
186: $text=~s/\</\<\;/g;
187: $text=~s/\>/\>\;/g;
188: $lineno=substr($lineno.' ',0,7);
189: $r->print('<font color='.(($sign eq '+')?'green':'red').'>'.
190: $sign.' '.$lineno.' '.$text."</font>\n");
191: }
192: $r->print("<hr>\n");
193: }
194: $r->print('</pre>');
195:
196: } else {
197: $r->print('<h1><font color=red>'.&mt('Binary File').'</font></h1>');
198: }
199: $r->print('<center><a href="javascript:window.close();">'.&mt('Close This Window').'</a></center>');
200: $r->print(&Apache::loncommon::end_page());
201: return OK;
202: }
203:
204:
205: 1;
206: __END__
207:
208:
209:
210:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>