r104813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104812‎ | r104813 | r104814 >
Date:00:42, 1 December 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
bug 32732, patch by Van de Bugger, removed a whole load of useless and confusing brackets
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php
@@ -217,45 +217,47 @@
218218 $unclearparts = array();
219219 $prevmatchwasnumber = $matchisnumber = false; // used for looking back; numbers are days/months/years by default but may be re-interpreted if certain further symbols are found
220220 $prevmatchwasdate = $matchisdate = false; // used for ensuring that date parts are in one block
 221+
221222 foreach ( $matches as $match ) {
222223 $prevmatchwasnumber = $matchisnumber;
223224 $prevmatchwasdate = $matchisdate;
224225 $matchisnumber = $matchisdate = false;
 226+
225227 if ( $match == ' ' ) {
226228 $matchisdate = $prevmatchwasdate; // spaces in dates do not end the date
227229 } elseif ( $match == '-' ) { // can only occur separately between date components
228230 $datecomponents[] = $match; // we check later if this makes sense
229231 $matchisdate = true;
230232 } elseif ( is_numeric( $match ) &&
231 - ( $prevmatchwasdate || ( count( $datecomponents ) == 0 ) ) ) {
 233+ ( $prevmatchwasdate || count( $datecomponents ) == 0 ) ) {
232234 $datecomponents[] = $match;
233235 $matchisnumber = true;
234236 $matchisdate = true;
235 - } elseif ( ( $era === false ) && ( in_array( $match, array( 'AD', 'CE' ) ) ) ) {
 237+ } elseif ( $era === false && in_array( $match, array( 'AD', 'CE' ) ) ) {
236238 $era = '+';
237 - } elseif ( ( $era === false ) && ( in_array( $match, array( 'BC', 'BCE' ) ) ) ) {
 239+ } elseif ( $era === false && in_array( $match, array( 'BC', 'BCE' ) ) ) {
238240 $era = '-';
239 - } elseif ( ( $calendarmodel === false ) && ( in_array( $match, array( 'Gr', 'He', 'Jl', 'MJD', 'JD', 'OS' ) ) ) ) {
 241+ } elseif ( $calendarmodel === false && in_array( $match, array( 'Gr', 'He', 'Jl', 'MJD', 'JD', 'OS' ) ) ) {
240242 $calendarmodel = $match;
241 - } elseif ( ( $ampm === false ) && ( ( strtolower( $match ) == 'am' ) || ( strtolower( $match ) == 'pm' ) ) ) {
 243+ } elseif ( $ampm === false && ( strtolower( $match ) === 'am' || strtolower( $match ) === 'pm' ) ) {
242244 $ampm = strtolower( $match );
243 - } elseif ( ( $hours === false ) && ( self::parseTimeString( $match, $hours, $minutes, $seconds, $timeoffset ) ) ) {
 245+ } elseif ( $hours === false && self::parseTimeString( $match, $hours, $minutes, $seconds, $timeoffset ) ) {
244246 // nothing to do
245 - } elseif ( ( $hours === true ) && ( $timezoneoffset === false ) &&
246 - ( array_key_exists( $match, self::$m_tz ) ) ) {
 247+ } elseif ( $hours !== false && $timezoneoffset === false &&
 248+ array_key_exists( $match, self::$m_tz ) ) {
247249 // only accept timezone if time has already been set
248250 $timezoneoffset = self::$m_tz[ $match ];
249 - } elseif ( ( $prevmatchwasnumber ) && ( $hours === false ) && ( $timezoneoffset === false ) &&
250 - ( array_key_exists( $match, self::$m_miltz ) ) &&
251 - ( self::parseMilTimeString( end( $datecomponents ), $hours, $minutes, $seconds ) ) ) {
 251+ } elseif ( $prevmatchwasnumber && $hours === false && $timezoneoffset === false &&
 252+ array_key_exists( $match, self::$m_miltz ) &&
 253+ self::parseMilTimeString( end( $datecomponents ), $hours, $minutes, $seconds ) ) {
252254 // military timezone notation is found after a number -> re-interpret the number as military time
253255 array_pop( $datecomponents );
254256 $timezoneoffset = self::$m_miltz[ $match ];
255 - } elseif ( ( $prevmatchwasdate || ( count( $datecomponents ) == 0 ) ) &&
 257+ } elseif ( ( $prevmatchwasdate || count( $datecomponents ) == 0 ) &&
256258 $this->parseMonthString( $match, $monthname ) ) {
257259 $datecomponents[] = $monthname;
258260 $matchisdate = true;
259 - } elseif ( $prevmatchwasnumber && $prevmatchwasdate && ( in_array( $match, array( 'st', 'nd', 'rd', 'th' ) ) ) ) {
 261+ } elseif ( $prevmatchwasnumber && $prevmatchwasdate && in_array( $match, array( 'st', 'nd', 'rd', 'th' ) ) ) {
260262 $datecomponents[] = 'd' . strval( array_pop( $datecomponents ) ); // must be a day; add standard marker
261263 $matchisdate = true;
262264 } else {
@@ -269,21 +271,24 @@
270272 // debug_zval_dump( $unclearparts );
271273
272274 // Abort if we found unclear or over-specific information:
273 - if ( ( count( $unclearparts ) != 0 ) ||
274 - ( ( $timezoneoffset !== false ) && ( $timeoffset !== false ) ) ) {
 275+ if ( count( $unclearparts ) != 0 ||
 276+ ( $timezoneoffset !== false && $timeoffset !== false ) ) {
275277 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
276278 return false;
277279 }
 280+
278281 $timeoffset = $timeoffset + $timezoneoffset;
279282 // Check if the a.m. and p.m. information is meaningful
280 - if ( ( $ampm !== false ) && ( ( $hours > 12 ) || ( $hours == 0 ) ) ) { // Note: the == 0 check subsumes $hours===false
 283+
 284+ if ( $ampm !== false && ( $hours > 12 || $hours == 0 ) ) { // Note: the == 0 check subsumes $hours===false
281285 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
282286 return false;
283 - } elseif ( ( $ampm == 'am' ) && ( $hours == 12 ) ) {
 287+ } elseif ( $ampm == 'am' && $hours == 12 ) {
284288 $hours = 0;
285 - } elseif ( ( $ampm == 'pm' ) && ( $hours < 12 ) ) {
 289+ } elseif ( $ampm == 'pm' && $hours < 12 ) {
286290 $hours += 12;
287291 }
 292+
288293 return true;
289294 }
290295

Status & tagging log