fix some spacing
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index 8fec0d6..2b83110 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();
@@ -77,7 +78,7 @@ abstract class ResourceLoaderModule {
        }
 
        /**
-        * Set this module's name. This is called by ResourceLodaer::register()
+        * 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
@@ -91,7 +92,7 @@ abstract class ResourceLoaderModule {
         * with ResourceLoader::register()
         *
         * @return Int ResourceLoaderModule class constant, the subclass default
-        *     if not set manuall
+        *     if not set manually
         */
        public function getOrigin() {
                return $this->origin;
@@ -289,6 +290,15 @@ 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.
@@ -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 $filename string 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;
+               }
        }
 }