Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
PageDeleteLogger | |
0.00% |
0 / 26 |
|
0.00% |
0 / 7 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
logBundleSuccess | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
logPageSuccess | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
logBundleError | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
logPageError | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
publishError | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getManualLogEntry | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\MessageGroupProcessing; |
5 | |
6 | use ManualLogEntry; |
7 | use MediaWiki\Title\Title; |
8 | use Status; |
9 | use User; |
10 | |
11 | /** |
12 | * Helper class for logging translatable bundle and translation page deletions |
13 | * @author Abijeet Patro |
14 | * @author Niklas Laxström |
15 | * @since 2022.05 |
16 | * @license GPL-2.0-or-later |
17 | */ |
18 | class PageDeleteLogger { |
19 | /** @var string */ |
20 | private $logType; |
21 | /** @var Title */ |
22 | private $baseSourceTitle; |
23 | |
24 | public function __construct( Title $baseSourceTitle, string $logType ) { |
25 | $this->baseSourceTitle = $baseSourceTitle; |
26 | $this->logType = $logType; |
27 | } |
28 | |
29 | public function logBundleSuccess( User $performer, string $reason ): void { |
30 | $entry = $this->getManualLogEntry( $this->logType, 'deletefok', $performer, $reason ); |
31 | $logid = $entry->insert(); |
32 | $entry->publish( $logid ); |
33 | } |
34 | |
35 | public function logPageSuccess( User $performer, string $reason ): void { |
36 | $entry = $this->getManualLogEntry( $this->logType, 'deletelok', $performer, $reason ); |
37 | $logid = $entry->insert(); |
38 | $entry->publish( $logid ); |
39 | } |
40 | |
41 | public function logBundleError( User $performer, string $reason, Status $error ): void { |
42 | $entry = $this->getManualLogEntry( $this->logType, 'deletefnok', $performer, $reason ); |
43 | $this->publishError( $entry, $error ); |
44 | } |
45 | |
46 | public function logPageError( User $performer, string $reason, Status $error ): void { |
47 | $entry = $this->getManualLogEntry( $this->logType, 'deletelnok', $performer, $reason ); |
48 | $this->publishError( $entry, $error ); |
49 | } |
50 | |
51 | private function publishError( ManualLogEntry $entry, Status $error ): void { |
52 | $entry->setParameters( [ |
53 | 'target' => $this->baseSourceTitle->getPrefixedText(), |
54 | 'error' => $error->getErrorsArray(), |
55 | ] ); |
56 | $logid = $entry->insert(); |
57 | $entry->publish( $logid ); |
58 | } |
59 | |
60 | private function getManualLogEntry( |
61 | string $logType, |
62 | string $logKey, |
63 | User $performer, |
64 | string $reason |
65 | ): ManualLogEntry { |
66 | $entry = new ManualLogEntry( $logType, $logKey ); |
67 | $entry->setPerformer( $performer ); |
68 | $entry->setTarget( $this->baseSourceTitle ); |
69 | $entry->setParameters( [ |
70 | 'target' => $this->baseSourceTitle->getPrefixedText(), |
71 | ] ); |
72 | $entry->setComment( $reason ); |
73 | |
74 | return $entry; |
75 | } |
76 | } |