summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-10-08 18:16:46 +0200
committerYorhel <git@yorhel.nl>2019-10-10 16:40:30 +0200
commitb3a9130763879d60c0e413c724a759860bd396af (patch)
tree2de6f9d21d4ce9f00fc11595906570be43d8ae5c
parent4c1dfc8bb62171c4c21057c47f238c8747bac3f8 (diff)
rewards: Apply supporters badge and unicode name (almost) everywhere
Only place where this isn't applied (yet?): Sorting user lists still goes by the old username and board names don't use the new unicode names. I have to say, I quite like the sql_user() and user_() pattern. It's not without problems when applied to everything, but it's good enough for several use cases.
-rw-r--r--elm/User/Edit.elm4
-rw-r--r--lib/VNDB/DB/Chars.pm2
-rw-r--r--lib/VNDB/DB/Discussions.pm10
-rw-r--r--lib/VNDB/DB/Misc.pm4
-rw-r--r--lib/VNDB/DB/Producers.pm2
-rw-r--r--lib/VNDB/DB/Releases.pm2
-rw-r--r--lib/VNDB/DB/Staff.pm2
-rw-r--r--lib/VNDB/DB/Tags.pm4
-rw-r--r--lib/VNDB/DB/Traits.pm2
-rw-r--r--lib/VNDB/DB/ULists.pm2
-rw-r--r--lib/VNDB/DB/Users.pm16
-rw-r--r--lib/VNDB/DB/VN.pm2
-rw-r--r--lib/VNDB/Func.pm8
-rw-r--r--lib/VNDB/Handler/Discussions.pm17
-rw-r--r--lib/VNDB/Handler/Misc.pm8
-rw-r--r--lib/VNDB/Handler/Tags.pm12
-rw-r--r--lib/VNDB/Handler/Traits.pm2
-rw-r--r--lib/VNDB/Handler/ULists.pm8
-rw-r--r--lib/VNDB/Handler/Users.pm15
-rw-r--r--lib/VNDB/Util/Auth.pm4
-rw-r--r--lib/VNDB/Util/BrowseHTML.pm41
-rw-r--r--lib/VNDB/Util/CommonHTML.pm4
-rw-r--r--lib/VNWeb/Auth.pm25
-rw-r--r--lib/VNWeb/DB.pm17
-rw-r--r--lib/VNWeb/HTML.pm42
-rw-r--r--lib/VNWeb/Misc/History.pm8
-rw-r--r--lib/VNWeb/User/Page.pm21
27 files changed, 136 insertions, 148 deletions
diff --git a/elm/User/Edit.elm b/elm/User/Edit.elm
index 93eb407a..6a335d75 100644
--- a/elm/User/Edit.elm
+++ b/elm/User/Edit.elm
@@ -165,9 +165,9 @@ view model =
, if not data.nodistract_can && not data.authmod then text ""
else formField "" [ label [] [ inputCheck "" data.nodistract_noads (Set << NoAds), text " Disable advertising and other distractions (doesn't hide affiliate links for the moment)" ] ]
, if not data.nodistract_can && not data.authmod then text ""
- else formField "" [ label [] [ inputCheck "" data.nodistract_nofancy (Set << NoFancy), text " Disable supporters badges, custom usernames and profile skins" ] ]
+ else formField "" [ label [] [ inputCheck "" data.nodistract_nofancy (Set << NoFancy), text " Disable supporters badges, custom display names and profile skins" ] ]
, if not data.support_can && not data.authmod then text ""
- else formField "" [ label [] [ inputCheck "" data.support_enabled (Set << Support), text " Display supporters badge" ] ]
+ else formField "" [ label [] [ inputCheck "" data.support_enabled (Set << Support), text " Display my supporters badge" ] ]
, if not data.pubskin_can && not data.authmod then text ""
else formField "" [ label [] [ inputCheck "" data.pubskin_enabled (Set << PubSkin), text " Apply my skin and custom CSS when others visit my profile" ] ]
, if not data.uniname_can && not data.authmod then text ""
diff --git a/lib/VNDB/DB/Chars.pm b/lib/VNDB/DB/Chars.pm
index 23953028..e2581f87 100644
--- a/lib/VNDB/DB/Chars.pm
+++ b/lib/VNDB/DB/Chars.pm
@@ -90,7 +90,7 @@ sub dbCharGetRev {
$o{rev} ||= $self->dbRow('SELECT MAX(rev) AS rev FROM changes WHERE type = \'c\' AND itemid = ?', $o{id})->{rev};
my $select = 'c.itemid AS id, ch.name, ch.original, ch.gender';
- $select .= ', extract(\'epoch\' from c.added) as added, c.requester, c.comments, u.username, c.rev, c.ihid, c.ilock';
+ $select .= ', extract(\'epoch\' from c.added) as added, c.comments, c.rev, c.ihid, c.ilock, '.VNWeb::DB::sql_user();
$select .= ', c.id AS cid, NOT EXISTS(SELECT 1 FROM changes c2 WHERE c2.type = c.type AND c2.itemid = c.itemid AND c2.rev = c.rev+1) AS lastrev';
$select .= ', ch.alias, ch.desc, ch.image, ch.b_month, ch.b_day, ch.s_bust, ch.s_waist, ch.s_hip, ch.height, ch.weight, ch.bloodt, ch.main, ch.main_spoil, co.hidden, co.locked' if $o{what} =~ /extended/;
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm
index 6139b83b..75fb93e8 100644
--- a/lib/VNDB/DB/Discussions.pm
+++ b/lib/VNDB/DB/Discussions.pm
@@ -41,7 +41,7 @@ sub dbThreadGet {
my @select = (
qw|t.id t.title t.count t.locked t.hidden t.private|, 't.poll_question IS NOT NULL AS haspoll',
- $o{what} =~ /lastpost/ ? ('tpl.uid AS luid', q|EXTRACT('epoch' from tpl.date) AS ldate|, 'ul.username AS lusername') : (),
+ $o{what} =~ /lastpost/ ? (q|EXTRACT('epoch' from tpl.date) AS lastpost_date|, VNWeb::DB::sql_user('ul', 'lastpost_')) : (),
$o{what} =~ /poll/ ? (qw|t.poll_question t.poll_max_options t.poll_preview t.poll_recast|) : (),
);
@@ -94,12 +94,12 @@ sub dbThreadGet {
}
if($o{what} =~ /firstpost/) {
- do { my $x = $r->[$r{$_->{tid}}]; $x->{fuid} = $_->{uid}; $x->{fdate} = $_->{date}; $x->{fusername} = $_->{username} } for (@{$self->dbAll(q|
- SELECT tpf.tid, tpf.uid, EXTRACT('epoch' from tpf.date) AS date, uf.username
+ do { my $idx = $r{ delete $_->{tid} }; $r->[$idx] = { $r->[$idx]->%*, %$_ } } for (@{$self->dbAll(q|
+ SELECT tpf.tid, EXTRACT('epoch' from tpf.date) AS firstpost_date, !s
FROM threads_posts tpf
JOIN users uf ON tpf.uid = uf.id
WHERE tpf.num = 1 AND tpf.tid IN(!l)|,
- [ keys %r ]
+ VNWeb::DB::sql_user('uf', 'firstpost_'), [ keys %r ]
)});
}
@@ -237,7 +237,7 @@ sub dbPostGet {
my @select = (
qw|tp.tid tp.num tp.hidden|, q|extract('epoch' from tp.date) as date|, q|extract('epoch' from tp.edited) as edited|,
$o{search} ? () : 'tp.msg',
- $o{what} =~ /user/ ? qw|tp.uid u.username| : (),
+ $o{what} =~ /user/ ? (VNWeb::DB::sql_user()) : (),
$o{what} =~ /thread/ ? ('t.title', 't.hidden AS thread_hidden') : (),
);
my @join = (
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm
index e1a1103c..27494380 100644
--- a/lib/VNDB/DB/Misc.pm
+++ b/lib/VNDB/DB/Misc.pm
@@ -79,11 +79,11 @@ sub dbRevisionGet {
);
my($r, $np) = $self->dbPage(\%o, q|
- SELECT c.id, c.type, c.itemid, c.requester, c.comments, c.rev, extract('epoch' from c.added) as added, u.username
+ SELECT c.id, c.type, c.itemid, c.comments, c.rev, extract('epoch' from c.added) as added, !s
FROM changes c
JOIN users u ON c.requester = u.id
!W
- ORDER BY c.id DESC|, \%where
+ ORDER BY c.id DESC|, VNWeb::DB::sql_user(), \%where
);
# I couldn't find a way to fetch the titles the main query above without slowing it down considerably, so let's just do it this way.
diff --git a/lib/VNDB/DB/Producers.pm b/lib/VNDB/DB/Producers.pm
index 548f70c5..0caf0ece 100644
--- a/lib/VNDB/DB/Producers.pm
+++ b/lib/VNDB/DB/Producers.pm
@@ -68,7 +68,7 @@ sub dbProducerGetRev {
$o{rev} ||= $self->dbRow('SELECT MAX(rev) AS rev FROM changes WHERE type = \'p\' AND itemid = ?', $o{id})->{rev};
my $select = 'c.itemid AS id, p.type, p.name, p.original, p.lang, po.rgraph';
- $select .= ', extract(\'epoch\' from c.added) as added, c.requester, c.comments, u.username, c.rev, c.ihid, c.ilock';
+ $select .= ', extract(\'epoch\' from c.added) as added, c.comments, c.rev, c.ihid, c.ilock, '.VNWeb::DB::sql_user();
$select .= ', c.id AS cid, NOT EXISTS(SELECT 1 FROM changes c2 WHERE c2.type = c.type AND c2.itemid = c.itemid AND c2.rev = c.rev+1) AS lastrev';
$select .= ', p.desc, p.alias, p.website, p.l_wp, p.l_wikidata, po.hidden, po.locked' if $o{what} =~ /extended/;
diff --git a/lib/VNDB/DB/Releases.pm b/lib/VNDB/DB/Releases.pm
index 940ff087..1c95a3c0 100644
--- a/lib/VNDB/DB/Releases.pm
+++ b/lib/VNDB/DB/Releases.pm
@@ -127,7 +127,7 @@ sub dbReleaseGetRev {
my $select = 'c.itemid AS id, r.title, r.original, r.website, r.released, r.minage, r.type, r.patch';
$select .= ', r.notes, r.catalog, r.gtin, r.resolution, r.voiced, r.freeware, r.doujin, r.uncensored, r.ani_story, r.ani_ero, r.engine, ro.hidden, ro.locked' if $o{what} =~ /extended/;
- $select .= ', extract(\'epoch\' from c.added) as added, c.requester, c.comments, u.username, c.rev, c.ihid, c.ilock';
+ $select .= ', extract(\'epoch\' from c.added) as added, c.comments, c.rev, c.ihid, c.ilock, '.VNWeb::DB::sql_user();
$select .= ', c.id AS cid, NOT EXISTS(SELECT 1 FROM changes c2 WHERE c2.type = c.type AND c2.itemid = c.itemid AND c2.rev = c.rev+1) AS lastrev';
my $r = $self->dbAll(q|
diff --git a/lib/VNDB/DB/Staff.pm b/lib/VNDB/DB/Staff.pm
index e5f38705..b8995d04 100644
--- a/lib/VNDB/DB/Staff.pm
+++ b/lib/VNDB/DB/Staff.pm
@@ -85,7 +85,7 @@ sub dbStaffGetRev {
$o{rev} ||= $self->dbRow('SELECT MAX(rev) AS rev FROM changes WHERE type = \'s\' AND itemid = ?', $o{id})->{rev};
my $select = 'c.itemid AS id, sa.aid, sa.name, sa.original, s.gender, s.lang';
- $select .= ', extract(\'epoch\' from c.added) as added, c.requester, c.comments, u.username, c.rev, c.ihid, c.ilock';
+ $select .= ', extract(\'epoch\' from c.added) as added, c.comments, c.rev, c.ihid, c.ilock, '.VNWeb::DB::sql_user();
$select .= ', c.id AS cid, NOT EXISTS(SELECT 1 FROM changes c2 WHERE c2.type = c.type AND c2.itemid = c.itemid AND c2.rev = c.rev+1) AS lastrev';
$select .= ', s.desc, s.l_wp, s.l_site, s.l_twitter, s.l_anidb, s.l_wikidata, s.l_pixiv, so.hidden, so.locked' if $o{what} =~ /extended/;
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index 75be42d8..875ff6e9 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -41,7 +41,7 @@ sub dbTagGet {
my @select = (
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') : (),
+ $o{what} =~ /addedby/ ? (VNWeb::DB::sql_user()) : (),
);
my @join = $o{what} =~ /addedby/ ? 'JOIN users u ON u.id = t.addedby' : ();
@@ -187,7 +187,7 @@ sub dbTagLinks {
my @select = (
qw|tv.tag tv.vid tv.uid tv.vote tv.spoiler tv.ignore|, "EXTRACT('epoch' from tv.date) AS date",
- $o{what} =~ /details/ ? (qw|v.title u.username t.name|) : (),
+ $o{what} =~ /details/ ? (qw|v.title t.name|, VNWeb::DB::sql_user()) : (),
);
my @join = $o{what} =~ /details/ ? (
diff --git a/lib/VNDB/DB/Traits.pm b/lib/VNDB/DB/Traits.pm
index f1c55b24..019f512f 100644
--- a/lib/VNDB/DB/Traits.pm
+++ b/lib/VNDB/DB/Traits.pm
@@ -46,7 +46,7 @@ sub dbTraitGet {
my @select = (
qw|t.id t.searchable t.applicable t.name t.description t.state t.alias t."group" t."order" t.sexual t.c_items t.defaultspoil|,
'tg.name AS groupname', 'tg."order" AS grouporder', q|extract('epoch' from t.added) as added|,
- $o{what} =~ /addedby/ ? ('t.addedby', 'u.username') : (),
+ $o{what} =~ /addedby/ ? (VNWeb::DB::sql_user()) : (),
);
my @join = $o{what} =~ /addedby/ ? 'JOIN users u ON u.id = t.addedby' : ();
push @join, 'LEFT JOIN traits tg ON tg.id = t."group"';
diff --git a/lib/VNDB/DB/ULists.pm b/lib/VNDB/DB/ULists.pm
index 6de6b25b..6f061e97 100644
--- a/lib/VNDB/DB/ULists.pm
+++ b/lib/VNDB/DB/ULists.pm
@@ -193,7 +193,7 @@ sub dbVoteGet {
my @select = (
qw|n.vid n.vote n.uid|, q|extract('epoch' from n.date) as date|,
- $o{what} =~ /user/ ? ('u.username') : (),
+ $o{what} =~ /user/ ? (VNWeb::DB::sql_user()) : (),
$o{what} =~ /vn/ ? (qw|v.title v.original|) : (),
$o{what} =~ /hide_list/ ? ('u.hide_list') : (),
);
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index cccac169..663184cb 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -13,7 +13,7 @@ our @EXPORT = qw|
# %options->{ username session uid ip registered search results page what sort reverse notperm }
-# what: notifycount stats scryptargs extended
+# what: extended
# sort: username registered votes changes tags
sub dbUserGet {
my $s = shift;
@@ -54,19 +54,9 @@ sub dbUserGet {
my @select = (
qw|id username c_votes c_changes c_tags hide_list|,
+ VNWeb::DB::sql_user(), # XXX: This duplicates id and username, but updating all the code isn't going to be easy
q|extract('epoch' from registered) as registered|,
$o{what} =~ /extended/ ? qw|perm ign_votes| : (), # mail
- $o{what} =~ /scryptargs/ ? 'user_getscryptargs(id) AS scryptargs' : (),
- $o{what} =~ /notifycount/ ?
- '(SELECT COUNT(*) FROM notifications WHERE uid = u.id AND read IS NULL) AS notifycount' : (),
- $o{what} =~ /stats/ ? (
- '(SELECT COUNT(*) FROM rlists WHERE uid = u.id) AS releasecount',
- '(SELECT COUNT(*) FROM vnlists WHERE uid = u.id) AS vncount',
- '(SELECT COUNT(*) FROM threads_posts WHERE uid = u.id) AS postcount',
- '(SELECT COUNT(*) FROM threads_posts WHERE uid = u.id AND num = 1) AS threadcount',
- '(SELECT COUNT(DISTINCT tag) FROM tags_vn WHERE uid = u.id) AS tagcount',
- '(SELECT COUNT(DISTINCT vid) FROM tags_vn WHERE uid = u.id) AS tagvncount',
- ) : (),
$token ? qq|extract('epoch' from user_isloggedin(id, decode('$token', 'hex'))) as session_lastused| : (),
);
@@ -122,7 +112,7 @@ sub dbNotifyGet {
qw|n.id n.ntype n.ltype n.iid n.subid|,
q|extract('epoch' from n.date) as date|,
q|extract('epoch' from n.read) as read|,
- $o{what} =~ /titles/ ? qw|u.username n.c_title| : (),
+ $o{what} =~ /titles/ ? ('n.c_title', VNWeb::DB::sql_user()) : (),
);
my($r, $np) = $s->dbPage(\%o, q|
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index b29ee3c6..9f0e4b1e 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -161,7 +161,7 @@ sub dbVNGetRev {
my $uid = $self->authInfo->{id};
my $select = 'c.itemid AS id, vo.c_released, vo.c_languages::text[], vo.c_platforms::text[], v.title, v.original, vo.rgraph';
- $select .= ', extract(\'epoch\' from c.added) as added, c.requester, c.comments, u.username, c.rev, c.ihid, c.ilock';
+ $select .= ', extract(\'epoch\' from c.added) as added, c.comments, c.rev, c.ihid, c.ilock, '.VNWeb::DB::sql_user();
$select .= ', c.id AS cid, NOT EXISTS(SELECT 1 FROM changes c2 WHERE c2.type = c.type AND c2.itemid = c.itemid AND c2.rev = c.rev+1) AS lastrev';
$select .= ', v.alias, v.image, v.img_nsfw, v.length, v.desc, v.l_wp, v.l_encubed, v.l_renai, v.l_wikidata, vo.hidden, vo.locked' if $o{what} =~ /extended/;
$select .= ', vo.c_popularity, vo.c_rating, vo.c_votecount' if $o{what} =~ /rating/;
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 11e3dfee..32830459 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -13,7 +13,7 @@ use VNDB::BBCode;
our @EXPORT = (@VNDBUtil::EXPORT, 'bb2html', 'bb2text', qw|
clearfloat cssicon tagscore minage fil_parse fil_serialize parenttags
childtags charspoil imgpath imgurl
- fmtvote fmtmedia fmtvnlen fmtage fmtdatestr fmtdate fmtuser fmtrating fmtspoil
+ fmtvote fmtmedia fmtvnlen fmtage fmtdatestr fmtdate fmtrating fmtspoil
json_encode json_decode script_json
form_compare
|);
@@ -253,12 +253,6 @@ sub fmtdate {
return strftime '%Y-%m-%d at %R', gmtime $t;
}
-# Arguments: (uid, username), or a hashref containing that info
-sub fmtuser {
- my($id,$n) = ref($_[0]) eq 'HASH' ? ($_[0]{uid}||$_[0]{requester}, $_[0]{username}) : @_;
- return !$id ? '[deleted]' : sprintf '<a href="/u%d">%s</a>', $id, xml_escape $n;
-}
-
# Turn a (natural number) vote into a rating indication
sub fmtrating {
['worst ever',
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index 30512cfa..c17ca3b7 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -26,7 +26,7 @@ TUWF::register(
sub caneditpost {
my($self, $post) = @_;
return $self->authCan('boardmod') ||
- ($self->authInfo->{id} && $post->{uid} == $self->authInfo->{id} && !$post->{hidden} && time()-$post->{date} < $self->{board_edit_time})
+ ($self->authInfo->{id} && $post->{user_id} == $self->authInfo->{id} && !$post->{hidden} && time()-$post->{date} < $self->{board_edit_time})
}
@@ -75,7 +75,8 @@ sub thread {
td class => 'tc1';
a href => "/t$tid.$_->{num}", name => $_->{num}, "#$_->{num}";
if(!$_->{hidden}) {
- lit ' by '.fmtuser($_);
+ lit ' by ';
+ VNWeb::HTML::user_($_);
br;
txt fmtdate $_->{date}, 'full';
}
@@ -312,7 +313,7 @@ sub edit {
'Edit post';
$self->htmlHeader(title => $title, noindex => 1);
$self->htmlForm({ frm => $frm, action => $url }, 'postedit' => [$title,
- [ static => label => 'Username', content => fmtuser($p ? ($p->{uid}, $p->{username}) : ($self->authInfo->{id}, $self->authInfo->{username})) ],
+ [ static => label => 'Username', content => sub { VNWeb::HTML::user_($p || VNWeb::Auth::auth->user); '' } ],
!$tid || $num == 1 ? (
[ input => short => 'title', name => 'Thread title' ],
[ input => short => 'boards', name => 'Board(s)' ],
@@ -394,7 +395,7 @@ sub board {
$type eq 'p' ? $self->dbProducerGet(id => $iid)->[0] :
$self->dbVNGet(id => $iid)->[0];
return $self->resNotFound if $iid && !$obj;
- my $ititle = $obj && ($obj->{title}||$obj->{name}||$obj->{username});
+ my $ititle = $obj && ($obj->{title}||$obj->{name}||VNWeb::HTML::user_displayname($obj));
my $title = $obj ? "Related discussions for $ititle" : $type eq 'all' ? 'All boards' : $BOARD_TYPE{$type}{txt};
my($list, $np) = $self->dbThreadGet(
@@ -576,7 +577,7 @@ sub search {
td class => 'tc1_1'; a href => $link, 't'.$l->{tid}; end;
td class => 'tc1_2'; a href => $link, '.'.$l->{num}; end;
td class => 'tc2', fmtdate $l->{date};
- td class => 'tc3'; lit fmtuser $l->{uid}, $l->{username}; end;
+ td class => 'tc3'; VNWeb::HTML::user_($l); end;
td class => 'tc4';
div class => 'title';
a href => $link, $l->{title};
@@ -634,12 +635,12 @@ sub _threadlist {
end;
td class => 'tc2', $o->{count}-1;
td class => 'tc3';
- lit fmtuser $o->{fuid}, $o->{fusername};
+ VNWeb::HTML::user_($o, 'firstpost_');
end;
td class => 'tc4';
- lit fmtuser $o->{luid}, $o->{lusername};
+ VNWeb::HTML::user_($o, 'lastpost_');
lit ' @ ';
- a href => "/t$o->{id}.$o->{count}", fmtdate $o->{ldate}, 'full';
+ a href => "/t$o->{id}.$o->{count}", fmtdate $o->{lastpost_date}, 'full';
end;
end 'tr';
}
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 9b4073ce..76663601 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -85,7 +85,8 @@ sub homepage {
li;
txt "$_->{type}:";
a href => "/$_->{type}$_->{itemid}.$_->{rev}", title => $_->{ioriginal}||$_->{ititle}, shorten $_->{ititle}, 33;
- lit " by ".fmtuser($_);
+ lit " by ";
+ VNWeb::HTML::user_($_);
end;
}
end;
@@ -120,9 +121,10 @@ sub homepage {
for (@$posts) {
my $boards = join ', ', map $BOARD_TYPE{$_->{type}}{txt}.($_->{iid}?' > '.$_->{title}:''), @{$_->{boards}};
li;
- txt fmtage($_->{ldate}).' ';
+ txt fmtage($_->{lastpost_date}).' ';
a href => "/t$_->{id}.$_->{count}", title => "Posted in $boards", shorten $_->{title}, 25;
- lit ' by '.fmtuser($_->{luid}, $_->{lusername});
+ lit ' by ';
+ VNWeb::HTML::user_($_, 'lastpost_');
end;
}
end;
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index d674498c..cbc7b293 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -255,7 +255,7 @@ sub tagedit {
[ input => short => 'name', name => 'Primary name' ],
$self->authCan('tagmod') ? (
$tag ?
- [ static => label => 'Added by', content => fmtuser($t->{addedby}, $t->{username}) ] : (),
+ [ static => label => 'Added by', content => sub { VNWeb::HTML::user_($t); '' } ] : (),
[ select => short => 'state', name => 'State', options => [
[0, 'Awaiting moderation'], [1, 'Deleted/hidden'], [2, 'Approved'] ] ],
[ checkbox => short => 'searchable', name => 'Searchable (people can use this tag to filter VNs)' ],
@@ -428,7 +428,7 @@ sub taglinks {
li;
txt '['; a href => $url->(u=>0), 'remove'; txt '] ';
txt 'User: ';
- a href => "/u$f->{u}", $o->{username}||'Unknown user';
+ VNWeb::HTML::user_($o);
end;
}
if($f->{t}) {
@@ -472,12 +472,8 @@ sub taglinks {
Tr;
td class => 'tc1', fmtdate $l->{date};
td class => 'tc2';
- if($l->{uid}) {
- a href => $url->(u=>$l->{uid}), class => 'setfil', '> ' if !$f->{u};
- a href => "/u$l->{uid}", $l->{username};
- } else {
- txt '[deleted]';
- }
+ a href => $url->(u=>$l->{uid}), class => 'setfil', '> ' if $l->{user_id} && !$f->{u};
+ VNWeb::HTML::user_($l);
end;
td class => 'tc3'.($l->{ignore}?' ignored':'');
tagscore $l->{vote};
diff --git a/lib/VNDB/Handler/Traits.pm b/lib/VNDB/Handler/Traits.pm
index 4bf9a33d..f9802cff 100644
--- a/lib/VNDB/Handler/Traits.pm
+++ b/lib/VNDB/Handler/Traits.pm
@@ -233,7 +233,7 @@ sub traitedit {
[ input => short => 'name', name => 'Primary name' ],
$self->authCan('tagmod') ? (
$t ?
- [ static => label => 'Added by', content => fmtuser($t->{addedby}, $t->{username}) ] : (),
+ [ static => label => 'Added by', content => sub { VNWeb::HTML::user_($t); '' } ] : (),
[ select => short => 'state', name => 'State', options => [
[0,'Awaiting moderation'], [1,'Deleted/hidden'], [2,'Approved'] ] ],
[ checkbox => short => 'searchable', name => 'Searchable (people can use this trait to filter characters)' ],
diff --git a/lib/VNDB/Handler/ULists.pm b/lib/VNDB/Handler/ULists.pm
index b66d0419..49d31788 100644
--- a/lib/VNDB/Handler/ULists.pm
+++ b/lib/VNDB/Handler/ULists.pm
@@ -155,7 +155,7 @@ sub votelist {
$type eq 'u' && $f->{c} ne 'all' ? (vn_char => $f->{c}) : (),
);
- my $title = $type eq 'v' ? "Votes for $obj->{title}" : "Votes by $obj->{username}";
+ my $title = $type eq 'v' ? "Votes for $obj->{title}" : 'Votes by '.VNWeb::HTML::user_displayname($obj);
$self->htmlHeader(noindex => 1, title => $title);
$self->htmlMainTabs($type => $obj, 'votes');
div class => 'mainbox';
@@ -201,7 +201,7 @@ sub votelist {
} elsif($l->{hide_list}) {
b class => 'grayedout', 'hidden';
} else {
- a href => "/u$l->{uid}", $l->{username};
+ VNWeb::HTML::user_($l);
}
end;
end;
@@ -265,7 +265,7 @@ sub wishlist {
page => $f->{p},
);
- my $title = $own ? 'My wishlist' : "$u->{username}'s wishlist";
+ my $title = $own ? 'My wishlist' : VNWeb::HTML::user_displayname($u)."'s wishlist";
$self->htmlHeader(title => $title, noindex => 1);
$self->htmlMainTabs('u', $u, 'wish');
div class => 'mainbox';
@@ -382,7 +382,7 @@ sub vnlist {
$f->{t} >= 0 ? (status => $f->{t}) : (),
);
- my $title = $own ? 'My visual novel list' : "$u->{username}'s visual novel list";
+ my $title = $own ? 'My visual novel list' : VNWeb::HTML::user_displayname($u)."'s visual novel list";
$self->htmlHeader(title => $title, noindex => 1);
$self->htmlMainTabs('u', $u, 'list');
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index 32648ee4..e31dbd77 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -34,13 +34,13 @@ sub posts {
my($posts, $np) = $self->dbPostGet(uid => $uid, hide => 1, what => 'thread', page => $f->{p}, sort => 'date', reverse => 1);
- my $title = "Posts made by $u->{username}";
+ my $title = 'Posts made by '.VNWeb::HTML::user_displayname($u);
$self->htmlHeader(title => $title, noindex => 1);
$self->htmlMainTabs(u => $u, 'posts');
div class => 'mainbox';
h1 $title;
if(!@$posts) {
- p "$u->{username} hasn't made any posts yet.";
+ p VNWeb::HTML::user_displayname($u)." hasn't made any posts yet.";
}
end;
@@ -168,7 +168,7 @@ sub list {
my($s, $n, $l) = @_;
Tr;
td class => 'tc1';
- a href => '/u'.$l->{id}, $l->{username};
+ VNWeb::HTML::user_($l);
end;
td class => 'tc2', fmtdate $l->{registered};
td class => 'tc3'.($l->{hide_list} && $self->authCan('usermod') ? ' linethrough' : '');
@@ -283,11 +283,10 @@ sub notifies {
a href => "/u$uid/notify/$l->{id}", "$l->{ltype}$l->{iid}".($l->{subid}?".$l->{subid}":'');
end;
td class => 'tc5 clickable', id => "notify_$l->{id}";
- lit sprintf
- $l->{ltype} ne 't' ? 'Edit of %s by %s' :
- $l->{subid} == 1 ? 'New thread %s by %s' : 'Reply to %s by %s',
- sprintf('<i>%s</i>', xml_escape $l->{c_title}),
- sprintf('<i>%s</i>', xml_escape $l->{username});
+ txt $l->{ltype} eq 't' ? 'Edit of ' : $l->{subid} == 1 ? 'New thread ' : 'Reply to ';
+ i $l->{c_title};
+ txt ' by ';
+ i VNWeb::HTML::user_displayname($l);
end;
end 'tr';
},
diff --git a/lib/VNDB/Util/Auth.pm b/lib/VNDB/Util/Auth.pm
index 91453edf..4394149f 100644
--- a/lib/VNDB/Util/Auth.pm
+++ b/lib/VNDB/Util/Auth.pm
@@ -63,9 +63,9 @@ sub authAdminSetPass {
sub authInfo {
- # Used to return a lot more, but this was by far the most common use
+ # Used to return a lot more, but only the id is still used now.
# (code using other fields has been migrated)
- +{ id => auth->uid, username => auth->username }
+ +{ id => auth->uid }
}
diff --git a/lib/VNDB/Util/BrowseHTML.pm b/lib/VNDB/Util/BrowseHTML.pm
index 09bf55b2..24e657ae 100644
--- a/lib/VNDB/Util/BrowseHTML.pm
+++ b/lib/VNDB/Util/BrowseHTML.pm
@@ -10,7 +10,7 @@ use VNDB::Types;
use POSIX 'ceil';
-our @EXPORT = qw| htmlBrowse htmlBrowseNavigate htmlBrowseHist htmlBrowseVN |;
+our @EXPORT = qw| htmlBrowse htmlBrowseNavigate htmlBrowseVN |;
# generates a browse box, arguments:
@@ -122,45 +122,6 @@ sub htmlBrowseNavigate {
}
-sub htmlBrowseHist {
- my($self, $list, $f, $np, $url) = @_;
- $self->htmlBrowse(
- items => $list,
- options => $f,
- nextpage => $np,
- pageurl => $url,
- class => 'history',
- header => [
- sub { td class => 'tc1_1', 'Rev.'; td class => 'tc1_2', ''; },
- [ 'Date' ],
- [ 'User' ],
- [ 'Page' ],
- ],
- row => sub {
- my($s, $n, $i) = @_;
- my $revurl = "/$i->{type}$i->{itemid}.$i->{rev}";
-
- Tr;
- td class => 'tc1_1';
- a href => $revurl, "$i->{type}$i->{itemid}";
- end;
- td class => 'tc1_2';
- a href => $revurl, ".$i->{rev}";
- end;
- td class => 'tc2', fmtdate $i->{added}, 'full';
- td class => 'tc3';
- lit fmtuser $i;
- end;
- td class => 'tc4';
- a href => $revurl, title => $i->{ioriginal}, shorten $i->{ititle}, 80;
- b class => 'grayedout'; lit bb2html $i->{comments}, 150; end;
- end;
- end 'tr';
- },
- );
-}
-
-
sub htmlBrowseVN {
my($self, $list, $f, $np, $url, $tagscore) = @_;
$self->htmlBrowse(
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index d8e584ab..72febd63 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -214,7 +214,7 @@ sub revheader { # type, obj
txt ')';
br;
txt 'By ';
- lit fmtuser $obj;
+ VNWeb::HTML::user_($obj);
txt ' on ';
txt fmtdate $obj->{added}, 'full';
}
@@ -401,7 +401,7 @@ sub htmlVoteStats {
} elsif($_->{hide_list}) {
b class => 'grayedout', 'hidden';
} else {
- a href => "/u$_->{uid}", $_->{username};
+ VNWeb::HTML::user_($_);
}
end;
td fmtvote $_->{vote};
diff --git a/lib/VNWeb/Auth.pm b/lib/VNWeb/Auth.pm
index 7143f203..bd1fba49 100644
--- a/lib/VNWeb/Auth.pm
+++ b/lib/VNWeb/Auth.pm
@@ -11,7 +11,6 @@
# auth->logout;
#
# my $uid = auth->uid;
-# my $username = auth->username;
# my $wants_spoilers = auth->pref('spoilers');
# ..etc
#
@@ -56,17 +55,17 @@ TUWF::hook after => sub { $auth = __PACKAGE__->new() };
# have a lot of influence in this)
TUWF::set log_format => sub {
my(undef, $uri, $msg) = @_;
- sprintf "[%s] %s %s: %s\n", scalar localtime(), $uri, auth ? auth->uid : '-', $msg;
+ sprintf "[%s] %s %s: %s\n", scalar localtime(), $uri, auth ? 'u'.auth->uid : '-', $msg;
};
-use overload bool => sub { defined shift->{uid} };
+use overload bool => sub { defined shift->{user}{user_id} };
-sub uid { shift->{uid} }
-sub username { shift->{username} }
-sub perm { shift->{perm}||0 }
-sub token { shift->{token} }
+sub uid { shift->{user}{user_id} }
+sub perm { shift->{user}{perm}||0 }
+sub user { shift->{user} }
+sub token { shift->{token} }
@@ -150,18 +149,16 @@ sub _load_session {
my($self, $uid, $token_db) = @_;
my $user = $uid ? tuwf->dbRowi(
- 'SELECT id, username, perm FROM users
+ 'SELECT perm, ', sql_user(), ' FROM users u
WHERE id = ', \$uid,
'AND', sql_func(user_isvalidsession => 'id', sql_fromhex($token_db), \'web')
) : {};
# Drop the cookie if it's not valid
- tuwf->resCookie(auth => undef) if !$user->{id} && tuwf->reqCookie('auth');
+ tuwf->resCookie(auth => undef) if !$user->{user_id} && tuwf->reqCookie('auth');
- $self->{uid} = $user->{id};
- $self->{username} = $user->{username};
- $self->{perm} = $user->{perm}||0;
- $self->{token} = $token_db;
+ $self->{user} = $user;
+ $self->{token} = $token_db;
delete $self->{pref};
}
@@ -279,7 +276,7 @@ sub csrfcheck {
my @pref_columns = qw/
email_confirmed skin customcss filter_vn filter_release show_nsfw hide_list notify_dbedit notify_announce
- vn_list_own vn_list_wish tags_all tags_cont tags_ero tags_tech spoilers traits_sexual
+ vn_list_own vn_list_wish tags_all tags_cont tags_ero tags_tech spoilers traits_sexual nodistract_can nodistract_nofancy
/;
# Returns a user preference column for the current user. Lazily loads all
diff --git a/lib/VNWeb/DB.pm b/lib/VNWeb/DB.pm
index 0d5616e0..8b63c167 100644
--- a/lib/VNWeb/DB.pm
+++ b/lib/VNWeb/DB.pm
@@ -10,7 +10,7 @@ use VNDB::Schema;
our @EXPORT = qw/
sql
- sql_join sql_comma sql_and sql_or sql_array sql_func sql_fromhex sql_tohex sql_fromtime sql_totime
+ sql_join sql_comma sql_and sql_or sql_array sql_func sql_fromhex sql_tohex sql_fromtime sql_totime sql_user
enrich enrich_merge enrich_flatten
db_entry db_edit
/;
@@ -88,6 +88,21 @@ sub sql_totime($) {
sql "extract('epoch' from ", $_[0], ')';
}
+# Returns a list of column names to fetch for displaying a username with HTML::user_().
+# Arguments: Name of the 'users' table (default: 'u'), prefix for the fetched fields (default: 'user_').
+# (This function returns a plain string so that old non-SQL-Interp functions can also use it)
+sub sql_user {
+ my $tbl = shift||'u';
+ my $prefix = shift||'user_';
+ join ', ',
+ "$tbl.id as ${prefix}id",
+ "$tbl.username as ${prefix}name",
+ "$tbl.support_can as ${prefix}support_can",
+ "$tbl.support_enabled as ${prefix}support_enabled",
+ "$tbl.uniname_can as ${prefix}uniname_can",
+ "$tbl.uniname as ${prefix}uniname";
+}
+
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 8d99f43a..893bbe2b 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -21,7 +21,7 @@ our @EXPORT = qw/
clearfloat_
debug_
join_
- user_
+ user_ user_displayname
elm_
framework_
revision_
@@ -56,11 +56,32 @@ sub join_($&@) {
}
-# Display a user link.
+# Display a user link, the given object must have the columns as fetched using DB::sql_user().
+# Args: $object, $prefix
sub user_ {
- my($uid, $username) = @_;
- return lit_ '[deleted]' if !$uid;
- a_ href => "/u$uid", $username;
+ my $obj = shift;
+ my $prefix = shift||'user_';
+ my sub f($) { $obj->{"${prefix}$_[0]"} }
+
+ return lit_ '[deleted]' if !f 'id';
+ my $fancy = !(auth->pref('nodistract_can') && auth->pref('nodistract_nofancy'));
+ my $uniname = f 'uniname_can' && f 'uniname';
+ a_ href => '/u'.f('id'),
+ $fancy && $uniname ? (title => f('name'), $uniname) :
+ (!$fancy && $uniname ? (title => $uniname) : (), f 'name');
+ txt_ '⭐' if $fancy && f 'support_can' && f 'support_enabled';
+}
+
+
+# Similar to user_(), but just returns a string. Mainly for use in titles.
+sub user_displayname {
+ my $obj = shift;
+ my $prefix = shift||'user_';
+ my sub f($) { $obj->{"${prefix}$_[0]"} }
+
+ return '[deleted]' if !f 'id';
+ my $fancy = !(auth->pref('nodistract_can') && auth->pref('nodistract_nofancy'));
+ $fancy && f 'uniname_can' && f 'uniname' ? f 'uniname' : f 'name'
}
@@ -160,7 +181,7 @@ sub _menu_ {
div_ class => 'menubox', sub {
my $uid = sprintf '/u%d', auth->uid;
my $nc = auth && tuwf->dbVali('SELECT count(*) FROM notifications WHERE uid =', \auth->uid, 'AND read IS NULL');
- h2_ sub { a_ href => $uid, ucfirst auth->username };
+ h2_ sub { user_ auth->user };
div_ sub {
a_ href => "$uid/edit", 'My Profile'; br_;
a_ href => "$uid/list", 'My Visual Novel List'; br_;
@@ -377,15 +398,15 @@ sub _revision_header_ {
if(auth) {
lit_ ' (';
a_ href => "/$type$obj->{id}.$obj->{chrev}/edit", $obj->{chrev} == $obj->{maxrev} ? 'edit' : 'revert to';
- if($obj->{rev_requester}) {
+ if($obj->{rev_user_id}) {
lit_ ' / ';
- a_ href => "/t/u$obj->{rev_requester}/new?title=Regarding%20$type$obj->{id}.$obj->{chrev}", 'msg user';
+ a_ href => "/t/u$obj->{rev_user_id}/new?title=Regarding%20$type$obj->{id}.$obj->{chrev}", 'msg user';
}
lit_ ')';
}
br_;
lit_ 'By ';
- user_ @{$obj}{'rev_requester', 'rev_username'};
+ user_ $obj, 'rev_user_';
lit_ ' on ';
txt_ fmtdate $obj->{rev_added}, 'full';
}
@@ -540,8 +561,7 @@ sub revision_ {
$enrich->($old) if $old;
enrich_merge chid => sql(
- 'SELECT c.id AS chid, c.comments as rev_comments,', sql_totime('c.added'), 'as rev_added
- , c.requester as rev_requester, u.username as rev_username
+ 'SELECT c.id AS chid, c.comments as rev_comments,', sql_totime('c.added'), 'as rev_added, ', sql_user('u', 'rev_user_'), '
FROM changes c LEFT JOIN users u ON u.id = c.requester
WHERE c.id IN'),
$new, $old||();
diff --git a/lib/VNWeb/Misc/History.pm b/lib/VNWeb/Misc/History.pm
index 9d814644..2b24b86a 100644
--- a/lib/VNWeb/Misc/History.pm
+++ b/lib/VNWeb/Misc/History.pm
@@ -29,8 +29,7 @@ sub fetch {
AND c_i.rev = (SELECT MAX(c_ii.rev) FROM changes c_ii WHERE c_ii.type = c.type AND c_ii.itemid = c.itemid))' : ();
my($lst, $np) = tuwf->dbPagei({ page => $filt->{p}, results => $opt->{results}||50 }, q{
- SELECT c.id, c.type, c.itemid, c.comments, c.rev,}, sql_totime('c.added'), q{ AS added
- , c.requester, u.username
+ SELECT c.id, c.type, c.itemid, c.comments, c.rev,}, sql_totime('c.added'), q{ AS added, }, sql_user(), q{
FROM changes c
JOIN users u ON c.requester = u.id
WHERE}, $where, q{
@@ -87,7 +86,7 @@ sub tablebox_ {
td_ class => 'tc1_1', sub { a_ href => $revurl, "$i->{type}$i->{itemid}" };
td_ class => 'tc1_2', sub { a_ href => $revurl, ".$i->{rev}" };
td_ class => 'tc2', fmtdate $i->{added}, 'full';
- td_ class => 'tc3', sub { user_ $i->{requester}, $i->{username} };
+ td_ class => 'tc3', sub { user_ $i };
td_ class => 'tc4', sub {
a_ href => $revurl, title => $i->{original}, shorten $i->{title}, 80;
b_ class => 'grayedout', sub { lit_ bb2html $i->{comments}, 150 };
@@ -188,7 +187,7 @@ TUWF::get qr{/(?:([upvrcsd])([1-9]\d*)/)?hist} => sub {
};
my $obj = !$type ? undef :
- $type eq 'u' ? tuwf->dbRowi('SELECT id, username AS title FROM users WHERE id =', \$id) :
+ $type eq 'u' ? tuwf->dbRowi('SELECT id, ', sql_user(), 'FROM users u WHERE id =', \$id) :
$type eq 'p' ? dbitem producers => 'name' :
$type eq 'v' ? dbitem vn => 'title' :
$type eq 'r' ? dbitem releases => 'title' :
@@ -197,6 +196,7 @@ TUWF::get qr{/(?:([upvrcsd])([1-9]\d*)/)?hist} => sub {
$type eq 'd' ? dbitem docs => 'title' : die;
return tuwf->resNotFound if $type && !$obj->{id};
+ $obj->{title} = user_displayname $obj if $type eq 'u';
my $title = $type ? "Edit history of $obj->{title}" : 'Recent changes';
framework_ title => $title, index => 0, type => $type, dbobj => $obj, tab => 'hist',
diff --git a/lib/VNWeb/User/Page.pm b/lib/VNWeb/User/Page.pm
index 175ce3de..2ad6d796 100644
--- a/lib/VNWeb/User/Page.pm
+++ b/lib/VNWeb/User/Page.pm
@@ -7,13 +7,25 @@ use VNWeb::Misc::History;
sub _info_table_ {
my($u, $vis) = @_;
+ my sub sup {
+ b_ ' ⭐supporter⭐' if $u->{user_support_can} && $u->{user_support_enabled};
+ }
+
+ tr_ sub {
+ td_ class => 'key', 'Display name';
+ td_ sub {
+ txt_ $u->{user_uniname};
+ sup;
+ };
+ } if $u->{user_uniname_can} && $u->{user_uniname};
tr_ sub {
td_ class => 'key', 'Username';
td_ sub {
- txt_ ucfirst $u->{username};
+ txt_ $u->{user_name};
txt_ ' ('; a_ href => "/u$u->{id}", "u$u->{id}";
txt_ ')';
debug_ $u;
+ sup if !($u->{user_uniname_can} && $u->{user_uniname});
};
};
tr_ sub {
@@ -113,9 +125,10 @@ sub _votestats_ {
TUWF::get qr{/$RE{uid}}, sub {
my $u = tuwf->dbRowi(q{
- SELECT id, username, hide_list, c_changes, c_votes, c_tags
+ SELECT id, hide_list, c_changes, c_votes, c_tags
,}, sql_totime('registered'), q{ AS registered
- FROM users
+ ,}, sql_user(), q{
+ FROM users u
WHERE id =}, \tuwf->capture('id')
);
return tuwf->resNotFound if !$u->{id};
@@ -129,7 +142,7 @@ TUWF::get qr{/$RE{uid}}, sub {
GROUP BY (vote::numeric/10)::int
});
- my $title = "$u->{username}'s profile";
+ my $title = user_displayname($u)."'s profile";
framework_ title => $title, index => 0, type => 'u', dbobj => $u,
sub {
div_ class => 'mainbox userpage', sub {