Annotation of loncom/publisher/londiff.pm, revision 1.14
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to show differences between file versions
3: #
1.14 ! www 4: # $Id: londiff.pm,v 1.13 2003/12/10 15:42:49 sakharuk Exp $
1.6 albertel 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: #
1.1 www 29: # (Handler to retrieve an old version of a file
30: #
31: # (Publication Handler
32: #
33: # (TeX Content Handler
34: #
35: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
36: #
37: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
38: # 03/23 Guy Albertelli
39: # 03/24,03/29 Gerd Kortemeyer)
40: #
41: # 03/31,04/03 Gerd Kortemeyer)
42: #
1.5 www 43: # 05/02/01,05/09 Gerd Kortemeyer
1.7 harris41 44: #
45: ###
1.1 www 46:
47: package Apache::londiff;
48:
49: use strict;
50: use Apache::File;
51: use File::Copy;
52: use Algorithm::Diff qw(diff);
53: use Apache::Constants qw(:common :http :methods);
1.5 www 54: use Apache::loncacc;
1.7 harris41 55: use Apache::lonnet();
56: use Apache::loncommon();
1.13 sakharuk 57: use Apache::lonlocal;
1.1 www 58:
59: sub handler {
60:
61: my $r=shift;
62:
63: # Get query string for limited number of parameters
64:
1.8 stredwic 65: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
66: ['filename','versiontwo','versionone']);
1.1 www 67: # Get the files
68:
1.5 www 69: my $cuname=$ENV{'user.name'};
70: my $cudom=$ENV{'user.domain'};
71:
1.10 www 72: if ($ENV{'form.filename'}=~/^\/res\//) {
73: ($cudom,$cuname,$ENV{'form.filename'})=
74: ($ENV{'form.filename'}=~/^\/res\/(\w+)\/(\w+)\/(.*)$/);
75: } else {
76: unless (($cuname,$cudom)=
1.5 www 77: &Apache::loncacc::constructaccess($ENV{'form.filename'},
78: $r->dir_config('lonDefDomain'))) {
79: $r->log_reason($cuname.' at '.$cudom.
80: ' trying to get diffs file '.$ENV{'form.filename'}.
81: ' - not authorized',
82: $r->filename);
83: return HTTP_NOT_ACCEPTABLE;
1.10 www 84: }
1.5 www 85: }
86:
87: my $efn=$ENV{'form.filename'};
88:
89: $efn=~s/\/\~(\w+)//g;
90:
1.1 www 91: my @f1=();
92: my @f2=();
93:
1.14 ! www 94: &Apache::loncommon::content_type($r,'text/html');
1.2 www 95: $r->send_http_header;
96:
97: $r->print('<html><head><title>LON-CAPA Construction Diffs</title></head>');
98:
1.14 ! www 99: $r->print(&Apache::loncommon::bodytag('Resource Differences'));
1.2 www 100:
101:
1.13 sakharuk 102: $r->print('<h1>'.&mt('Compare versions of').' <tt>'.$efn.'</tt></h1>');
1.5 www 103:
104: if (($cuname ne $ENV{'user.name'}) || ($cudom ne $ENV{'user.domain'})) {
105: $r->print('<h3><font color=red>Co-Author: '.$cuname.' at '.$cudom.
106: '</font></h3>');
107: }
108:
1.2 www 109:
1.7 harris41 110: if (&Apache::loncommon::fileembstyle(($efn=~/\.(\w+)$/)) eq
1.2 www 111: 'ssi') {
1.10 www 112: $r->print('<p><font color="red">');
1.1 www 113: if ($ENV{'form.versionone'} eq 'priv') {
1.5 www 114: my $fn='/home/'.$cuname.'/public_html/'.$efn;
1.1 www 115: if (-e $fn) {
116: my $fh=Apache::File->new($fn);
117: my $line;
118: while($line=<$fh>) {
119: chomp($line);
120: $f1[$#f1+1]=$line;
121: }
122: }
1.13 sakharuk 123: $r->print('<b>'.&mt('Construction Space Version').'</b>');
1.1 www 124: } else {
125: my $fn=
1.5 www 126: '/home/httpd/html//res/'.$cudom.'/'.$cuname.'/';
1.1 www 127: if ($ENV{'form.versionone'}) {
1.5 www 128: my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
1.1 www 129: $fn.=$main.'.'.$ENV{'form.versionone'}.'.'.$suffix;
1.13 sakharuk 130: $r->print('<b>'.&mt('Version').' '.$ENV{'form.versionone'}.'</b>');
1.1 www 131: } else {
1.5 www 132: $fn.=$efn;
1.13 sakharuk 133: $r->print('<b>'.&mt('Current Version').'</b>');
1.1 www 134: }
135: @f1=split(/\n/,&Apache::lonnet::getfile($fn));
136: }
137:
1.13 sakharuk 138: $r->print('</font><br />'.&mt('versus').'<br /><font color="green">');
1.1 www 139:
140: if ($ENV{'form.versiontwo'} eq 'priv') {
1.5 www 141: my $fn='/home/'.$cuname.'/public_html/'.$efn;
1.1 www 142: if (-e $fn) {
143: my $fh=Apache::File->new($fn);
144: my $line;
145: while($line=<$fh>) {
146: chomp($line);
147: $f2[$#f2+1]=$line;
148: }
149: }
1.13 sakharuk 150: $r->print('<b>'.&mt('Construction Space Version').'</b>');
1.1 www 151: } else {
152: my $fn=
1.5 www 153: '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
1.1 www 154: if ($ENV{'form.versiontwo'}) {
1.5 www 155: my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
1.1 www 156: $fn.=$main.'.'.$ENV{'form.versiontwo'}.'.'.$suffix;
1.13 sakharuk 157: $r->print('<b>'.&mt('Version').' '.$ENV{'form.versiontwo'}.'</b>');
1.1 www 158: } else {
1.5 www 159: $fn.=$efn;
1.13 sakharuk 160: $r->print('<b>'.&mt('Current Version').'</b>');
1.1 www 161: }
162: @f2=split(/\n/,&Apache::lonnet::getfile($fn));
163: }
1.10 www 164: $r->print('</font></p>');
1.1 www 165: # Run diff
166:
167: my $diffs = diff(\@f1, \@f2);
168:
169: # Start page output
170:
171: my $chunk;
172: my $line;
173:
1.3 www 174: $r->print('<pre>');
175:
1.1 www 176: foreach $chunk (@$diffs) {
1.3 www 177:
1.1 www 178: foreach $line (@$chunk) {
179: my ($sign, $lineno, $text) = @$line;
180: $text=~s/\</\<\;/g;
181: $text=~s/\>/\>\;/g;
1.3 www 182: $lineno=substr($lineno.' ',0,7);
183: $r->print('<font color='.(($sign eq '+')?'green':'red').'>'.
184: $sign.' '.$lineno.' '.$text."</font>\n");
1.1 www 185: }
1.3 www 186: $r->print("<hr>\n");
1.1 www 187: }
1.3 www 188: $r->print('</pre>');
1.1 www 189:
1.2 www 190: } else {
1.13 sakharuk 191: $r->print('<h1><font color=red>'.&mt('Binary File').'</font></h1>');
1.2 www 192: }
1.13 sakharuk 193: $r->print('<center><a href="javascript:window.close();">'.&mt('Close This Window').'</a></center></body></html>');
1.1 www 194: return OK;
195: }
196:
197:
198: 1;
199: __END__
1.2 www 200:
1.1 www 201:
202:
203:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>