Merge "Add rc_name_type_patrolled_timestamp index"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderFileModule.php
index 1e7329a..2816126 100644 (file)
@@ -255,6 +255,9 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                                                $this->{$member}[$key] = (array)$value;
                                        }
                                        break;
+                               case 'deprecated':
+                                       $this->deprecated = $option;
+                                       break;
                                // Lists of strings
                                case 'dependencies':
                                case 'messages':
@@ -352,7 +355,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         */
        public function getScript( ResourceLoaderContext $context ) {
                $files = $this->getScriptFiles( $context );
-               return $this->readScriptFiles( $files );
+               return $this->getDeprecationInformation() . $this->readScriptFiles( $files );
        }
 
        /**
@@ -468,7 +471,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                if ( !file_exists( $localPath ) ) {
                        throw new MWException( __METHOD__ . ": skip function file not found: \"$localPath\"" );
                }
-               $contents = file_get_contents( $localPath );
+               $contents = $this->stripBom( file_get_contents( $localPath ) );
                if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
                        $contents = $this->validateScriptFile( $localPath, $contents );
                }
@@ -810,7 +813,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        if ( !file_exists( $localPath ) ) {
                                throw new MWException( __METHOD__ . ": script file not found: \"$localPath\"" );
                        }
-                       $contents = file_get_contents( $localPath );
+                       $contents = $this->stripBom( file_get_contents( $localPath ) );
                        if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
                                // Static files don't really need to be checked as often; unlike
                                // on-wiki module they shouldn't change unexpectedly without
@@ -882,7 +885,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        $style = $this->compileLessFile( $localPath, $context );
                        $this->hasGeneratedStyles = true;
                } else {
-                       $style = file_get_contents( $localPath );
+                       $style = $this->stripBom( file_get_contents( $localPath ) );
                }
 
                if ( $flip ) {
@@ -922,6 +925,28 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                return $this->targets;
        }
 
+       /**
+        * Get the module's load type.
+        *
+        * @since 1.28
+        * @return string
+        */
+       public function getType() {
+               $canBeStylesOnly = !(
+                       // All options except 'styles', 'skinStyles' and 'debugRaw'
+                       $this->scripts
+                       || $this->debugScripts
+                       || $this->templates
+                       || $this->languageScripts
+                       || $this->skinScripts
+                       || $this->dependencies
+                       || $this->messages
+                       || $this->skipFunction
+                       || $this->raw
+               );
+               return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
+       }
+
        /**
         * Compile a LESS file into CSS.
         *
@@ -990,7 +1015,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        $localPath = $this->getLocalPath( $templatePath );
                        if ( file_exists( $localPath ) ) {
                                $content = file_get_contents( $localPath );
-                               $templates[$alias] = $content;
+                               $templates[$alias] = $this->stripBom( $content );
                        } else {
                                $msg = __METHOD__ . ": template file not found: \"$localPath\"";
                                wfDebugLog( 'resourceloader', $msg );
@@ -999,4 +1024,20 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                }
                return $templates;
        }
+
+       /**
+        * Takes an input string and removes the UTF-8 BOM character if present
+        *
+        * We need to remove these after reading a file, because we concatenate our files and
+        * the BOM character is not valid in the middle of a string.
+        * We already assume UTF-8 everywhere, so this should be safe.
+        *
+        * @return string input minus the intial BOM char
+        */
+       protected function stripBom( $input ) {
+               if ( substr_compare( "\xef\xbb\xbf", $input, 0, 3 ) === 0 ) {
+                       return substr( $input, 3 );
+               }
+               return $input;
+       }
 }