r68740 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68739‎ | r68740 | r68741 >
Date:20:39, 29 June 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Some random style improvements
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php
@@ -409,4 +409,4 @@
410410 );
411411 }
412412
413 -}
 413+}
\ No newline at end of file
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php
@@ -211,12 +211,14 @@
212212 // This method is called when we encountered an opening '[['. The following
213213 // block could be a Category-statement, fixed object, or property statement.
214214 $chunk = $this->readChunk( '', true, false ); // NOTE: untrimmed, initial " " escapes prop. chains
 215+
215216 if ( ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) || // category statement or
216217 ( smwfNormalTitleText( $chunk ) == $this->m_conceptprefix ) ) { // concept statement
217218 return $this->getClassDescription( $setNS, $label,
218219 ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) );
219220 } else { // fixed subject, namespace restriction, property query, or subquery
220221 $sep = $this->readChunk( '', false ); // do not consume hit, "look ahead"
 222+
221223 if ( ( $sep == '::' ) || ( $sep == ':=' ) ) {
222224 if ( $chunk { 0 } != ':' ) { // property statement
223225 return $this->getPropertyDescription( $chunk, $setNS, $label );
@@ -239,8 +241,10 @@
240242 // note: no subqueries allowed here, inline disjunction allowed, wildcards allowed
241243 $result = null;
242244 $continue = true;
 245+
243246 while ( $continue ) {
244247 $chunk = $this->readChunk();
 248+
245249 if ( $chunk == '+' ) {
246250 // wildcard, ignore for categories (semantically meaningless, everything is in some class)
247251 } else { // assume category/concept title
@@ -251,6 +255,7 @@
252256 $result = $this->addDescription( $result, $desc, false );
253257 }
254258 }
 259+
255260 $chunk = $this->readChunk();
256261 $continue = ( $chunk == '||' ) && $category; // disjunctions only for cateories
257262 }
@@ -267,21 +272,26 @@
268273 protected function getPropertyDescription( $propertyname, &$setNS, &$label ) {
269274 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
270275 $this->readChunk(); // consume separator ":=" or "::"
 276+
271277 // first process property chain syntax (e.g. "property1.property2::value"), escaped by initial " ":
272278 $propertynames = ( $propertyname { 0 } == ' ' ) ? array( $propertyname ):explode( '.', $propertyname );
273279 $properties = array();
274280 $typeid = '_wpg';
275281 $inverse = false;
 282+
276283 foreach ( $propertynames as $name ) {
277284 if ( $typeid != '_wpg' ) { // non-final property in chain was no wikipage: not allowed
278285 $this->m_errors[] = wfMsgForContent( 'smw_valuesubquery', $prevname );
279286 return null; ///TODO: read some more chunks and try to finish [[ ]]
280287 }
 288+
281289 $property = SMWPropertyValue::makeUserProperty( $name );
 290+
282291 if ( !$property->isValid() ) { // illegal property identifier
283292 $this->m_errors = array_merge( $this->m_errors, $property->getErrors() );
284293 return null; ///TODO: read some more chunks and try to finish [[ ]]
285294 }
 295+
286296 $typeid = $property->getPropertyTypeID();
287297 $inverse = $property->isInverse();
288298 $prevname = $name;
@@ -290,8 +300,10 @@
291301
292302 $innerdesc = null;
293303 $continue = true;
 304+
294305 while ( $continue ) {
295306 $chunk = $this->readChunk();
 307+
296308 switch ( $chunk ) {
297309 case '+': // wildcard, add namespaces for page-type properties
298310 if ( ( $this->m_defaultns !== null ) && ( ( $typeid == '_wpg' ) || $inverse ) ) {
@@ -356,11 +368,15 @@
357369 $this->addDescription( $innerdesc, new SMWThingDescription(), false );
358370 $this->m_errors[] = wfMsgForContent( 'smw_propvalueproblem', $property->getWikiValue() );
359371 }
 372+
360373 $properties = array_reverse( $properties );
 374+
361375 foreach ( $properties as $property ) {
362376 $innerdesc = new SMWSomeProperty( $property, $innerdesc );
363377 }
 378+
364379 $result = $innerdesc;
 380+
365381 return $this->finishLinkDescription( $chunk, false, $result, $setNS, $label );
366382 }
367383
@@ -373,33 +389,40 @@
374390 */
375391 protected function getArticleDescription( $firstchunk, &$setNS, &$label ) {
376392 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 393+
377394 $chunk = $firstchunk;
378395 $result = null;
379396 $continue = true;
380397 // $innerdesc = null;
 398+
381399 while ( $continue ) {
382400 if ( $chunk == '<q>' ) { // no subqueries of the form [[<q>...</q>]] (not needed)
383401 $this->m_errors[] = wfMsgForContent( 'smw_misplacedsubquery' );
384402 return null;
385403 }
 404+
386405 $list = preg_split( '/:/', $chunk, 3 ); // ":Category:Foo" "User:bar" ":baz" ":+"
 406+
387407 if ( ( $list[0] == '' ) && ( count( $list ) == 3 ) ) {
388408 $list = array_slice( $list, 1 );
389409 }
390410 if ( ( count( $list ) == 2 ) && ( $list[1] == '+' ) ) { // try namespace restriction
391411 global $wgContLang;
392412 $idx = $wgContLang->getNsIndex( $list[0] );
 413+
393414 if ( $idx !== false ) {
394415 $result = $this->addDescription( $result, new SMWNamespaceDescription( $idx ), false );
395416 }
396417 } else {
397418 $value = SMWDataValueFactory::newTypeIDValue( '_wpg', $chunk );
 419+
398420 if ( $value->isValid() ) {
399421 $result = $this->addDescription( $result, new SMWValueDescription( $value ), false );
400422 }
401423 }
402424
403425 $chunk = $this->readChunk( '\[\[|\]\]|\|\||\|' );
 426+
404427 if ( $chunk == '||' ) {
405428 $chunk = $this->readChunk( '\[\[|\]\]|\|\||\|' );
406429 $continue = true;
@@ -413,17 +436,20 @@
414437
415438 protected function finishLinkDescription( $chunk, $hasNamespaces, $result, &$setNS, &$label ) {
416439 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 440+
417441 if ( $result === null ) { // no useful information or concrete error found
418442 $this->m_errors[] = wfMsgForContent( 'smw_badqueryatom' );
419443 } elseif ( !$hasNamespaces && $setNS && ( $this->m_defaultns !== null ) ) {
420444 $result = $this->addDescription( $result, $this->m_defaultns );
421445 $hasNamespaces = true;
422446 }
 447+
423448 $setNS = $hasNamespaces;
424449
425450 // terminate link (assuming that next chunk was read already)
426451 if ( $chunk == '|' ) {
427452 $chunk = $this->readChunk( '\]\]' );
 453+
428454 if ( $chunk != ']]' ) {
429455 $label .= $chunk;
430456 $chunk = $this->readChunk( '\]\]' );
@@ -431,14 +457,17 @@
432458 $chunk = ']]';
433459 }
434460 }
 461+
435462 if ( $chunk != ']]' ) {
436463 // What happended? We found some chunk that could not be processed as
437464 // link content (as in [[Category:Test<q>]]) and there was no label to
438465 // eat it. Or the closing ]] are just missing entirely.
439466 if ( $chunk != '' ) {
440467 $this->m_errors[] = wfMsgForContent( 'smw_misplacedsymbol', htmlspecialchars( $chunk ) );
 468+
441469 // try to find a later closing ]] to finish this misshaped subpart
442470 $chunk = $this->readChunk( '\]\]' );
 471+
443472 if ( $chunk != ']]' ) {
444473 $chunk = $this->readChunk( '\]\]' );
445474 }
@@ -447,6 +476,7 @@
448477 $this->m_errors[] = wfMsgForContent( 'smw_noclosingbrackets' );
449478 }
450479 }
 480+
451481 return $result;
452482 }
453483
@@ -477,17 +507,20 @@
478508 if ( $consume ) {
479509 $this->m_curstring = '';
480510 }
 511+
481512 return $trim ? trim( $chunks[0] ):$chunks[0];
482513 } elseif ( count( $chunks ) == 3 ) { // this should generally happen if count is not 1
483514 if ( $chunks[0] == '' ) { // string started with delimiter
484515 if ( $consume ) {
485516 $this->m_curstring = $chunks[2];
486517 }
 518+
487519 return $trim ? trim( $chunks[1] ):$chunks[1];
488520 } else {
489521 if ( $consume ) {
490522 $this->m_curstring = $chunks[1] . $chunks[2];
491523 }
 524+
492525 return $trim ? trim( $chunks[0] ):$chunks[0];
493526 }
494527 } else { return false; } // should never happen
@@ -541,10 +574,12 @@
542575 } else {
543576 $allowed = true;
544577 }
 578+
545579 if ( !$allowed ) {
546580 $this->m_errors[] = wfMsgForContent( $notallowedmessage, str_replace( '[', '&#x005B;', $newdesc->getQueryString() ) );
547581 return $curdesc;
548582 }
 583+
549584 if ( $newdesc === null ) {
550585 return $curdesc;
551586 } elseif ( $curdesc === null ) {
@@ -571,4 +606,4 @@
572607 }
573608 }
574609 }
575 -}
 610+}
\ No newline at end of file
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -149,9 +149,9 @@
150150 } elseif ( $format == 'rss' ) { // unsorted RSS: use *descending* default order
151151 ///TODO: the default sort field should be "modification date" (now it is the title, but
152152 ///likely to be overwritten by printouts with label "date").
153 - $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ):'DESC';
 153+ $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ) : 'DESC';
154154 } else { // sort by page title (main column) by default
155 - $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ):'ASC';
 155+ $query->sortkeys[''] = ( current( $orders ) != false ) ? current( $orders ) : 'ASC';
156156 } // TODO: check and report if there are further order statements?
157157
158158 return $query;
@@ -213,7 +213,7 @@
214214 } elseif ( $title->getNamespace() == NS_CATEGORY ) {
215215 $printmode = SMWPrintRequest::PRINT_CCAT;
216216 $data = $title;
217 - $label = $showmode ? '':$title->getText(); // default
 217+ $label = $showmode ? '' : $title->getText(); // default
218218 } // else?
219219 }
220220

Status & tagging log