MediaWiki  REL1_24
ResourceLoaderUserCSSPrefsModule.php
Go to the documentation of this file.
00001 <?php
00028 class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule {
00029 
00030     /* Protected Members */
00031 
00032     protected $modifiedTime = array();
00033 
00034     protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
00035 
00036     /* Methods */
00037 
00042     public function getModifiedTime( ResourceLoaderContext $context ) {
00043         $hash = $context->getHash();
00044         if ( !isset( $this->modifiedTime[$hash] ) ) {
00045             global $wgUser;
00046             $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() );
00047         }
00048 
00049         return $this->modifiedTime[$hash];
00050     }
00051 
00056     public function getStyles( ResourceLoaderContext $context ) {
00057         global $wgUser;
00058 
00059         if ( !$this->getConfig()->get( 'AllowUserCssPrefs' ) ) {
00060             return array();
00061         }
00062 
00063         $options = $wgUser->getOptions();
00064 
00065         // Build CSS rules
00066         $rules = array();
00067 
00068         // Underline: 2 = browser default, 1 = always, 0 = never
00069         if ( $options['underline'] < 2 ) {
00070             $rules[] = "a { text-decoration: " .
00071                 ( $options['underline'] ? 'underline' : 'none' ) . "; }";
00072         } else {
00073             # The scripts of these languages are very hard to read with underlines
00074             $rules[] = 'a:lang(ar), a:lang(kk-arab), a:lang(mzn), ' .
00075             'a:lang(ps), a:lang(ur) { text-decoration: none; }';
00076         }
00077         if ( $options['editfont'] !== 'default' ) {
00078             // Double-check that $options['editfont'] consists of safe characters only
00079             if ( preg_match( '/^[a-zA-Z0-9_, -]+$/', $options['editfont'] ) ) {
00080                 $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
00081             }
00082         }
00083         $style = implode( "\n", $rules );
00084         if ( $this->getFlip( $context ) ) {
00085             $style = CSSJanus::transform( $style, true, false );
00086         }
00087         return array( 'all' => $style );
00088     }
00089 
00093     public function getGroup() {
00094         return 'private';
00095     }
00096 
00100     public function getDependencies() {
00101         return array( 'mediawiki.user' );
00102     }
00103 }