MediaWiki  master
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                         return $this->modifiedTime[$hash];
00046                 }
00047 
00048                 global $wgUser;
00049                 return $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() );
00050         }
00051 
00056         public function getStyles( ResourceLoaderContext $context ) {
00057                 global $wgAllowUserCssPrefs, $wgUser;
00058 
00059                 if ( $wgAllowUserCssPrefs ) {
00060                         $options = $wgUser->getOptions();
00061 
00062                         // Build CSS rules
00063                         $rules = array();
00064 
00065                         // Underline: 2 = browser default, 1 = always, 0 = never
00066                         if ( $options['underline'] < 2 ) {
00067                                 $rules[] = "a { text-decoration: " .
00068                                         ( $options['underline'] ? 'underline' : 'none' ) . "; }";
00069                         } else {
00070                                 # The scripts of these languages are very hard to read with underlines
00071                                 $rules[] = 'a:lang(ar), a:lang(ckb), a:lang(fa),a:lang(kk-arab), ' .
00072                                 'a:lang(mzn), a:lang(ps), a:lang(ur) { text-decoration: none; }';
00073                         }
00074                         if ( $options['justify'] ) {
00075                                 $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
00076                         }
00077                         if ( !$options['showtoc'] ) {
00078                                 $rules[] = "#toc { display: none; }\n";
00079                         }
00080                         if ( !$options['editsection'] ) {
00081                                 $rules[] = ".editsection { display: none; }\n";
00082                         }
00083                         if ( $options['editfont'] !== 'default' ) {
00084                                 $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
00085                         }
00086                         $style = implode( "\n", $rules );
00087                         if ( $this->getFlip( $context ) ) {
00088                                 $style = CSSJanus::transform( $style, true, false );
00089                         }
00090                         return array( 'all' => $style );
00091                 }
00092                 return array();
00093         }
00094 
00098         public function getGroup() {
00099                 return 'private';
00100         }
00101 
00105         public function getDependencies() {
00106                 return array( 'mediawiki.user' );
00107         }
00108 }