r71937 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71936‎ | r71937 | r71938 >
Date:10:45, 30 August 2010
Author:mkroetzsch
Status:ok
Tags:
Comment:
Remove option to set mainlabel parameter of queries using "|label" in query conditions.
This option was a relict from SMW <1.0 and has not been in the user documentation since then.
We now separate query condition and formatting parameters more cleanly.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php
@@ -17,7 +17,6 @@
1818 protected $m_sepstack; // list of open blocks ("parentheses") that need closing at current step
1919 protected $m_curstring; // remaining string to be parsed (parsing eats query string from the front)
2020 protected $m_errors; // empty array if all went right, array of strings otherwise
21 - protected $m_label; // label of the main query result
2221 protected $m_defaultns; // description of the default namespace restriction, or NULL if not used
2322
2423 protected $m_categoryprefix; // cache label of category namespace . ':'
@@ -58,11 +57,10 @@
5958 wfProfileIn( 'SMWQueryParser::getQueryDescription (SMW)' );
6059
6160 $this->m_errors = array();
62 - $this->m_label = '';
6361 $this->m_curstring = $querystring;
6462 $this->m_sepstack = array();
6563 $setNS = false;
66 - $result = $this->getSubqueryDescription( $setNS, $this->m_label );
 64+ $result = $this->getSubqueryDescription( $setNS );
