Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PremadeIntuitionTextdomains
0.00% covered (danger)
0.00%
0 / 39
0.00% covered (danger)
0.00%
0 / 3
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getDefaultNamespace
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 processGroups
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\MessageGroupConfiguration;
5
6/**
7 * Support for tools using Intuition at the Toolserver and Wikimedia Labs. Used on translatewiki.net
8 * @author Niklas Laxström
9 * @author Krinkle
10 * @copyright Copyright © 2008-2013, Niklas Laxström
11 * @copyright Copyright © 2011, Krinkle
12 * @license GPL-2.0-or-later
13 */
14class PremadeIntuitionTextdomains extends PremadeMediaWikiExtensionGroups {
15    protected array $groups;
16
17    /** @inheritDoc */
18    public function __construct( string $def, string $path ) {
19        parent::__construct( $def, $path );
20        $this->idPrefix = 'tsint-';
21    }
22
23    protected function getDefaultNamespace(): int {
24        return NS_INTUITION;
25    }
26
27    protected function processGroups( array $groups ): array {
28        $fixedGroups = [];
29        foreach ( $groups as $g ) {
30            $name = $g['name'];
31            $sanitizedName = preg_replace( '/\s+/', '', strtolower( $name ) );
32
33            $id = $g['id'] ?? $this->idPrefix . $sanitizedName;
34
35            // Canonical names for Intuition text-domains are lowercase
36            // e.g. "MyTool" -> "mytool/en.json"
37            $file = $g['file'] ?? "$sanitizedName/%CODE%.json";
38
39            $descMsg = $g['descmsg'] ?? "$id-desc";
40
41            $newGroup = [
42                'name' => 'Intuition - ' . $name,
43                'file' => $file,
44                'descmsg' => $descMsg,
45            ];
46
47            // Prefix is required, if not customized use the sanitized name
48            if ( !isset( $g['prefix'] ) ) {
49                $g['prefix'] = "$sanitizedName-";
50            }
51
52            // All messages are prefixed with their groupname
53            $g['mangle'] = [ '*' ];
54
55            // Prevent E_NOTICE undefined index.
56            // PremadeMediaWikiExtensionGroups::factory should probably check this better instead
57            if ( !isset( $g['ignored'] ) ) {
58                $g['ignored'] = [];
59            }
60
61            if ( !isset( $g['optional'] ) ) {
62                $g['optional'] = [];
63            }
64
65            $g['format'] = 'json';
66
67            $copyVars = [
68                'aliasfile',
69                'desc',
70                'format',
71                'ignored',
72                'magicfile',
73                'mangle',
74                'optional',
75                'prefix',
76                'var',
77            ];
78
79            foreach ( $copyVars as $var ) {
80                if ( isset( $g[$var] ) ) {
81                    $newGroup[$var] = $g[$var];
82                }
83            }
84
85            $fixedGroups[$id] = $newGroup;
86        }
87
88        return $fixedGroups;
89    }
90}
91
92class_alias( PremadeIntuitionTextdomains::class, 'PremadeIntuitionTextdomains' );