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