MediaWiki
REL1_24
|
00001 <?php 00028 class ResourceLoaderEditToolbarModule extends ResourceLoaderFileModule { 00036 private static function cssSerializeString( $value ) { 00037 if ( strstr( $value, "\0" ) ) { 00038 throw new Exception( "Invalid character in CSS string" ); 00039 } 00040 $value = strtr( $value, array( '\\' => '\\\\', '"' => '\\"' ) ); 00041 $value = preg_replace_callback( '/[\x01-\x1f\x7f-\x9f]/', function ( $match ) { 00042 return '\\' . base_convert( ord( $match[0] ), 10, 16 ) . ' '; 00043 }, $value ); 00044 return '"' . $value . '"'; 00045 } 00046 00052 private function getLessVars( ResourceLoaderContext $context ) { 00053 $language = Language::factory( $context->getLanguage() ); 00054 00055 // This is very conveniently formatted and we can pass it right through 00056 $vars = $language->getImageFiles(); 00057 00058 // lessc tries to be helpful and parse our variables as LESS source code 00059 foreach ( $vars as $key => &$value ) { 00060 $value = self::cssSerializeString( $value ); 00061 } 00062 00063 return $vars; 00064 } 00065 00070 public function getModifiedTime( ResourceLoaderContext $context ) { 00071 return max( 00072 parent::getModifiedTime( $context ), 00073 $this->getHashMtime( $context ) 00074 ); 00075 } 00076 00081 public function getModifiedHash( ResourceLoaderContext $context ) { 00082 return md5( 00083 parent::getModifiedHash( $context ) . 00084 serialize( $this->getLessVars( $context ) ) 00085 ); 00086 } 00087 00097 protected function getLessCompiler( ResourceLoaderContext $context = null ) { 00098 $compiler = parent::getLessCompiler(); 00099 $compiler->setVariables( $this->getLessVars( $context ) ); 00100 return $compiler; 00101 } 00102 }