[dw-free] new sysban type: spamreport
[commit: http://hg.dwscoalition.org/dw-free/rev/51ee4b0fec37]
http://bugs.dwscoalition.org/show_bug.cgi?id=2104
Add ability to sysban people from reporting spam.
Patch by
afuna.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2104
Add ability to sysban people from reporting spam.
Patch by
Files modified:
- bin/ljsysban.pl
- cgi-bin/LJ/Comment.pm
- cgi-bin/LJ/Entry.pm
- cgi-bin/LJ/Event/UserMessageRecvd.pm
- cgi-bin/LJ/S2.pm
- cgi-bin/LJ/S2/EntryPage.pm
- cgi-bin/LJ/Talk.pm
- cgi-bin/ljlib.pl
- cgi-bin/sysban.pl
- htdocs/admin/sysban.bml
- htdocs/community/moderate.bml
- htdocs/delcomment.bml
- htdocs/editjournal.bml
- htdocs/inbox/markspam.bml
- htdocs/js/commentmanage.js
- htdocs/talkmulti.bml
- htdocs/talkread.bml
- htdocs/tools/recent_comments.bml
--------------------------------------------------------------------------------
diff -r 5e837b3c4787 -r 51ee4b0fec37 bin/ljsysban.pl
--- a/bin/ljsysban.pl Tue Jan 05 23:58:20 2010 +0000
+++ b/bin/ljsysban.pl Wed Jan 06 00:20:55 2010 +0000
@@ -125,6 +125,11 @@ if ($add) {
'exptime' => LJ::mysqldate_to_time($banuntil) });
LJ::MemCache::delete("sysban:uniq");
}
+ if ( $what eq 'spamreport' ) {
+ LJ::procnotify_add( 'ban_spamreport', { spamreport => $value,
+ exptime => LJ::mysqldate_to_time( $banuntil ) } );
+ LJ::MemCache::delete( 'sysban:spamreport' );
+ }
# log in statushistory
LJ::statushistory_add(0, 0, 'sysban_add',
@@ -161,6 +166,11 @@ if ($modify) {
LJ::procnotify_add("unban_uniq", { 'uniq' => $value || $ban->{'value'} });
LJ::MemCache::delete("sysban:uniq");
}
+
+ if ( $ban->{what} eq 'spamreport' ) {
+ LJ::procnotify_add( 'unban_spamreport', { spamreport => $value || $ban->{value} } );
+ LJ::MemCache::delete( 'sysban:spamreport' );
+ }
}
# what - must have a value
@@ -186,6 +196,12 @@ if ($modify) {
LJ::procnotify_add("ban_uniq", { 'uniq' => $value || $ban->{'value'},
'exptime' => LJ::mysqldate_to_time($new_banuntil) });
LJ::MemCache::delete("sysban:uniq");
+ }
+
+ if ( $ban->{what} eq 'spamreport' ) {
+ LJ::procnotify_add( 'ban_spamreport', { spamreport => $value || $ban->{value},
+ exptime => LJ::mysqldate_to_time( $new_banuntil ) } );
+ LJ::MemCache::delete( 'sysban:spamreport' );
}
}
diff -r 5e837b3c4787 -r 51ee4b0fec37 cgi-bin/LJ/Comment.pm
--- a/cgi-bin/LJ/Comment.pm Tue Jan 05 23:58:20 2010 +0000
+++ b/cgi-bin/LJ/Comment.pm Wed Jan 06 00:20:55 2010 +0000
@@ -1096,6 +1096,7 @@ sub info {
my %LJ_cmtinfo;
$LJ_cmtinfo{'canAdmin'} = LJ::can_manage($remote, $self->journal);
+ $LJ_cmtinfo{'canSpam'} = ! LJ::sysban_check( 'spamreport', $self->journal->user );
$LJ_cmtinfo{'journal'} = $self->journal->{user};
$LJ_cmtinfo{'remote'} = $remote->{user};
diff -r 5e837b3c4787 -r 51ee4b0fec37 cgi-bin/LJ/Entry.pm
--- a/cgi-bin/LJ/Entry.pm Tue Jan 05 23:58:20 2010 +0000
+++ b/cgi-bin/LJ/Entry.pm Wed Jan 06 00:20:55 2010 +0000
@@ -1918,6 +1918,7 @@ sub mark_entry_as_spam {
$journalu = LJ::want_user($journalu);
$jitemid += 0;
return 0 unless $journalu && $jitemid;
+ return 0 if LJ::sysban_check( 'spamreport', $journalu->user );
my $dbcr = LJ::get_cluster_def_reader($journalu);
my $dbh = LJ::get_db_writer();
@@ -1946,6 +1947,7 @@ sub reject_entry_as_spam {
$journalu = LJ::want_user($journalu);
$modid += 0;
return 0 unless $journalu && $modid;
+ return 0 if LJ::sysban_check( 'spamreport', $journalu->user );
my $dbcr = LJ::get_cluster_def_reader($journalu);
my $dbh = LJ::get_db_writer();
diff -r 5e837b3c4787 -r 51ee4b0fec37 cgi-bin/LJ/Event/UserMessageRecvd.pm
--- a/cgi-bin/LJ/Event/UserMessageRecvd.pm Tue Jan 05 23:58:20 2010 +0000
+++ b/cgi-bin/LJ/Event/UserMessageRecvd.pm Wed Jan 06 00:20:55 2010 +0000
@@ -127,7 +127,8 @@ sub as_html_actions {
$ret .= " <a href='$LJ::SITEROOT/inbox/compose?mode=reply&msgid=$msgid'>Reply</a>";
$ret .= " | <a href='$LJ::SITEROOT/manage/circle/add?user=". $msg->other_u->user ."&action=subscribe'>Add to reading list</a>"
unless $u->watches( $msg->other_u );
- $ret .= " | <a href='$LJ::SITEROOT/inbox/markspam?msgid=". $msg->msgid ."'>Mark as Spam</a>";
+ $ret .= " | <a href='$LJ::SITEROOT/inbox/markspam?msgid=". $msg->msgid ."'>Mark as Spam</a>"
+ unless LJ::sysban_check( 'spamreport', $u->user );
$ret .= "</div>";
return $ret;
diff -r 5e837b3c4787 -r 51ee4b0fec37 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm Tue Jan 05 23:58:20 2010 +0000
+++ b/cgi-bin/LJ/S2.pm Wed Jan 06 00:20:55 2010 +0000
@@ -3747,11 +3747,13 @@ sub EntryPage__print_multiform_actionlin
my ($ctx, $this) = @_;
return unless $this->{'multiform_on'};
my $pr = $ctx->[S2::PROPS];
+ my @actions = qw( unscreen screen delete );
+ push @actions, "deletespam" unless LJ::sysban_check( 'spamreport', $this->{entry}->{journal}->{username} );
$S2::pout->( LJ::labelfy( 'multiform_mode', $pr->{text_multiform_des} ) . "\n" .
LJ::html_select( { name => 'mode', id => 'multiform_mode' },
"" => "",
map { $_ => $pr->{"text_multiform_opt_$_"} }
- qw(unscreen screen delete deletespam)) . "\n" .
+ @actions ) . "\n" .
LJ::html_submit('', $pr->{'text_multiform_btn'},
{ "onclick" =>
'return ((document.multiform.mode.value != "delete" ' .
diff -r 5e837b3c4787 -r 51ee4b0fec37 cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm Tue Jan 05 23:58:20 2010 +0000
+++ b/cgi-bin/LJ/S2/EntryPage.pm Wed Jan 06 00:20:55 2010 +0000
@@ -328,12 +328,14 @@ sub EntryPage
# print comment info
{
my $canAdmin = LJ::can_manage($remote, $u) ? 1 : 0;
+ my $canSpam = LJ::sysban_check( 'spamreport', $u->user ) ? 0 : 1;
my $formauth = LJ::ejs(LJ::eurl(LJ::form_auth(1)));
my $cmtinfo = {
form_auth => $formauth,
journal => $u->user,
canAdmin => $canAdmin,
+ canSpam => $canSpam,
remote => $remote ? $remote->user : undef,
};
diff -r 5e837b3c4787 -r 51ee4b0fec37 cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm Tue Jan 05 23:58:20 2010 +0000
+++ b/cgi-bin/LJ/Talk.pm Wed Jan 06 00:20:55 2010 +0000
@@ -1921,6 +1921,9 @@ sub mark_comment_as_spam {
# can't mark your own comments as spam.
return 0 if $posterid && $posterid == $journalu->id;
+
+ # can't mark comments as spam if sysbanned
+ return 0 if LJ::sysban_check( 'spamreport', $journalu->user );
# step 2a: if it's a suspended user, don't add, but pretend that we were successful
if ($posterid) {
diff -r 5e837b3c4787 -r 51ee4b0fec37 cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl Tue Jan 05 23:58:20 2010 +0000
+++ b/cgi-bin/ljlib.pl Wed Jan 06 00:20:55 2010 +0000
@@ -1883,6 +1883,28 @@ sub procnotify_callback
return;
}
+ # spamreport bans
+ if ( $cmd eq "ban_spamreport" ) {
+ $LJ::SPAMREPORT_BANNED{$arg->{spamreport}} = $arg->{exptime};
+ return;
+ }
+
+ if ( $cmd eq "unban_spamreport" ) {
+ $LJ::SPAMREPORT_BANNED{$arg->{spamreport}} = $arg->{exptime};
+ return;
+ }
+
+ # spamreport bans
+ if ( $cmd eq "ban_spamreport" ) {
+ $LJ::SPAMREPORT_BANNED{$arg->{spamreport}} = $arg->{exptime};
+ return;
+ }
+
+ if ( $cmd eq "unban_spamreport" ) {
+ delete $LJ::SPAMREPORT_BANNED{$arg->{spamreport}};
+ return;
+ }
+
# cluster switchovers
if ($cmd eq 'cluster_switch') {
$LJ::CLUSTER_PAIR_ACTIVE{ $arg->{'cluster'} } = $arg->{ 'role' };
diff -r 5e837b3c4787 -r 51ee4b0fec37 cgi-bin/sysban.pl
--- a/cgi-bin/sysban.pl Tue Jan 05 23:58:20 2010 +0000
+++ b/cgi-bin/sysban.pl Wed Jan 06 00:20:55 2010 +0000
@@ -100,6 +100,38 @@ sub sysban_check {
return $LJ::UNIQ_BANNED{$value};
}
+ # cache if spamreport ban
+ if ( $what eq 'spamreport' ) {
+ # check memcache first if not loaded
+ unless ( $LJ::SPAMREPORT_BANNED_LOADED ) {
+ my $memval = LJ::MemCache::get( "sysban:spamreport" );
+ if ( $memval ) {
+ *LJ::SPAMREPORT_BANNED = $memval;
+ $LJ::SPAMREPORT_BANNED_LOADED++;
+ }
+ }
+
+ # is it already cached in memory?
+ if ( $LJ::SPAMREPORT_BANNED_LOADED ) {
+ return ( defined $LJ::SPAMREPORT_BANNED{$value} &&
+ ( $LJ::SPAMREPORT_BANNED{$value} == 0 || # forever
+ $LJ::SPAMREPORT_BANNED{$value} > time() ) ); # not expired
+ }
+
+ # set this now before the query
+ $LJ::SPAMREPORT_BANNED_LOADED++;
+
+ LJ::sysban_populate( \%LJ::SPAMREPORT_BANNED, "spamreport" )
+ or return undef $LJ::SPAMREPORT_BANNED_LOADED;
+
+ # set in memcache
+ my $exp = 60 * 30; # 30 minutes
+ LJ::MemCache::set( "sysban:spamreport", \%LJ::SPAMREPORT_BANNED, $exp );
+
+ # return value to user
+ return $LJ::SPAMREPORT_BANNED{$value};
+ }
+
# need the db below here
my $dbr = LJ::get_db_reader();
return undef unless $dbr;
@@ -350,7 +382,7 @@ sub sysban_create {
my $banid = $dbh->{'mysql_insertid'};
my $exptime = $opts{bandays} ? time() + 86400*$opts{bandays} : 0;
- # special case: creating ip/uniq ban
+ # special case: creating ip/uniq/spamreport ban
if ($opts{'what'} eq 'ip') {
LJ::procnotify_add("ban_ip", { 'ip' => $opts{'value'}, exptime => $exptime });
LJ::MemCache::delete("sysban:ip");
@@ -359,6 +391,11 @@ sub sysban_create {
if ($opts{'what'} eq 'uniq') {
LJ::procnotify_add("ban_uniq", { 'uniq' => $opts{'value'}, exptime => $exptime});
LJ::MemCache::delete("sysban:uniq");
+ }
+
+ if ( $opts{what} eq 'spamreport' ) {
+ LJ::procnotify_add( 'ban_spamreport', { spamreport => $opts{value}, exptime => $exptime } );
+ LJ::MemCache::delete( 'sysban:spamreport' );
}
# log in statushistory
@@ -450,6 +487,7 @@ sub sysban_validate {
'invite_user' => 'user',
'invite_email' => 'email',
'noanon_ip' => 'ip',
+ 'spamreport' => 'user',
);
while (my ($new, $existing) = splice(@map, 0, 2)) {
diff -r 5e837b3c4787 -r 51ee4b0fec37 htdocs/admin/sysban.bml
--- a/htdocs/admin/sysban.bml Tue Jan 05 23:58:20 2010 +0000
+++ b/htdocs/admin/sysban.bml Wed Jan 06 00:20:55 2010 +0000
@@ -33,7 +33,7 @@ body<=
my @all_sb_args = qw( ip uniq email email_domain user pay_cc
pay_user pay_email pay_uniq support_user
support_uniq lostpassword talk_ip_test
- invite_user invite_email noanon_ip );
+ invite_user invite_email noanon_ip spamreport );
my $remote = LJ::get_remote();
return "<?needlogin?>" unless $remote;
diff -r 5e837b3c4787 -r 51ee4b0fec37 htdocs/community/moderate.bml
--- a/htdocs/community/moderate.bml Tue Jan 05 23:58:20 2010 +0000
+++ b/htdocs/community/moderate.bml Wed Jan 06 00:20:55 2010 +0000
@@ -195,6 +195,9 @@ body<=
$ret .= "<?h1 $ML{'Error'} h1?><?p $ML{'.error.notfound'} p?>";
return $ret;
}
+
+ my $can_spam = LJ::sysban_check( 'spamreport', $c->user ) ? 0 : 1;
+
my $dbcr = LJ::get_cluster_def_reader($c);
unless (LJ::check_rel($c, $remote, 'M')) {
@@ -408,7 +411,7 @@ body<=
$actions .= "<input type='hidden' name='modid' value='$modid' />";
$actions .= "<input type='submit' name='action:approve' value='$ML{'.choice.approve'}' style='font-size: 15pt; background: #82dd88; color: #000000' />";
$actions .= " <input type='submit' name='action:reject' value='$ML{'.choice.reject'}' style='font-size: 15pt; background: #e08291; color: #000000' />";
- $actions .= " <input type='submit' name='action:mark_as_spam' value='$ML{'.choice.mark_as_spam'}' style='font-size: 15pt; background: #e08291; color: #000000' />";
+ $actions .= " <input type='submit' name='action:mark_as_spam' value='$ML{'.choice.mark_as_spam'}' style='font-size: 15pt; background: #e08291; color: #000000' />" if $can_spam;
$ret .= "<form method='post' action='/community/moderate'>";
$ret .= BML::fill_template("standout", {'DATA'=> $actions});
diff -r 5e837b3c4787 -r 51ee4b0fec37 htdocs/delcomment.bml
--- a/htdocs/delcomment.bml Tue Jan 05 23:58:20 2010 +0000
+++ b/htdocs/delcomment.bml Wed Jan 06 00:20:55 2010 +0000
@@ -96,7 +96,8 @@ _info?><?_code
my $can_delthread = $can_manage || $jposterid == $remote->{userid};
# can mark as spam if they're not the comment poster
- my $can_spam = $remote && $remote->id != $tp->{'posterid'};
+ # or if the account is not sysbanned
+ my $can_spam = $remote && $remote->id != $tp->{'posterid'} && ! LJ::sysban_check( 'spamreport', $u->user );
### perform actions
if (LJ::did_post() && $POST{'confirm'}) {
@@ -123,7 +124,7 @@ _info?><?_code
$msg = BML::ml('.success.andban', { 'user' => LJ::ljuser($tp->{'userpost'}) });
}
$msg ||= $ML{'.success.noban'};
- $msg .= "<?p $ML{'.success.spam'} p?>" if $POST{spam};
+ $msg .= "<?p $ML{'.success.spam'} p?>" if $POST{spam} && $can_spam;
if ($jsmode) {
BML::finish();
@@ -152,7 +153,7 @@ _info?><?_code
$body .= "</label></div>";
}
- if ($tp->{'posterid'} != $remote->{'userid'}) { # Despite the idea of natural selection, don't let users report their own comments as spam
+ if ( $can_spam ) { # Despite the idea of natural selection, don't let users report their own comments as spam
$body .= "<div>" . LJ::html_check({name => 'spam', id => 'spam'});
$body .= "<label for='spam'>$ML{'.confirm.spam'}</label></div>";
}
diff -r 5e837b3c4787 -r 51ee4b0fec37 htdocs/editjournal.bml
--- a/htdocs/editjournal.bml Tue Jan 05 23:58:20 2010 +0000
+++ b/htdocs/editjournal.bml Wed Jan 06 00:20:55 2010 +0000
@@ -164,6 +164,7 @@ body<=
}
$disabled_save++ if $usejournal && ! $u->can_post_to( $usejournal_u );
$disabled_spamdelete = $disabled_delete || !$usejournal || ($res{'events_1_poster'} eq $u->{'user'});
+ $disabled_spamdelete ||= LJ::sysban_check( 'spamreport', $usejournal_u->user ) if $usejournal_u;
# read-only posters and journals cannot be edited
if (!$disabled_save && ($u->is_readonly || ($usejournal_u && $usejournal_u->is_readonly))) {
diff -r 5e837b3c4787 -r 51ee4b0fec37 htdocs/inbox/markspam.bml
--- a/htdocs/inbox/markspam.bml Tue Jan 05 23:58:20 2010 +0000
+++ b/htdocs/inbox/markspam.bml Wed Jan 06 00:20:55 2010 +0000
@@ -25,6 +25,9 @@ body<=
return "<?p You cannot report a message you sent as spam. p?>"
if $msg->type eq "out";
+
+ return "<?p You are not allowed to report messages as spam. p?>"
+ if LJ::sysban_check( 'spamreport', $remote->user );
my $body = '';
diff -r 5e837b3c4787 -r 51ee4b0fec37 htdocs/js/commentmanage.js
--- a/htdocs/js/commentmanage.js Tue Jan 05 23:58:20 2010 +0000
+++ b/htdocs/js/commentmanage.js Wed Jan 06 00:20:55 2010 +0000
@@ -366,6 +366,7 @@ function createDeleteFunction (ae, dItem
if (!com || !remoteUser)
return true;
var canAdmin = LJ_cmtinfo["canAdmin"];
+ var canSpam = LJ_cmtinfo["canSpam"];
var clickTarget = getTarget(e);
@@ -410,7 +411,7 @@ function createDeleteFunction (ae, dItem
finalHeight -= 15;
}
- if (remoteUser != "" && remoteUser != com.u) {
+ if (remoteUser != "" && remoteUser != com.u && canSpam) {
lbl = "ljpopdel" + dItemid + "spam";
inHTML += "<input type='checkbox' value='spam' id='" + lbl + "'> <label for='" + lbl + "'>Mark this comment as spam</label><br />";
} else {
diff -r 5e837b3c4787 -r 51ee4b0fec37 htdocs/talkmulti.bml
--- a/htdocs/talkmulti.bml Tue Jan 05 23:58:20 2010 +0000
+++ b/htdocs/talkmulti.bml Wed Jan 06 00:20:55 2010 +0000
@@ -82,7 +82,7 @@
# then delete, updating the log2 replycount as necessary
# Mark as spam
- if ($mode eq 'deletespam') {
+ if ( $mode eq 'deletespam' && ! LJ::sysban_check( 'spamreport', $u->user ) ) {
# don't let $remote mark their own comments as spam
foreach (grep { $talkinfo{$_}->[1] != $remote->id } @talkids) {
my $s = LJ::Talk::mark_comment_as_spam($u, $_);
diff -r 5e837b3c4787 -r 51ee4b0fec37 htdocs/talkread.bml
--- a/htdocs/talkread.bml Tue Jan 05 23:58:20 2010 +0000
+++ b/htdocs/talkread.bml Wed Jan 06 00:20:55 2010 +0000
@@ -453,6 +453,7 @@ body<=
$LJ_cmtinfo{'form_auth'} = LJ::form_auth(1);
$LJ_cmtinfo{'journal'} = $u->{user};
$LJ_cmtinfo{'canAdmin'} = LJ::can_manage($remote, $u) ? 1 : 0;
+ $LJ_cmtinfo{'canSpam'} = LJ::sysban_check( 'spamreport', $u->user ) ? 0 : 1;
$LJ_cmtinfo{'remote'} = $remote ? $remote->{user} : "";
my $fmt_time_short = "%%hh%%:%%min%% %%a%%m";
my $show_thread_expander = $u->show_thread_expander( $remote );
@@ -851,13 +852,13 @@ body<=
if ($showmultiform && $multiform_selects) {
$ret .= "<p><label for='multiform_mode'>$ML{'.talkmulti.des'}</label>";
- $ret .= LJ::html_select( { name => 'mode', id => 'multiform_mode' },
- '' => '',
- 'unscreen' => $ML{'.talkmulti.unscreen'},
- 'screen' => $ML{'.talkmulti.screen'},
- 'delete' => $ML{'.talkmulti.delete'},
- 'deletespam' => $ML{'.talkmulti.deletespam'},
- );
+ my @actions = ( '' => '',
+ unscreen => $ML{'.talkmulti.unscreen'},
+ screen => $ML{'.talkmulti.screen'},
+ delete => $ML{'.talkmulti.delete'},
+ );
+ push @actions, deletespam => $ML{'.talkmulti.deletespam'} unless LJ::sysban_check( 'spamreport', $u->user );
+ $ret .= LJ::html_select( { name => 'mode', id => 'multiform_mode' }, @actions );
$ret .= " " . LJ::html_submit('', $ML{'.talkmulti.submit'},
{
"onclick" =>
diff -r 5e837b3c4787 -r 51ee4b0fec37 htdocs/tools/recent_comments.bml
--- a/htdocs/tools/recent_comments.bml Tue Jan 05 23:58:20 2010 +0000
+++ b/htdocs/tools/recent_comments.bml Wed Jan 06 00:20:55 2010 +0000
@@ -25,6 +25,8 @@ body<=
unless $u;
my $user = $u->{'user'};
+
+ $LJ_cmtinfo{canSpam} = LJ::sysban_check( 'spamreport', $user ) ? 0 : 1;
my $dbcr = LJ::get_cluster_reader($u);
return "Error: can't get DB for user" unless $dbcr;
--------------------------------------------------------------------------------
