Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -71,6 +71,12 @@ |
72 | 72 | public static $maxRecursionDepth = 2; |
73 | 73 | |
74 | 74 | /** |
| 75 | + * Return serialised results in specified format. |
| 76 | + * Implemented by subclasses. |
| 77 | + */ |
| 78 | + abstract protected function getResultText( /* SMWQueryResult */ $res, $outputmode ); |
| 79 | + |
| 80 | + /** |
75 | 81 | * Constructor. The parameter $format is a format string |
76 | 82 | * that may influence the processing details. |
77 | 83 | */ |
— | — | @@ -150,18 +156,23 @@ |
151 | 157 | |
152 | 158 | // Get output from printer: |
153 | 159 | $result = $this->getResultText( $results, $outputmode ); |
| 160 | + |
154 | 161 | if ( $outputmode == SMW_OUTPUT_FILE ) { // just return result in file mode |
155 | 162 | return $result; |
156 | 163 | } |
| 164 | + |
157 | 165 | $result .= $this->getErrorString( $results ); // append errors |
| 166 | + |
158 | 167 | if ( ( !$this->isHTML ) && ( $this->hasTemplates ) ) { // preprocess embedded templates if needed |
159 | 168 | if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) { |
160 | 169 | SMWResultPrinter::$mRecursionDepth++; |
| 170 | + |
161 | 171 | if ( SMWResultPrinter::$mRecursionDepth <= SMWResultPrinter::$maxRecursionDepth ) { // restrict recursion |
162 | 172 | $result = '[[SMW::off]]' . $wgParser->replaceVariables( $result ) . '[[SMW::on]]'; |
163 | 173 | } else { |
164 | 174 | $result = ''; /// TODO: explain problem (too much recursive parses) |
165 | 175 | } |
| 176 | + |
166 | 177 | SMWResultPrinter::$mRecursionDepth--; |
167 | 178 | } else { // not during parsing, no preprocessing needed, still protect the result |
168 | 179 | $result = '[[SMW::off]]' . $result . '[[SMW::on]]'; |
— | — | @@ -172,15 +183,18 @@ |
173 | 184 | $result = array( $result, 'isHTML' => true ); |
174 | 185 | } elseif ( ( !$this->isHTML ) && ( $outputmode == SMW_OUTPUT_HTML ) ) { |
175 | 186 | SMWResultPrinter::$mRecursionDepth++; |
| 187 | + |
176 | 188 | // check whether we are in an existing parse, or if we should start a new parse for $wgTitle |
177 | 189 | if ( SMWResultPrinter::$mRecursionDepth <= SMWResultPrinter::$maxRecursionDepth ) { // retrict recursion |
178 | 190 | if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) { |
179 | 191 | $result = $wgParser->recursiveTagParse( $result ); |
180 | 192 | } else { |
181 | 193 | global $wgTitle; |
| 194 | + |
182 | 195 | $popt = new ParserOptions(); |
183 | 196 | $popt->setEditSection( false ); |
184 | 197 | $pout = $wgParser->parse( $result . '__NOTOC__', $wgTitle, $popt ); |
| 198 | + |
185 | 199 | /// NOTE: as of MW 1.14SVN, there is apparently no better way to hide the TOC |
186 | 200 | SMWOutputs::requireFromParserOutput( $pout ); |
187 | 201 | $result = $pout->getText(); |
— | — | @@ -188,6 +202,7 @@ |
189 | 203 | } else { |
190 | 204 | $result = ''; /// TODO: explain problem (too much recursive parses) |
191 | 205 | } |
| 206 | + |
192 | 207 | SMWResultPrinter::$mRecursionDepth--; |
193 | 208 | } |
194 | 209 | |
— | — | @@ -268,12 +283,6 @@ |
269 | 284 | } |
270 | 285 | |
271 | 286 | /** |
272 | | - * Return serialised results in specified format. |
273 | | - * Implemented by subclasses. |
274 | | - */ |
275 | | - abstract protected function getResultText( /* SMWQueryResult */ $res, $outputmode ); |
276 | | - |
277 | | - /** |
278 | 287 | * Depending on current linking settings, returns a linker object |
279 | 288 | * for making hyperlinks or NULL if no links should be created. |
280 | 289 | * |
— | — | @@ -337,6 +346,8 @@ |
338 | 347 | * refer to messages here. The format name is normally not used in |
339 | 348 | * wiki text but only in forms etc. hence the user language should be |
340 | 349 | * used when retrieving messages. |
| 350 | + * |
| 351 | + * @return string |
341 | 352 | */ |
342 | 353 | public function getName() { |
343 | 354 | return $this->mFormat; |
— | — | @@ -346,13 +357,17 @@ |
347 | 358 | * Provides a simple formatted string of all the error messages that occurred. |
348 | 359 | * Can be used if not specific error formatting is desired. Compatible with HTML |
349 | 360 | * and Wiki. |
| 361 | + * |
| 362 | + * @return string |
350 | 363 | */ |
351 | 364 | public function getErrorString( $res ) { |
352 | | - return $this->mShowErrors ? smwfEncodeMessages( $res->getErrors() ):''; |
| 365 | + return $this->mShowErrors ? smwfEncodeMessages( $res->getErrors() ) : ''; |
353 | 366 | } |
354 | 367 | |
355 | 368 | /** |
356 | 369 | * Set whether errors should be shown. By default they are. |
| 370 | + * |
| 371 | + * @param boolean $show |
357 | 372 | */ |
358 | 373 | public function setShowErrors( $show ) { |
359 | 374 | $this->mShowErrors = $show; |
— | — | @@ -361,14 +376,18 @@ |
362 | 377 | /** |
363 | 378 | * If $outputmode is SMW_OUTPUT_HTML, escape special characters occuring in the |
364 | 379 | * given text. Otherwise return text as is. |
| 380 | + * |
| 381 | + * @return string |
365 | 382 | */ |
366 | 383 | protected function escapeText( $text, $outputmode ) { |
367 | | - return ( $outputmode == SMW_OUTPUT_HTML ) ? htmlspecialchars( $text ):$text; |
| 384 | + return ( $outputmode == SMW_OUTPUT_HTML ) ? htmlspecialchars( $text ) : $text; |
368 | 385 | } |
369 | 386 | |
370 | 387 | /** |
371 | 388 | * Get the string the user specified as a text for the "further results" link, |
372 | 389 | * properly escaped for the current output mode. |
| 390 | + * |
| 391 | + * @return string |
373 | 392 | */ |
374 | 393 | protected function getSearchLabel( $outputmode ) { |
375 | 394 | return $this->escapeText( $this->mSearchlabel, $outputmode ); |
— | — | @@ -378,6 +397,8 @@ |
379 | 398 | * Check whether a "further results" link would normally be generated for this |
380 | 399 | * result set with the given parameters. Individual result printers may decide to |
381 | 400 | * create or hide such a link independent of that, but this is the default. |
| 401 | + * |
| 402 | + * @return boolean |
382 | 403 | */ |
383 | 404 | protected function linkFurtherResults( $results ) { |
384 | 405 | return ( $this->mInline && $results->hasFurtherResults() && ( $this->mSearchlabel !== '' ) ); |
— | — | @@ -387,6 +408,10 @@ |
388 | 409 | * Return an array describing the parameters of specifically text-based |
389 | 410 | * formats, like 'list' and 'table', for use in their getParameters() |
390 | 411 | * functions |
| 412 | + * |
| 413 | + * @since 1.5.0 |
| 414 | + * |
| 415 | + * @return array |
391 | 416 | */ |
392 | 417 | protected function textDisplayParameters() { |
393 | 418 | return array( |
— | — | @@ -399,6 +424,10 @@ |
400 | 425 | /** |
401 | 426 | * Return an array describing the parameters of the export formats |
402 | 427 | * like 'rss' and 'csv', for use in their getParameters() functions |
| 428 | + * |
| 429 | + * @since 1.5.0 |
| 430 | + * |
| 431 | + * @return array |
403 | 432 | */ |
404 | 433 | protected function exportFormatParameters() { |
405 | 434 | return array( |
— | — | @@ -413,6 +442,10 @@ |
414 | 443 | * A function to describe the allowed parameters of a query using |
415 | 444 | * any specific format - most query printers should override this |
416 | 445 | * function |
| 446 | + * |
| 447 | + * @since 1.5.0 |
| 448 | + * |
| 449 | + * @return array |
417 | 450 | */ |
418 | 451 | public function getParameters() { |
419 | 452 | return array( |