r71565 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71564‎ | r71565 | r71566 >
Date:15:14, 24 August 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Documentation and style improvements
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php
@@ -49,27 +49,38 @@
5050 * Compute an SMWDescription from a query string. Returns whatever descriptions could be
5151 * wrestled from the given string (the most general result being SMWThingDescription if
5252 * no meaningful condition was extracted).
 53+ *
 54+ * @param string $querystring
 55+ *
 56+ * @return SMWDescription
5357 */
5458 public function getQueryDescription( $querystring ) {
5559 wfProfileIn( 'SMWQueryParser::getQueryDescription (SMW)' );
 60+
5661 $this->m_errors = array();
5762 $this->m_label = '';
5863 $this->m_curstring = $querystring;
5964 $this->m_sepstack = array();
6065 $setNS = false;
6166 $result = $this->getSubqueryDescription( $setNS, $this->m_label );
 67+
6268 if ( !$setNS ) { // add default namespaces if applicable
6369 $result = $this->addDescription( $this->m_defaultns, $result );
6470 }
 71+
6572 if ( $result === null ) { // parsing went wrong, no default namespaces
6673 $result = new SMWThingDescription();
6774 }
 75+
6876 wfProfileOut( 'SMWQueryParser::getQueryDescription (SMW)' );
 77+
6978 return $result;
7079 }
7180
7281 /**
7382 * Return array of error messages (possibly empty).
 83+ *
 84+ * @return array
7485 */
7586 public function getErrors() {
7687 return $this->m_errors;
@@ -77,6 +88,8 @@
7889
7990 /**
8091 * Return error message or empty string if no error occurred.
 92+ *
 93+ * @return string
8194 */
8295 public function getErrorString() {
8396 return smwfEncodeMessages( $this->m_errors );
@@ -113,17 +126,22 @@
114127 * should be set to NULL.
115128 *
116129 * The call-by-ref parameter $label is used to append any label strings found.
 130+ *
 131+ * @return SMWDescription or null
117132 */
118133 protected function getSubqueryDescription( &$setNS, &$label ) {
119134 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 135+
120136 $conjunction = null; // used for the current inner conjunction
121137 $disjuncts = array(); // (disjunctive) array of subquery conjunctions
122138 $hasNamespaces = false; // does the current $conjnuction have its own namespace restrictions?
123139 $mustSetNS = $setNS; // must ns restrictions be set? (may become true even if $setNS is false)
124140
125141 $continue = ( $chunk = $this->readChunk() ) != ''; // skip empty subquery completely, thorwing an error
 142+
126143 while ( $continue ) {
127144 $setsubNS = false;
 145+
128146 switch ( $chunk ) {
129147 case '[[': // start new link block
130148 $ld = $this->getLinkDescription( $setsubNS, $label );
@@ -141,19 +159,23 @@
142160 // add ns restrictions to all earlier conjunctions (all of which did not have them yet)
143161 $mustSetNS = true; // enforce NS restrictions from now on
144162 $newdisjuncts = array();
 163+
145164 foreach ( $disjuncts as $conj ) {
146165 $newdisjuncts[] = $this->addDescription( $conj, $this->m_defaultns );
147166 }
 167+
148168 $disjuncts = $newdisjuncts;
149169 } elseif ( !$hasNamespaces && $mustSetNS ) {
150170 // add ns restriction to current result
151171 $conjunction = $this->addDescription( $conjunction, $this->m_defaultns );
152172 }
153173 }
 174+
154175 $disjuncts[] = $conjunction;
155176 // start anew
156177 $conjunction = null;
157178 $hasNamespaces = false;
 179+
158180 // finish subquery?
159181 if ( $chunk == '</q>' ) {
160182 if ( $this->popDelimiter( '</q>' ) ) {
@@ -172,9 +194,11 @@
173195 $this->m_errors[] = wfMsgForContent( 'smw_unexpectedpart', $chunk );
174196 // return null; // Try to go on, it can only get better ...
175197 }
 198+
176199 if ( $setsubNS ) { // namespace restrictions encountered in current conjunct
177200 $hasNamespaces = true;
178201 }
 202+
179203 if ( $continue ) { // read on only if $continue remained true
180204 $chunk = $this->readChunk();
181205 }
@@ -182,6 +206,7 @@
183207
184208 if ( count( $disjuncts ) > 0 ) { // make disjunctive result
185209 $result = null;
 210+
186211 foreach ( $disjuncts as $d ) {
187212 if ( $d === null ) {
188213 $this->m_errors[] = wfMsgForContent( 'smw_emptysubquery' );
@@ -196,6 +221,7 @@
197222 $setNS = false;
198223 return null;
199224 }
 225+
200226 $setNS = $mustSetNS; // NOTE: also false if namespaces were given but no default NS descs are available
201227
202228 return $result;

Status & tagging log