Use classes to apply the 'editfont' preference
authorEd Sanders <esanders@wikimedia.org>
Wed, 7 Sep 2016 21:59:57 +0000 (14:59 -0700)
committerEsanders <esanders@wikimedia.org>
Tue, 27 Sep 2016 21:07:12 +0000 (21:07 +0000)
This class can be re-used on non textarea inputs
(e.g. ContentEditable or <input>).

The 'default' preference can't be achieved in CSS alone, so
for non-textarea cases, use 'monospace' as is used in the majority of
browsers/OSes. In future a client script could compute the default
font of textarea and add it to the -default rule.

Bug: T145015
Change-Id: I5f0433e9cae6f692396537412c11b79b61db062f

includes/EditPage.php
includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
resources/src/mediawiki.legacy/shared.css

index 4e9aeba..3314e39 100644 (file)
@@ -3235,6 +3235,12 @@ HTML
                        'id' => $name,
                        'cols' => $wgUser->getIntOption( 'cols' ),
                        'rows' => $wgUser->getIntOption( 'rows' ),
+                       // The following classes can be used here:
+                       // * mw-editfont-default
+                       // * mw-editfont-monospace
+                       // * mw-editfont-sans-serif
+                       // * mw-editfont-serif
+                       'class' => 'mw-editfont-' . $wgUser->getOption( 'editfont' ),
                        // Avoid PHP notices when appending preferences
                        // (appending allows customAttribs['style'] to still work).
                        'style' => ''
index 4d0bff7..aef1c74 100644 (file)
@@ -55,12 +55,6 @@ class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule {
                        $rules[] = "a { text-decoration: " .
                                ( $options['underline'] ? 'underline' : 'none' ) . "; }";
                }
-               if ( $options['editfont'] !== 'default' ) {
-                       // Double-check that $options['editfont'] consists of safe characters only
-                       if ( preg_match( '/^[a-zA-Z0-9_, -]+$/', $options['editfont'] ) ) {
-                               $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
-                       }
-               }
                $style = implode( "\n", $rules );
                if ( $this->getFlip( $context ) ) {
                        $style = CSSJanus::transform( $style, true, false );
index de442e9..698e19e 100644 (file)
@@ -105,6 +105,25 @@ span.comment {
        clear: both;
 }
 
+/* Edit font preference */
+/* TODO: for 'default' on non-textareas we could compute the default font of textarea in the client */
+.mw-editfont-default:not( textarea ) {
+       font-family: monospace;
+}
+
+/* Keep this rule separate from the :not rule above so it still works in older browsers */
+.mw-editfont-monospace {
+       font-family: monospace;
+}
+
+.mw-editfont-sans-serif {
+       font-family: sans-serif;
+}
+
+.mw-editfont-serif {
+       font-family: serif;
+}
+
 /**
  * rev_deleted stuff
  */