Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
CodeView | |
0.00% |
0 / 37 |
|
0.00% |
0 / 8 |
240 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
validPost | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
execute | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
authorLink | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
statusDesc | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
formatMessage | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
messageFragment | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
formatMetaData | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getRepo | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CodeReview\UI; |
4 | |
5 | use MediaWiki\Extension\CodeReview\Backend\CodeCommentLinkerHtml; |
6 | use MediaWiki\Extension\CodeReview\Backend\CodeCommentLinkerWiki; |
7 | use MediaWiki\Extension\CodeReview\Backend\CodeRepository; |
8 | use MediaWiki\MediaWikiServices; |
9 | use MediaWiki\Permissions\Authority; |
10 | use RequestContext; |
11 | use SpecialPage; |
12 | |
13 | /** |
14 | * Extended by CodeRevisionListView and CodeRevisionView |
15 | */ |
16 | abstract class CodeView { |
17 | /** |
18 | * @var CodeRepository |
19 | */ |
20 | public $mRepo; |
21 | |
22 | /** |
23 | * @var CodeCommentLinkerHtml |
24 | */ |
25 | public $codeCommentLinkerHtml; |
26 | |
27 | /** |
28 | * @var CodeCommentLinkerWiki |
29 | */ |
30 | public $codeCommentLinkerWiki; |
31 | |
32 | /** |
33 | * @var string |
34 | */ |
35 | public $mPath; |
36 | |
37 | /** |
38 | * @var string |
39 | */ |
40 | public $mAuthor; |
41 | |
42 | /** |
43 | * @var string |
44 | */ |
45 | public $mStatus; |
46 | |
47 | public function __construct( $repo ) { |
48 | $this->mRepo = ( $repo instanceof CodeRepository ) |
49 | ? $repo |
50 | : CodeRepository::newFromName( $repo ); |
51 | |
52 | $this->codeCommentLinkerHtml = new CodeCommentLinkerHtml( $this->mRepo ); |
53 | $this->codeCommentLinkerWiki = new CodeCommentLinkerWiki( $this->mRepo ); |
54 | } |
55 | |
56 | public function validPost( $permission, Authority $performer ) { |
57 | $context = RequestContext::getMain(); |
58 | $request = $context->getRequest(); |
59 | $userToken = $context->getCsrfTokenSet(); |
60 | return $request->wasPosted() |
61 | && $userToken->matchToken( $request->getVal( 'wpEditToken' ) ) |
62 | && $performer->isAllowed( $permission ); |
63 | } |
64 | |
65 | abstract public function execute(); |
66 | |
67 | public function authorLink( $author, $extraParams = [] ) { |
68 | $repo = $this->mRepo->getName(); |
69 | $special = SpecialPage::getTitleFor( 'Code', "$repo/author/$author" ); |
70 | $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); |
71 | return $linkRenderer->makeLink( $special, $author, [], $extraParams ); |
72 | } |
73 | |
74 | public function statusDesc( $status ) { |
75 | return wfMessage( "code-status-$status" )->text(); |
76 | } |
77 | |
78 | public function formatMessage( $text ) { |
79 | $escText = nl2br( htmlspecialchars( $text ) ); |
80 | return $this->codeCommentLinkerHtml->link( $escText ); |
81 | } |
82 | |
83 | public function messageFragment( $value ) { |
84 | global $wgLang; |
85 | $message = trim( $value ); |
86 | $lines = explode( "\n", $message, 2 ); |
87 | $first = $lines[0]; |
88 | |
89 | $html = $this->formatMessage( $first ); |
90 | $truncated = $wgLang->truncateHtml( $html, 80 ); |
91 | |
92 | if ( count( $lines ) > 1 ) { |
93 | // If multiline, we might want to add an ellipse |
94 | $ellipsis = wfMessage( 'ellipsis' )->text(); |
95 | // Hack: don't add if the end is already an ellipse |
96 | if ( substr( $truncated, -strlen( $ellipsis ) ) !== $ellipsis ) { |
97 | $truncated .= $ellipsis; |
98 | } |
99 | } |
100 | |
101 | return $truncated; |
102 | } |
103 | |
104 | /** |
105 | * Formatted HTML array for properties display |
106 | * @param array $fields 'propname' => HTML data |
107 | * @return string |
108 | */ |
109 | public function formatMetaData( $fields ) { |
110 | $html = '<table class="mw-codereview-meta">'; |
111 | foreach ( $fields as $label => $data ) { |
112 | $html .= "<tr><td>" . wfMessage( $label )->escaped() . "</td><td>$data</td></tr>\n"; |
113 | } |
114 | return $html . "</table>\n"; |
115 | } |
116 | |
117 | /** |
118 | * @return bool|CodeRepository |
119 | */ |
120 | public function getRepo() { |
121 | if ( $this->mRepo ) { |
122 | return $this->mRepo; |
123 | } |
124 | return false; |
125 | } |
126 | } |