summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-11-21 15:30:50 +0100
committerYorhel <git@yorhel.nl>2008-11-21 15:30:50 +0100
commit3088f3f65241df4f58894f9938e346a57a60720b (patch)
treefc4d0e41fdc8aad5948be3794c1bcd579db3925d /lib
parent77fb942f189c5b5cd187532d131db2e5e5f5fe75 (diff)
Improved htmlRevision and added revision browser for VN pages
Now the only thing left to finish the VN pages is adding some stats, but I'll stall that for now as I haven't really decided what to do with it. Also, diff calculation on large (~800 chars) textfields is horribly slow (~200ms) T.T
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Handler/VNPage.pm63
-rw-r--r--lib/VNDB/Util/CommonHTML.pm27
2 files changed, 82 insertions, 8 deletions
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 664267de..88bd876c 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -3,7 +3,7 @@ package VNDB::Handler::VNPage;
use strict;
use warnings;
-use YAWF ':html';
+use YAWF ':html', 'xml_escape';
use VNDB::Func;
@@ -48,6 +48,8 @@ sub page {
$self->htmlMainTabs('v', $v);
return if $self->htmlHiddenMessage('v', $v);
+ _revision($self, $v, $rev);
+
div class => 'mainbox';
p class => 'locked', 'Locked for editing' if $v->{locked};
h1 $v->{title};
@@ -131,12 +133,67 @@ sub page {
_releases($self, $v, $r);
_screenshots($self, $v, $r) if @{$v->{screenshots}};
- # TODO: stats, relation graph
+ # TODO: stats
$self->htmlFooter;
}
+sub _revision {
+ my($self, $v, $rev) = @_;
+ return if !$rev;
+
+ my $prev = $rev && $rev > 1 && $self->dbVNGet(
+ id => $v->{id}, rev => $rev-1, what => 'extended categories anime relations screenshots changes'
+ )->[0];
+
+ $self->htmlRevision('v', $prev, $v,
+ [ title => 'Title (romaji)', diff => 1 ],
+ [ original => 'Original title', diff => 1 ],
+ [ alias => 'Alias', diff => 1 ],
+ [ desc => 'Description', diff => 1 ],
+ [ length => 'Length', serialize => sub { $self->{vn_lengths}[$_[0]][0] } ],
+ [ l_wp => 'Wikipedia link', htmlize => sub {
+ $_[0] ? sprintf '<a href="http://en.wikipedia.org/wiki/%s">%1$s</a>', xml_escape $_[0] : '[no link]'
+ }],
+ [ l_encubed => 'Encubed tag', htmlize => sub {
+ $_[0] ? sprintf '<a href="http://novelnews.net/tag/%s/">%1$s</a>', xml_escape $_[0] : '[no link]'
+ }],
+ [ l_renai => 'Renai.us link', htmlize => sub {
+ $_[0] ? sprintf '<a href="http://renai.us/game/%s.shtml">%1$s</a>', xml_escape $_[0] : '[no link]'
+ }],
+ [ l_vnn => 'V-N.net link', htmlize => sub {
+ $_[0] ? sprintf '<a href="http://visual-novels.net/vn/index.php?option=com_content&amp;task=view&amp;id=%d">%1$d</a>', xml_escape $_[0] : '[no link]'
+ }],
+ [ categories => 'Categories', join => ', ', split => sub {
+ my @r = map $self->{categories}{substr($_->[0],0,1)}[1]{substr($_->[0],1,2)}."($_->[1])", sort { $a->[0] cmp $b->[0] } @{$_[0]};
+ return @r ? @r : ('[no categories selected]');
+ }],
+ [ relations => 'Relations', join => '<br />', split => sub {
+ my @r = map sprintf('%s: <a href="/v%d" title="%s">%s</a>',
+ $self->{vn_relations}[$_->{relation}][0], $_->{id}, xml_escape($_->{original}||$_->{title}), xml_escape shorten $_->{title}, 40
+ ), sort { $a->{id} <=> $b->{id} } @{$_[0]};
+ return @r ? @r : ('[none]');
+ }],
+ [ anime => 'Anime', join => ', ', split => sub {
+ my @r = map sprintf('<a href="http://anidb.net/a%d">a%1$d</a>', $_->{id}), sort { $a->{id} <=> $b->{id} } @{$_[0]};
+ return @r ? @r : ('[none]');
+ }],
+ [ screenshots => 'Screenshots', join => '<br />', split => sub {
+ my @r = map sprintf('[%s] <a href="%s/sf/%02d/%d.jpg" rel="iv:%dx%d">%4$d</a> (%s)',
+ $_->{rid} ? qq|<a href="/r$_->{rid}">r$_->{rid}</a>| : 'no release',
+ $self->{url_static}, $_->{id}%100, $_->{id}, $_->{width}, $_->{height}, $_->{nsfw} ? 'NSFW' : 'Safe'
+ ), @{$_[0]};
+ return @r ? @r : ('[no screenshots]');
+ }],
+ [ image => 'Image', htmlize => sub {
+ $_[0] > 0 ? sprintf '<img src="%s/cv/%02d/%d.jpg" />', $self->{url_static}, $_[0]%100, $_[0] : $_[0] < 0 ? '[processing]' : 'No image';
+ }],
+ [ img_nsfw => 'Image NSFW', serialize => sub { $_[0] ? 'Not safe' : 'Safe' } ],
+ );
+}
+
+
sub _producers {
my($self, $i, $r) = @_;
return if !grep @{$_->{producers}}, @$r;
@@ -336,7 +393,7 @@ sub _screenshots {
h1 'Screenshots';
table;
for my $rel (@$r) {
- my @scr = grep $rel->{id} == $_->{rid}, @{$v->{screenshots}};
+ my @scr = grep $_->{rid} && $rel->{id} == $_->{rid}, @{$v->{screenshots}};
next if !@scr;
Tr class => 'rel';
td colspan => 5;
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index 04f2d9fa..6daee951 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -215,6 +215,9 @@ sub htmlBrowseNavigate {
# Where %options:
# diff => 1/0, whether do show a diff on this field
# serialize => coderef, should convert the field into a readable string, no HTML allowed
+# htmlize => same as serialize, but HTML is allowed and this can't be diff'ed
+# split => coderef, should return an array of HTML strings that can be diff'ed. (implies diff => 1)
+# join => used in combination with split, specifies the string used for joining the HTML strings
sub htmlRevision {
my($self, $type, $old, $new, @fields) = @_;
div class => 'mainbox revision';
@@ -281,30 +284,44 @@ sub revheader { # type, obj
sub revdiff {
my($i, $old, $new, $short, $name, %o) = @_;
+ $o{serialize} ||= $o{htmlize};
+ $o{diff}++ if $o{split};
+ $o{join} ||= '';
+
my $ser1 = $o{serialize} ? $o{serialize}->($old->{$short}) : $old->{$short};
my $ser2 = $o{serialize} ? $o{serialize}->($new->{$short}) : $new->{$short};
return if $ser1 eq $ser2;
if($o{diff} && $ser1 && $ser2) {
- my($r1,$r2,$ch) = ('','','u');
- for (sdiff([ split //, $ser1 ], [ split //, $ser2 ])) {
+ my @ser1 = $o{split} ? $o{split}->($ser1) : map xml_escape($_), split //, $ser1;
+ my @ser2 = $o{split} ? $o{split}->($ser2) : map xml_escape($_), split //, $ser2;
+ return if $o{split} && $#ser1 == $#ser2 && !grep $ser1[$_] ne $ser2[$_], 0..$#ser1;
+
+ my($r1,$r2,$ch,$count,$changes) = ('','','u',0,0);
+ for (sdiff(\@ser1, \@ser2)) {
if($ch ne $_->[0]) {
if($ch ne 'u') {
$r1 .= '</b>';
$r2 .= '</b>';
}
+ $r1 .= $o{join} if $count && $ch ne '+';
+ $r2 .= $o{join} if $count && $ch ne '-';
$r1 .= '<b class="diff_del">' if $_->[0] eq '-' || $_->[0] eq 'c';
$r2 .= '<b class="diff_add">' if $_->[0] eq '+' || $_->[0] eq 'c';
+ } else {
+ $r1 .= $o{join} if $count && $ch ne '+';
+ $r2 .= $o{join} if $count && $ch ne '-';
}
$ch = $_->[0];
- $r1 .= xml_escape $_->[1] if $ch ne '+';
- $r2 .= xml_escape $_->[2] if $ch ne '-';
+ $r1 .= $_->[1] if $ch ne '+';
+ $r2 .= $_->[2] if $ch ne '-';
+ $count++;
}
$r1 .= '</b>' if $ch eq '-' || $ch eq 'c';
$r2 .= '</b>' if $ch eq '+' || $ch eq 'c';
$ser1 = $r1;
$ser2 = $r2;
- } else {
+ } elsif(!$o{htmlize}) {
$ser1 = xml_escape $ser1;
$ser2 = xml_escape $ser2;
}