From: Ed Sanders Date: Wed, 3 Jan 2018 17:31:34 +0000 (+0000) Subject: HTMLTextAreaField: Add 'useeditfont' param X-Git-Tag: 1.31.0-rc.0~1006^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=5f49c61c632734d4b2a2d4ee573a284d6d94718a HTMLTextAreaField: Add 'useeditfont' param Change-Id: I7c76e911b4d71842b49272186e880051eee8de2b --- diff --git a/includes/htmlform/fields/HTMLTextAreaField.php b/includes/htmlform/fields/HTMLTextAreaField.php index 466a2511a3..3370e4af13 100644 --- a/includes/htmlform/fields/HTMLTextAreaField.php +++ b/includes/htmlform/fields/HTMLTextAreaField.php @@ -5,12 +5,14 @@ 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 ); @@ -20,6 +22,10 @@ class HTMLTextAreaField extends HTMLFormField { } 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,6 +89,8 @@ 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" ); } @@ -74,11 +98,25 @@ class HTMLTextAreaField extends HTMLFormField { $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', diff --git a/includes/specials/SpecialExpandTemplates.php b/includes/specials/SpecialExpandTemplates.php index 35344aaa69..970c903126 100644 --- a/includes/specials/SpecialExpandTemplates.php +++ b/includes/specials/SpecialExpandTemplates.php @@ -172,11 +172,7 @@ class SpecialExpandTemplates extends SpecialPage { 'rows' => 10, 'default' => $input, 'id' => 'input', - // The following classes can be used here: - // * mw-editfont-monospace - // * mw-editfont-sans-serif - // * mw-editfont-serif - 'cssclass' => 'mw-editfont-' . $this->getUser()->getOption( 'editfont' ), + 'useeditfont' => true, ], 'removecomments' => [ 'type' => 'check', @@ -208,8 +204,6 @@ class SpecialExpandTemplates extends SpecialPage { ], ]; - $this->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' ); - $form = HTMLForm::factory( 'ooui', $fields, $this->getContext() ); $form ->setSubmitTextMsg( 'expand_templates_ok' )