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\Status\Status; |
8 | use MediaWiki\Title\Title; |
9 | use MediaWiki\User\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 | private string $logType; |
20 | private Title $baseSourceTitle; |
21 | |
22 | public function __construct( Title $baseSourceTitle, string $logType ) { |
23 | $this->baseSourceTitle = $baseSourceTitle; |
24 | $this->logType = $logType; |
25 | } |
26 | |
27 | public function logBundleSuccess( User $performer, string $reason ): void { |
28 | $entry = $this->getManualLogEntry( $this->logType, 'deletefok', $performer, $reason ); |
29 | $logid = $entry->insert(); |
30 | $entry->publish( $logid ); |
31 | } |
32 | |
33 | public function logPageSuccess( User $performer, string $reason ): void { |
34 | $entry = $this->getManualLogEntry( $this->logType, 'deletelok', $performer, $reason ); |
35 | $logid = $entry->insert(); |
36 | $entry->publish( $logid ); |
37 | } |
38 | |
39 | public function logBundleError( User $performer, string $reason, Status $error ): void { |
40 | $entry = $this->getManualLogEntry( $this->logType, 'deletefnok', $performer, $reason ); |
41 | $this->publishError( $entry, $error ); |
42 | } |
43 | |
44 | public function logPageError( User $performer, string $reason, Status $error ): void { |
45 | $entry = $this->getManualLogEntry( $this->logType, 'deletelnok', $performer, $reason ); |
46 | $this->publishError( $entry, $error ); |
47 | } |
48 | |
49 | private function publishError( ManualLogEntry $entry, Status $error ): void { |
50 | $entry->setParameters( [ |
51 | 'target' => $this->baseSourceTitle->getPrefixedText(), |
52 | 'error' => $error->getErrorsArray(), |
53 | ] ); |
54 | $logid = $entry->insert(); |
55 | $entry->publish( $logid ); |
56 | } |
57 | |
58 | private function getManualLogEntry( |
59 | string $logType, |
60 | string $logKey, |
61 | User $performer, |
62 | string $reason |
63 | ): ManualLogEntry { |
64 | $entry = new ManualLogEntry( $logType, $logKey ); |
65 | $entry->setPerformer( $performer ); |
66 | $entry->setTarget( $this->baseSourceTitle ); |
67 | $entry->setParameters( [ |
68 | 'target' => $this->baseSourceTitle->getPrefixedText(), |
69 | ] ); |
70 | $entry->setComment( $reason ); |
71 | |
72 | return $entry; |
73 | } |
74 | } |