Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
4 / 5
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ContentLengthFilter
80.00% covered (warning)
80.00%
4 / 5
66.67% covered (warning)
66.67%
2 / 3
4.13
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 enabled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validate
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Flow\SpamFilter;
4
5use Flow\Model\AbstractRevision;
6use MediaWiki\Context\IContextSource;
7use MediaWiki\Status\Status;
8use MediaWiki\Title\Title;
9
10class ContentLengthFilter implements SpamFilter {
11
12    /**
13     * @var int The maximum number of characters of wikitext to allow through filter
14     */
15    protected $maxLength;
16
17    public function __construct( $maxLength ) {
18        $this->maxLength = $maxLength;
19    }
20
21    public function enabled() {
22        return true;
23    }
24
25    /**
26     * @param IContextSource $context
27     * @param AbstractRevision $newRevision
28     * @param AbstractRevision|null $oldRevision
29     * @param Title $title
30     * @param Title $ownerTitle
31     * @return Status
32     */
33    public function validate(
34        IContextSource $context,
35        AbstractRevision $newRevision,
36        ?AbstractRevision $oldRevision,
37        Title $title,
38        Title $ownerTitle
39    ) {
40        return $newRevision->getContentLength() > $this->maxLength
41            ? Status::newFatal( 'flow-error-content-too-long', $this->maxLength )
42            : Status::newGood();
43    }
44}