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