From 2c688cfb11ea6cee0e975ed35fc8e503ea127127 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Wed, 7 Sep 2016 14:59:57 -0700 Subject: [PATCH] Use classes to apply the 'editfont' preference This class can be re-used on non textarea inputs (e.g. ContentEditable or ). 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 | 6 ++++++ .../ResourceLoaderUserCSSPrefsModule.php | 6 ------ resources/src/mediawiki.legacy/shared.css | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 4e9aebaf63..3314e39d7a 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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' => '' diff --git a/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php b/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php index 4d0bff7949..aef1c74452 100644 --- a/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php +++ b/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php @@ -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 ); diff --git a/resources/src/mediawiki.legacy/shared.css b/resources/src/mediawiki.legacy/shared.css index de442e91f6..698e19e478 100644 --- a/resources/src/mediawiki.legacy/shared.css +++ b/resources/src/mediawiki.legacy/shared.css @@ -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 */ -- 2.20.1