Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
LogFormatter.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate;
5
6use LogFormatter as CoreLogFormatter;
8use MediaWiki\MediaWikiServices;
9use MediaWiki\Message\Message;
10use MediaWiki\Title\Title;
11
19class 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
67 private function formatStateMessage( $value ): string {
68 $message = $this->msg( "translate-workflow-state-$value" );
69
70 return $message->isBlank() ? $value : $message->text();
71 }
72
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}
Class for formatting Translate logs.
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:31