Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php |
— | — | @@ -49,27 +49,38 @@ |
50 | 50 | * Compute an SMWDescription from a query string. Returns whatever descriptions could be |
51 | 51 | * wrestled from the given string (the most general result being SMWThingDescription if |
52 | 52 | * no meaningful condition was extracted). |
| 53 | + * |
| 54 | + * @param string $querystring |
| 55 | + * |
| 56 | + * @return SMWDescription |
53 | 57 | */ |
54 | 58 | public function getQueryDescription( $querystring ) { |
55 | 59 | wfProfileIn( 'SMWQueryParser::getQueryDescription (SMW)' ); |
| 60 | + |
56 | 61 | $this->m_errors = array(); |
57 | 62 | $this->m_label = ''; |
58 | 63 | $this->m_curstring = $querystring; |
59 | 64 | $this->m_sepstack = array(); |
60 | 65 | $setNS = false; |
61 | 66 | $result = $this->getSubqueryDescription( $setNS, $this->m_label ); |
| 67 | + |
62 | 68 | if ( !$setNS ) { // add default namespaces if applicable |
63 | 69 | $result = $this->addDescription( $this->m_defaultns, $result ); |
64 | 70 | } |
| 71 | + |
65 | 72 | if ( $result === null ) { // parsing went wrong, no default namespaces |
66 | 73 | $result = new SMWThingDescription(); |
67 | 74 | } |
| 75 | + |
68 | 76 | wfProfileOut( 'SMWQueryParser::getQueryDescription (SMW)' ); |
| 77 | + |
69 | 78 | return $result; |
70 | 79 | } |
71 | 80 | |
72 | 81 | /** |
73 | 82 | * Return array of error messages (possibly empty). |
| 83 | + * |
| 84 | + * @return array |
74 | 85 | */ |
75 | 86 | public function getErrors() { |
76 | 87 | return $this->m_errors; |
— | — | @@ -77,6 +88,8 @@ |
78 | 89 | |
79 | 90 | /** |
80 | 91 | * Return error message or empty string if no error occurred. |
| 92 | + * |
| 93 | + * @return string |
81 | 94 | */ |
82 | 95 | public function getErrorString() { |
83 | 96 | return smwfEncodeMessages( $this->m_errors ); |
— | — | @@ -113,17 +126,22 @@ |
114 | 127 | * should be set to NULL. |
115 | 128 | * |
116 | 129 | * The call-by-ref parameter $label is used to append any label strings found. |
| 130 | + * |
| 131 | + * @return SMWDescription or null |
117 | 132 | */ |
118 | 133 | protected function getSubqueryDescription( &$setNS, &$label ) { |
119 | 134 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
| 135 | + |
120 | 136 | $conjunction = null; // used for the current inner conjunction |
121 | 137 | $disjuncts = array(); // (disjunctive) array of subquery conjunctions |
122 | 138 | $hasNamespaces = false; // does the current $conjnuction have its own namespace restrictions? |
123 | 139 | $mustSetNS = $setNS; // must ns restrictions be set? (may become true even if $setNS is false) |
124 | 140 | |
125 | 141 | $continue = ( $chunk = $this->readChunk() ) != ''; // skip empty subquery completely, thorwing an error |
| 142 | + |
126 | 143 | while ( $continue ) { |
127 | 144 | $setsubNS = false; |
| 145 | + |
128 | 146 | switch ( $chunk ) { |
129 | 147 | case '[[': // start new link block |
130 | 148 | $ld = $this->getLinkDescription( $setsubNS, $label ); |
— | — | @@ -141,19 +159,23 @@ |
142 | 160 | // add ns restrictions to all earlier conjunctions (all of which did not have them yet) |
143 | 161 | $mustSetNS = true; // enforce NS restrictions from now on |
144 | 162 | $newdisjuncts = array(); |
| 163 | + |
145 | 164 | foreach ( $disjuncts as $conj ) { |
146 | 165 | $newdisjuncts[] = $this->addDescription( $conj, $this->m_defaultns ); |
147 | 166 | } |
| 167 | + |
148 | 168 | $disjuncts = $newdisjuncts; |
149 | 169 | } elseif ( !$hasNamespaces && $mustSetNS ) { |
150 | 170 | // add ns restriction to current result |
151 | 171 | $conjunction = $this->addDescription( $conjunction, $this->m_defaultns ); |
152 | 172 | } |
153 | 173 | } |
| 174 | + |
154 | 175 | $disjuncts[] = $conjunction; |
155 | 176 | // start anew |
156 | 177 | $conjunction = null; |
157 | 178 | $hasNamespaces = false; |
| 179 | + |
158 | 180 | // finish subquery? |
159 | 181 | if ( $chunk == '</q>' ) { |
160 | 182 | if ( $this->popDelimiter( '</q>' ) ) { |
— | — | @@ -172,9 +194,11 @@ |
173 | 195 | $this->m_errors[] = wfMsgForContent( 'smw_unexpectedpart', $chunk ); |
174 | 196 | // return null; // Try to go on, it can only get better ... |
175 | 197 | } |
| 198 | + |
176 | 199 | if ( $setsubNS ) { // namespace restrictions encountered in current conjunct |
177 | 200 | $hasNamespaces = true; |
178 | 201 | } |
| 202 | + |
179 | 203 | if ( $continue ) { // read on only if $continue remained true |
180 | 204 | $chunk = $this->readChunk(); |
181 | 205 | } |
— | — | @@ -182,6 +206,7 @@ |
183 | 207 | |
184 | 208 | if ( count( $disjuncts ) > 0 ) { // make disjunctive result |
185 | 209 | $result = null; |
| 210 | + |
186 | 211 | foreach ( $disjuncts as $d ) { |
187 | 212 | if ( $d === null ) { |
188 | 213 | $this->m_errors[] = wfMsgForContent( 'smw_emptysubquery' ); |
— | — | @@ -196,6 +221,7 @@ |
197 | 222 | $setNS = false; |
198 | 223 | return null; |
199 | 224 | } |
| 225 | + |
200 | 226 | $setNS = $mustSetNS; // NOTE: also false if namespaces were given but no default NS descs are available |
201 | 227 | |
202 | 228 | return $result; |