Skip to content

Commit

Permalink
Var formkey_minloggedinkarma and associated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiemccarthy committed Jun 9, 2005
1 parent aea2bc7 commit 832b767
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Slash/DB/MySQL/MySQL.pm
Expand Up @@ -4809,35 +4809,42 @@ sub updateFormkey {
sub checkPostInterval {
my($self, $formname) = @_;
$formname ||= getCurrentUser('currentPage');
my $user = getCurrentUser();
my $user = getCurrentUser();
my $constants = getCurrentStatic();
my $form = getCurrentForm();

my $counts_as_anon =
$user->{is_anon}
|| $user->{karma} < $constants->{formkey_minloggedinkarma}
|| $form->{postanon};

my $speedlimit_name = "${formname}_speed_limit";
my $speedlimit_anon_name = "${formname}_anon_speed_limit";
my $speedlimit = 0;
$speedlimit = $constants->{$speedlimit_anon_name} if $user->{is_anon} || getCurrentForm("postanon");
my $speedlimit = $counts_as_anon ? $constants->{$speedlimit_anon_name} : 0;
$speedlimit ||= $constants->{$speedlimit_name} || 0;

# If this user has access modifiers applied, check for possible
# different speed limits based on those. First match, if any,
# wins.
my $reader = getObject('Slash::DB', { db_type => 'reader' });
my $srcids = getCurrentUser('srcids');
my $al2_hr = $reader->getAL2($srcids) if $srcids;
my $srcids = $user->{srcids};
my $al2_hr = $srcids ? $reader->getAL2($srcids) : { };
my $al2_name_used = "_none_";
AL2_NAME: for my $al2_name (sort keys %$al2_hr) {
my $speedlimit_name_al2 = "${speedlimit_name}_$al2_name";
if (defined $constants->{$speedlimit_name_al2}) {
my $sl_name_al2 = $counts_as_anon
? "${speedlimit_anon_name}_$al2_name"
: "${speedlimit_name}_$al2_name";
if (defined $constants->{$sl_name_al2}) {
$al2_name_used = $al2_name;
$speedlimit = $constants->{$speedlimit_name_al2};
$speedlimit = $constants->{$sl_name_al2};
last AL2_NAME;
}
}

# Anonymous comment posting can be forced slower progressively.
if ($formname eq 'comments'
&& $counts_as_anon
&& $constants->{comments_anon_speed_limit_mult}
&& ($user->{is_anon} || getCurrentForm('postanon'))
) {
my $multiplier = $constants->{comments_anon_speed_limit_mult};
my $num_comm = $reader->getNumCommPostedAnonByIPID($user->{ipid});
Expand All @@ -4851,18 +4858,18 @@ sub checkPostInterval {
my $formkey_earliest = $time - $timeframe;

my $options = {};
$options->{force_ipid} = 1 if getCurrentForm("postanon");
$options->{force_ipid} = 1 if $form->{postanon};
my $where = $self->_whereFormkey($options);
$where .= " AND formname = '$formname' ";
$where .= "AND ts >= $formkey_earliest";
$where .= " AND formname = '$formname'";
$where .= " AND ts >= $formkey_earliest";

my($interval) = $self->sqlSelect(
"$time - MAX(submit_ts)",
"formkeys",
$where);

$interval ||= 0;
print STDERR "CHECK INTERVAL $interval speedlimit $speedlimit al2_used $al2_name_used f_e $formkey_earliest\n" if $constants->{DEBUG};
print STDERR "CHECK INTERVAL $interval speedlimit $speedlimit al2_used $al2_name_used f_e $formkey_earliest uid $user->{uid} c_a_n $counts_as_anon\n" if $constants->{DEBUG};

return ($interval < $speedlimit && $speedlimit > 0) ? $interval : 0;
}
Expand Down
1 change: 1 addition & 0 deletions sql/mysql/defaults.sql
Expand Up @@ -767,6 +767,7 @@ INSERT INTO vars (name, value, description) VALUES ('enable_index_topic','','set
INSERT INTO vars (name, value, description) VALUES ('fancyboxwidth','200','What size should the boxes be in?');
INSERT INTO vars (name, value, description) VALUES ('feature_story_enabled','0','Simple Boolean to determine if homepage prints feature story');
INSERT INTO vars (name, value, description) VALUES ('formkey_timeframe','14400','The time frame that we check for a formkey');
INSERT INTO vars (name, value, description) VALUES ('formkey_minloggedinkarma','1','The min karma a user must have to "count" as a logged-in user for some purposes');
INSERT INTO vars (name, value, description) VALUES ('freshenup_text_render_daysback','7','Oldest stories to write a story_text.rendered field for, in days');
INSERT INTO vars (name, value, description) VALUES ('freshenup_max_stories','100','Maximum number of article.shtml files to write at a time in freshenup.pl');
INSERT INTO vars (name, value, description) VALUES ('freshenup_small_cc','30','How many comments is considered a small commentcount, indicating a story needs its commentcount updated frequently?');
Expand Down
2 changes: 2 additions & 0 deletions sql/mysql/upgrades
Expand Up @@ -3058,3 +3058,5 @@ UPDATE vars SET description='HumanConf switch for posting comments: 0=off, 1=ano

# End of T_2_5_0_70, Start of T_2_5_0_71 - 2005/06/07

INSERT INTO vars (name, value, description) VALUES ('formkey_minloggedinkarma','1','The min karma a user must have to "count" as a logged-in user for some purposes');

0 comments on commit 832b767

Please sign in to comment.