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
24 * Module for user preference customizations
26 class ResourceLoaderUserOptionsModule
extends ResourceLoaderModule
{
28 /* Protected Members */
30 protected $modifiedTime = array();
32 protected $origin = self
::ORIGIN_CORE_INDIVIDUAL
;
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] = wfTimestamp( TS_UNIX
, $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: Context object
56 * @return Array: List of user options keyed by option name
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 return Xml
::encodeJsCall( 'mediaWiki.user.options.set',
71 array( $this->contextUserOptions( $context ) ) );
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: " .
84 ( $options['underline'] ?
'underline' : 'none' ) . "; }";
86 if ( $options['highlightbroken'] ) {
87 $rules[] = "a.new, #quickbar a.new { color: #ba0000; }\n";
89 $rules[] = "a.new, #quickbar a.new, a.stub, #quickbar a.stub { color: inherit; }";
90 $rules[] = "a.new:after, #quickbar a.new:after { content: '?'; color: #ba0000; }";
91 $rules[] = "a.stub:after, #quickbar a.stub:after { content: '!'; color: #772233; }";
93 if ( $options['justify'] ) {
94 $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
96 if ( !$options['showtoc'] ) {
97 $rules[] = "#toc { display: none; }\n";
99 if ( !$options['editsection'] ) {
100 $rules[] = ".editsection { display: none; }\n";
102 if ( $options['editfont'] !== 'default' ) {
103 $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
105 $style = implode( "\n", $rules );
106 if ( $this->getFlip( $context ) ) {
107 $style = CSSJanus
::transform( $style, true, false );
109 return array( 'all' => $style );
115 * @param $context ResourceLoaderContext
118 public function getFlip( $context ) {
121 return $wgContLang->getDir() !== $context->getDirection();
124 public function getGroup() {