SessionManager: Save user name to metadata even if the user doesn't exist locally
[mediawiki.git] / includes / resourceloader / ResourceLoaderUserCSSPrefsModule.php
blob04b04349c89bdd5806924d79fd6a8152f6a4377c
1 <?php
2 /**
3 * ResourceLoader module for user preference customizations.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author Trevor Parscal
22 * @author Roan Kattouw
25 /**
26 * Module for user preference customizations
28 class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule {
30 protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
32 /**
33 * @return bool
35 public function enableModuleContentVersion() {
36 return true;
39 /**
40 * @param ResourceLoaderContext $context
41 * @return array
43 public function getStyles( ResourceLoaderContext $context ) {
44 if ( !$this->getConfig()->get( 'AllowUserCssPrefs' ) ) {
45 return array();
48 $options = $context->getUserObj()->getOptions();
50 // Build CSS rules
51 $rules = array();
53 // Underline: 2 = skin default, 1 = always, 0 = never
54 if ( $options['underline'] < 2 ) {
55 $rules[] = "a { text-decoration: " .
56 ( $options['underline'] ? 'underline' : 'none' ) . "; }";
58 if ( $options['editfont'] !== 'default' ) {
59 // Double-check that $options['editfont'] consists of safe characters only
60 if ( preg_match( '/^[a-zA-Z0-9_, -]+$/', $options['editfont'] ) ) {
61 $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
64 $style = implode( "\n", $rules );
65 if ( $this->getFlip( $context ) ) {
66 $style = CSSJanus::transform( $style, true, false );
68 return array( 'all' => $style );
71 /**
72 * @param ResourceLoaderContext $context
73 * @return bool
75 public function isKnownEmpty( ResourceLoaderContext $context ) {
76 $styles = $this->getStyles( $context );
77 return isset( $styles['all'] ) && $styles['all'] === '';
80 /**
81 * @return string
83 public function getGroup() {
84 return 'private';