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\HTMLForm\Field\HTMLTextAreaField; |
| 27 | use MediaWiki\MediaWikiServices; |
| 28 | |
| 29 | /** |
| 30 | * Produces a preview div of a banner message that can be included in an HTMLForm |
| 31 | * |
| 32 | * Expects the following options: |
| 33 | * - 'language' - ISO language code to render message in |
| 34 | * - 'banner' - Canonical name of banner message belongs to |
| 35 | * - 'message' - Canonical name of the message |
| 36 | */ |
| 37 | class HTMLCentralNoticeBannerMessage extends HTMLTextAreaField { |
| 38 | protected const DEFAULT_COLS = 45; |
| 39 | protected const DEFAULT_ROWS = 1; |
| 40 | |
| 41 | /** @inheritDoc */ |
| 42 | public function __construct( $params ) { |
| 43 | if ( !array_key_exists( 'default', $params ) ) { |
| 44 | $message = new BannerMessage( $params[ 'banner' ], $params[ 'message' ] ); |
| 45 | $params[ 'default' ] = $message->getContents( $params[ 'language' ] ); |
| 46 | } |
| 47 | |
| 48 | parent::__construct( $params ); |
| 49 | } |
| 50 | |
| 51 | /** @inheritDoc */ |
| 52 | public function validate( $value, $alldata ) { |
| 53 | // Empty - no validation can be done on a banner message |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get a preview of the banner message |
| 59 | * @param string $value |
| 60 | * @return string HTML |
| 61 | */ |
| 62 | public function getInputHTML( $value ) { |
| 63 | $message = new BannerMessage( $this->mParams[ 'banner' ], $this->mParams[ 'message' ] ); |
| 64 | |
| 65 | $html = Html::openElement( 'table', [ 'class' => 'cn-message-table' ] ); |
| 66 | $html .= Html::openElement( 'tr' ); |
| 67 | |
| 68 | $originText = $message->getContents( |
| 69 | MediaWikiServices::getInstance()->getContentLanguageCode()->toString() |
| 70 | ); |
| 71 | $html .= Html::element( |
| 72 | 'td', |
| 73 | [ 'class' => 'cn-message-text-origin' ], |
| 74 | $originText |
| 75 | ); |
| 76 | |
| 77 | $this->mParams[ 'placeholder' ] = $originText; |
| 78 | $html .= Html::rawElement( 'td', [ 'class' => 'cn-message-text-native' ], |
| 79 | parent::getInputHTML( $message->getContents( $this->mParams[ 'language' ] ) ) |
| 80 | ); |
| 81 | |
| 82 | $html .= Html::closeElement( 'tr' ); |
| 83 | $html .= Html::closeElement( 'table' ); |
| 84 | |
| 85 | return $html; |
| 86 | } |
| 87 | } |