Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ContributionsFormatter | |
0.00% |
0 / 51 |
|
0.00% |
0 / 3 |
132 | |
0.00% |
0 / 1 |
getHistoryType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
format | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
30 | |||
getHideUnhide | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | namespace Flow\Formatter; |
4 | |
5 | use ChangesList; |
6 | use Flow\Conversion\Utils; |
7 | use Flow\Exception\FlowException; |
8 | use Flow\Model\Anchor; |
9 | use Flow\Model\PostRevision; |
10 | use MediaWiki\Context\IContextSource; |
11 | use MediaWiki\Html\Html; |
12 | |
13 | class ContributionsFormatter extends AbstractFormatter { |
14 | protected function getHistoryType() { |
15 | return 'contributions'; |
16 | } |
17 | |
18 | /** |
19 | * @param FormatterRow $row With properties workflow, revision, previous_revision |
20 | * @param IContextSource $ctx |
21 | * @return string|false HTML for contributions entry, or false on failure |
22 | * @throws FlowException |
23 | */ |
24 | public function format( FormatterRow $row, IContextSource $ctx ) { |
25 | $this->serializer->setIncludeHistoryProperties( true ); |
26 | $data = $this->serializer->formatApi( $row, $ctx, 'contributions' ); |
27 | if ( !$data ) { |
28 | return false; |
29 | } |
30 | |
31 | $isNewPage = isset( $data['isNewPage'] ) && $data['isNewPage']; |
32 | |
33 | $charDiff = ChangesList::showCharacterDifference( |
34 | $data['size']['old'], |
35 | $data['size']['new'], |
36 | $ctx |
37 | ); |
38 | |
39 | $separator = $this->changeSeparator(); |
40 | |
41 | $links = []; |
42 | $links[] = $this->getDiffAnchor( $data['links'], $ctx ); |
43 | $links[] = $this->getHistAnchor( $data['links'], $ctx ); |
44 | |
45 | $description = $this->formatDescription( $data, $ctx ); |
46 | |
47 | $flags = ''; |
48 | if ( $isNewPage ) { |
49 | $flags .= ChangesList::flag( 'newpage' ) . ' '; |
50 | } |
51 | |
52 | // Put it all together |
53 | return $this->formatTimestamp( $data ) . ' ' . |
54 | $this->formatAnchorsAsPipeList( $links, $ctx ) . |
55 | $separator . |
56 | $charDiff . |
57 | $separator . |
58 | $flags . |
59 | $this->getTitleLink( $data, $row, $ctx ) . |
60 | ( Utils::htmlToPlaintext( $description ) ? $separator . $description : '' ) . |
61 | $this->getHideUnhide( $data, $row, $ctx ); |
62 | } |
63 | |
64 | /** |
65 | * @todo can be generic? |
66 | * @param array $data |
67 | * @param FormatterRow $row |
68 | * @param IContextSource $ctx |
69 | * @return string |
70 | */ |
71 | protected function getHideUnhide( array $data, FormatterRow $row, IContextSource $ctx ) { |
72 | if ( !$row->revision instanceof PostRevision ) { |
73 | return ''; |
74 | } |
75 | |
76 | // @phan-suppress-next-line PhanUndeclaredMethod Phan doesn't infer $row->revision is PostRevision |
77 | $type = $row->revision->isTopicTitle() ? 'topic' : 'post'; |
78 | |
79 | if ( isset( $data['actions']['hide'] ) ) { |
80 | $key = 'hide'; |
81 | // flow-post-action-hide-post, flow-post-action-hide-topic |
82 | $msg = "flow-$type-action-hide-$type"; |
83 | } elseif ( isset( $data['actions']['unhide'] ) ) { |
84 | $key = 'unhide'; |
85 | // flow-topic-action-restore-topic, flow-post-action-restore-post |
86 | $msg = "flow-$type-action-restore-$type"; |
87 | } else { |
88 | return ''; |
89 | } |
90 | |
91 | /** @var Anchor $anchor */ |
92 | $anchor = $data['actions'][$key]; |
93 | $message = ' ' . $ctx->msg( 'parentheses' )->rawParams( Html::rawElement( |
94 | 'a', |
95 | [ |
96 | 'href' => $anchor->getFullURL(), |
97 | 'data-flow-interactive-handler' => 'moderationDialog', |
98 | 'data-flow-template' => "flow_moderate_$type.partial", |
99 | 'data-role' => $key, |
100 | 'class' => 'flow-history-moderation-action flow-click-interactive', |
101 | ], |
102 | $ctx->msg( $msg )->escaped() |
103 | ) )->escaped(); |
104 | |
105 | return $message; |
106 | } |
107 | } |