summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-06-26 11:19:52 +0200
committerYorhel <git@yorhel.nl>2019-06-26 11:34:30 +0200
commit4d67310a2cb148925b6f8ba96a4fade124e83854 (patch)
tree824fc08cafa2812b126049c5ff85cd932aaea310 /lib
parent940c8dc80bcfbd4dea0f286032b00873e31daac4 (diff)
Tags: Split "meta" field into "searchable" and "applicable"
As discussed in https://vndb.org/t12507 TODO: - Same conversion for traits - Re-add mod ability to delete all votes for a particular tag?
Diffstat (limited to 'lib')
-rw-r--r--lib/Multi/APIDump.pm6
-rw-r--r--lib/VNDB/DB/Tags.pm15
-rw-r--r--lib/VNDB/Handler/Tags.pm44
-rw-r--r--lib/VNDB/Util/Misc.pm2
4 files changed, 42 insertions, 25 deletions
diff --git a/lib/Multi/APIDump.pm b/lib/Multi/APIDump.pm
index c84c3d1c..28e944ca 100644
--- a/lib/Multi/APIDump.pm
+++ b/lib/Multi/APIDump.pm
@@ -20,7 +20,7 @@ sub run {
sub tags_gen {
# The subqueries are kinda ugly, but it's convenient to have everything in a single query.
pg_cmd q|
- SELECT id, name, description, meta, c_items AS vns, cat,
+ SELECT id, name, description, searchable, applicable, c_items AS vns, cat,
(SELECT string_agg(alias,'$$$-$$$') FROM tags_aliases where tag = id) AS aliases,
(SELECT string_agg(parent::text, ',') FROM tags_parents WHERE tag = id) AS parents
FROM tags WHERE state = 2
@@ -31,7 +31,9 @@ sub tags_gen {
my @res = $res->rowsAsHashes;
for(@res) {
$_->{id} *= 1;
- $_->{meta} = $_->{meta} eq 't' ? JSON::XS::true : JSON::XS::false;
+ $_->{meta} = $_->{searchable} ne 't' ? JSON::XS::true : JSON::XS::false; # For backwards compat
+ $_->{searchable} = $_->{searchable} eq 't' ? JSON::XS::true : JSON::XS::false;
+ $_->{applicable} = $_->{applicable} eq 't' ? JSON::XS::true : JSON::XS::false;
$_->{vns} *= 1;
$_->{aliases} = [ split /\$\$\$-\$\$\$/, ($_->{aliases}||'') ];
$_->{parents} = [ map $_*1, split /,/, ($_->{parents}||'') ];
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index fb4717d8..389e172a 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -8,7 +8,7 @@ use Exporter 'import';
our @EXPORT = qw|dbTagGet dbTTTree dbTagEdit dbTagAdd dbTagMerge dbTagLinks dbTagLinkEdit dbTagStats|;
-# %options->{ id noid name search state meta page results what sort reverse }
+# %options->{ id noid name search state searchable applicable page results what sort reverse }
# what: parents childs(n) aliases addedby
# sort: id name added items search
sub dbTagGet {
@@ -35,11 +35,11 @@ sub dbTagGet {
't.state <> 1' => 1 ) : (),
$o{search} ? (
't.id IN (SELECT id FROM tags LEFT JOIN tags_aliases ON id = tag WHERE name ILIKE ? OR alias ILIKE ?)' => [ "%$o{search}%", "%$o{search}%" ] ) : (),
- defined $o{meta} ? (
- 't.meta = ?' => $o{meta}?1:0 ) : (),
+ defined $o{searchable} ? ('t.searchable = ?' => $o{searchable}?1:0 ) : (),
+ defined $o{applicable} ? ('t.applicable = ?' => $o{applicable}?1:0 ) : (),
);
my @select = (
- qw|t.id t.meta t.name t.description t.state t.cat t.c_items t.defaultspoil|,
+ qw|t.id t.searchable t.applicable t.name t.description t.state t.cat t.c_items t.defaultspoil|,
q|extract('epoch' from t.added) as added|,
$o{what} =~ /addedby/ ? ('t.addedby', 'u.username') : (),
);
@@ -129,7 +129,7 @@ sub dbTagEdit {
$self->dbExec('UPDATE tags !H WHERE id = ?', {
$o{upddate} ? ('added = NOW()' => 1) : (),
- map exists($o{$_}) ? ("$_ = ?" => $o{$_}) : (), qw|name meta description state cat defaultspoil|
+ map exists($o{$_}) ? ("$_ = ?" => $o{$_}) : (), qw|name searchable applicable description state cat defaultspoil|
}, $id);
if($o{aliases}) {
$self->dbExec('DELETE FROM tags_aliases WHERE tag = ?', $id);
@@ -139,7 +139,6 @@ sub dbTagEdit {
$self->dbExec('DELETE FROM tags_parents WHERE tag = ?', $id);
$self->dbExec('INSERT INTO tags_parents (tag, parent) VALUES (?, ?)', $id, $_) for(@{$o{parents}});
}
- $self->dbExec('DELETE FROM tags_vn WHERE tag = ?', $id) if $o{meta} || ($o{state} && $o{state} == 1);
}
@@ -147,8 +146,8 @@ sub dbTagEdit {
# returns the id of the new tag
sub dbTagAdd {
my($self, %o) = @_;
- my $id = $self->dbRow('INSERT INTO tags (name, meta, description, state, cat, defaultspoil, addedby) VALUES (!l, ?) RETURNING id',
- [ map $o{$_}, qw|name meta description state cat defaultspoil| ], $o{addedby}||$self->authInfo->{id}
+ my $id = $self->dbRow('INSERT INTO tags (name, searchable, applicable, description, state, cat, defaultspoil, addedby) VALUES (!l, ?) RETURNING id',
+ [ map $o{$_}, qw|name searchable applicable description state cat defaultspoil| ], $o{addedby}||$self->authInfo->{id}
)->{id};
$self->dbExec('INSERT INTO tags_parents (tag, parent) VALUES (?, ?)', $id, $_) for(@{$o{parents}});
$self->dbExec('INSERT INTO tags_aliases (tag, alias) VALUES (?, ?)', $id, $_) for (@{$o{aliases}});
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 165aadd0..33da3dd6 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -39,7 +39,7 @@ sub tagpage {
return $self->resNotFound if $f->{_err};
$f->{fil} //= $self->authPref('filter_vn');
- my($list, $np) = $t->{meta} || $t->{state} != 2 ? ([],0) : $self->filFetchDB(vn => $f->{fil}, undef, {
+ my($list, $np) = !$t->{searchable} || $t->{state} != 2 ? ([],0) : $self->filFetchDB(vn => $f->{fil}, undef, {
what => 'rating',
results => 50,
page => $f->{p},
@@ -49,7 +49,7 @@ sub tagpage {
tag_exc => undef,
});
- my $title = ($t->{meta} ? 'Meta tag: ' : 'Tag: ').$t->{name};
+ my $title = "Tag: $t->{name}";
$self->htmlHeader(title => $title, noindex => $t->{state} != 2);
$self->htmlMainTabs('g', $t);
@@ -87,6 +87,15 @@ sub tagpage {
lit bb2html $t->{description};
end;
}
+ if(!$t->{applicable} || !$t->{searchable}) {
+ p class => 'center';
+ b 'Properties';
+ br;
+ txt 'Not searchable.' if !$t->{searchable};
+ br;
+ txt 'Can not be directly applied to visual novels.' if !$t->{applicable};
+ end;
+ }
p class => 'center';
b 'Category';
br;
@@ -103,7 +112,7 @@ sub tagpage {
childtags($self, 'Child tags', 'g', $t) if @{$t->{childs}};
- if(!$t->{meta} && $t->{state} == 2) {
+ if($t->{searchable} && $t->{state} == 2) {
form action => "/g$t->{id}", 'accept-charset' => 'UTF-8', method => 'get';
div class => 'mainbox';
a class => 'addnew', href => "/g/links?t=$tag", 'Recently tagged';
@@ -160,7 +169,8 @@ sub tagedit {
{ post => 'state', required => 0, default => 0, enum => [ 0..2 ] },
{ post => 'cat', required => 1, enum => [ keys %{$self->{tag_categories}} ] },
{ post => 'catrec', required => 0 },
- { post => 'meta', required => 0, default => 0 },
+ { post => 'searchable', required => 0, default => 0 },
+ { post => 'applicable', required => 0, default => 0 },
{ post => 'alias', required => 0, maxlength => 1024, default => '', regex => [ qr/^[^,]+$/s, 'No comma allowed in aliases' ] },
{ post => 'description', required => 0, maxlength => 10240, default => '' },
{ post => 'defaultspoil',required => 0, default => 0, enum => [ 0..2 ] },
@@ -182,13 +192,17 @@ sub tagedit {
}
if(!$frm->{_err}) {
- $frm->{state} = $frm->{meta} = 0 if !$self->authCan('tagmod');
+ if(!$self->authCan('tagmod')) {
+ $frm->{state} = 0;
+ $frm->{searchable} = $frm->{applicable} = 1;
+ }
my %opts = (
name => $frm->{name},
state => $frm->{state},
cat => $frm->{cat},
description => $frm->{description},
- meta => $frm->{meta}?1:0,
+ searchable => $frm->{searchable}?1:0,
+ applicable => $frm->{applicable}?1:0,
defaultspoil => $frm->{defaultspoil},
aliases => \@aliases,
parents => \@parents,
@@ -206,7 +220,7 @@ sub tagedit {
}
if($tag) {
- $frm->{$_} ||= $t->{$_} for (qw|name meta description state cat defaultspoil|);
+ $frm->{$_} ||= $t->{$_} for (qw|name searchable applicable description state cat defaultspoil|);
$frm->{alias} ||= join "\n", @{$t->{aliases}};
$frm->{parents} ||= join ', ', map $_->{name}, @{$t->{parents}};
}
@@ -239,9 +253,8 @@ sub tagedit {
[ static => label => 'Added by', content => fmtuser($t->{addedby}, $t->{username}) ] : (),
[ select => short => 'state', name => 'State', options => [
[0, 'Awaiting moderation'], [1, 'Deleted/hidden'], [2, 'Approved'] ] ],
- [ checkbox => short => 'meta', name => 'This is a meta-tag (only to be used as parent for other tags, not for linking to VN entries)' ],
- $tag ?
- [ static => content => 'WARNING: Checking this option or selecting "Deleted" as state will permanently delete all existing VN relations!' ] : (),
+ [ checkbox => short => 'searchable', name => 'Searchable (people can use this tag to filter VNs)' ],
+ [ checkbox => short => 'applicable', name => 'Applicable (people can apply this tag to VNs)' ],
) : (),
[ select => short => 'cat', name => 'Category', options => [
map [$_, $self->{tag_categories}{$_}], keys %{$self->{tag_categories}} ] ],
@@ -504,6 +517,11 @@ sub vntagmod {
my %insert; # tag => [ vote, spoiler, ignore ]
my %overrule; # tag => 0/1
+ # remove tags in the deleted state
+ delete $new{$_->{id}} for(keys %new ? @{$self->dbTagGet(id => [ keys %new ], state => 1)} : ());
+ # and not-applicable tags
+ delete $new{$_->{id}} for(keys %new ? @{$self->dbTagGet(id => [ keys %new ], applicable => 0)} : ());
+
for my $t (keys %old, keys %new) {
my $prev_over = $old{$t} && !$old{$t}{ignore} && $tags{$t}{overruled};
@@ -525,8 +543,6 @@ sub vntagmod {
$update{$t} = [ $new{$t}[0], $new{$t}[1] ];
}
}
- # remove tags in the deleted state.
- delete $insert{$_->{id}} for(keys %insert ? @{$self->dbTagGet(id => [ keys %insert ], state => 1)} : ());
$self->dbTagLinkEdit($self->authInfo->{id}, $vid, \%insert, \%update, \%delete, \%overrule);
@@ -668,7 +684,7 @@ sub tagindex {
# Popular
td;
a class => 'addnew', href => "/g/links", 'Recently tagged';
- $r = $self->dbTagGet(sort => 'items', reverse => 1, meta => 0, results => 10);
+ $r = $self->dbTagGet(sort => 'items', reverse => 1, searchable => 1, applicable => 1, results => 10);
h1 'Popular tags';
ul;
for (@$r) {
@@ -758,7 +774,7 @@ sub tagxml {
xml;
tag 'tags', more => $np ? 'yes' : 'no', $f->{q} ? (query => $f->{q}) : ();
for(@$list) {
- tag 'item', id => $_->{id}, meta => $_->{meta} ? 'yes' : 'no', state => $_->{state}, $_->{name};
+ tag 'item', id => $_->{id}, searchable => $_->{searchable} ? 'yes' : 'no', applicable => $_->{applicable} ? 'yes' : 'no', state => $_->{state}, $_->{name};
}
end;
}
diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm
index 1146c687..0f6a7448 100644
--- a/lib/VNDB/Util/Misc.pm
+++ b/lib/VNDB/Util/Misc.pm
@@ -90,7 +90,7 @@ sub filCompat {
my $tagfind = sub {
return map {
my $i = $self->dbTagGet(name => $_)->[0];
- $i && !$i->{meta} ? $i->{id} : ();
+ $i && $i->{searchable} ? $i->{id} : ();
} grep $_, ref $_[0] ? @{$_[0]} : ($_[0]||'')
};
$fil->{tag_inc} //= [ $tagfind->(delete $fil->{taginc}) ] if $fil->{taginc};