MediaWiki  REL1_22
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             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(ckb), a:lang(kk-arab), ' .
00075             'a:lang(mzn), a:lang(ps), a:lang(ur) { text-decoration: none; }';
00076         }
00077         if ( $options['justify'] ) {
00078             $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
00079         }
00080         if ( !$options['showtoc'] ) {
00081             $rules[] = "#toc { display: none; }\n";
00082         }
00083         if ( !$options['editsection'] ) {
00084             $rules[] = ".mw-editsection { display: none; }\n";
00085         }
00086         if ( $options['editfont'] !== 'default' ) {
00087             // Double-check that $options['editfont'] consists of safe characters only
00088             if ( preg_match( '/^[a-zA-Z0-9_, -]+$/', $options['editfont'] ) ) {
00089                 $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
00090             }
00091         }
00092         $style = implode( "\n", $rules );
00093         if ( $this->getFlip( $context ) ) {
00094             $style = CSSJanus::transform( $style, true, false );
00095         }
00096         return array( 'all' => $style );
00097     }
00098 
00102     public function getGroup() {
00103         return 'private';
00104     }
00105 
00109     public function getDependencies() {
00110         return array( 'mediawiki.user' );
00111     }
00112 }