From: Aaron Schulz Date: Sun, 26 Jun 2011 04:50:24 +0000 (+0000) Subject: Made '^' (XOR) in recCheckCondition() act as a one-hot detector. Before r28805, XOR... X-Git-Tag: 1.31.0-rc.0~29271 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=072ce42b5fdc2dea7cacd7e6a905893248a842ad;p=lhc%2Fweb%2Fwiklou.git Made '^' (XOR) in recCheckCondition() act as a one-hot detector. Before r28805, XOR silently ignored subconds beyond the first two. After r28805, XOR passed iff an odd number of subconds passed. It now passes iff exactly one subcond passes. This should be more intuitive, as I highly doubt anyone using 3+ subconds was doing it correctly before. --- diff --git a/includes/Autopromote.php b/includes/Autopromote.php index bdb2cb066c..2a869edb11 100644 --- a/includes/Autopromote.php +++ b/includes/Autopromote.php @@ -87,7 +87,7 @@ class Autopromote { if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], $validOps ) ) { # Recursive condition - if ( $cond[0] == '&' ) { + if ( $cond[0] == '&' ) { // AND (all conds pass) foreach ( array_slice( $cond, 1 ) as $subcond ) { if ( !self::recCheckCondition( $subcond, $user ) ) { return false; @@ -95,7 +95,7 @@ class Autopromote { } return true; - } elseif ( $cond[0] == '|' ) { + } elseif ( $cond[0] == '|' ) { // OR (at least one cond passes) foreach ( array_slice( $cond, 1 ) as $subcond ) { if ( self::recCheckCondition( $subcond, $user ) ) { return true; @@ -103,18 +103,20 @@ class Autopromote { } return false; - } elseif ( $cond[0] == '^' ) { - $res = null; + } elseif ( $cond[0] == '^' ) { // XOR (exactly one cond passes) + $res = false; foreach ( array_slice( $cond, 1 ) as $subcond ) { - if ( is_null( $res ) ) { - $res = self::recCheckCondition( $subcond, $user ); - } else { - $res = ( $res xor self::recCheckCondition( $subcond, $user ) ); + if ( self::recCheckCondition( $subcond, $user ) ) { + if ( $res ) { + return false; + } else { + $res = true; + } } } return $res; - } elseif ( $cond[0] == '!' ) { + } elseif ( $cond[0] == '!' ) { // NOT (no conds pass) foreach ( array_slice( $cond, 1 ) as $subcond ) { if ( self::recCheckCondition( $subcond, $user ) ) { return false;