Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
HTMLCentralNoticeBannerMessage | |
0.00% |
0 / 23 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
validate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getInputHTML | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This file is part of the CentralNotice Extension to MediaWiki |
4 | * https://www.mediawiki.org/wiki/Extension:CentralNotice |
5 | * |
6 | * @section LICENSE |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; if not, write to the Free Software Foundation, Inc., |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | * http://www.gnu.org/copyleft/gpl.html |
21 | * |
22 | * @file |
23 | */ |
24 | |
25 | use MediaWiki\Html\Html; |
26 | use MediaWiki\MediaWikiServices; |
27 | |
28 | /** |
29 | * Produces a preview div of a banner message that can be included in an HTMLForm |
30 | * |
31 | * Expects the following options: |
32 | * - 'language' - ISO language code to render message in |
33 | * - 'banner' - Canonical name of banner message belongs to |
34 | * - 'message' - Canonical name of the message |
35 | */ |
36 | class HTMLCentralNoticeBannerMessage extends HTMLTextAreaField { |
37 | protected const DEFAULT_COLS = 45; |
38 | protected const DEFAULT_ROWS = 1; |
39 | |
40 | public function __construct( $params ) { |
41 | if ( !array_key_exists( 'default', $params ) ) { |
42 | $message = new BannerMessage( $params[ 'banner' ], $params[ 'message' ] ); |
43 | $params[ 'default' ] = $message->getContents( $params[ 'language' ] ); |
44 | } |
45 | |
46 | parent::__construct( $params ); |
47 | } |
48 | |
49 | public function validate( $value, $alldata ) { |
50 | // Empty - no validation can be done on a banner message |
51 | return true; |
52 | } |
53 | |
54 | /** |
55 | * Get a preview of the banner message |
56 | * @param string $value |
57 | * @return string HTML |
58 | */ |
59 | public function getInputHTML( $value ) { |
60 | $message = new BannerMessage( $this->mParams[ 'banner' ], $this->mParams[ 'message' ] ); |
61 | |
62 | $html = Html::openElement( 'table', [ 'class' => 'cn-message-table' ] ); |
63 | $html .= Html::openElement( 'tr' ); |
64 | |
65 | $originText = $message->getContents( |
66 | MediaWikiServices::getInstance()->getContentLanguage()->getCode() |
67 | ); |
68 | $html .= Xml::element( |
69 | 'td', |
70 | [ 'class' => 'cn-message-text-origin' ], |
71 | $originText |
72 | ); |
73 | |
74 | $this->mParams[ 'placeholder' ] = $originText; |
75 | $html .= Html::rawElement( 'td', [ 'class' => 'cn-message-text-native' ], |
76 | parent::getInputHTML( $message->getContents( $this->mParams[ 'language' ] ) ) |
77 | ); |
78 | |
79 | $html .= Html::closeElement( 'tr' ); |
80 | $html .= Html::closeElement( 'table' ); |
81 | |
82 | return $html; |
83 | } |
84 | } |