MediaWiki  REL1_20
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                                 // Double-check that $options['editfont'] consists of safe characters only
00085                                 if ( preg_match( '/^[a-zA-Z0-9_, -]+$/', $options['editfont'] ) ) {
00086                                         $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
00087                                 }
00088                         }
00089                         $style = implode( "\n", $rules );
00090                         if ( $this->getFlip( $context ) ) {
00091                                 $style = CSSJanus::transform( $style, true, false );
00092                         }
00093                         return array( 'all' => $style );
00094                 }
00095                 return array();
00096         }
00097 
00101         public function getGroup() {
00102                 return 'private';
00103         }
00104 
00108         public function getDependencies() {
00109                 return array( 'mediawiki.user' );
00110         }
00111 }