Merge "Do not support new installations via .php5 entrypoint any longer"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderUserCSSPrefsModule.php
1 <?php
2 /**
3 * Resource loader module for user preference customizations.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Trevor Parscal
22 * @author Roan Kattouw
23 */
24
25 /**
26 * Module for user preference customizations
27 */
28 class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule {
29
30 protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
31
32 /**
33 * @param ResourceLoaderContext $context
34 * @return array|int|mixed
35 */
36 public function getModifiedTime( ResourceLoaderContext $context ) {
37 return wfTimestamp( TS_UNIX, $context->getUserObj()->getTouched() );
38 }
39
40 /**
41 * @param ResourceLoaderContext $context
42 * @return array
43 */
44 public function getStyles( ResourceLoaderContext $context ) {
45 if ( !$this->getConfig()->get( 'AllowUserCssPrefs' ) ) {
46 return array();
47 }
48
49 $options = $context->getUserObj()->getOptions();
50
51 // Build CSS rules
52 $rules = array();
53
54 // Underline: 2 = browser default, 1 = always, 0 = never
55 if ( $options['underline'] < 2 ) {
56 $rules[] = "a { text-decoration: " .
57 ( $options['underline'] ? 'underline' : 'none' ) . "; }";
58 } else {
59 # The scripts of these languages are very hard to read with underlines
60 $rules[] = 'a:lang(ar), a:lang(kk-arab), a:lang(mzn), ' .
61 'a:lang(ps), a:lang(ur) { text-decoration: none; }';
62 }
63 if ( $options['editfont'] !== 'default' ) {
64 // Double-check that $options['editfont'] consists of safe characters only
65 if ( preg_match( '/^[a-zA-Z0-9_, -]+$/', $options['editfont'] ) ) {
66 $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
67 }
68 }
69 $style = implode( "\n", $rules );
70 if ( $this->getFlip( $context ) ) {
71 $style = CSSJanus::transform( $style, true, false );
72 }
73 return array( 'all' => $style );
74 }
75
76 /**
77 * @return string
78 */
79 public function getGroup() {
80 return 'private';
81 }
82 }