@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3abstract class PhabricatorSystemAction extends Phobject {
4
5 final public function getActionConstant() {
6 return $this->getPhobjectClassConstant('TYPECONST', 32);
7 }
8
9 abstract public function getScoreThreshold();
10
11 public function shouldBlockActor($actor, $score) {
12 return ($score > $this->getScoreThreshold());
13 }
14
15 public function getLimitExplanation() {
16 return pht('You are performing too many actions too quickly.');
17 }
18
19 public function getRateExplanation($score) {
20 return pht(
21 'The maximum allowed rate for this action is %s. You are taking '.
22 'actions at a rate of %s.',
23 $this->formatRate($this->getScoreThreshold()),
24 $this->formatRate($score));
25 }
26
27 protected function formatRate($rate) {
28 if ($rate > 10) {
29 $str = pht('%d / second', $rate);
30 } else {
31 $rate *= 60;
32 if ($rate > 10) {
33 $str = pht('%d / minute', $rate);
34 } else {
35 $rate *= 60;
36 $str = pht('%d / hour', $rate);
37 }
38 }
39
40 return phutil_tag('strong', array(), $str);
41 }
42
43}