Use classes to apply the 'editfont' preference

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
This commit is contained in:
Ed Sanders 2016-09-07 14:59:57 -07:00 committed by Esanders
parent 2066dec868
commit 2c688cfb11
3 changed files with 25 additions and 6 deletions

View 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' => ''

View 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 );

View 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
*/