Invalid language" unless $l;
return "Invalid item" unless $GET{'it'} =~ /^(\d+):(\d+)$/;
my ($dmid, $itid) = ($1, $2);
my @lnids = $l->{'lnid'};
{
my $il = $l;
while ($il && $il->{'parentlnid'}) {
push @lnids, $il->{'parentlnid'};
$il = LJ::Lang::get_lang_id($il->{'parentlnid'});
}
}
my $lnids = join(",", @lnids);
my $dbr = LJ::get_db_reader();
my ($sth, $ret);
my $sth = $dbr->prepare("select * from ml_text where dmid=$dmid and itid=$itid and lnid in ($lnids) ORDER BY txtid");
$sth->execute;
my @tlist;
while (my $t = $sth->fetchrow_hashref) {
next if @tlist && $t->{'text'} eq $tlist[-1]->{'text'};
push @tlist, $t;
}
my $changes = scalar @tlist - 1;
return "No changes" unless $changes;
my $view_change = $GET{'change'} || $changes;
return "bogus change" if $view_change < 1 || $view_change > $changes;
for (1..$changes) {
if ($_ eq $view_change) {
$ret .= "[Change $_]\n";
} else {
$ret .= "[Change $_]\n";
}
}
$ret .= "
";
my $was = $tlist[$view_change-1]->{'text'};
my $then = $tlist[$view_change]->{'text'};
my ($was_alt, $then_alt) = ($was, $then);
foreach (\$was_alt, \$then_alt) {
$$_ =~ s/\n/*NEWLINE*/g;
$$_ =~ s/\s+/\1\n/g;
$$_ .= "\n";
}
my ($was_file, $then_file, $fh);
my $tries = 0;
($fh, $was_file) = tempfile();
print $fh $was_alt; close $fh;
($fh, $then_file) = tempfile();
print $fh $then_alt; close $fh;
my @words = split(/\n/, $was_alt);
my $diff = `diff -u $was_file $then_file`;
my $pos = 0;
my $mode;
my $setmode = sub {
my $newmode = shift;
return " " if $newmode eq $mode;
my $ret;
$ret .= "$mode>" if $mode;
$ret .= " ";
$ret .= "<$newmode>" if $newmode;
$mode = $newmode;
return $ret;
};
foreach my $dl (split(/\n/, $diff)) {
next if $dl =~ /^(\+\+\+|\-\-\-)/;
if ($dl =~ /^\@\@ \-(\d+),(\d+)/) {
my $newpos = $1;
$ret .= $setmode->("");
for (my $i=$pos+1; $i<$newpos; $i++) {
my $word = LJ::ehtml($words[$i-1]);
$word =~ s/\*NEWLINE\*/
\n/g;
$ret .= "$word ";
$pos++;
}
next;
}
if ($dl =~ /^ /) {
$pos++;
my $word = LJ::ehtml($words[$pos-1]);
$word =~ s/\*NEWLINE\*/
\n/g;
$ret .= $setmode->("") . $word;
}
if ($dl =~ /^\-/) {
$pos++;
my $word = LJ::ehtml($words[$pos-1]);
$word =~ s/\*NEWLINE\*/
\n/g;
$ret .= $setmode->("del") . $word;
}
if ($dl =~ /^\+(.*)/) {
my $word = LJ::ehtml($1);
$word =~ s/\*NEWLINE\*/
\n/g;
$ret .= $setmode->("ins") . $word;
}
}
$ret .= $setmode->("");
while ($pos < @words) {
my $word = LJ::ehtml($words[$pos]);
$word =~ s/\*NEWLINE\*/
\n/g;
$ret .= "$word ";
$pos++;
}
$was = LJ::eall($was);
$was =~ s/\n( *)/"
" . " "x length($1)/eg;
$then = LJ::eall($then);
$then =~ s/\n( *)/"
" . " "x length($1)/eg;
$ret .= "Before: $was | ";
$ret .= "After: $then |
";
unlink($was_file, $then_file);
return $ret;
}
_code?>