r69625 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69624‎ | r69625 | r69626 >
Date:15:33, 20 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Style improvements
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -132,15 +132,19 @@
133133 public function prune( &$maxsize, &$maxdepth, &$log ) {
134134 if ( ( $maxsize < $this->getSize() ) || ( $maxdepth < $this->getDepth() ) ) {
135135 $log[] = $this->getQueryString();
 136+
136137 $result = new SMWThingDescription();
137138 $result->setPrintRequests( $this->getPrintRequests() );
 139+
138140 return $result;
139141 } else {
140142 $maxsize = $maxsize - $this->getSize();
141143 $maxdepth = $maxdepth - $this->getDepth();
 144+
142145 return $this;
143146 }
144147 }
 148+
145149 }
146150
147151 /**
@@ -154,7 +158,7 @@
155159 class SMWThingDescription extends SMWDescription {
156160
157161 public function getQueryString( $asvalue = false ) {
158 - return $asvalue?'+':'';
 162+ return $asvalue?'+' : '';
159163 }
160164
161165 public function isSingleton() {
@@ -188,6 +192,7 @@
189193 * @ingroup SMWQuery
190194 */
191195 class SMWClassDescription extends SMWDescription {
 196+
192197 protected $m_titles;
193198
194199 public function __construct( $content ) {
@@ -208,6 +213,7 @@
209214
210215 public function getQueryString( $asvalue = false ) {
211216 $first = true;
 217+
212218 foreach ( $this->m_titles as $cat ) {
213219 if ( $first ) {
214220 $result = '[[' . $cat->getPrefixedText();
@@ -216,7 +222,9 @@
217223 $result .= '||' . $cat->getText();
218224 }
219225 }
 226+
220227 $result .= ']]';
 228+
221229 if ( $asvalue ) {
222230 return ' &lt;q&gt;' . $result . '&lt;/q&gt; ';
223231 } else {
@@ -255,9 +263,11 @@
256264 } else {
257265 $result = new SMWClassDescription( array_slice( $this->m_titles, 0, $maxsize ) );
258266 $rest = new SMWClassDescription( array_slice( $this->m_titles, $maxsize ) );
 267+
259268 $log[] = $rest->getQueryString();
260269 $maxsize = 0;
261270 }
 271+
262272 $result->setPrintRequests( $this->getPrintRequests() );
263273 return $result;
264274 }
@@ -272,6 +282,7 @@
273283 * @ingroup SMWQuery
274284 */
275285 class SMWConceptDescription extends SMWDescription {
 286+
276287 protected $m_concept;
277288
278289 public function __construct( Title $concept ) {
@@ -315,6 +326,7 @@
316327 * @ingroup SMWQuery
317328 */
318329 class SMWNamespaceDescription extends SMWDescription {
 330+
319331 protected $m_namespace;
320332
321333 public function __construct( $namespace ) {
@@ -355,6 +367,7 @@
356368 * @ingroup SMWQuery
357369 */
358370 class SMWValueDescription extends SMWDescription {
 371+
359372 protected $m_datavalue;
360373 protected $m_comparator;
361374
@@ -420,6 +433,7 @@
421434 * @ingroup SMWQuery
422435 */
423436 class SMWConjunction extends SMWDescription {
 437+
424438 protected $m_descriptions;
425439
426440 public function __construct( $descriptions = array() ) {
@@ -439,6 +453,7 @@
440454 } else {
441455 $this->m_descriptions[] = $description;
442456 }
 457+
443458 // move print descriptions downwards
444459 ///TODO: This may not be a good solution, since it does modify $description and since it does not react to future changes
445460 $this->m_printreqs = array_merge( $this->m_printreqs, $description->getPrintRequests() );
@@ -448,9 +463,11 @@
449464
450465 public function getQueryString( $asvalue = false ) {
451466 $result = '';
 467+
452468 foreach ( $this->m_descriptions as $desc ) {
453469 $result .= ( $result ? ' ':'' ) . $desc->getQueryString( false );
454470 }
 471+
455472 if ( $result == '' ) {
456473 return $asvalue ? '+':'';
457474 } else { // <q> not needed for stand-alone conjunctions (AND binds stronger than OR)
@@ -464,22 +481,27 @@
465482 return true;
466483 }
467484 }
 485+
468486 return false;
469487 }
470488
471489 public function getSize() {
472490 $size = 0;
 491+
473492 foreach ( $this->m_descriptions as $desc ) {
474493 $size += $desc->getSize();
475494 }
 495+
476496 return $size;
477497 }
478498
479499 public function getDepth() {
480500 $depth = 0;
 501+
481502 foreach ( $this->m_descriptions as $desc ) {
482503 $depth = max( $depth, $desc->getDepth() );
483504 }
 505+
484506 return $depth;
485507 }
486508
@@ -493,9 +515,11 @@
494516
495517 public function getQueryFeatures() {
496518 $result = SMW_CONJUNCTION_QUERY;
 519+
497520 foreach ( $this->m_descriptions as $desc ) {
498521 $result = $result | $desc->getQueryFeatures();
499522 }
 523+
500524 return $result;
501525 }
502526
@@ -504,30 +528,39 @@
505529 $log[] = $this->getQueryString();
506530 return new SMWThingDescription();
507531 }
 532+
508533 $prunelog = array();
509534 $newdepth = $maxdepth;
510535 $result = new SMWConjunction();
 536+
511537 foreach ( $this->m_descriptions as $desc ) {
512538 $restdepth = $maxdepth;
513539 $result->addDescription( $desc->prune( $maxsize, $restdepth, $prunelog ) );
514540 $newdepth = min( $newdepth, $restdepth );
515541 }
 542+
516543 if ( count( $result->getDescriptions() ) > 0 ) {
517544 $log = array_merge( $log, $prunelog );
518545 $maxdepth = $newdepth;
 546+
519547 if ( count( $result->getDescriptions() ) == 1 ) { // simplify unary conjunctions!
520548 $descriptions = $result->getDescriptions();
521549 $result = array_shift( $descriptions );
522550 }
 551+
523552 $result->setPrintRequests( $this->getPrintRequests() );
 553+
524554 return $result;
525555 } else {
526556 $log[] = $this->getQueryString();
 557+
527558 $result = new SMWThingDescription();
528559 $result->setPrintRequests( $this->getPrintRequests() );
 560+
529561 return $result;
530562 }
531563 }
 564+
532565 }
533566
534567 /**
@@ -559,6 +592,7 @@
560593 $this->m_descriptions = array(); // no conditions any more
561594 $this->m_classdesc = null;
562595 }
 596+
563597 if ( !$this->m_true ) {
564598 if ( $description instanceof SMWClassDescription ) { // combine class descriptions
565599 if ( $this->m_classdesc === null ) { // first class description
@@ -577,6 +611,7 @@
578612 $this->m_descriptions[] = $description;
579613 }
580614 }
 615+
581616 // move print descriptions downwards
582617 ///TODO: This may not be a good solution, since it does modify $description and since it does not react to future cahges
583618 $this->m_printreqs = array_merge( $this->m_printreqs, $description->getPrintRequests() );
@@ -587,10 +622,13 @@
588623 if ( $this->m_true ) {
589624 return '+';
590625 }
 626+
591627 $result = '';
592628 $sep = $asvalue ? '||':' OR ';
 629+
593630 foreach ( $this->m_descriptions as $desc ) {
594631 $subdesc = $desc->getQueryString( $asvalue );
 632+
595633 if ( $desc instanceof SMWSomeProperty ) { // enclose in <q> for parsing
596634 if ( $asvalue ) {
597635 $subdesc = ' &lt;q&gt;[[' . $subdesc . ']]&lt;/q&gt; ';
@@ -598,6 +636,7 @@
599637 $subdesc = ' &lt;q&gt;' . $subdesc . '&lt;/q&gt; ';
600638 }
601639 }
 640+
602641 $result .= ( $result ? $sep:'' ) . $subdesc;
603642 }
604643 if ( $asvalue ) {
@@ -618,17 +657,21 @@
619658
620659 public function getSize() {
621660 $size = 0;
 661+
622662 foreach ( $this->m_descriptions as $desc ) {
623663 $size += $desc->getSize();
624664 }
 665+
625666 return $size;
626667 }
627668
628669 public function getDepth() {
629670 $depth = 0;
 671+
630672 foreach ( $this->m_descriptions as $desc ) {
631673 $depth = max( $depth, $desc->getDepth() );
632674 }
 675+
633676 return $depth;
634677 }
635678
@@ -642,9 +685,11 @@
643686
644687 public function getQueryFeatures() {
645688 $result = SMW_DISJUNCTION_QUERY;
 689+
646690 foreach ( $this->m_descriptions as $desc ) {
647691 $result = $result | $desc->getQueryFeatures();
648692 }
 693+
649694 return $result;
650695 }
651696
@@ -653,27 +698,35 @@
654699 $log[] = $this->getQueryString();
655700 return new SMWThingDescription();
656701 }
 702+
657703 $prunelog = array();
658704 $newdepth = $maxdepth;
659705 $result = new SMWDisjunction();
 706+
660707 foreach ( $this->m_descriptions as $desc ) {
661708 $restdepth = $maxdepth;
662709 $result->addDescription( $desc->prune( $maxsize, $restdepth, $prunelog ) );
663710 $newdepth = min( $newdepth, $restdepth );
664711 }
 712+
665713 if ( count( $result->getDescriptions() ) > 0 ) {
666714 $log = array_merge( $log, $prunelog );
667715 $maxdepth = $newdepth;
 716+
668717 if ( count( $result->getDescriptions() ) == 1 ) { // simplify unary disjunctions!
669718 $descriptions = $result->getDescriptions();
670719 $result = array_shift( $descriptions );
671720 }
 721+
672722 $result->setPrintRequests( $this->getPrintRequests() );
 723+
673724 return $result;
674725 } else {
675726 $log[] = $this->getQueryString();
 727+
676728 $result = new SMWThingDescription();
677729 $result->setPrintRequests( $this->getPrintRequests() );
 730+
678731 return $result;
679732 }
680733 }
@@ -689,6 +742,7 @@
690743 * @ingroup SMWQuery
691744 */
692745 class SMWSomeProperty extends SMWDescription {
 746+
693747 protected $m_description;
694748 protected $m_property;
695749
@@ -709,6 +763,7 @@
710764 $subdesc = $this->m_description;
711765 $propertychain = $this->m_property->getWikiValue();
712766 $propertyname = 'loop ...';
 767+
713768 while ( ( $propertyname != '' ) && ( $subdesc instanceof SMWSomeProperty ) ) { // try to use property chain syntax
714769 $propertyname = $subdesc->getProperty()->getWikiValue();
715770 if ( $propertyname != '' ) {
@@ -716,6 +771,7 @@
717772 $subdesc = $subdesc->getDescription();
718773 }
719774 }
 775+
720776 if ( $asvalue ) {
721777 return '&lt;q&gt;[[' . $propertychain . '::' . $subdesc->getQueryString( true ) . ']]&lt;/q&gt;';
722778 } else {
@@ -744,10 +800,14 @@
745801 $log[] = $this->getQueryString();
746802 return new SMWThingDescription();
747803 }
 804+
748805 $maxsize--;
749806 $maxdepth--;
 807+
750808 $result = new SMWSomeProperty( $this->m_property, $this->m_description->prune( $maxsize, $maxdepth, $log ) );
751809 $result->setPrintRequests( $this->getPrintRequests() );
 810+
752811 return $result;
753812 }
 813+
754814 }
\ No newline at end of file

Status & tagging log