r23215 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23214‎ | r23215 | r23216 >
Date:13:04, 22 June 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Parser suport for unit requests in queries.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -2,14 +2,15 @@
33 /**
44 * This file contains a static class for accessing functions to generate and execute
55 * semantic queries and to serialise their results.
6 - *
 6+ *
77 * @author Markus Krötzsch
88 */
9 -
 9+
1010 global $smwgIP;
1111 require_once($smwgIP . '/includes/storage/SMW_Store.php');
1212 require_once($smwgIP . '/includes/SMW_QueryPrinters.php');
1313
 14+
1415 /**
1516 * This hook registers a parser-hook to the current parser.
1617 * Note that parser hooks are something different than MW hooks
@@ -56,6 +57,13 @@
5758 * as a string. Otherwise an object of type SMWQuery is returned.
5859 */
5960 static public function createQuery($querystring, $params, $inline = true) {
 61+ // This should be the proper way of substituting templates in a safe and comprehensive way:
 62+ global $wgTitle;
 63+ $parser = new Parser();
 64+ $parserOptions = new ParserOptions();
 65+ $parser->startExternalParse( $wgTitle, $parserOptions, OT_HTML );
 66+ $querystring = $parser->transformMsg( $querystring, $parserOptions );
 67+
6068 // parse query:
6169 $qp = new SMWQueryParser();
6270 $desc = $qp->getQueryDescription($querystring);
@@ -383,6 +391,13 @@
384392 }
385393 }
386394 // note that at this point, we already read one more chunk behind the value
 395+ $list = preg_split('/^\*/',$value,2);
 396+ if (count($list) == 2) { //hit
 397+ $value = '*';
 398+ $printmodifier = $list[1];
 399+ } else {
 400+ $printmodifier = '';
 401+ }
387402 switch ($value) {
388403 case '*': // print statement
389404 /// TODO: no support for selecting output unit yet
@@ -398,8 +413,7 @@
399414 $label = $att->getText();
400415 }
401416 if ($chunk == ']]') {
402 - $dv = SMWDataValueFactory::newAttributeValue($att->getText());
403 - return new SMWPrintRequest(SMW_PRINT_ATTS, $label, $att, $dv);
 417+ return new SMWPrintRequest(SMW_PRINT_ATTS, $label, $att, $printmodifier);
404418 } else {
405419 $this->m_error = 'Misshaped print statement.'; //TODO: internationalise
406420 return NULL;

Status & tagging log