Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 55
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
TranslatableBundleLogFormatter
0.00% covered (danger)
0.00%
0 / 55
0.00% covered (danger)
0.00%
0 / 3
342
0.00% covered (danger)
0.00%
0 / 1
 getMessageParameters
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 1
156
 getComment
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 getMessageKey
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\MessageGroupProcessing;
5
6use LogFormatter;
7use MediaWiki\Extension\Translate\Utilities\Utilities;
8use MediaWiki\MediaWikiServices;
9use MediaWiki\Message\Message;
10use MediaWiki\Title\Title;
11
12/**
13 * Class for formatting translatable bundle logs.
14 * @author Niklas Laxström
15 * @license GPL-2.0-or-later
16 */
17class TranslatableBundleLogFormatter extends LogFormatter {
18    protected function getMessageParameters(): array {
19        $params = parent::getMessageParameters();
20        $legacy = $this->entry->getParameters();
21
22        $type = $this->entry->getFullType();
23        switch ( $type ) {
24            case 'pagetranslation/mark':
25                $revision = $legacy['revision'];
26
27                $targetPage = $this->makePageLink(
28                    $this->entry->getTarget(),
29                    [ 'oldid' => $revision ]
30                );
31
32                $params[2] = Message::rawParam( $targetPage );
33                break;
34
35            case 'pagetranslation/moveok':
36            case 'pagetranslation/movenok':
37            case 'pagetranslation/deletefnok':
38            case 'pagetranslation/deletelnok':
39            case 'messagebundle/moveok':
40            case 'messagebundle/movenok':
41                $target = $legacy['target'] ?? 'Special:Badtitle';
42                $moveTarget = $this->makePageLink( Title::newFromText( $target ) );
43                $params[3] = Message::rawParam( $moveTarget );
44                break;
45
46            case 'pagetranslation/prioritylanguages':
47                $params[3] = $legacy['force'];
48                $languages = $legacy['languages'];
49                if ( $languages !== false ) {
50                    $lang = $this->context->getLanguage();
51                    $inLanguage = $lang->getCode();
52
53                    $languages = array_map(
54                        static function ( string $code ) use ( $inLanguage ): string {
55                            return Utilities::getLanguageName( trim( $code ), $inLanguage );
56                        },
57                        preg_split( '/,/', $languages, -1, PREG_SPLIT_NO_EMPTY )
58                    );
59
60                    $params[4] = $lang->listToText( $languages );
61                }
62                break;
63
64            case 'pagetranslation/associate':
65            case 'pagetranslation/dissociate':
66                $params[3] = $legacy['aggregategroup'];
67                break;
68        }
69
70        return $params;
71    }
72
73    public function getComment(): string {
74        $legacy = $this->entry->getParameters();
75        if ( isset( $legacy['reason'] ) ) {
76            $commentFormatter = MediaWikiServices::getInstance()->getCommentFormatter();
77            $comment = $commentFormatter->formatBlock( (string)$legacy['reason'] );
78
79            // No hard coded spaces thanx
80            return ltrim( $comment );
81        }
82
83        return parent::getComment();
84    }
85
86    protected function getMessageKey(): string {
87        $key = parent::getMessageKey();
88        $type = $this->entry->getFullType();
89
90        // logentry-pagetranslation-prioritylanguages-unset
91        // logentry-pagetranslation-prioritylanguages-force
92        if ( $type === 'pagetranslation/prioritylanguages' ) {
93            $params = $this->getMessageParameters();
94            if ( !isset( $params[4] ) ) {
95                $key .= '-unset';
96            } elseif ( $params['3'] === 'on' ) {
97                $key .= '-force';
98            }
99        }
100
101        return $key;
102    }
103}