Hi all,
I've been working on enhancing the Theme extension [1] to add a
preference option so that registered users can set their preferred
theme [2], just like how they can set a skin and other such options.
The theme selector is shown on Special:Preferences, below the list of
available skins, and since themes are nothing but a set of CSS
modifications on top of a skin's base CSS, previewing them in real
time is easy. Or so I thought, anyway.
Turns out that this is a bit more complicated than that. I'm loading
the theme-specific CSS module via mw.loader.load(), which seems to
append a <style> tag to the <head> of the page.
To prevent "stacking" of theme CSS and to ensure that themes will
display as intended, I'm using $( 'head style' ).last().remove(); to
remove the last added <style> tag from head. This has the unintended
side-effect that previewing a theme works only once, and after that
the theme CSS is no longer applied because ResourceLoader thinks it
has already been loaded.
What would be the proper way to signal to ResourceLoader, "actually I
need you to load this module again"?
To test out my patch [2], you'll need a skin which supports themes,
such as MonoBook or Vector. Then simply git clone the
mediawiki/extensions/Theme repository, apply the patch on top of that,
load the extension via wfLoadExtension( 'Theme' ); in
LocalSettings.php (you may also need to set $wgDefaultTheme =
'default'; in your LocalSettings.php) and then visit
Special:Preferences and you should see the new "Theme" drop-down menu
there.
[1]
https://www.mediawiki.org/wiki/Extension:Theme
[2]
https://gerrit.wikimedia.org/r/#/c/359643/
Thanks and regards,
--
Jack Phoenix
MediaWiki developer