r71566 MediaWiki - Code Review archive

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

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php
@@ -71,6 +71,12 @@
7272 public static $maxRecursionDepth = 2;
7373
7474 /**
 75+ * Return serialised results in specified format.
 76+ * Implemented by subclasses.
 77+ */
 78+ abstract protected function getResultText( /* SMWQueryResult */ $res, $outputmode );
 79+
 80+ /**
7581 * Constructor. The parameter $format is a format string
7682 * that may influence the processing details.
7783 */
@@ -150,18 +156,23 @@
151157
152158 // Get output from printer:
153159 $result = $this->getResultText( $results, $outputmode );
 160+
154161 if ( $outputmode == SMW_OUTPUT_FILE ) { // just return result in file mode
155162 return $result;
156163 }
 164+
157165 $result .= $this->getErrorString( $results ); // append errors
 166+
158167 if ( ( !$this->isHTML ) && ( $this->hasTemplates ) ) { // preprocess embedded templates if needed
159168 if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) {
160169 SMWResultPrinter::$mRecursionDepth++;
 170+
161171 if ( SMWResultPrinter::$mRecursionDepth <= SMWResultPrinter::$maxRecursionDepth ) { // restrict recursion
162172 $result = '[[SMW::off]]' . $wgParser->replaceVariables( $result ) . '[[SMW::on]]';
163173 } else {
164174 $result = ''; /// TODO: explain problem (too much recursive parses)
165175 }
 176+
166177 SMWResultPrinter::$mRecursionDepth--;
167178 } else { // not during parsing, no preprocessing needed, still protect the result
168179 $result = '[[SMW::off]]' . $result . '[[SMW::on]]';
@@ -172,15 +183,18 @@
173184 $result = array( $result, 'isHTML' => true );
174185 } elseif ( ( !$this->isHTML ) && ( $outputmode == SMW_OUTPUT_HTML ) ) {
175186 SMWResultPrinter::$mRecursionDepth++;
 187+
176188 // check whether we are in an existing parse, or if we should start a new parse for $wgTitle
177189 if ( SMWResultPrinter::$mRecursionDepth <= SMWResultPrinter::$maxRecursionDepth ) { // retrict recursion
178190 if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) {
179191 $result = $wgParser->recursiveTagParse( $result );
180192 } else {
181193 global $wgTitle;
 194+
182195 $popt = new ParserOptions();
183196 $popt->setEditSection( false );
184197 $pout = $wgParser->parse( $result . '__NOTOC__', $wgTitle, $popt );
 198+
185199 /// NOTE: as of MW 1.14SVN, there is apparently no better way to hide the TOC
186200 SMWOutputs::requireFromParserOutput( $pout );
187201 $result = $pout->getText();
@@ -188,6 +202,7 @@
189203 } else {
190204 $result = ''; /// TODO: explain problem (too much recursive parses)
191205 }
 206+
192207 SMWResultPrinter::$mRecursionDepth--;
193208 }
194209
@@ -268,12 +283,6 @@
269284 }
270285
271286 /**
272 - * Return serialised results in specified format.
273 - * Implemented by subclasses.
274 - */
275 - abstract protected function getResultText( /* SMWQueryResult */ $res, $outputmode );
276 -
277 - /**
278287 * Depending on current linking settings, returns a linker object
279288 * for making hyperlinks or NULL if no links should be created.
280289 *
@@ -337,6 +346,8 @@
338347 * refer to messages here. The format name is normally not used in
339348 * wiki text but only in forms etc. hence the user language should be
340349 * used when retrieving messages.
 350+ *
 351+ * @return string
341352 */
342353 public function getName() {
343354 return $this->mFormat;
@@ -346,13 +357,17 @@
347358 * Provides a simple formatted string of all the error messages that occurred.
348359 * Can be used if not specific error formatting is desired. Compatible with HTML
349360 * and Wiki.
 361+ *
 362+ * @return string
350363 */
351364 public function getErrorString( $res ) {
352 - return $this->mShowErrors ? smwfEncodeMessages( $res->getErrors() ):'';
 365+ return $this->mShowErrors ? smwfEncodeMessages( $res->getErrors() ) : '';
353366 }
354367
355368 /**
356369 * Set whether errors should be shown. By default they are.
 370+ *
 371+ * @param boolean $show
357372 */
358373 public function setShowErrors( $show ) {
359374 $this->mShowErrors = $show;
@@ -361,14 +376,18 @@
362377 /**
363378 * If $outputmode is SMW_OUTPUT_HTML, escape special characters occuring in the
364379 * given text. Otherwise return text as is.
 380+ *
 381+ * @return string
365382 */
366383 protected function escapeText( $text, $outputmode ) {
367 - return ( $outputmode == SMW_OUTPUT_HTML ) ? htmlspecialchars( $text ):$text;
 384+ return ( $outputmode == SMW_OUTPUT_HTML ) ? htmlspecialchars( $text ) : $text;
368385 }
369386
370387 /**
371388 * Get the string the user specified as a text for the "further results" link,
372389 * properly escaped for the current output mode.
 390+ *
 391+ * @return string
373392 */
374393 protected function getSearchLabel( $outputmode ) {
375394 return $this->escapeText( $this->mSearchlabel, $outputmode );
@@ -378,6 +397,8 @@
379398 * Check whether a "further results" link would normally be generated for this
380399 * result set with the given parameters. Individual result printers may decide to
381400 * create or hide such a link independent of that, but this is the default.
 401+ *
 402+ * @return boolean
382403 */
383404 protected function linkFurtherResults( $results ) {
384405 return ( $this->mInline && $results->hasFurtherResults() && ( $this->mSearchlabel !== '' ) );
@@ -387,6 +408,10 @@
388409 * Return an array describing the parameters of specifically text-based
389410 * formats, like 'list' and 'table', for use in their getParameters()
390411 * functions
 412+ *
 413+ * @since 1.5.0
 414+ *
 415+ * @return array
391416 */
392417 protected function textDisplayParameters() {
393418 return array(
@@ -399,6 +424,10 @@
400425 /**
401426 * Return an array describing the parameters of the export formats
402427 * like 'rss' and 'csv', for use in their getParameters() functions
 428+ *
 429+ * @since 1.5.0
 430+ *
 431+ * @return array
403432 */
404433 protected function exportFormatParameters() {
405434 return array(
@@ -413,6 +442,10 @@
414443 * A function to describe the allowed parameters of a query using
415444 * any specific format - most query printers should override this
416445 * function
 446+ *
 447+ * @since 1.5.0
 448+ *
 449+ * @return array
417450 */
418451 public function getParameters() {
419452 return array(

Status & tagging log