From: Timo Tijhof Date: Wed, 5 Dec 2012 07:37:48 +0000 (+0100) Subject: ResourceLoader: Move safeFilemtime() to ResourceLoaderModule. X-Git-Tag: 1.31.0-rc.0~21279^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=799db0b44bc4b1d5212d802016789d8cf77bcc54;p=lhc%2Fweb%2Fwiklou.git ResourceLoader: Move safeFilemtime() to ResourceLoaderModule. This is a useful method not just for inside and sub classes of ResourceLoaderFileModule (i.e. it could've been useful in VisualEditor's ResourceLoaderModule class as well) Also moved up getTargets() to be in the right section (looking at the file as a whole). Change-Id: If696ffbdc5aa7f0a51603bcf9d52adab38b9c686 --- diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index ffa3046711..08e1620cf6 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -649,23 +649,6 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { ); } - /** - * 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 - */ - 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; - } - } - /** * Get whether CSS for this module should be flipped * @param $context ResourceLoaderContext diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index 0e170fbd97..b3e1f93083 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -289,6 +289,16 @@ abstract class ResourceLoaderModule { return array(); } + /** + * Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'] + * Default implementation hardcodes 'desktop'. + * + * @return array of strings + */ + public function getTargets() { + return array( 'desktop' ); + } + /** * Get the files this module depends on indirectly for a given skin. * Currently these are only image files referenced by the module's CSS. @@ -451,12 +461,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; + } } }