r85269 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85268‎ | r85269 | r85270 >
Date:19:36, 3 April 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r85213
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php
@@ -76,6 +76,8 @@
7777 /// This can be set in LocalSettings.php, but only after enableSemantics().
7878 public static $maxRecursionDepth = 2;
7979
 80+ protected $useValidator;
 81+
8082 /**
8183 * Return serialised results in specified format.
8284 * Implemented by subclasses.
@@ -85,14 +87,19 @@
8688 /**
8789 * Constructor. The parameter $format is a format string
8890 * that may influence the processing details.
 91+ *
 92+ * @param string $format
 93+ * @param $inline
 94+ * @param boolean $useValidator Since 1.6
8995 */
90 - public function __construct( $format, $inline ) {
 96+ public function __construct( $format, $inline, $useValidator = false ) {
9197 global $smwgQDefaultLinking;
9298 $this->mFormat = $format;
9399 $this->mInline = $inline;
94100 $this->mLinkFirst = ( $smwgQDefaultLinking != 'none' );
95101 $this->mLinkOthers = ( $smwgQDefaultLinking == 'all' );
96102 $this->mLinker = new Linker(); ///TODO: how can we get the default or user skin here (depending on context)?
 103+ $this->useValidator = $useValidator;
97104 }
98105
99106 /**
@@ -131,6 +138,11 @@
132139
133140 $this->isHTML = false;
134141 $this->hasTemplates = false;
 142+
 143+ if ( $this->useValidator ) {
 144+ $params = $this->handleParameters( $params );
 145+ }
 146+
135147 $this->readParameters( $params, $outputmode );
136148
137149 // Default output for normal printers:
@@ -163,10 +175,14 @@
164176 // Get output from printer:
165177 $result = $this->getResultText( $results, $outputmode );
166178
167 - if ( $outputmode == SMW_OUTPUT_FILE ) { // just return result in file mode
168 - return $result;
 179+ if ( $outputmode != SMW_OUTPUT_FILE ) {
 180+ $result = $this->handleNonFileResult( $result );
169181 }
170 -
 182+
 183+ return $result;
 184+ }
 185+
 186+ protected function handleNonFileResult( $result ) {
171187 $result .= $this->getErrorString( $results ); // append errors
172188
173189 if ( ( !$this->isHTML ) && ( $this->hasTemplates ) ) { // preprocess embedded templates if needed
@@ -230,10 +246,33 @@
231247 }
232248 }
233249
234 - return $result;
 250+ return $result;
235251 }
236252
237253 /**
 254+ * Handles the user-provided parameters and returns the processes key-value pairs.
 255+ *
 256+ * @since 1.6
 257+ *
 258+ * @param array $keyValuePairs
 259+ *
 260+ * @return array
 261+ */
 262+ protected function handleParameters( array $keyValuePairs ) {
 263+ $validator = new Validator();
 264+ $validator->setParameters( $keyValuePairs, $this->getParameters() );
 265+ $validator->validateParameters();
 266+
 267+ if ( $validator->hasFatalError() ) {
 268+ // TODO
 269+ throw new Exception( 'Validator: fatal param validation error' );
 270+ }
 271+ else {
 272+ return $validator->getParameterValues();
 273+ }
 274+ }
 275+
 276+ /**
238277 * Read an array of parameter values given as key-value-pairs and
239278 * initialise internal member fields accordingly. Possibly overwritten
240279 * (extended) by subclasses.

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85213some preliminary work on switching the query printers to use validator, the s...jeroendedauw21:51, 2 April 2011

Status & tagging log