Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
LogFormatter | |
0.00% |
0 / 36 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
getMessageParameters | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
30 | |||
formatStateMessage | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
makePageLinkWithText | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate; |
5 | |
6 | use LogFormatter as CoreLogFormatter; |
7 | use MediaWiki\Extension\Translate\Utilities\Utilities; |
8 | use MediaWiki\MediaWikiServices; |
9 | use MediaWiki\Message\Message; |
10 | use MediaWiki\Title\Title; |
11 | |
12 | /** |
13 | * Class for formatting Translate logs. |
14 | * |
15 | * @author Niklas Laxström |
16 | * @copyright Copyright © 2013, Niklas Laxström |
17 | * @license GPL-2.0-or-later |
18 | */ |
19 | class LogFormatter extends CoreLogFormatter { |
20 | public function getMessageParameters(): array { |
21 | $params = parent::getMessageParameters(); |
22 | |
23 | $type = $this->entry->getFullType(); |
24 | |
25 | if ( $type === 'translationreview/message' ) { |
26 | $targetPage = $this->makePageLink( |
27 | $this->entry->getTarget(), |
28 | [ 'oldid' => $params[3] ] |
29 | ); |
30 | |
31 | $params[2] = Message::rawParam( $targetPage ); |
32 | } elseif ( $type === 'translationreview/group' ) { |
33 | /* |
34 | * - 3: language code |
35 | * - 4: label of the message group |
36 | * - 5: old state |
37 | * - 6: new state |
38 | */ |
39 | |
40 | $uiLanguage = $this->context->getLanguage(); |
41 | $language = $params[3]; |
42 | |
43 | $targetPage = $this->makePageLinkWithText( |
44 | $this->entry->getTarget(), |
45 | $params[4], |
46 | [ 'language' => $language ] |
47 | ); |
48 | |
49 | $params[2] = Message::rawParam( $targetPage ); |
50 | $params[3] = Utilities::getLanguageName( $language, $uiLanguage->getCode() ); |
51 | $params[5] = $this->formatStateMessage( $params[5] ); |
52 | $params[6] = $this->formatStateMessage( $params[6] ); |
53 | } elseif ( $type === 'translatorsandbox/rejected' ) { |
54 | // No point linking to the user page which cannot have existed |
55 | $params[2] = $this->entry->getTarget()->getText(); |
56 | } elseif ( $type === 'translatorsandbox/promoted' ) { |
57 | // Gender for the target |
58 | $params[3] = MediaWikiServices::getInstance()->getUserFactory() |
59 | ->newFromId( $params[3] ) |
60 | ->getName(); |
61 | } |
62 | |
63 | return $params; |
64 | } |
65 | |
66 | /** @param string|bool $value */ |
67 | private function formatStateMessage( $value ): string { |
68 | $message = $this->msg( "translate-workflow-state-$value" ); |
69 | |
70 | return $message->isBlank() ? $value : $message->text(); |
71 | } |
72 | |
73 | /** @return-taint onlysafefor_html */ |
74 | private function makePageLinkWithText( |
75 | ?Title $pageTitle, ?string $text, array $queryParameters = [] |
76 | ): string { |
77 | if ( !$this->plaintext ) { |
78 | $link = $this->getLinkRenderer()->makeLink( $pageTitle, $text, [], $queryParameters ); |
79 | } else { |
80 | $target = '***'; |
81 | if ( $pageTitle instanceof Title ) { |
82 | $target = $pageTitle->getPrefixedText(); |
83 | } |
84 | $link = "[[$target|$text]]"; |
85 | } |
86 | |
87 | return $link; |
88 | } |
89 | } |