Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ parameters:
path: pinc/DifferenceEngineWrapper.inc
- message: '#Call to function is_array\(\) with array<string> will always evaluate to true.#'
path: pinc/3rdparty/mediawiki/WordLevelDiff.php
- message: '#Function get_dpl_enforcement_for_user\(\) never returns null.*#'
path: pinc/daily_page_limit.inc

- message: '#invoked with \d+ parameter(s?), \d+((-\d+)?) required#'
- message: '#Variable .* might not be defined#'
Expand Down
6 changes: 4 additions & 2 deletions pinc/LPage.inc
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ class LPage
public function attemptSaveAsDone(string $text_data, string $pguser): array
{
if ($this->round->has_a_daily_page_limit()) {
$pre_save_dpl_count = get_dpl_count_for_user_in_round($pguser, $this->round);
if ($pre_save_dpl_count >= $this->round->daily_page_limit) {
$pre_save_dpl_count = get_dpl_enforcement_for_user($pguser, $this->round, $this->project);
if ($pre_save_dpl_count !== null && $pre_save_dpl_count >= $this->round->daily_page_limit) {
// The user has already reached their limit of this kind of page.
return [false, true];
}
Expand All @@ -415,6 +415,8 @@ class LPage
$dpl_has_now_been_reached = (
$this->round->has_a_daily_page_limit()
&&
$pre_save_dpl_count !== null
&&
($pre_save_dpl_count + 1 >= $this->round->daily_page_limit)
);
return [true, $dpl_has_now_been_reached];
Expand Down
18 changes: 17 additions & 1 deletion pinc/daily_page_limit.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,27 @@ include_once($relPath.'TallyBoard.inc');
* page-tally for that round since the last snapshot.
* (i.e., the net number of save-as-dones in that round today.)
*/
function get_dpl_count_for_user_in_round($username, $round)
function get_dpl_count_for_user_in_round(string $username, Round $round): int
{
$user = new User($username);

$round_tallyboard = new TallyBoard($round->id, 'U');

return $round_tallyboard->get_delta_since_latest_snapshot($user->u_id);
}

/**
* Get the current daily page limit enforcement value
*
* If the DPL is enforced for this user, it returns the number of pages
* the user has done in the specified round. If the DPL is not enforced
* for this user/round/project for some reason, return Null.
*/
function get_dpl_enforcement_for_user(string $username, Round $round, Project $project): ?int
{
// This function is a placeholder for sites to add any per-project
// customizations that might bypass the DPL enforcement. So while it
// doesn't currently return null, it might after site-specific updates.

return get_dpl_count_for_user_in_round($username, $round);
}
9 changes: 6 additions & 3 deletions project.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
include_once($relPath.'project_edit.inc'); // check_user_can_load_projects
include_once($relPath.'forum_interface.inc'); // get_last_post_time_in_topic & get_url_*()
include_once($relPath.'faq.inc');
include_once($relPath.'daily_page_limit.inc'); // get_dpl_count_for_user_in_round
include_once($relPath.'daily_page_limit.inc'); // get_dpl_enforcement_for_user
include_once($relPath.'special_colors.inc'); // load_special_days

// This page originally allowed unauthenticated users and showed them a limited
Expand Down Expand Up @@ -264,8 +264,11 @@ function decide_blurbs(): array
//
$page_limit_warning = "";
if ($round->has_a_daily_page_limit()) {
$user_dpl_count = get_dpl_count_for_user_in_round($pguser, $round);
if ($user_dpl_count >= $round->daily_page_limit) {
$user_dpl_count = get_dpl_enforcement_for_user($pguser, $round, $project);
if ($user_dpl_count === null) {
$msg = _('This project is currently exempt from the daily page limit.');
$page_limit_warning = "<br>\n<span class='warning'>$msg</span>\n";
} elseif ($user_dpl_count >= $round->daily_page_limit) {
// User has reached this round's DPL.
$msg = sprintf(
_('%1$s limits you to %2$d page-saves per day, and you have already reached that limit today.'),
Expand Down