Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
FileTextRevisionValidator | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
validate | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace FileImporter\Services; |
4 | |
5 | use Content; |
6 | use FileImporter\HookRunner; |
7 | use MediaWiki\Context\DerivativeContext; |
8 | use MediaWiki\Context\RequestContext; |
9 | use MediaWiki\MediaWikiServices; |
10 | use MediaWiki\Request\FauxRequest; |
11 | use MediaWiki\Status\Status; |
12 | use MediaWiki\Title\Title; |
13 | use MediaWiki\User\User; |
14 | use StatusValue; |
15 | |
16 | /** |
17 | * Class that can be used to validate the content of a text revision |
18 | * |
19 | * @license GPL-2.0-or-later |
20 | * @author Christoph Jauera <christoph.jauera@wikimedia.de> |
21 | */ |
22 | class FileTextRevisionValidator { |
23 | |
24 | /** @var DerivativeContext */ |
25 | private $context; |
26 | |
27 | public function __construct() { |
28 | $this->context = new DerivativeContext( RequestContext::getMain() ); |
29 | $this->context->setRequest( new FauxRequest() ); |
30 | } |
31 | |
32 | /** |
33 | * @param Title $title |
34 | * @param User $user |
35 | * @param Content $content |
36 | * @param string $summary |
37 | * @param bool $minor |
38 | * |
39 | * @return StatusValue isOK when validation succeeds |
40 | */ |
41 | public function validate( |
42 | Title $title, |
43 | User $user, |
44 | Content $content, |
45 | string $summary, |
46 | $minor |
47 | ): StatusValue { |
48 | if ( !$title->inNamespace( NS_FILE ) ) { |
49 | return StatusValue::newFatal( 'fileimporter-badnamespace' ); |
50 | } |
51 | |
52 | $status = Status::newGood(); |
53 | $this->context->setUser( $user ); |
54 | $this->context->setTitle( $title ); |
55 | |
56 | ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onEditFilterMergedContent( |
57 | $this->context, |
58 | $content, |
59 | $status, |
60 | $summary, |
61 | $user, |
62 | $minor |
63 | ); |
64 | |
65 | return $status; |
66 | } |
67 | |
68 | } |