6765
6866 if ( !$setNS ) { // add default namespaces if applicable
6967 $result = $this->addDescription( $this->m_defaultns, $result );
@@ -96,15 +94,6 @@
9795 }
9896
9997 /**
100 - * Return label for the results of this query (which
101 - * might be empty if no such information was passed).
102 - */
103 - public function getLabel() {
104 - return $this->m_label;
105 - }
106 -
107 -
108 - /**
10998 * Compute an SMWDescription for current part of a query, which should
11099 * be a standalone query (the main query or a subquery enclosed within
111100 * "\<q\>...\</q\>". Recursively calls similar methods and returns NULL upon error.
@@ -124,12 +113,10 @@
125114 * Note that $setNS is no means to switch on or off default namespaces in general,
126115 * but just controls query generation. For general effect, the default namespaces
127116 * should be set to NULL.
128 - *
129 - * The call-by-ref parameter $label is used to append any label strings found.
130117 *
131118 * @return SMWDescription or null
132119 */
133 - protected function getSubqueryDescription( &$setNS, &$label ) {
 120+ protected function getSubqueryDescription( &$setNS ) {
134121 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
135122
136123 $conjunction = null; // used for the current inner conjunction
@@ -144,14 +131,14 @@
145132
146133 switch ( $chunk ) {
147134 case '[[': // start new link block
148 - $ld = $this->getLinkDescription( $setsubNS, $label );
 135+ $ld = $this->getLinkDescription( $setsubNS );
149136 if ( $ld !== null ) {
150137 $conjunction = $this->addDescription( $conjunction, $ld );
151138 }
152139 break;
153140 case '<q>': // enter new subquery, currently irrelevant but possible
154141 $this->pushDelimiter( '</q>' );
155 - $conjunction = $this->addDescription( $conjunction, $this->getSubqueryDescription( $setsubNS, $label ) );
 142+ $conjunction = $this->addDescription( $conjunction, $this->getSubqueryDescription( $setsubNS ) );
156143 break;
157144 case 'OR': case '||': case '': case '</q>': // finish disjunction and maybe subquery
158145 if ( $this->m_defaultns !== null ) { // possibly add namespace restrictions
@@ -231,29 +218,28 @@
232219 * Compute an SMWDescription for current part of a query, which should
233220 * be the content of "[[ ... ]]". Returns NULL upon error.
234221 *
235 - * Parameters $setNS and $label have the same use as in getSubqueryDescription().
 222+ * Parameters $setNS has the same use as in getSubqueryDescription().
236223 */
237 - protected function getLinkDescription( &$setNS, &$label ) {
 224+ protected function getLinkDescription( &$setNS ) {
238225 // This method is called when we encountered an opening '[['. The following
239226 // block could be a Category-statement, fixed object, or property statement.
240227 $chunk = $this->readChunk( '', true, false ); // NOTE: untrimmed, initial " " escapes prop. chains
241228
242229 if ( ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) || // category statement or
243230 ( smwfNormalTitleText( $chunk ) == $this->m_conceptprefix ) ) { // concept statement
244 - return $this->getClassDescription( $setNS, $label,
245 - ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) );
 231+ return $this->getClassDescription( $setNS, ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) );
246232 } else { // fixed subject, namespace restriction, property query, or subquery
247233 $sep = $this->readChunk( '', false ); // do not consume hit, "look ahead"
248234
249235 if ( ( $sep == '::' ) || ( $sep == ':=' ) ) {
250236 if ( $chunk { 0 } != ':' ) { // property statement
251 - return $this->getPropertyDescription( $chunk, $setNS, $label );
 237+ return $this->getPropertyDescription( $chunk, $setNS );
252238 } else { // escaped article description, read part after :: to get full contents
253239 $chunk .= $this->readChunk( '\[\[|\]\]|\|\||\|' );
254 - return $this->getArticleDescription( trim( $chunk ), $setNS, $label );
 240+ return $this->getArticleDescription( trim( $chunk ), $setNS );
255241 }
256242 } else { // Fixed article/namespace restriction. $sep should be ]] or ||
257 - return $this->getArticleDescription( trim( $chunk ), $setNS, $label );
 243+ return $this->getArticleDescription( trim( $chunk ), $setNS );
258244 }
259245 }
260246 }
@@ -263,7 +249,7 @@
264250 * is in between "[[Category:" and the closing "]]" and create a
265251 * suitable description.
266252 */
267 - protected function getClassDescription( &$setNS, &$label, $category = true ) {
 253+ protected function getClassDescription( &$setNS, $category = true ) {
268254 // note: no subqueries allowed here, inline disjunction allowed, wildcards allowed
269255 $result = null;
270256 $continue = true;
@@ -286,7 +272,7 @@
287273 $continue = ( $chunk == '||' ) && $category; // disjunctions only for cateories
288274 }
289275
290 - return $this->finishLinkDescription( $chunk, false, $result, $setNS, $label );
 276+ return $this->finishLinkDescription( $chunk, false, $result, $setNS );
291277 }
292278
293279 /**
@@ -295,7 +281,7 @@
296282 * suitable description. The "::" is the first chunk on the current
297283 * string.
298284 */
299 - protected function getPropertyDescription( $propertyname, &$setNS, &$label ) {
 285+ protected function getPropertyDescription( $propertyname, &$setNS ) {
300286 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
301287 $this->readChunk(); // consume separator ":=" or "::"
302288
@@ -343,8 +329,7 @@
344330 if ( ( $typeid == '_wpg' ) || $inverse ) {
345331 $this->pushDelimiter( '</q>' );
346332 $setsubNS = true;
347 - $sublabel = '';
348 - $innerdesc = $this->addDescription( $innerdesc, $this->getSubqueryDescription( $setsubNS, $sublabel ), false );
 333+ $innerdesc = $this->addDescription( $innerdesc, $this->getSubqueryDescription( $setsubNS ), false );
349334 } else { // no subqueries allowed for non-pages
350335 $this->m_errors[] = wfMsgForContent( 'smw_valuesubquery', end( $propertynames ) );
351336 $innerdesc = $this->addDescription( $innerdesc, new SMWThingDescription(), false );
@@ -403,7 +388,7 @@
404389
405390 $result = $innerdesc;
406391
407 - return $this->finishLinkDescription( $chunk, false, $result, $setNS, $label );
 392+ return $this->finishLinkDescription( $chunk, false, $result, $setNS );
408393 }
409394
410395 /**
@@ -413,7 +398,7 @@
414399 * The first chunk behind the "[[" has already been read and is
415400 * passed as a parameter.
416401 */
417 - protected function getArticleDescription( $firstchunk, &$setNS, &$label ) {
 402+ protected function getArticleDescription( $firstchunk, &$setNS ) {
418403 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
419404
420405 $chunk = $firstchunk;
@@ -457,10 +442,10 @@
458443 }
459444 }
460445
461 - return $this->finishLinkDescription( $chunk, true, $result, $setNS, $label );
 446+ return $this->finishLinkDescription( $chunk, true, $result, $setNS );
462447 }
463448
464 - protected function finishLinkDescription( $chunk, $hasNamespaces, $result, &$setNS, &$label ) {
 449+ protected function finishLinkDescription( $chunk, $hasNamespaces, $result, &$setNS ) {
465450 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
466451
467452 if ( $result === null ) { // no useful information or concrete error found
@@ -472,22 +457,21 @@
473458
474459 $setNS = $hasNamespaces;
475460
476 - // terminate link (assuming that next chunk was read already)
477 - if ( $chunk == '|' ) {
 461+ if ( $chunk == '|' ) { // skip content after single |, but report a warning
 462+ // Note: Using "|label" in query atoms used to be a way to set the mainlabel in SMW <1.0; no longer supported now
478463 $chunk = $this->readChunk( '\]\]' );
479 -
 464+ $labelpart = '|';
480465 if ( $chunk != ']]' ) {
481 - $label .= $chunk;
 466+ $labelpart .= $chunk;
482467 $chunk = $this->readChunk( '\]\]' );
483 - } else { // empty label does not add to overall label
484 - $chunk = ']]';
485468 }
 469+ $this->m_errors[] = wfMsgForContent( 'smw_unexpectedpart', htmlspecialchars( $labelpart ) );
486470 }
487471
488472 if ( $chunk != ']]' ) {
489473 // What happended? We found some chunk that could not be processed as
490 - // link content (as in [[Category:Test<q>]]) and there was no label to
491 - // eat it. Or the closing ]] are just missing entirely.
 474+ // link content (as in [[Category:Test<q>]]), or the closing ]] are
 475+ // just missing entirely.
492476 if ( $chunk != '' ) {
493477 $this->m_errors[] = wfMsgForContent( 'smw_misplacedsymbol', htmlspecialchars( $chunk ) );
494478
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -59,11 +59,7 @@
6060 $querymode = $printer->getQueryMode( $context );
6161 }
6262
63 - if ( array_key_exists( 'mainlabel', $params ) ) {
64 - $mainlabel = $params['mainlabel'] . $qp->getLabel();
65 - } else {
66 - $mainlabel = $qp->getLabel();
67 - }
 63+ $mainlabel = array_key_exists( 'mainlabel', $params ) ? $params['mainlabel'] : '';
6864
6965 if ( ( $querymode == SMWQuery::MODE_NONE ) ||
7066 ( ( !$desc->isSingleton() ||

Status & tagging log