From: Alexandre Emsenhuber Date: Tue, 18 Mar 2014 08:41:45 +0000 (+0100) Subject: Fix profiling error in LocalisationCache::readJSONFile() X-Git-Tag: 1.31.0-rc.0~16593 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=c4ff5e4b6a772e28b1bc3a1f78766a43301ce950;p=lhc%2Fweb%2Fwiklou.git Fix profiling error in LocalisationCache::readJSONFile() Follow-up I8d137e15e1 (6380e81). Also added more blank lines for better readability. Change-Id: Iae7921b017f81d5512e71384d7999502154c034c --- diff --git a/includes/cache/LocalisationCache.php b/includes/cache/LocalisationCache.php index 409160c5ec..c56111f85e 100644 --- a/includes/cache/LocalisationCache.php +++ b/includes/cache/LocalisationCache.php @@ -541,18 +541,27 @@ class LocalisationCache { */ protected function readJSONFile( $fileName ) { wfProfileIn( __METHOD__ ); + if ( !is_readable( $fileName ) ) { + wfProfileOut( __METHOD__ ); + return array(); } $json = file_get_contents( $fileName ); if ( $json === false ) { + wfProfileOut( __METHOD__ ); + return array(); } + $data = FormatJson::decode( $json, true ); if ( $data === null ) { + wfProfileOut( __METHOD__ ); + throw new MWException( __METHOD__ . ": Invalid JSON file: $fileName" ); } + // Remove keys starting with '@', they're reserved for metadata and non-message data foreach ( $data as $key => $unused ) { if ( $key === '' || $key[0] === '@' ) { @@ -560,6 +569,8 @@ class LocalisationCache { } } + wfProfileOut( __METHOD__ ); + // The JSON format only supports messages, none of the other variables, so wrap the data return array( 'messages' => $data ); }