3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @author Trevor Parscal
20 * @author Roan Kattouw
23 defined( 'MEDIAWIKI' ) ||
die( 1 );
26 * Module for user preference customizations
28 class ResourceLoaderUserOptionsModule
extends ResourceLoaderModule
{
30 /* Protected Members */
32 protected $modifiedTime = array();
36 public function getModifiedTime( ResourceLoaderContext
$context ) {
37 $hash = $context->getHash();
38 if ( isset( $this->modifiedTime
[$hash] ) ) {
39 return $this->modifiedTime
[$hash];
44 if ( $context->getUser() === $wgUser->getName() ) {
45 return $this->modifiedTime
[$hash] = $wgUser->getTouched();
52 * Fetch the context's user options, or if it doesn't match current user,
53 * the default options.
55 * @param $context ResourceLoaderContext
58 protected function contextUserOptions( ResourceLoaderContext
$context ) {
61 // Verify identity -- this is a private module
62 if ( $context->getUser() === $wgUser->getName() ) {
63 return $wgUser->getOptions();
65 return User
::getDefaultOptions();
69 public function getScript( ResourceLoaderContext
$context ) {
70 $encOptions = FormatJson
::encode( $this->contextUserOptions( $context ) );
71 return "mediaWiki.user.options.set( $encOptions );";
74 public function getStyles( ResourceLoaderContext
$context ) {
75 global $wgAllowUserCssPrefs;
77 if ( $wgAllowUserCssPrefs ) {
78 $options = $this->contextUserOptions( $context );
82 if ( $options['underline'] < 2 ) {
83 $rules[] = "a { text-decoration: " . ( $options['underline'] ?
'underline' : 'none' ) . "; }";
85 if ( $options['highlightbroken'] ) {
86 $rules[] = "a.new, #quickbar a.new { color: #ba0000; }\n";
88 $rules[] = "a.new, #quickbar a.new, a.stub, #quickbar a.stub { color: inherit; }";
89 $rules[] = "a.new:after, #quickbar a.new:after { content: '?'; color: #ba0000; }";
90 $rules[] = "a.stub:after, #quickbar a.stub:after { content: '!'; color: #772233; }";
92 if ( $options['justify'] ) {
93 $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
95 if ( !$options['showtoc'] ) {
96 $rules[] = "#toc { display: none; }\n";
98 if ( !$options['editsection'] ) {
99 $rules[] = ".editsection { display: none; }\n";
101 if ( $options['editfont'] !== 'default' ) {
102 $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
104 return array( 'all' => implode( "\n", $rules ) );
109 public function getFlip( $context ) {
112 return $wgContLang->getDir() !== $context->getDirection();
115 public function getGroup() {