Skip to content

Commit

Permalink
Merge pull request #429 from paulej72/Mod_Updates
Browse files Browse the repository at this point in the history
karma points are different from points
  • Loading branch information
paulej72 committed Mar 15, 2015
2 parents c042a38 + 4acc5ec commit 0c69605
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
4 changes: 2 additions & 2 deletions plugins/Admin/templates/modBomb;admin;default
Expand Up @@ -39,8 +39,8 @@ __template__
<th class="mb7">Moderatee</th>
<th class="mb8">IPID </th>
<th class="mb9">Moderator</th>
<th class="mb10">&nbsp;</th>
<th class="mb11">&nbsp;</th>
<th class="mb10">&nbsp;</th>
</tr>
[% FOREACH moderation = mods %]
<tr class="[% bg_toggle ? "data_hl1" : "data_hl2" %]">
Expand All @@ -57,8 +57,8 @@ __template__
<th class="mb7">[% PROCESS nick_and_uid nickname=moderation.nickname2 uid=moderation.uid2 %]</td>
<td class="mb8">[% PROCESS link_ipid ipid=moderation.ipid ipid_vis=moderation.ipid_vis %]</td>
<th class="mb9">[% PROCESS nick_and_uid nickname=moderation.nickname uid=moderation.uid %]</td>
<td class="mb10"><a href="[% gskin.rootdir %]/admin.pl?op=mod_bombs&amp;mb_del=1&amp;id=[% moderation.id %]&amp;uid=[% moderation.uid %]">Unmod and Ban</a></td>
<td class="mb11"><a href="[% gskin.rootdir %]/admin.pl?op=mod_bombs&amp;mb_del=1&amp;id=[% moderation.id %]&amp;uid=[% moderation.uid %]&amp;noban=1">Unmod Only</a></td>
<td class="mb10"><a href="[% gskin.rootdir %]/admin.pl?op=mod_bombs&amp;mb_del=1&amp;id=[% moderation.id %]&amp;uid=[% moderation.uid %]">Unmod and Ban</a></td>
</td>
</tr>
[% END %]
Expand Down
26 changes: 19 additions & 7 deletions plugins/Moderation/Moderation.pm
Expand Up @@ -1020,19 +1020,24 @@ sub undoModeration {
$self->removeModTags($uid, $cid);

# Restore modded user's karma, again within the proper boundaries.
my $adjust = -$val;
my $adjust = -$self->sqlSelect('karma', 'modreasons', " id = $reason ");
$adjust =~ s/^([^+-])/+$1/;
$self->sqlUpdate(
my $rows = $self->sqlUpdate(
"users_info",
{ -karma => $adjust > 0
? "LEAST($max_karma, karma $adjust)"
: "GREATEST($min_karma, karma $adjust)" },
"uid=$cuid"
) unless isAnon($cuid);


print STDERR "\nWTF karma adjust fail\n" unless $rows || isAnon($cuid);


# Adjust the comment score up or down, but don't push it
# beyond the maximum or minimum. Also recalculate its reason.
# Its pointsmax logically can't change.
$adjust = -$val;
$adjust =~ s/^([^+-])/+$1/;
my $points = $adjust > 0
? "LEAST($max_score, points $adjust)"
: "GREATEST($min_score, points $adjust)";
Expand All @@ -1042,7 +1047,7 @@ sub undoModeration {
-points => $points,
reason => $new_reason,
};
$self->sqlUpdate("comments", $comm_update, "cid=$cid");
$rows = $self->sqlUpdate("comments", $comm_update, "cid=$cid");

push @removed, {
cid => $cid,
Expand Down Expand Up @@ -1488,19 +1493,24 @@ sub undoSingleModeration {
$self->sqlUpdate("moderatorlog", { active => 0 }, "id = $mod->{id}");

# Restore modded user's karma, again within the proper boundaries.
my $adjust = -$mod->{val};
my $adjust = -$self->sqlSelect('karma', 'modreasons', " id = $mod->{reason} ");
$adjust =~ s/^([^+-])/+$1/;
$self->sqlUpdate(
my $rows = $self->sqlUpdate(
"users_info",
{ -karma => $adjust > 0
? "LEAST($max_karma, karma $adjust)"
: "GREATEST($min_karma, karma $adjust)" },
"uid=$mod->{cuid}"
) unless isAnon($mod->{cuid});

print STDERR "\nWTF karma adjust fail\n" unless $rows || isAnon($mod->{cuid});


# Adjust the comment score up or down, but don't push it
# beyond the maximum or minimum. Also recalculate its reason.
# Its pointsmax logically can't change.
$adjust = -$mod->{val};
$adjust =~ s/^([^+-])/+$1/;
my $points = $adjust > 0
? "LEAST($max_score, points $adjust)"
: "GREATEST($min_score, points $adjust)";
Expand All @@ -1510,7 +1520,9 @@ sub undoSingleModeration {
-points => $points,
reason => $new_reason,
};
$self->sqlUpdate("comments", $comm_update, "cid=$mod->{cid}");
$rows = $self->sqlUpdate("comments", $comm_update, "cid=$mod->{cid}");

print STDERR "\nWTF comment adjust fail\n" unless $rows;

return 1;

Expand Down
26 changes: 13 additions & 13 deletions plugins/Moderation/mysql_dump.sql
Expand Up @@ -18,18 +18,18 @@ INSERT IGNORE INTO vars (name, value, description) VALUES ('m1_pointgrant_factor
INSERT IGNORE INTO vars (name, value, description) VALUES ('m1_pointgrant_factor_stirratio', '1.3', 'Factor of stirred-points ratio in deciding who is eligible for moderation (1=irrelevant, 2=top user twice as likely)');
INSERT IGNORE INTO vars (name, value, description) VALUES ('moderator_or_post', '1', 'Can users moderate and post in the same discussion (1=yes, 0=no)');

INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 0, 'Normal', 0, 0, 0, 0, 0.5, 0, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 1, 'Offtopic', 1, 1, -1, -1, 0.5, 10, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 2, 'Flamebait', 1, 1, -1, -1, 0.5, 12, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 3, 'Troll', 1, 1, -1, -1, 0.5, 13, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 4, 'Redundant', 1, 1, -1, -1, 0.5, 11, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 5, 'Insightful', 1, 1, 1, 1, 0.5, 2, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 6, 'Interesting', 1, 1, 1, 1, 0.5, 3, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 7, 'Informative', 1, 1, 1, 1, 0.5, 4, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 8, 'Funny', 1, 1, 1, 1, 0.5, 5, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 9, 'Overrated', 0, 0, -1, 0, 0.5, 8, 1);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES (10, 'Underrated', 0, 0, 1, 0, 0.5, 7), 1;
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 0, 'Normal', 0, 0, 0, 0, 0.5, 0, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 1, 'Offtopic', 1, 1, -1, -1, 0.5, 10, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 2, 'Flamebait', 1, 1, -1, -1, 0.5, 12, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 3, 'Troll', 1, 1, -1, -1, 0.5, 13, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 4, 'Redundant', 1, 1, -1, -1, 0.5, 11, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 5, 'Insightful', 1, 1, 1, 1, 0.5, 2, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 6, 'Interesting', 1, 1, 1, 1, 0.5, 3, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 7, 'Informative', 1, 1, 1, 1, 0.5, 4, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 8, 'Funny', 1, 1, 1, 1, 0.5, 5, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES ( 9, 'Overrated', 0, 0, -1, 0, 0.5, 8, 1);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES (10, 'Underrated', 0, 0, 1, 0, 0.5, 7, 1);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES (11, 'Spam', 0, 1, -1, -10, 0.5, 101, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES (12, 'Disagree', 0, 1, 0, 0, 0.5, 9, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES (13, 'Touché', 0, 1, 1, 1, 0.5, 6, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES (12, 'Disagree', 0, 1, 0, 0, 0.5, 9, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES (13, 'Touché', 0, 1, 1, 1, 0.5, 6, 0);
INSERT IGNORE INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered, needs_prior_mod) VALUES (100, '-----------', 0, 1, 1, 1, 0.5, 100, 0);
7 changes: 2 additions & 5 deletions sql/mysql/upgrades
Expand Up @@ -520,7 +520,7 @@ UPDATE vars SET value = '//www.paypalobjects.com/en_US/i/btn/x-click-but01.gif'

# Moderation Updates
ALTER TABLE modreasons ADD COLUMN ordered tinyint UNSIGNED DEFAULT '50' NOT NULL;
INSERT INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered) VALUES ( 9, 'Overrated', 0, 0, -0, 0, 0.5, 8);
INSERT INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered) VALUES ( 9, 'Overrated', 0, 0, -1, 0, 0.5, 8);
INSERT INTO modreasons (id, name, m2able, listable, val, karma, fairfrac, ordered) VALUES ( 100, '-----------', 0, 0, 0, 0, 0.5, 100);
UPDATE modreasons SET name = 'Touch�' WHERE id = 13;
UPDATE modreasons SET ordered = 0 WHERE id = 0;
Expand All @@ -529,7 +529,7 @@ UPDATE modreasons SET ordered = 3 WHERE id = 6;
UPDATE modreasons SET ordered = 4 WHERE id = 7;
UPDATE modreasons SET ordered = 5 WHERE id = 8;
UPDATE modreasons SET ordered = 6 WHERE id = 13;
UPDATE modreasons SET ordered = 7 WHERE id = 10;
UPDATE modreasons SET ordered = 7, karma = 0 WHERE id = 10;
UPDATE modreasons SET ordered = 9 WHERE id = 12;
UPDATE modreasons SET ordered = 10 WHERE id = 1;
UPDATE modreasons SET ordered = 11 WHERE id = 4;
Expand All @@ -544,9 +544,6 @@ INSERT INTO vars (name, value, description) VALUES ('allow_other_users_comments'
INSERT INTO vars (name, value, description) VALUES ('mod_mb_floor', '3', 'Min amount of downmods needed to trigger mod bomb list');
INSERT INTO vars (name, value, description) VALUES ('mod_mb_time_span', '72', 'Lenght of search span for mod bomb search in hours.');

# Quick fix for Overrated/Underrated
UPDATE modreasons SET karma = 0 WHERE id = 10;
UPDATE modreasons SET val = 1 WHERE id = 9;

# Add a karma floor for downmods
INSERT INTO vars (name, value, description) VALUES ("downmod_karma_floor", "10", "Below this level of karma, users cannot use negative moderations");
Expand Down

0 comments on commit 0c69605

Please sign in to comment.