X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fhtmlform%2Ffields%2FHTMLTextAreaField.php;h=3370e4af13af12ca7f12a434eb7ed42723925225;hp=82ec3bf201211788b0fd7dc5f8bcbb2eca42b0b9;hb=5f49c61c632734d4b2a2d4ee573a284d6d94718a;hpb=3a2853e218acb586a00f2e59638de4176aee287f diff --git a/includes/htmlform/fields/HTMLTextAreaField.php b/includes/htmlform/fields/HTMLTextAreaField.php index 82ec3bf201..3370e4af13 100644 --- a/includes/htmlform/fields/HTMLTextAreaField.php +++ b/includes/htmlform/fields/HTMLTextAreaField.php @@ -5,21 +5,27 @@ class HTMLTextAreaField extends HTMLFormField { const DEFAULT_ROWS = 25; protected $mPlaceholder = ''; + protected $mUseEditFont = false; /** * @param array $params * - cols, rows: textarea size * - placeholder/placeholder-message: set HTML placeholder attribute * - spellcheck: set HTML spellcheck attribute + * - useeditfont: add CSS classes to use the same font as the wikitext editor */ public function __construct( $params ) { parent::__construct( $params ); if ( isset( $params['placeholder-message'] ) ) { - $this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->parse(); + $this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->text(); } elseif ( isset( $params['placeholder'] ) ) { $this->mPlaceholder = $params['placeholder']; } + + if ( isset( $params['useeditfont'] ) ) { + $this->mUseEditFont = $params['useeditfont']; + } } public function getCols() { @@ -40,6 +46,8 @@ class HTMLTextAreaField extends HTMLFormField { } public function getInputHTML( $value ) { + $classes = []; + $attribs = [ 'id' => $this->mID, 'cols' => $this->getCols(), @@ -48,11 +56,25 @@ class HTMLTextAreaField extends HTMLFormField { ] + $this->getTooltipAndAccessKey(); if ( $this->mClass !== '' ) { - $attribs['class'] = $this->mClass; + array_push( $classes, $this->mClass ); + } + if ( $this->mUseEditFont ) { + // The following classes can be used here: + // * mw-editfont-monospace + // * mw-editfont-sans-serif + // * mw-editfont-serif + array_push( + $classes, + 'mw-editfont-' . $this->mParent->getUser()->getOption( 'editfont' ) + ); + $this->mParent->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' ); } if ( $this->mPlaceholder !== '' ) { $attribs['placeholder'] = $this->mPlaceholder; } + if ( count( $classes ) ) { + $attribs['class'] = implode( ' ', $classes ); + } $allowedParams = [ 'tabindex', @@ -67,18 +89,34 @@ class HTMLTextAreaField extends HTMLFormField { } function getInputOOUI( $value ) { + $classes = []; + if ( isset( $this->mParams['cols'] ) ) { throw new Exception( "OOUIHTMLForm does not support the 'cols' parameter for textareas" ); } - $attribs = $this->getTooltipAndAccessKey(); + $attribs = $this->getTooltipAndAccessKeyOOUI(); if ( $this->mClass !== '' ) { - $attribs['classes'] = [ $this->mClass ]; + array_push( $classes, $this->mClass ); + } + if ( $this->mUseEditFont ) { + // The following classes can be used here: + // * mw-editfont-monospace + // * mw-editfont-sans-serif + // * mw-editfont-serif + array_push( + $classes, + 'mw-editfont-' . $this->mParent->getUser()->getOption( 'editfont' ) + ); + $this->mParent->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' ); } if ( $this->mPlaceholder !== '' ) { $attribs['placeholder'] = $this->mPlaceholder; } + if ( count( $classes ) ) { + $attribs['classes'] = $classes; + } $allowedParams = [ 'tabindex', @@ -92,10 +130,9 @@ class HTMLTextAreaField extends HTMLFormField { $this->getAttributes( $allowedParams ) ); - return new OOUI\TextInputWidget( [ + return new OOUI\MultilineTextInputWidget( [ 'id' => $this->mID, 'name' => $this->mName, - 'multiline' => true, 'value' => $value, 'rows' => $this->getRows(), ] + $attribs );