Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MessageDefinitions | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getDefinitions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPages | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\MessageLoading; |
5 | |
6 | use MediaWiki\Title\Title; |
7 | |
8 | /** |
9 | * Wrapper for message definitions, just to beauty the code. |
10 | * @author Niklas Laxström |
11 | * @copyright Copyright © 2007-2011, Niklas Laxström |
12 | * @license GPL-2.0-or-later |
13 | */ |
14 | class MessageDefinitions { |
15 | private ?int $namespace; |
16 | /** @var string[] */ |
17 | private array $messages; |
18 | /** @var Title[]|null */ |
19 | private ?array $pages; |
20 | |
21 | /** |
22 | * @param string[] $messages |
23 | * @param int|false $namespace |
24 | */ |
25 | public function __construct( array $messages, $namespace = false ) { |
26 | $this->messages = $messages; |
27 | $this->namespace = $namespace === false ? null : $namespace; |
28 | } |
29 | |
30 | /** @return string[] */ |
31 | public function getDefinitions(): array { |
32 | return $this->messages; |
33 | } |
34 | |
35 | /** @return Title[] List of title indexed by message key. */ |
36 | public function getPages(): array { |
37 | $namespace = $this->namespace; |
38 | if ( isset( $this->pages ) ) { |
39 | return $this->pages; |
40 | } |
41 | |
42 | $pages = []; |
43 | foreach ( array_keys( $this->messages ) as $key ) { |
44 | if ( $namespace === null ) { |
45 | // pages are in format ex. "8:jan" |
46 | [ $tns, $tkey ] = explode( ':', $key, 2 ); |
47 | $title = Title::makeTitleSafe( (int)$tns, $tkey ); |
48 | } else { |
49 | $title = Title::makeTitleSafe( $namespace, $key ); |
50 | } |
51 | |
52 | if ( !$title ) { |
53 | wfWarn( "Invalid title ($namespace:)$key" ); |
54 | continue; |
55 | } |
56 | |
57 | $pages[$key] = $title; |
58 | } |
59 | |
60 | $this->pages = $pages; |
61 | |
62 | return $this->pages; |
63 | } |
64 | } |