File:  [LON-CAPA] / loncom / publisher / londiff.pm
Revision 1.11: download - view: text, annotated - select for diffs
Mon Feb 3 18:03:53 2003 UTC (21 years, 3 months ago) by harris41
Branches: MAIN
CVS tags: version_1_0_3, version_1_0_2, version_1_0_1, version_1_0_0, version_0_99_5, version_0_99_4, version_0_99_3, version_0_99_2, version_0_99_1, version_0_99_0, conference_2003, HEAD
best wishes to all.

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>