Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
44 / 44 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
HtmlSplitConflictView | |
100.00% |
44 / 44 |
|
100.00% |
5 / 5 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getHtml | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
4 | |||
buildAddedLine | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
buildRemovedLine | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
buildCopiedLine | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace TwoColConflict\Html; |
4 | |
5 | use MediaWiki\Html\Html; |
6 | use MessageLocalizer; |
7 | |
8 | /** |
9 | * @license GPL-2.0-or-later |
10 | * @author Andrew Kostka <andrew.kostka@wikimedia.de> |
11 | */ |
12 | class HtmlSplitConflictView { |
13 | |
14 | private HtmlEditableTextComponent $editableTextComponent; |
15 | private MessageLocalizer $messageLocalizer; |
16 | |
17 | public function __construct( |
18 | HtmlEditableTextComponent $editableTextComponent, |
19 | MessageLocalizer $messageLocalizer |
20 | ) { |
21 | $this->editableTextComponent = $editableTextComponent; |
22 | $this->messageLocalizer = $messageLocalizer; |
23 | } |
24 | |
25 | /** |
26 | * @param array[] $unifiedDiff |
27 | * @param bool $markAllAsIncomplete |
28 | * |
29 | * @return string HTML |
30 | */ |
31 | public function getHtml( |
32 | array $unifiedDiff, |
33 | bool $markAllAsIncomplete |
34 | ): string { |
35 | $out = ''; |
36 | |
37 | foreach ( $unifiedDiff as $i => $changeSet ) { |
38 | if ( $changeSet['action'] === 'copy' ) { |
39 | // Copy block across both columns. |
40 | $line = $this->buildCopiedLine( $changeSet['copytext'], $i ); |
41 | $markAsIncomplete = false; |
42 | } else { |
43 | // Old and new split across two columns. |
44 | $line = $this->buildRemovedLine( |
45 | $changeSet['oldhtml'], |
46 | $changeSet['oldtext'], |
47 | $i |
48 | ) . |
49 | ( new HtmlSideSelectorComponent( $this->messageLocalizer ) ) |
50 | ->getRowHtml( $i ) . |
51 | $this->buildAddedLine( |
52 | $changeSet['newhtml'], |
53 | $changeSet['newtext'], |
54 | $i |
55 | ); |
56 | $markAsIncomplete = $markAllAsIncomplete; |
57 | } |
58 | |
59 | $out .= Html::rawElement( |
60 | 'div', |
61 | [ |
62 | 'class' => 'mw-twocolconflict-split-row' . |
63 | ( $markAsIncomplete ? ' mw-twocolconflict-no-selection' : '' ), |
64 | ], |
65 | $line |
66 | ); |
67 | } |
68 | |
69 | return Html::rawElement( 'div', [ 'class' => 'mw-twocolconflict-split-view' ], $out ); |
70 | } |
71 | |
72 | private function buildAddedLine( string $diffHtml, ?string $text, int $rowNum ): string { |
73 | return Html::rawElement( |
74 | 'div', |
75 | [ 'class' => 'mw-twocolconflict-split-add mw-twocolconflict-split-column' ], |
76 | $this->editableTextComponent->getHtml( $diffHtml, $text, $rowNum, 'your' ) |
77 | ); |
78 | } |
79 | |
80 | private function buildRemovedLine( string $diffHtml, ?string $rawText, int $rowNum ): string { |
81 | return Html::rawElement( |
82 | 'div', |
83 | [ 'class' => 'mw-twocolconflict-split-delete mw-twocolconflict-split-column' ], |
84 | $this->editableTextComponent->getHtml( $diffHtml, $rawText, $rowNum, 'other' ) |
85 | ); |
86 | } |
87 | |
88 | private function buildCopiedLine( string $text, int $rowNum ): string { |
89 | return Html::rawElement( |
90 | 'div', |
91 | [ 'class' => 'mw-twocolconflict-split-copy mw-twocolconflict-split-column' ], |
92 | $this->editableTextComponent->getHtml( htmlspecialchars( $text ), $text, $rowNum, 'copy' ) |
93 | ); |
94 | } |
95 | |
96 | } |