Fix hook situation for Skin::doEditSectionLink
[mediawiki.git] / includes / resourceloader / ResourceLoaderUserCSSPrefsModule.php
blob472ceb26e90beff99cfb5feaf4c9ee02ecbe5391
1 <?php
2 /**
3 * Resource loader 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 Members */
32 protected $modifiedTime = array();
34 protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
36 /* Methods */
38 /**
39 * @param ResourceLoaderContext $context
40 * @return array|int|mixed
42 public function getModifiedTime( ResourceLoaderContext $context ) {
43 $hash = $context->getHash();
44 if ( !isset( $this->modifiedTime[$hash] ) ) {
45 $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $context->getUserObj()->getTouched() );
48 return $this->modifiedTime[$hash];
51 /**
52 * @param ResourceLoaderContext $context
53 * @return array
55 public function getStyles( ResourceLoaderContext $context ) {
56 if ( !$this->getConfig()->get( 'AllowUserCssPrefs' ) ) {
57 return array();
60 $options = $context->getUserObj()->getOptions();
62 // Build CSS rules
63 $rules = array();
65 // Underline: 2 = browser default, 1 = always, 0 = never
66 if ( $options['underline'] < 2 ) {
67 $rules[] = "a { text-decoration: " .
68 ( $options['underline'] ? 'underline' : 'none' ) . "; }";
69 } else {
70 # The scripts of these languages are very hard to read with underlines
71 $rules[] = 'a:lang(ar), a:lang(kk-arab), a:lang(mzn), ' .
72 'a:lang(ps), a:lang(ur) { text-decoration: none; }';
74 if ( $options['editfont'] !== 'default' ) {
75 // Double-check that $options['editfont'] consists of safe characters only
76 if ( preg_match( '/^[a-zA-Z0-9_, -]+$/', $options['editfont'] ) ) {
77 $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
80 $style = implode( "\n", $rules );
81 if ( $this->getFlip( $context ) ) {
82 $style = CSSJanus::transform( $style, true, false );
84 return array( 'all' => $style );
87 /**
88 * @return string
90 public function getGroup() {
91 return 'private';