Merge "HTMLTextAreaField: Add 'useeditfont' param"
[lhc/web/wiklou.git] / includes / htmlform / fields / HTMLTextAreaField.php
index 466a251..3370e4a 100644 (file)
@@ -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',