r75306 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75305‎ | r75306 | r75307 >
Date:13:27, 24 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r75295
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/SMW_Settings.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryLanguage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -396,22 +396,18 @@
397397 *
398398 * @param string $value
399399 * @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.
405400 */
406401 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+ }
415409 }
 410+
 411+ $comparator = SMWQueryLanguage::getComparatorFromString( $comparatorString, SMW_CMP_EQ );
416412 }
417413
418414 ///// Get methods /////
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryLanguage.php
@@ -23,6 +23,18 @@
2424 protected static $comparators = array();
2525
2626 /**
 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+ /**
2739 * Gets the SMW_CMP_ for a string comparator, falling back to the
2840 * $defaultComparator when none is found.
2941 *
@@ -54,7 +66,7 @@
5567 if ( $reverseCache === false ) {
5668 $reverseCache = array_reverse( self::$comparators );
5769 }
58 -
 70+
5971 if ( array_key_exists( $comparator, $reverseCache ) ) {
6072 return $reverseCache[$comparator];
6173 }
@@ -78,17 +90,18 @@
7991
8092 $initialized = true;
8193
 94+ // Note: Comparators that contain other comparators at the beginning of the string need to be at beginning of the array.
8295 $comparators = array(
83 - '' => SMW_CMP_EQ,
 96+ '!~' => SMW_CMP_NLKE,
 97+ '<<' => SMW_CMP_LESS,
 98+ '>>' => SMW_CMP_GRTR,
8499 '<' => $smwStrictComparators ? SMW_CMP_LESS : SMW_CMP_LEQ,
85100 '>' => $smwStrictComparators ? SMW_CMP_GRTR : SMW_CMP_GEQ,
86101 '≤' => SMW_CMP_LEQ,
87102 '≥' => SMW_CMP_GEQ,
88103 '!' => SMW_CMP_NEQ,
89104 '~' => SMW_CMP_LIKE,
90 - '!~' => SMW_CMP_NLKE,
91 - '<<' => SMW_CMP_LESS,
92 - '>>' => SMW_CMP_GRTR,
 105+ '' => SMW_CMP_EQ,
93106 );
94107
95108 $allowedComparators = explode( '|', $smwgQComparators );
Index: trunk/extensions/SemanticMediaWiki/SMW_Settings.php
@@ -210,7 +210,7 @@
211211 *
212212 * @var string
213213 */
214 -$smwgQComparators = '<|>|!~|!|~|≤|≥';
 214+$smwgQComparators = '<|>|!~|!|~|≤|≥|<<|>>';
215215
216216 ###
217217 # Sets whether the > and < comparators should be strict or not. If they are strict,

Follow-up revisions

RevisionCommit summaryAuthorDate
r75307follow up to r75306jeroendedauw13:52, 24 October 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r75295Rewrote comparator handling and added strictly strict comparators :)jeroendedauw22:17, 23 October 2010

Status & tagging log