Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
TranslateLogFormatter.php
Go to the documentation of this file.
1<?php
14class TranslateLogFormatter extends LogFormatter {
15 public function getMessageParameters() {
16 $params = parent::getMessageParameters();
17
18 $type = $this->entry->getFullType();
19
20 if ( $type === 'translationreview/message' ) {
21 $targetPage = $this->makePageLink(
22 $this->entry->getTarget(),
23 [ 'oldid' => $params[3] ]
24 );
25
26 $params[2] = Message::rawParam( $targetPage );
27 } elseif ( $type === 'translationreview/group' ) {
28 /*
29 * - 3: language code
30 * - 4: label of the message group
31 * - 5: old state
32 * - 6: new state
33 */
34
35 $uiLanguage = $this->context->getLanguage();
36 $language = $params[3];
37
38 // @phan-suppress-next-line SecurityCheck-DoubleEscaped Mixed plaintext/html mode
39 $targetPage = $this->makePageLinkWithText(
40 $this->entry->getTarget(),
41 $params[4],
42 [ 'language' => $language ]
43 );
44
45 $params[2] = Message::rawParam( $targetPage );
46 $params[3] = TranslateUtils::getLanguageName( $language, $uiLanguage->getCode() );
47 $params[5] = $this->formatStateMessage( $params[5] );
48 $params[6] = $this->formatStateMessage( $params[6] );
49 } elseif ( $type === 'translatorsandbox/rejected' ) {
50 // No point linking to the user page which cannot have existed
51 $params[2] = $this->entry->getTarget()->getText();
52 } elseif ( $type === 'translatorsandbox/promoted' ) {
53 // Gender for the target
54 $params[3] = User::newFromId( $params[3] )->getName();
55 }
56
57 return $params;
58 }
59
60 protected function formatStateMessage( $value ) {
61 $message = $this->msg( "translate-workflow-state-$value" );
62
63 return $message->isBlank() ? $value : $message->text();
64 }
65
73 protected function makePageLinkWithText(
74 ?Title $title, $text, array $parameters = []
75 ) {
76 if ( !$this->plaintext ) {
77 $link = $this->getLinkRenderer()->makeLink( $title, $text, [], $parameters );
78 } else {
79 $target = '***';
80 if ( $title instanceof Title ) {
81 $target = $title->getPrefixedText();
82 }
83 $link = "[[$target|$text]]";
84 }
85
86 return $link;
87 }
88}
Class for formatting Translate logs.
makePageLinkWithText(?Title $title, $text, array $parameters=[])