Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
82.05% |
32 / 39 |
|
20.00% |
1 / 5 |
CRAP | |
0.00% |
0 / 1 |
MassMessageListSlotDiffRenderer | |
82.05% |
32 / 39 |
|
20.00% |
1 / 5 |
9.47 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getDiff | |
88.24% |
30 / 34 |
|
0.00% |
0 / 1 |
5.04 | |||
getExtraCacheKeys | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addModules | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTablePrefix | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\MassMessage\Content; |
4 | |
5 | use MediaWiki\Content\Content; |
6 | use MediaWiki\Context\IContextSource; |
7 | use MediaWiki\Html\Html; |
8 | use MediaWiki\Output\OutputPage; |
9 | use MediaWiki\Title\Title; |
10 | use MessageLocalizer; |
11 | use TextSlotDiffRenderer; |
12 | |
13 | class MassMessageListSlotDiffRenderer extends \SlotDiffRenderer { |
14 | /** @var TextSlotDiffRenderer */ |
15 | private $textSlotDiffRenderer; |
16 | |
17 | /** @var MessageLocalizer */ |
18 | private $localizer; |
19 | |
20 | /** |
21 | * @param TextSlotDiffRenderer $textSlotDiffRenderer |
22 | * @param MessageLocalizer $localizer |
23 | */ |
24 | public function __construct( |
25 | TextSlotDiffRenderer $textSlotDiffRenderer, |
26 | MessageLocalizer $localizer |
27 | ) { |
28 | $this->textSlotDiffRenderer = $textSlotDiffRenderer; |
29 | $this->localizer = $localizer; |
30 | } |
31 | |
32 | /** |
33 | * @param Content|null $oldContent |
34 | * @param Content|null $newContent |
35 | * @return false|string |
36 | */ |
37 | public function getDiff( ?Content $oldContent = null, ?Content $newContent = null ) { |
38 | $this->normalizeContents( $oldContent, $newContent, [ MassMessageListContent::class ] ); |
39 | '@phan-var MassMessageListContent $oldContent'; /** @var MassMessageListContent $oldContent */ |
40 | '@phan-var MassMessageListContent $newContent'; /** @var MassMessageListContent $newContent */ |
41 | |
42 | if ( !$oldContent->isValid() || !$newContent->isValid() ) { |
43 | return $this->textSlotDiffRenderer->getTextDiff( |
44 | $oldContent->getText(), |
45 | $newContent->getText() |
46 | ); |
47 | } |
48 | |
49 | $output = ''; |
50 | |
51 | $descDiff = $this->textSlotDiffRenderer->getTextDiff( |
52 | $oldContent->getDescription(), |
53 | $newContent->getDescription() |
54 | ); |
55 | if ( trim( $descDiff ) !== '' ) { |
56 | $output .= Html::openElement( 'tr' ); |
57 | $output .= Html::openElement( 'td', |
58 | [ 'colspan' => 4, 'id' => 'mw-massmessage-diffdescheader' ] ); |
59 | $output .= Html::element( 'h4', [], |
60 | $this->localizer->msg( 'massmessage-diff-descheader' )->text() ); |
61 | $output .= Html::closeElement( 'td' ); |
62 | $output .= Html::closeElement( 'tr' ); |
63 | $output .= $descDiff; |
64 | } |
65 | |
66 | $targetsDiff = $this->textSlotDiffRenderer->getTextDiff( |
67 | implode( "\n", $oldContent->getTargetStrings() ), |
68 | implode( "\n", $newContent->getTargetStrings() ) |
69 | ); |
70 | if ( trim( $targetsDiff ) !== '' ) { |
71 | $output .= Html::openElement( 'tr' ); |
72 | $output .= Html::openElement( 'td', |
73 | [ 'colspan' => 4, 'id' => 'mw-massmessage-difftargetsheader' ] ); |
74 | $output .= Html::element( 'h4', [], |
75 | $this->localizer->msg( 'massmessage-diff-targetsheader' )->text() ); |
76 | $output .= Html::closeElement( 'td' ); |
77 | $output .= Html::closeElement( 'tr' ); |
78 | $output .= $targetsDiff; |
79 | } |
80 | return $output; |
81 | } |
82 | |
83 | /** |
84 | * @return string[] |
85 | */ |
86 | public function getExtraCacheKeys() { |
87 | return $this->textSlotDiffRenderer->getExtraCacheKeys(); |
88 | } |
89 | |
90 | /** |
91 | * @param OutputPage $output |
92 | */ |
93 | public function addModules( OutputPage $output ) { |
94 | $this->textSlotDiffRenderer->addModules( $output ); |
95 | } |
96 | |
97 | /** |
98 | * @param IContextSource $context |
99 | * @param Title $newTitle |
100 | * @return (string|null)[] |
101 | */ |
102 | public function getTablePrefix( IContextSource $context, Title $newTitle ): array { |
103 | return $this->textSlotDiffRenderer->getTablePrefix( $context, $newTitle ); |
104 | } |
105 | } |