]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/resourceloader/ResourceLoaderUserOptionsModule.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / resourceloader / ResourceLoaderUserOptionsModule.php
index fb33cd1f0c2f4597aed0e7b4a72e1c5c757d77f5..0c332cff8d35da534c4d0247b6fa12a456a1174f 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 /**
+ * ResourceLoader module for user preference customizations.
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  */
 class ResourceLoaderUserOptionsModule extends ResourceLoaderModule {
 
-       /* Protected Members */
-
-       protected $modifiedTime = array();
-
-       /* Methods */
+       protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
 
-       public function getModifiedTime( ResourceLoaderContext $context ) {
-               $hash = $context->getHash();
-               if ( isset( $this->modifiedTime[$hash] ) ) {
-                       return $this->modifiedTime[$hash];
-               }
+       protected $targets = [ 'desktop', 'mobile' ];
 
-               global $wgUser;
-
-               return $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() );
+       /**
+        * @param ResourceLoaderContext $context
+        * @return array List of module names as strings
+        */
+       public function getDependencies( ResourceLoaderContext $context = null ) {
+               return [ 'user.defaults' ];
        }
 
-       public function getScript( ResourceLoaderContext $context ) {
-               global $wgUser;
-               return Xml::encodeJsCall( 'mediaWiki.user.options.set', 
-                       array( $wgUser->getOptions() ) );
+       /**
+        * @return bool
+        */
+       public function enableModuleContentVersion() {
+               return true;
        }
 
-       public function getStyles( ResourceLoaderContext $context ) {
-               global $wgAllowUserCssPrefs, $wgUser;
-
-               if ( $wgAllowUserCssPrefs ) {
-                       $options = $wgUser->getOptions();
-
-                       // Build CSS rules
-                       $rules = array();
-                       if ( $options['underline'] < 2 ) {
-                               $rules[] = "a { text-decoration: " . 
-                                       ( $options['underline'] ? 'underline' : 'none' ) . "; }";
-                       }
-                       if ( $options['highlightbroken'] ) {
-                               $rules[] = "a.new, #quickbar a.new { color: #ba0000; }\n";
-                       } else {
-                               $rules[] = "a.new, #quickbar a.new, a.stub, #quickbar a.stub { color: inherit; }";
-                               $rules[] = "a.new:after, #quickbar a.new:after { content: '?'; color: #ba0000; }";
-                               $rules[] = "a.stub:after, #quickbar a.stub:after { content: '!'; color: #772233; }";
-                       }
-                       if ( $options['justify'] ) {
-                               $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
-                       }
-                       if ( !$options['showtoc'] ) {
-                               $rules[] = "#toc { display: none; }\n";
-                       }
-                       if ( !$options['editsection'] ) {
-                               $rules[] = ".editsection { display: none; }\n";
-                       }
-                       if ( $options['editfont'] !== 'default' ) {
-                               $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
-                       }
-                       $style = implode( "\n", $rules );
-                       if ( $this->getFlip( $context ) ) {
-                               $style = CSSJanus::transform( $style, true, false );
-                       }
-                       return array( 'all' => $style );
-               }
-               return array();
+       /**
+        * @param ResourceLoaderContext $context
+        * @return string JavaScript code
+        */
+       public function getScript( ResourceLoaderContext $context ) {
+               return Xml::encodeJsCall( 'mw.user.options.set',
+                       [ $context->getUserObj()->getOptions( User::GETOPTIONS_EXCLUDE_DEFAULTS ) ],
+                       ResourceLoader::inDebugMode()
+               );
        }
 
-       public function getFlip( $context ) {
-               global $wgContLang;
-
-               return $wgContLang->getDir() !== $context->getDirection();
+       /**
+        * @return bool
+        */
+       public function supportsURLLoading() {
+               return false;
        }
 
+       /**
+        * @return string
+        */
        public function getGroup() {
                return 'private';
        }