r66671 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66670‎ | r66671 | r66672 >
Date:00:19, 20 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 1.5.1 - added support for the !~ (not like) operator
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/SMW_Settings.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -294,15 +294,19 @@
295295 */
296296 static protected function prepareValue( &$value, &$comparator ) {
297297 global $smwgQComparators;
 298+
298299 $list = preg_split( '/^(' . $smwgQComparators . ')/u', $value, 2, PREG_SPLIT_DELIM_CAPTURE );
299300 $comparator = SMW_CMP_EQ;
 301+
300302 if ( count( $list ) == 3 ) { // initial comparator found ($list[0] should be empty)
301303 $value = $list[2];
 304+
302305 switch ( $list[1] ) {
303306 case '<': $comparator = SMW_CMP_LEQ; break;
304307 case '>': $comparator = SMW_CMP_GEQ; break;
305308 case '!': $comparator = SMW_CMP_NEQ; break;
306309 case '~': $comparator = SMW_CMP_LIKE; break;
 310+ case '!~': $comparator = SMW_CMP_NLKE; break;
307311 // default: not possible
308312 }
309313 }
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -378,6 +378,7 @@
379379 case SMW_CMP_GEQ: $comparator = '>'; break;
380380 case SMW_CMP_NEQ: $comparator = '!'; break;
381381 case SMW_CMP_LIKE: $comparator = '~'; break;
 382+ case SMW_CMP_NLKE: $comparator = '!~'; break;
382383 default: case SMW_CMP_EQ:
383384 $comparator = '';
384385 break;
@@ -388,7 +389,7 @@
389390 return '[[' . $comparator . $this->m_datavalue->getWikiValue() . ']]';
390391 }
391392 } else {
392 - return $asvalue ? '+':''; // the else case may result in an error here (query without proper condition)
 393+ return $asvalue ? '+' : ''; // the else case may result in an error here (query without proper condition)
393394 }
394395 }
395396
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
@@ -469,8 +469,9 @@
470470 case SMW_CMP_LEQ: $comp = '<='; break;
471471 case SMW_CMP_GEQ: $comp = '>='; break;
472472 case SMW_CMP_NEQ: $comp = '!='; break;
473 - case SMW_CMP_LIKE:
 473+ case SMW_CMP_LIKE: case SMW_CMP_NLKE:
474474 $comp = ' LIKE ';
 475+ if ( $description->getComparator() == SMW_CMP_NLKE ) $comp = " NOT{$comp}";
475476 $value = str_replace( array( '%', '_', '*', '?' ), array( '\%', '\_', '%', '_' ), $value );
476477 break;
477478 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -47,12 +47,13 @@
4848 define( 'SMW_OUTPUT_WIKI', 2 );
4949 define( 'SMW_OUTPUT_FILE', 3 );
5050
51 -// comparators for datavalues:
52 -define( 'SMW_CMP_EQ', 1 ); // matches only datavalues that are equal to the given value
53 -define( 'SMW_CMP_LEQ', 2 ); // matches only datavalues that are less or equal than the given value
54 -define( 'SMW_CMP_GEQ', 3 ); // matches only datavalues that are greater or equal to the given value
55 -define( 'SMW_CMP_NEQ', 4 ); // matches only datavalues that are unequal to the given value
56 -define( 'SMW_CMP_LIKE', 5 ); // matches only datavalues that are LIKE the given value
 51+// Comparators for datavalues:
 52+define( 'SMW_CMP_EQ', 1 ); // Matches only datavalues that are equal to the given value.
 53+define( 'SMW_CMP_LEQ', 2 ); // Matches only datavalues that are less or equal than the given value.
 54+define( 'SMW_CMP_GEQ', 3 ); // Matches only datavalues that are greater or equal to the given value.
 55+define( 'SMW_CMP_NEQ', 4 ); // Matches only datavalues that are unequal to the given value.
 56+define( 'SMW_CMP_LIKE', 5 ); // Matches only datavalues that are LIKE the given value.
 57+define( 'SMW_CMP_NLKE', 6 ); // Matches only datavalues that are not LIKE the given value.
5758
5859 // constants for date formats (using binary encoding of nine bits: 3 positions x 3 interpretations)
5960 define( 'SMW_MDY', 785 ); // Month-Day-Year
Index: trunk/extensions/SemanticMediaWiki/SMW_Settings.php
@@ -190,11 +190,23 @@
191191 $smwgQDefaultNamespaces = null; // Which namespaces should be searched by default?
192192 // (value NULL switches off default restrictions on searching -- this is faster)
193193 // Example with namespaces: $smwgQDefaultNamespaces = array(NS_MAIN, NS_IMAGE);
194 -$smwgQComparators = '<|>|!|~'; // List of comparator characters supported by queries, separated by '|'
195 - // Available entries: < (smaller than), < (greater than), ! (unequal to),
196 - // ~ (pattern with '*' as wildcard, only for Type:String)
197 - // If unsupported comparators are used, they are treated as part of the queried value
198194
 195+/**
 196+ * List of comparator characters supported by queries, separated by '|', for use in a regex.
 197+ *
 198+ * Available entries:
 199+ * < (smaller than)
 200+ * < (greater than)
 201+ * ! (unequal to)
 202+ * ~ (pattern with '*' as wildcard, only for Type:String)
 203+ * !~ (not a pattern with '*' as wildcard, only for Type:String, need to be placed before ! and ~ to work correctly)
 204+ *
 205+ * If unsupported comparators are used, they are treated as part of the queried value
 206+ *
 207+ * @var string
 208+ */
 209+$smwgQComparators = '<|>|!~|!|~';
 210+
199211 ###
200212 # Further settings for queries. The following settings affect inline queries
201213 # and querying special pages. Essentially they should mirror the kind of

Status & tagging log