summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-02-15 16:13:11 +0100
committerYorhel <git@yorhel.nl>2011-02-15 16:13:11 +0100
commit24680d31a5a3433db5fd0140d9cb80b371659342 (patch)
treeb8beae4bbcfa12c9e695126ebf5845214f1978bf /lib
parenta796407a552fb5422a81a4cf8a5029d1f39bf419 (diff)
chardb: Added char entry tables and updated the basic revision framework
The Perl code and SQL-revisioning code only handles the name, original, alias and desc fields at the moment. There is a basic /i+ and /i+.+ page for testing, which should have all the functionality required for the revisioning framework.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Chars.pm49
-rw-r--r--lib/VNDB/DB/Misc.pm8
-rw-r--r--lib/VNDB/Handler/Chars.pm54
-rw-r--r--lib/VNDB/Handler/Misc.pm3
-rw-r--r--lib/VNDB/Util/CommonHTML.pm19
5 files changed, 120 insertions, 13 deletions
diff --git a/lib/VNDB/DB/Chars.pm b/lib/VNDB/DB/Chars.pm
new file mode 100644
index 00000000..a1866fcf
--- /dev/null
+++ b/lib/VNDB/DB/Chars.pm
@@ -0,0 +1,49 @@
+
+package VNDB::DB::Chars;
+
+use strict;
+use warnings;
+use Exporter 'import';
+
+our @EXPORT = qw|dbCharGet|;
+
+
+# options: id rev what results page
+# what: extended changes
+sub dbCharGet {
+ my $self = shift;
+ my %o = (
+ page => 1,
+ results => 10,
+ what => '',
+ @_
+ );
+
+ my %where = (
+ !$o{id} && !$o{rev} ? ( 'c.hidden = FALSE' => 1 ) : (),
+ $o{id} ? ( 'c.id = ?' => $o{id} ) : (),
+ $o{rev} ? ( 'h.rev = ?' => $o{rev} ) : (),
+ );
+
+ my @select = qw|c.id cr.name cr.original|;
+ push @select, qw|c.hidden c.locked cr.alias cr.desc| if $o{what} =~ /extended/;
+ push @select, qw|h.requester h.comments c.latest u.username h.rev h.ihid h.ilock|, "extract('epoch' from h.added) as added", 'cr.id AS cid' if $o{what} =~ /changes/;
+
+ my @join;
+ push @join, $o{rev} ? 'JOIN chars c ON c.id = cr.cid' : 'JOIN chars c ON cr.id = c.latest';
+ push @join, 'JOIN changes h ON h.id = cr.id' if $o{what} =~ /changes/ || $o{rev};
+ push @join, 'JOIN users u ON u.id = h.requester' if $o{what} =~ /changes/;
+
+ my($r, $np) = $self->dbPage(\%o, q|
+ SELECT !s
+ FROM chars_rev cr
+ !s
+ !W|,
+ join(', ', @select), join(' ', @join), \%where);
+
+ return wantarray ? ($r, $np) : $r;
+}
+
+
+1;
+
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm
index f9eb459a..5fdad302 100644
--- a/lib/VNDB/DB/Misc.pm
+++ b/lib/VNDB/DB/Misc.pm
@@ -27,7 +27,7 @@ sub dbStats {
sub dbItemEdit {
my($self, $type, $oid, %o) = @_;
- my $fun = {qw|v vn r release p producer|}->{$type};
+ my $fun = {qw|v vn r release p producer c char|}->{$type};
$self->dbExec('SELECT edit_!s_init(?)', $fun, $oid);
$self->dbExec('UPDATE edit_revision !H', {
'requester = ?' => $o{uid}||$self->authInfo->{id},
@@ -59,10 +59,10 @@ sub dbRevisionGet {
$o{what} ||= '';
$o{releases} = 0 if !$o{type} || $o{type} ne 'v' || !$o{iid};
- my %tables = qw|v vn r releases p producers|;
+ my %tables = qw|v vn r releases p producers c chars|;
# what types should we join?
my @types = (
- !$o{type} ? ('v', 'r', 'p') :
+ !$o{type} ? ('v', 'r', 'p', 'c') :
$o{type} ne 'v' ? $o{type} :
$o{releases} ? ('v', 'r') : 'v'
);
@@ -102,7 +102,7 @@ sub dbRevisionGet {
$o{what} =~ /user/ ? 'u.username' : (),
$o{what} =~ /item/ ? (
'COALESCE('.join(', ', map "${_}r.${_}id", @types).') AS iid',
- 'COALESCE('.join(', ', map $_ eq 'p' ? 'pr.name' : "${_}r.title", @types).') AS ititle',
+ 'COALESCE('.join(', ', map /[pc]/ ? "${_}r.name" : "${_}r.title", @types).') AS ititle',
'COALESCE('.join(', ', map "${_}r.original", @types).') AS ioriginal',
) : (),
);
diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm
new file mode 100644
index 00000000..2ad1daa3
--- /dev/null
+++ b/lib/VNDB/Handler/Chars.pm
@@ -0,0 +1,54 @@
+
+package VNDB::Handler::Chars;
+
+use strict;
+use warnings;
+use TUWF ':html';
+use VNDB::Func;
+
+
+TUWF::register(
+ qr{c([1-9]\d*)(?:\.([1-9]\d*))?} => \&page,
+);
+
+
+sub page {
+ my($self, $id, $rev) = @_;
+
+ my $r = $self->dbCharGet(
+ id => $id,
+ what => 'extended'.($rev ? ' changes' : ''),
+ $rev ? ( rev => $rev ) : ()
+ )->[0];
+ return $self->resNotFound if !$r->{id};
+
+ $self->htmlHeader(title => $r->{name});
+ $self->htmlMainTabs(c => $r);
+ return if $self->htmlHiddenMessage('c', $r);
+
+ if($rev) {
+ my $prev = $rev && $rev > 1 && $self->dbCharGet(id => $id, rev => $rev-1, what => 'changes extended')->[0];
+ $self->htmlRevision('c', $prev, $r,
+ [ name => diff => 1 ],
+ [ original => diff => 1 ],
+ [ alias => diff => qr/[ ,\n\.]/ ],
+ [ desc => diff => qr/[ ,\n\.]/ ],
+ );
+ }
+
+ div class => 'mainbox';
+ $self->htmlItemMessage('c', $r);
+ h1 $r->{name};
+ h2 class => 'alttitle', $r->{original} if $r->{original};
+ if($r->{desc}) {
+ p class => 'description';
+ lit bb2html($r->{desc});
+ end;
+ }
+ end;
+ $self->htmlFooter;
+}
+
+
+1;
+
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 062e3ae4..8e449153 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -11,7 +11,7 @@ use POSIX 'strftime';
TUWF::register(
qr{}, \&homepage,
- qr{(?:([upvr])([1-9]\d*)/)?hist}, \&history,
+ qr{(?:([upvrc])([1-9]\d*)/)?hist}, \&history,
qr{d([1-9]\d*)}, \&docpage,
qr{setlang}, \&setlang,
qr{nospam}, \&nospam,
@@ -206,6 +206,7 @@ sub history {
my $obj = $type eq 'u' ? $self->dbUserGet(uid => $id, what => 'hide_list')->[0] :
$type eq 'p' ? $self->dbProducerGet(id => $id)->[0] :
$type eq 'r' ? $self->dbReleaseGet(id => $id)->[0] :
+ $type eq 'c' ? $self->dbCharGet(id => $id)->[0] :
$type eq 'v' ? $self->dbVNGet(id => $id)->[0] : undef;
my $title = mt $type ? ('_hist_title_item', $obj->{title} || $obj->{name} || $obj->{username}) : '_hist_title';
return $self->resNotFound if $type && !$obj->{id};
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index ba03aeac..0d794913 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -17,7 +17,7 @@ our @EXPORT = qw|
# generates the "main tabs". These are the commonly used tabs for
# 'objects', i.e. VN/producer/release entries and users
-# Arguments: u/v/r/p/g/i, object, currently selected item (empty=main)
+# Arguments: u/v/r/p/g/i/c, object, currently selected item (empty=main)
sub htmlMainTabs {
my($self, $type, $obj, $sel) = @_;
$sel ||= '';
@@ -26,7 +26,7 @@ sub htmlMainTabs {
return if $type eq 'g' && !$self->authCan('tagmod');
ul class => 'maintabs';
- if($type =~ /[uvrp]/) {
+ if($type =~ /[uvrpc]/) {
li $sel eq 'hist' ? (class => 'tabselected') : ();
a href => "/$id/hist", mt '_mtabs_hist';
end;
@@ -73,6 +73,7 @@ sub htmlMainTabs {
if( $type eq 'u' && ($self->authInfo->{id} && $obj->{id} == $self->authInfo->{id} || $self->authCan('usermod'))
|| $type =~ /[vrp]/ && $self->authCan('edit') && (!$obj->{locked} || $self->authCan('lock')) && (!$obj->{hidden} || $self->authCan('del'))
+ || $type eq 'c' && $self->authCan('charedit') && (!$obj->{locked} || $self->authCan('lock')) && (!$obj->{hidden} || $self->authCan('del'))
|| $type =~ /[gi]/ && $self->authCan('tagmod')
) {
li $sel eq 'edit' ? (class => 'tabselected') : ();
@@ -120,15 +121,16 @@ sub htmlDenied {
# Generates message saying that the current item has been deleted,
-# Arguments: [pvr], obj
+# Arguments: [pvrc], obj
# Returns 1 if the use doesn't have access to the page, 0 otherwise
sub htmlHiddenMessage {
my($self, $type, $obj) = @_;
return 0 if !$obj->{hidden};
- my $board = $type eq 'r' ? 'v'.$obj->{vn}[0]{vid} : $type.$obj->{id};
+ my $board = $type eq 'c' ? 'db' : $type eq 'r' ? 'v'.$obj->{vn}[0]{vid} : $type.$obj->{id};
# fetch edit summary (not present in $obj because the changes aren't fetched)
my $editsum = $type eq 'v' ? $self->dbVNGet(id => $obj->{id}, what => 'changes')->[0]{comments}
: $type eq 'r' ? $self->dbReleaseGet(id => $obj->{id}, what => 'changes')->[0]{comments}
+ : $type eq 'c' ? $self->dbCharGet(id => $obj->{id}, what => 'changes')->[0]{comments}
: $self->dbProducerGet(id => $obj->{id}, what => 'changes')->[0]{comments};
div class => 'mainbox';
h1 $obj->{title}||$obj->{name};
@@ -147,7 +149,7 @@ sub htmlHiddenMessage {
# Shows a revision, including diff if there is a previous revision.
-# Arguments: v|p|r, old revision, new revision, @fields
+# Arguments: v|p|r|c, old revision, new revision, @fields
# Where @fields is a list of fields as arrayrefs with:
# [ shortname, displayname, %options ],
# Where %options:
@@ -266,8 +268,8 @@ sub revdiff {
# Arguments: v/r/p, obj
sub htmlEditMessage {
my($self, $type, $obj, $title, $copy) = @_;
- my $num = {v => 0, r => 1, p => 2}->{$type};
- my $guidelines = {v => 2, r => 3, p => 4}->{$type};
+ my $num = {v => 0, r => 1, p => 2, c => 3}->{$type};
+ my $guidelines = {v => 2, r => 3, p => 4, c => 12}->{$type};
div class => 'mainbox';
h1 $title;
@@ -303,9 +305,10 @@ sub htmlEditMessage {
# Generates a small message when the user can't edit the item,
# or the item is locked.
-# Arguments: v/r/p, obj
+# Arguments: v/r/p/c, obj
sub htmlItemMessage {
my($self, $type, $obj) = @_;
+ # $type isn't being used at all... oh well.
if($obj->{locked}) {
p class => 'locked', mt '_itemmsg_locked';