Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
MIDIHandler | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
210 | |
0.00% |
0 / 1 |
getMetadataType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWebType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
verifyUpload | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
getStreamTypes | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
getShortDesc | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getLongDesc | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\TimedMediaHandler\Handlers\MIDIHandler; |
4 | |
5 | use File; |
6 | use MediaWiki\Status\Status; |
7 | use MediaWiki\TimedMediaHandler\Handlers\ID3Handler\ID3Handler; |
8 | |
9 | /** |
10 | * MIDI handler |
11 | */ |
12 | class MIDIHandler extends ID3Handler { |
13 | |
14 | /** |
15 | * @param File $file |
16 | * @return string |
17 | */ |
18 | public function getMetadataType( $file ) { |
19 | return 'midi'; |
20 | } |
21 | |
22 | /** |
23 | * @param File $file |
24 | * @return string |
25 | */ |
26 | public function getWebType( $file ) { |
27 | return 'audio/midi'; |
28 | } |
29 | |
30 | /** @inheritDoc */ |
31 | public function verifyUpload( $fileName ) { |
32 | $metadata = $this->getID3( $fileName ); |
33 | |
34 | if ( |
35 | isset( $metadata['audio'] ) |
36 | && $metadata['audio']['dataformat'] === 'midi' |
37 | ) { |
38 | return Status::newGood(); |
39 | } |
40 | } |
41 | |
42 | /** |
43 | * @param File $file |
44 | * @return string[]|false |
45 | */ |
46 | public function getStreamTypes( $file ) { |
47 | $streamTypes = []; |
48 | $metadata = $this->unpackMetadata( $file->getMetadata() ); |
49 | |
50 | if ( !$metadata || isset( $metadata['error'] ) ) { |
51 | return false; |
52 | } |
53 | |
54 | if ( isset( $metadata['audio'] ) && $metadata['audio']['dataformat'] === 'midi' ) { |
55 | $streamTypes[] = 'MIDI'; |
56 | } |
57 | |
58 | return $streamTypes; |
59 | } |
60 | |
61 | /** |
62 | * @param File $file |
63 | * @return string |
64 | */ |
65 | public function getShortDesc( $file ) { |
66 | global $wgLang; |
67 | |
68 | $streamTypes = $this->getStreamTypes( $file ); |
69 | if ( !$streamTypes ) { |
70 | return parent::getShortDesc( $file ); |
71 | } |
72 | |
73 | return wfMessage( 'timedmedia-midi-short-audio', |
74 | $wgLang->formatTimePeriod( $this->getLength( $file ) ) )->text(); |
75 | } |
76 | |
77 | /** |
78 | * @param File $file |
79 | * @return string |
80 | */ |
81 | public function getLongDesc( $file ) { |
82 | $streamTypes = $this->getStreamTypes( $file ); |
83 | if ( !$streamTypes ) { |
84 | return parent::getLongDesc( $file ); |
85 | } |
86 | |
87 | return wfMessage( |
88 | 'timedmedia-midi-long-audio' |
89 | )->timeperiodParams( |
90 | $this->getLength( $file ) |
91 | )->bitrateParams( |
92 | $this->getBitRate( $file ) |
93 | )->sizeParams( |
94 | $file->getSize() |
95 | )->text(); |
96 | } |
97 | |
98 | } |