Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
PatentFormField | |
0.00% |
0 / 25 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
getMessageFromParams | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
buildLine | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getInputHTML | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getOptionsArray | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * http://www.gnu.org/copyleft/gpl.html |
18 | */ |
19 | |
20 | namespace MediaWiki\Extension\ThreeD; |
21 | |
22 | use HTMLRadioField; |
23 | use Licenses; |
24 | |
25 | class PatentFormField extends Licenses { |
26 | /** |
27 | * @inheritDoc |
28 | */ |
29 | public static function getMessageFromParams( $params ) { |
30 | global $wgLanguageCode; |
31 | |
32 | if ( !empty( $params['patents'] ) ) { |
33 | return $params['patents']; |
34 | } |
35 | |
36 | // The 3d-patents page is in $wgForceUIMsgAsContentMsg (its translations will |
37 | // be in subpages). If such translation can't be found, fall back to default. |
38 | $defaultMsg = wfMessage( '3d-patents' )->inContentLanguage(); |
39 | if ( !$defaultMsg->exists() || $defaultMsg->plain() === '-' ) { |
40 | $defaultMsg = wfMessage( '3d-patents' )->inLanguage( $wgLanguageCode ); |
41 | } |
42 | |
43 | return $defaultMsg->plain(); |
44 | } |
45 | |
46 | /** |
47 | * @param string $line |
48 | * @return PatentLine |
49 | */ |
50 | protected function buildLine( $line ) { |
51 | return new PatentLine( $line ); |
52 | } |
53 | |
54 | /** |
55 | * @inheritDoc |
56 | */ |
57 | public function getInputHTML( $value ) { |
58 | $options = []; |
59 | $options[$this->msg( '3d-nopatent' )->text()] = ''; |
60 | $options += $this->getOptionsArray(); |
61 | |
62 | $field = new HTMLRadioField( [ |
63 | 'parent' => $this->mParent, |
64 | 'fieldname' => 'Patent', |
65 | 'id' => 'wpPatent', |
66 | 'options' => $options, |
67 | ] ); |
68 | return $field->getInputHTML( $value ); |
69 | } |
70 | |
71 | /** |
72 | * @return array |
73 | */ |
74 | protected function getOptionsArray() { |
75 | $lines = $this->getLines(); |
76 | $options = []; |
77 | foreach ( $lines as $line ) { |
78 | $msgObj = $this->msg( $line->text ); |
79 | $text = $msgObj->exists() ? $msgObj->text() : $line->text; |
80 | |
81 | $options[$text] = $line->template; |
82 | } |
83 | return $options; |
84 | } |
85 | } |