r57017 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57016‎ | r57017 | r57018 >
Date:16:01, 28 September 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
simplified query parsing code, printouts no longer supported in query strings
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php
@@ -115,11 +115,9 @@
116116 * The call-by-ref parameter $label is used to append any label strings found.
117117 */
118118 protected function getSubqueryDescription(&$setNS, &$label) {
119 - global $smwgQPrintoutLimit;
120119 wfLoadExtensionMessages('SemanticMediaWiki');
121120 $conjunction = NULL; // used for the current inner conjunction
122121 $disjuncts = array(); // (disjunctive) array of subquery conjunctions
123 - $printrequests = array(); // the printrequests found for this query level
124122 $hasNamespaces = false; // does the current $conjnuction have its own namespace restrictions?
125123 $mustSetNS = $setNS; // must ns restrictions be set? (may become true even if $setNS is false)
126124
@@ -129,9 +127,7 @@
130128 switch ($chunk) {
131129 case '[[': // start new link block
132130 $ld = $this->getLinkDescription($setsubNS, $label);
133 - if ($ld instanceof SMWPrintRequest) {
134 - $printrequests[] = $ld;
135 - } elseif ($ld instanceof SMWDescription) {
 131+ if ($ld !== NULL) {
136132 $conjunction = $this->addDescription($conjunction,$ld);
137133 }
138134 break;
@@ -202,31 +198,18 @@
203199 }
204200 $setNS = $mustSetNS; // NOTE: also false if namespaces were given but no default NS descs are available
205201
206 - $prcount = 0;
207 - foreach ($printrequests as $pr) { // add printrequests
208 - if ($prcount < $smwgQPrintoutLimit) {
209 - $result->addPrintRequest($pr);
210 - $prcount++;
211 - } else {
212 - $this->m_errors[] = wfMsgForContent('smw_overprintoutlimit');
213 - break;
214 - }
215 - }
216202 return $result;
217203 }
218204
219205 /**
220206 * Compute an SMWDescription for current part of a query, which should
221 - * be the content of "[[ ... ]]". Alternatively, if the current syntax
222 - * specifies a print request, return the print request object.
223 - * Returns NULL upon error.
 207+ * be the content of "[[ ... ]]". Returns NULL upon error.
224208 *
225209 * Parameters $setNS and $label have the same use as in getSubqueryDescription().
226210 */
227211 protected function getLinkDescription(&$setNS, &$label) {
228212 // This method is called when we encountered an opening '[['. The following
229 - // block could be a Category-statement, fixed object, property statements,
230 - // or according print statements.
 213+ // block could be a Category-statement, fixed object, or property statement.
231214 $chunk = $this->readChunk('',true,false); // NOTE: untrimmed, initial " " escapes prop. chains
232215 if ( (smwfNormalTitleText($chunk) == $this->m_categoryprefix) || // category statement or
233216 (smwfNormalTitleText($chunk) == $this->m_conceptprefix) ) { // concept statement
@@ -284,12 +267,8 @@
285268 protected function getPropertyDescription($propertyname, &$setNS, &$label) {
286269 wfLoadExtensionMessages('SemanticMediaWiki');
287270 $this->readChunk(); // consume separator ":=" or "::"
288 - // first process property chain syntax (e.g. "property1.property2::value"):
289 - if ($propertyname{0} == ' ') { // escape
290 - $propertynames = array($propertyname);
291 - } else {
292 - $propertynames = explode('.', $propertyname);
293 - }
 271+ // first process property chain syntax (e.g. "property1.property2::value"), escaped by initial " ":
 272+ $propertynames = ($propertyname{0} == ' ')?array($propertyname):explode('.', $propertyname);
294273 $properties = array();
295274 $typeid = '_wpg';
296275 foreach ($propertynames as $name) {
@@ -332,7 +311,7 @@
333312 }
334313 $chunk = $this->readChunk();
335314 break;
336 - default: //normal object value or print statement
 315+ default: //normal object value
337316 // read value(s), possibly with inner [[...]]
338317 $open = 1;
339318 $value = $chunk;
@@ -366,32 +345,12 @@
367346 $dv->acceptQuerySyntax();
368347 $dv->setUserValue($value);
369348 $vl = $dv->getValueList();
370 - $pm = $dv->getPrintModifier();
371 - if ($vl !== NULL) { // prefer conditions over print statements (only one possible right now)
 349+ if ($vl !== NULL) {
372350 $innerdesc = $this->addDescription($innerdesc, $vl, false);
373 - } elseif ($pm !== false) {
374 - if ($chunk == '|') {
375 - $printlabel = $this->readChunk('\]\]');
376 - if ($printlabel != ']]') {
377 - $chunk = $this->readChunk('\]\]');
378 - } else {
379 - $printlabel = '';
380 - $chunk = ']]';
381 - }
382 - } else {
383 - $printlabel = $property->getWikiValue();
384 - }
385 - if ($chunk == ']]') {
386 - return new SMWPrintRequest(SMWPrintRequest::PRINT_PROP, $printlabel, $property, $pm);
387 - } else {
388 - $this->m_errors[] = wfMsgForContent('smw_badprintout');
389 - return NULL;
390 - }
391351 }
392352 } else { // unary value
393353 $comparator = SMW_CMP_EQ;
394 - $printmodifier = '';
395 - SMWQueryParser::prepareValue($value, $comparator, $printmodifier);
 354+ SMWQueryParser::prepareValue($value, $comparator);
396355 $dv = SMWDataValueFactory::newPropertyObjectValue($property, $value);
397356 if (!$dv->isValid()) {
398357 $this->m_errors = $this->m_errors + $dv->getErrors();
@@ -406,11 +365,9 @@
407366 }
408367
409368 if ($innerdesc === NULL) { // make a wildcard search
410 - if ( ($this->m_defaultns !== NULL) && ($typeid == '_wpg') ) {
411 - $innerdesc = $this->addDescription($innerdesc, $this->m_defaultns, false);
412 - } else {
413 - $innerdesc = $this->addDescription($innerdesc, new SMWThingDescription(), false);
414 - }
 369+ $innerdesc = ( ($this->m_defaultns !== NULL) && ($typeid == '_wpg') )?
 370+ $this->addDescription($innerdesc, $this->m_defaultns, false):
 371+ $this->addDescription($innerdesc, new SMWThingDescription(), false);
415372 $this->m_errors[] = wfMsgForContent('smw_propvalueproblem', $property->getWikiValue());
416373 }
417374 $properties = array_reverse($properties);
@@ -423,31 +380,28 @@
424381
425382
426383 /**
427 - * Prepare a single value string, possibly extracting comparators and
428 - * printmodifier. $value is changed to consist only of the remaining
429 - * effective value string, or of "*" for print statements.
 384+ * Prepare a single value string, possibly extracting comparators. $value is
 385+ * changed to consist only of the remaining effective value string (without the
 386+ * comparator).
430387 */
431 - static public function prepareValue(&$value, &$comparator, &$printmodifier) {
 388+ static public function prepareValue(&$value, &$comparator) {
432389 global $smwgQComparators;
433390 $list = preg_split('/^(' . $smwgQComparators . ')/u',$value, 2, PREG_SPLIT_DELIM_CAPTURE);
434391 $comparator = SMW_CMP_EQ;
435 - if (count($list) == 3) { // initial comparator found ($list[1] should be empty)
 392+ if (count($list) == 3) { // initial comparator found ($list[0] should be empty)
 393+ $value = $list[2];
436394 switch ($list[1]) {
437395 case '<':
438396 $comparator = SMW_CMP_LEQ;
439 - $value = $list[2];
440397 break;
441398 case '>':
442399 $comparator = SMW_CMP_GEQ;
443 - $value = $list[2];
444400 break;
445401 case '!':
446402 $comparator = SMW_CMP_NEQ;
447 - $value = $list[2];
448403 break;
449404 case '~':
450405 $comparator = SMW_CMP_LIKE;
451 - $value = $list[2];
452406 break;
453407 //default: not possible
454408 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php
@@ -23,16 +23,12 @@
2424 private $m_type;
2525 /// Should this DV operate on query syntax (special mode for parsing queries in a compatible fashion)
2626 private $m_querysyntax = false;
27 -
 27+ /// Array of comparators as might be found in query strings (based on inputs like >, <, etc.)
2828 private $m_comparators;
29 - private $m_printstatement = false;
30 - private $m_outputmodifiers;
3129
3230 protected function parseUserValue($value) {
3331 $this->m_values = array();
3432 $this->m_comparators = array(); // only for query mode
35 - $this->m_printstatement = false; // only for query mode
36 - $this->m_outputmodifiers = array(); // only for query mode
3733 if ($value == '') {
3834 $this->addError('No values specified.');
3935 return;
@@ -46,15 +42,7 @@
4743 // special handling for supporting query parsing
4844 if ($this->m_querysyntax) {
4945 $comparator = SMW_CMP_EQ;
50 - $printmodifier = '';
51 - SMWQueryParser::prepareValue($values[$vi], $comparator, $printmodifier);
52 - if ($values[$vi] == '*') { // print statement, treat as omission
53 - $this->m_printstatement = true;
54 - $values[$vi] = '';
55 - $printmodifiers[$vi] = $printmodifier;
56 - } else {
57 - $printmodifiers[$vi] = '';
58 - }
 46+ SMWQueryParser::prepareValue($values[$vi], $comparator);
5947 }
6048 // generating the DVs:
6149 if ( (count($values) > $vi) &&
@@ -264,18 +252,6 @@
265253 return $vl;
266254 }
267255
268 - /**
269 - * If in querymode, return all printmodifiers given or false if no print request
270 - * was specified. This requires the input to be given to setUserValue().
271 - * Otherwise bad things will happen.
272 - */
273 - public function getPrintModifier() {
274 - if (!$this->m_printstatement || !$this->m_querysyntax) {
275 - return false;
276 - }
277 - return implode(';', $this->m_outputmodifiers);
278 - }
279 -
280256 public function getExportData() {
281257 if (!$this->isValid()) return NULL;
282258

Status & tagging log