summaryrefslogtreecommitdiff
path: root/lib/VNDB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-10-14 18:24:06 +0200
committerYorhel <git@yorhel.nl>2019-10-14 18:24:06 +0200
commitb7c525893bdd374d067e34d307bf0bc32df73f97 (patch)
tree1a3609d44bc3746fd8dfd66e73e0bd360255613d /lib/VNDB
parentb539ea56c2406a110ca6666e9f42c3b4af8e1a10 (diff)
v2rw: Convert user listing
Diffstat (limited to 'lib/VNDB')
-rw-r--r--lib/VNDB/DB/Users.pm40
-rw-r--r--lib/VNDB/Func.pm13
-rw-r--r--lib/VNDB/Handler/Users.pm79
-rw-r--r--lib/VNDB/Util/CommonHTML.pm17
4 files changed, 18 insertions, 131 deletions
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index d80e6547..6981d291 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -10,8 +10,8 @@ our @EXPORT = qw|
|;
-# %options->{ username session uid ip registered search results page what sort reverse notperm }
-# what: extended pubskin
+# %options->{ uid results page what }
+# what: pubskin
# sort: username registered votes changes tags
sub dbUserGet {
my $s = shift;
@@ -19,61 +19,29 @@ sub dbUserGet {
page => 1,
results => 10,
what => '',
- sort => '',
@_
);
- my $token = unpack 'H*', $o{session}||'';
- $o{search} =~ s/%// if $o{search};
my %where = (
- $o{username} ? (
- 'username = ?' => $o{username} ) : (),
- $o{firstchar} ? (
- 'SUBSTRING(username from 1 for 1) = ?' => $o{firstchar} ) : (),
- !$o{firstchar} && defined $o{firstchar} ? (
- 'ASCII(username) < 97 OR ASCII(username) > 122' => 1 ) : (),
$o{uid} && !ref($o{uid}) ? (
'id = ?' => $o{uid} ) : (),
$o{uid} && ref($o{uid}) ? (
'id IN(!l)' => [ $o{uid} ]) : (),
- !$o{uid} && !$o{username} ? (
- 'id > 0' => 1 ) : (),
- $o{ip} ? (
- 'ip !s ?' => [ $o{ip} =~ /\// ? '<<' : '=', $o{ip} ] ) : (),
- $o{registered} ? (
- 'registered > to_timestamp(?)' => $o{registered} ) : (),
- $o{search} ? (
- 'username ILIKE ?' => "%$o{search}%") : (),
- $token ? (
- q|user_isloggedin(id, decode(?, 'hex')) IS NOT NULL| => $token ) : (),
- $o{notperm} ? (
- 'perm & ~(?::smallint) > 0' => $o{notperm} ) : (),
);
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} =~ /pubskin/ ? qw|pubskin_can pubskin_enabled customcss skin| : (),
- $token ? qq|extract('epoch' from user_isloggedin(id, decode('$token', 'hex'))) as session_lastused| : (),
);
- my $order = sprintf {
- id => 'u.id %s',
- username => 'u.username %s',
- registered => 'u.registered %s',
- votes => 'u.hide_list, u.c_votes %s',
- changes => 'u.c_changes %s',
- tags => 'u.c_tags %s',
- }->{ $o{sort}||'username' }, $o{reverse} ? 'DESC' : 'ASC';
-
my($r, $np) = $s->dbPage(\%o, q|
SELECT !s
FROM users u
!W
- ORDER BY !s|,
- join(', ', @select), \%where, $order
+ ORDER BY id DESC|,
+ join(', ', @select), \%where
);
return wantarray ? ($r, $np) : $r;
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 3a1d9261..96a17106 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -3,7 +3,7 @@ package VNDB::Func;
use strict;
use warnings;
-use TUWF ':html', 'kv_validate', 'xml_escape';
+use TUWF ':html', 'kv_validate', 'xml_escape', 'uri_escape';
use Exporter 'import';
use POSIX 'strftime', 'ceil', 'floor';
use JSON::XS;
@@ -17,6 +17,7 @@ our @EXPORT = (@VNDBUtil::EXPORT, 'bb2html', 'bb2text', qw|
lang_attr
json_encode json_decode script_json
form_compare
+ query_encode
|);
@@ -334,5 +335,15 @@ sub form_compare {
return 0;
}
+
+# Encode query parameters. Takes a hash or hashref with key/values, supports array values.
+sub query_encode {
+ my $o = @_ == 1 ? $_[0] : {@_};
+ return join '&', map {
+ my($k, $v) = ($_, $o->{$_});
+ !defined $v ? () : ref $v ? map "$k=".uri_escape($_), sort @$v : "$k=".uri_escape($v)
+ } sort keys %$o;
+}
+
1;
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index 56a00d2a..a9c53206 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -3,17 +3,12 @@ package VNDB::Handler::Users;
use strict;
use warnings;
-use TUWF ':html', 'xml_escape';
+use TUWF ':html';
use VNDB::Func;
-use VNDB::Types;
-use VNWeb::Auth;
-use POSIX 'floor';
-use PWLookup;
TUWF::register(
qr{u([1-9]\d*)/posts} => \&posts,
- qr{u/(all|[0a-z])} => \&list,
);
@@ -70,77 +65,5 @@ sub posts {
}
-sub list {
- my($self, $char) = @_;
-
- my $f = $self->formValidate(
- { get => 's', required => 0, default => 'username', enum => [ qw|username registered votes changes tags| ] },
- { get => 'o', required => 0, default => 'a', enum => [ 'a','d' ] },
- { get => 'p', required => 0, default => 1, template => 'page' },
- { get => 'q', required => 0, default => '', maxlength => 50 },
- );
- return $self->resNotFound if $f->{_err};
-
- $self->htmlHeader(noindex => 1, title => 'Browse users');
-
- div class => 'mainbox';
- h1 'Browse users';
- form action => '/u/all', 'accept-charset' => 'UTF-8', method => 'get';
- $self->htmlSearchBox('u', $f->{q});
- end;
- p class => 'browseopts';
- for ('all', 'a'..'z', 0) {
- a href => "/u/$_", $_ eq $char ? (class => 'optselected') : (), $_ eq 'all' ? 'ALL' : $_ ? uc $_ : '#';
- }
- end;
- end;
-
- my($list, $np) = $self->dbUserGet(
- sort => $f->{s}, reverse => $f->{o} eq 'd',
- what => 'hide_list',
- $char ne 'all' ? (
- firstchar => $char ) : (),
- results => 50,
- page => $f->{p},
- search => $f->{q},
- );
-
- $self->htmlBrowse(
- items => $list,
- options => $f,
- nextpage => $np,
- pageurl => "/u/$char?o=$f->{o};s=$f->{s};q=$f->{q}",
- sorturl => "/u/$char?q=$f->{q}",
- header => [
- [ 'Username', 'username' ],
- [ 'Registered', 'registered' ],
- [ 'Votes', 'votes' ],
- [ 'Edits', 'changes' ],
- [ 'Tags', 'tags' ],
- ],
- row => sub {
- my($s, $n, $l) = @_;
- Tr;
- td class => 'tc1';
- VNWeb::HTML::user_($l);
- end;
- td class => 'tc2', fmtdate $l->{registered};
- td class => 'tc3'.($l->{hide_list} && $self->authCan('usermod') ? ' linethrough' : '');
- lit $l->{hide_list} && !$self->authCan('usermod') ? '-' : !$l->{c_votes} ? 0 :
- qq|<a href="/u$l->{id}/votes">$l->{c_votes}</a>|;
- end;
- td class => 'tc4';
- lit !$l->{c_changes} ? 0 : qq|<a href="/u$l->{id}/hist">$l->{c_changes}</a>|;
- end;
- td class => 'tc5';
- lit !$l->{c_tags} ? 0 : qq|<a href="/g/links?u=$l->{id}">$l->{c_tags}</a>|;
- end;
- end 'tr';
- },
- );
- $self->htmlFooter;
-}
-
-
1;
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index 3d18bdf5..81309325 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -418,22 +418,7 @@ sub htmlVoteStats {
sub htmlSearchBox {
- my($self, $sel, $v) = @_;
-
- fieldset class => 'search';
- p id => 'searchtabs';
- a href => '/v/all', $sel eq 'v' ? (class => 'sel') : (), 'Visual novels';
- a href => '/r', $sel eq 'r' ? (class => 'sel') : (), 'Releases';
- a href => '/p/all', $sel eq 'p' ? (class => 'sel') : (), 'Producers';
- a href => '/s/all', $sel eq 's' ? (class => 'sel') : (), 'Staff';
- a href => '/c/all', $sel eq 'c' ? (class => 'sel') : (), 'Characters';
- a href => '/g', $sel eq 'g' ? (class => 'sel') : (), 'Tags';
- a href => '/i', $sel eq 'i' ? (class => 'sel') : (), 'Traits';
- a href => '/u/all', $sel eq 'u' ? (class => 'sel') : (), 'Users';
- end;
- input type => 'text', name => 'q', id => 'q', class => 'text', value => $v;
- input type => 'submit', class => 'submit', value => 'Search!';
- end 'fieldset';
+ shift; VNWeb::HTML::searchbox_(@_);
}