Load all sysbans for a particular value so we can see notes for them
all.
Patch by afuna.
diffs (100 lines):
diff -r 2c8ee86c1880 -r d7d294f7f0af cgi-bin/sysban.pl
--- a/cgi-bin/sysban.pl Sat Feb 13 01:06:04 2010 +0000
+++ b/cgi-bin/sysban.pl Sat Feb 13 01:11:46 2010 +0000
@@ -276,6 +276,55 @@ sub _db_sysban_populate_full {
}
+=h2 C<< LJ::sysban_populate_full_by_value( $value, @types ) >>
+
+List all sysbans for the given value, of the specified types. This can be
used, for example, to limit the sysban to only the privs that this user can see.
+Returns a hashref of hashes in the format:
+ what => { expire => expiration, note => note, banid => banid }
+
+=cut
+sub sysban_populate_full_by_value {
+ my ( $value, @types ) = @_;
+ return LJ::_db_sysban_populate_full_by_value( $value, @types );
+}
+
+sub _db_sysban_populate_full_by_value {
+ my ( $value, @types ) = @_;
+ my $dbh = LJ::get_db_writer();
+ return undef unless $dbh;
+
+ my $in_what = "";
+ my $has_all = 0;
+
+ $in_what = join ", ", map { $dbh->quote( $_ ) } @types
+ unless $has_all;
+ $in_what = " AND what IN ( $in_what )"
+ if $in_what;
+
+ # build cache from db
+ my $sth = $dbh->prepare(
+ qq{SELECT banid, what, UNIX_TIMESTAMP(banuntil), note
+ FROM sysban
+ WHERE status = 'active'
+ AND value = ?
+ $in_what
+ AND NOW() > bandate
+ AND ( NOW() < banuntil OR banuntil IS NULL )
+ }
+ );
+ $sth->execute( $value );
+ return undef if $sth->err;
+
+ my $where;
+ while ( my ( $banid, $what, $exp, $note ) = $sth->fetchrow_array ) {
+ $where->{$what}->{banid} = $banid || 0;
+ $where->{$what}->{expire} = $exp || 0;
+ $where->{$what}->{note} = $note || 0;
+ }
+
+ return $where;
+}
+
# <LJFUNC>
# name: LJ::sysban_note
diff -r 2c8ee86c1880 -r d7d294f7f0af htdocs/admin/sysban.bml
--- a/htdocs/admin/sysban.bml Sat Feb 13 01:06:04 2010 +0000
+++ b/htdocs/admin/sysban.bml Sat Feb 13 01:11:46 2010 +0000
@@ -75,7 +75,9 @@ body<=
<input type='submit' name='addnew' value='Add New'>
<input type='submit' name='query' value='Query'>
<br /><br />
-<input type='text' name='queryvalue' /> <input type='submit' name='queryone'
value='Query This Value' />
+
+<label for="queryvalue">Query all sysbans for this value:</label><br />
+<input type='text' id="queryvalue" name='queryvalue' /> <input type='submit'
name='queryone' value='Query This Value' />
</form>
FORM
@@ -138,11 +140,22 @@ QUERYFORM
return $err->("Requires post") unless LJ::did_post();
return $err->("Invalid form") unless LJ::check_form_auth();
- my $bantype = $POST{bantype};
my $banquery = $POST{queryvalue};
-
- $ret .= "<br />" . LJ::ehtml( $bantype ) . ": " . LJ::ehtml(
$banquery );
- $ret .= LJ::sysban_check( $bantype, $banquery ) ? " is sysbanned." :
" is not sysbanned.";
+ my $sysbans = LJ::sysban_populate_full_by_value( $banquery,
@sysban_privs ) || {};
+ if ( %$sysbans ) {
+ $ret .= "Sysbans for " . LJ::ehtml( $banquery );
+ $ret .=
"<table><tr><th>Type</th><th>Expiration</th><th>Note</th></tr>";
+ while ( my ( $what, $details ) = each %$sysbans ) {
+ $ret .= "<tr>";
+ $ret .= "<td>$what</td>";
+ $ret .= "<td>" . localtime( $details->{expire} ) . "</td> ";
+ $ret .= "<td>" . LJ::ehtml( $details->{note} ) . "</td>";
+ $ret .= "</tr>";
+ }
+ $ret .= "</table>";
+ } else {
+ $ret .= "No sysbans matching " . LJ::ehtml( $banquery );
+ }
}
# this action comes from the query section
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog