phpcs: Pass includes/resourceloader/
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index 0e170fb..f6a7114 100644 (file)
@@ -58,6 +58,7 @@ abstract class ResourceLoaderModule {
        /* Protected Members */
 
        protected $name = null;
+       protected $targets = array( 'desktop' );
 
        // In-object cache for file dependencies
        protected $fileDeps = array();
@@ -80,7 +81,7 @@ abstract class ResourceLoaderModule {
         * Set this module's name. This is called by ResourceLoader::register()
         * when registering the module. Other code should not call this.
         *
-        * @param $name String: Name
+        * @param string $name Name
         */
        public function setName( $name ) {
                $this->name = $name;
@@ -98,10 +99,10 @@ abstract class ResourceLoaderModule {
        }
 
        /**
-        * Set this module's origin. This is called by ResourceLodaer::register()
+        * Set this module's origin. This is called by ResourceLoader::register()
         * when registering the module. Other code should not call this.
         *
-        * @param $origin Int origin
+        * @param int $origin origin
         */
        public function setOrigin( $origin ) {
                $this->origin = $origin;
@@ -289,11 +290,20 @@ abstract class ResourceLoaderModule {
                return array();
        }
 
+       /**
+        * Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile']
+        *
+        * @return array of strings
+        */
+       public function getTargets() {
+               return $this->targets;
+       }
+
        /**
         * Get the files this module depends on indirectly for a given skin.
         * Currently these are only image files referenced by the module's CSS.
         *
-        * @param $skin String: Skin name
+        * @param string $skin Skin name
         * @return Array: List of files
         */
        public function getFileDependencies( $skin ) {
@@ -309,7 +319,7 @@ abstract class ResourceLoaderModule {
                        ), __METHOD__
                );
                if ( !is_null( $deps ) ) {
-                       $this->fileDeps[$skin] = (array) FormatJson::decode( $deps, true );
+                       $this->fileDeps[$skin] = (array)FormatJson::decode( $deps, true );
                } else {
                        $this->fileDeps[$skin] = array();
                }
@@ -319,8 +329,8 @@ abstract class ResourceLoaderModule {
        /**
         * Set preloaded file dependency information. Used so we can load this
         * information for all modules at once.
-        * @param $skin String: Skin name
-        * @param $deps Array: Array of file names
+        * @param string $skin Skin name
+        * @param array $deps Array of file names
         */
        public function setFileDependencies( $skin, $deps ) {
                $this->fileDeps[$skin] = $deps;
@@ -329,7 +339,7 @@ abstract class ResourceLoaderModule {
        /**
         * Get the last modification timestamp of the message blob for this
         * module in a given language.
-        * @param $lang String: Language code
+        * @param string $lang Language code
         * @return Integer: UNIX timestamp, or 0 if the module doesn't have messages
         */
        public function getMsgBlobMtime( $lang ) {
@@ -357,7 +367,7 @@ abstract class ResourceLoaderModule {
        /**
         * Set a preloaded message blob last modification timestamp. Used so we
         * can load this information for all modules at once.
-        * @param $lang String: Language code
+        * @param string $lang Language code
         * @param $mtime Integer: UNIX timestamp or 0 if there is no such blob
         */
        public function setMsgBlobMtime( $lang, $mtime ) {
@@ -398,7 +408,6 @@ abstract class ResourceLoaderModule {
                return false;
        }
 
-
        /** @var JSParser lazy-initialized; use self::javaScriptParser() */
        private static $jsParser;
        private static $parseCacheVersion = 1;
@@ -451,12 +460,19 @@ abstract class ResourceLoaderModule {
        }
 
        /**
-        * Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile']
-        * Default implementation hardcodes 'desktop'.
-        *
-        * @return array of strings
+        * Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist
+        * but returns 1 instead.
+        * @param string $filename File name
+        * @return int UNIX timestamp, or 1 if the file doesn't exist
         */
-       public function getTargets() {
-               return array( 'desktop' );
+       protected static function safeFilemtime( $filename ) {
+               if ( file_exists( $filename ) ) {
+                       return filemtime( $filename );
+               } else {
+                       // We only ever map this function on an array if we're gonna call max() after,
+                       // so return our standard minimum timestamps here. This is 1, not 0, because
+                       // wfTimestamp(0) == NOW
+                       return 1;
+               }
        }
 }