Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -76,6 +76,8 @@ |
77 | 77 | /// This can be set in LocalSettings.php, but only after enableSemantics(). |
78 | 78 | public static $maxRecursionDepth = 2; |
79 | 79 | |
| 80 | + protected $useValidator; |
| 81 | + |
80 | 82 | /** |
81 | 83 | * Return serialised results in specified format. |
82 | 84 | * Implemented by subclasses. |
— | — | @@ -85,14 +87,19 @@ |
86 | 88 | /** |
87 | 89 | * Constructor. The parameter $format is a format string |
88 | 90 | * that may influence the processing details. |
| 91 | + * |
| 92 | + * @param string $format |
| 93 | + * @param $inline |
| 94 | + * @param boolean $useValidator Since 1.6 |
89 | 95 | */ |
90 | | - public function __construct( $format, $inline ) { |
| 96 | + public function __construct( $format, $inline, $useValidator = false ) { |
91 | 97 | global $smwgQDefaultLinking; |
92 | 98 | $this->mFormat = $format; |
93 | 99 | $this->mInline = $inline; |
94 | 100 | $this->mLinkFirst = ( $smwgQDefaultLinking != 'none' ); |
95 | 101 | $this->mLinkOthers = ( $smwgQDefaultLinking == 'all' ); |
96 | 102 | $this->mLinker = new Linker(); ///TODO: how can we get the default or user skin here (depending on context)? |
| 103 | + $this->useValidator = $useValidator; |
97 | 104 | } |
98 | 105 | |
99 | 106 | /** |
— | — | @@ -131,6 +138,11 @@ |
132 | 139 | |
133 | 140 | $this->isHTML = false; |
134 | 141 | $this->hasTemplates = false; |
| 142 | + |
| 143 | + if ( $this->useValidator ) { |
| 144 | + $params = $this->handleParameters( $params ); |
| 145 | + } |
| 146 | + |
135 | 147 | $this->readParameters( $params, $outputmode ); |
136 | 148 | |
137 | 149 | // Default output for normal printers: |
— | — | @@ -163,10 +175,14 @@ |
164 | 176 | // Get output from printer: |
165 | 177 | $result = $this->getResultText( $results, $outputmode ); |
166 | 178 | |
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 ); |
169 | 181 | } |
170 | | - |
| 182 | + |
| 183 | + return $result; |
| 184 | + } |
| 185 | + |
| 186 | + protected function handleNonFileResult( $result ) { |
171 | 187 | $result .= $this->getErrorString( $results ); // append errors |
172 | 188 | |
173 | 189 | if ( ( !$this->isHTML ) && ( $this->hasTemplates ) ) { // preprocess embedded templates if needed |
— | — | @@ -230,10 +246,33 @@ |
231 | 247 | } |
232 | 248 | } |
233 | 249 | |
234 | | - return $result; |
| 250 | + return $result; |
235 | 251 | } |
236 | 252 | |
237 | 253 | /** |
| 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 | + /** |
238 | 277 | * Read an array of parameter values given as key-value-pairs and |
239 | 278 | * initialise internal member fields accordingly. Possibly overwritten |
240 | 279 | * (extended) by subclasses. |