Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php |
— | — | @@ -396,22 +396,18 @@ |
397 | 397 | * |
398 | 398 | * @param string $value |
399 | 399 | * @param string $comparator |
400 | | - * |
401 | | - * TODO: It would be better to have an associative array that maps comparator strings |
402 | | - * to their internal meaning, so this switch and the reverse one in SMWValueDescription |
403 | | - * can be thrown away. This would allow to extend the comparators more easily, without |
404 | | - * breaking things. |
405 | 400 | */ |
406 | 401 | static protected function prepareValue( &$value, &$comparator ) { |
407 | | - global $smwgQComparators, $smwStrictComparators; |
408 | | - |
409 | | - $list = preg_split( '/^(' . $smwgQComparators . ')/u', $value, 2, PREG_SPLIT_DELIM_CAPTURE ); |
410 | | - $comparator = SMW_CMP_EQ; |
411 | | - |
412 | | - if ( count( $list ) == 3 ) { // Initial comparator found ($list[0] should be empty). |
413 | | - $value = $list[2]; |
414 | | - $comparator = SMWQueryLanguage::getComparatorFromString( $list[1], SMW_CMP_EQ ); |
| 402 | + // Loop over the comparators to determine which one is used and what the actual value is. |
| 403 | + foreach ( SMWQueryLanguage::getComparatorStrings() as $srting ) { |
| 404 | + if ( strpos( $value, $srting ) === 0 ) { |
| 405 | + $comparatorString = substr( $value, 0, strlen( $srting ) ); |
| 406 | + $value = substr( $value, strlen( $srting ) ); |
| 407 | + break; |
| 408 | + } |
415 | 409 | } |
| 410 | + |
| 411 | + $comparator = SMWQueryLanguage::getComparatorFromString( $comparatorString, SMW_CMP_EQ ); |
416 | 412 | } |
417 | 413 | |
418 | 414 | ///// Get methods ///// |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryLanguage.php |
— | — | @@ -23,6 +23,18 @@ |
24 | 24 | protected static $comparators = array(); |
25 | 25 | |
26 | 26 | /** |
| 27 | + * Gets an array with all suported comparator strings. |
| 28 | + * |
| 29 | + * @since 1.5.3 |
| 30 | + * |
| 31 | + * @return array |
| 32 | + */ |
| 33 | + public static function getComparatorStrings() { |
| 34 | + self::initializeComparators(); |
| 35 | + return array_keys( self::$comparators ); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
27 | 39 | * Gets the SMW_CMP_ for a string comparator, falling back to the |
28 | 40 | * $defaultComparator when none is found. |
29 | 41 | * |
— | — | @@ -54,7 +66,7 @@ |
55 | 67 | if ( $reverseCache === false ) { |
56 | 68 | $reverseCache = array_reverse( self::$comparators ); |
57 | 69 | } |
58 | | - |
| 70 | + |
59 | 71 | if ( array_key_exists( $comparator, $reverseCache ) ) { |
60 | 72 | return $reverseCache[$comparator]; |
61 | 73 | } |
— | — | @@ -78,17 +90,18 @@ |
79 | 91 | |
80 | 92 | $initialized = true; |
81 | 93 | |
| 94 | + // Note: Comparators that contain other comparators at the beginning of the string need to be at beginning of the array. |
82 | 95 | $comparators = array( |
83 | | - '' => SMW_CMP_EQ, |
| 96 | + '!~' => SMW_CMP_NLKE, |
| 97 | + '<<' => SMW_CMP_LESS, |
| 98 | + '>>' => SMW_CMP_GRTR, |
84 | 99 | '<' => $smwStrictComparators ? SMW_CMP_LESS : SMW_CMP_LEQ, |
85 | 100 | '>' => $smwStrictComparators ? SMW_CMP_GRTR : SMW_CMP_GEQ, |
86 | 101 | '≤' => SMW_CMP_LEQ, |
87 | 102 | '≥' => SMW_CMP_GEQ, |
88 | 103 | '!' => SMW_CMP_NEQ, |
89 | 104 | '~' => SMW_CMP_LIKE, |
90 | | - '!~' => SMW_CMP_NLKE, |
91 | | - '<<' => SMW_CMP_LESS, |
92 | | - '>>' => SMW_CMP_GRTR, |
| 105 | + '' => SMW_CMP_EQ, |
93 | 106 | ); |
94 | 107 | |
95 | 108 | $allowedComparators = explode( '|', $smwgQComparators ); |
Index: trunk/extensions/SemanticMediaWiki/SMW_Settings.php |
— | — | @@ -210,7 +210,7 @@ |
211 | 211 | * |
212 | 212 | * @var string |
213 | 213 | */ |
214 | | -$smwgQComparators = '<|>|!~|!|~|≤|≥'; |
| 214 | +$smwgQComparators = '<|>|!~|!|~|≤|≥|<<|>>'; |
215 | 215 | |
216 | 216 | ### |
217 | 217 | # Sets whether the > and < comparators should be strict or not. If they are strict, |