Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | $querymode = $printer->getQueryMode( $context ); |
57 | 57 | } |
58 | 58 | |
59 | | - $mainlabel = array_key_exists( 'mainlabel', $params ) ? $params['mainlabel'] : ''; |
| 59 | + $mainlabel = array_key_exists( 'mainlabel', $params ) ? $params['mainlabel'] : ''; |
60 | 60 | if ( ( $querymode == SMWQuery::MODE_NONE ) || |
61 | 61 | ( ( !$desc->isSingleton() || ( count( $desc->getPrintRequests() ) + count( $extraprintouts ) == 0 ) ) |
62 | 62 | && ( trim( $mainlabel ) != '-' ) ) ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -1,21 +1,26 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * File with abstract base class for printing query results. |
| 5 | + * |
| 6 | + * @file SMW_QueryPrinter.php |
| 7 | + * @ingroup SMWQuery |
| 8 | + * |
| 9 | + * @licence GNU GPL v2+ |
5 | 10 | * @author Markus Krötzsch |
6 | | - * @file |
7 | | - * @ingroup SMWQuery |
| 11 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
8 | 12 | */ |
9 | 13 | |
10 | | -// constants that define how/if headers should be displayed |
| 14 | +// Constants that define how/if headers should be displayed. |
11 | 15 | define( 'SMW_HEADERS_SHOW', 2 ); |
12 | 16 | define( 'SMW_HEADERS_PLAIN', 1 ); |
13 | | -define( 'SMW_HEADERS_HIDE', 0 ); // used to be "false" hence use "0" to support extensions that still assume this |
| 17 | +define( 'SMW_HEADERS_HIDE', 0 ); // Used to be "false" hence use "0" to support extensions that still assume this. |
14 | 18 | |
15 | 19 | /** |
16 | 20 | * Abstract base class for SMW's novel query printing mechanism. It implements |
17 | 21 | * part of the former functionality of SMWInlineQuery (everything related to |
18 | 22 | * output formatting and the correspoding parameters) and is subclassed by concrete |
19 | 23 | * printers that provide the main formatting functionality. |
| 24 | + * |
20 | 25 | * @ingroup SMWQuery |
21 | 26 | */ |
22 | 27 | abstract class SMWResultPrinter { |
— | — | @@ -140,11 +145,13 @@ |
141 | 146 | $this->hasTemplates = false; |
142 | 147 | |
143 | 148 | if ( $this->useValidator ) { |
144 | | - $params = $this->handleParameters( $params ); |
| 149 | + // TODO: retain behaviour of base readParameters |
| 150 | + $this->handleParameters( $this->handleRawParameters( $params ), $outputmode ); |
145 | 151 | } |
| 152 | + else { |
| 153 | + $this->readParameters( $params, $outputmode ); |
| 154 | + } |
146 | 155 | |
147 | | - $this->readParameters( $params, $outputmode ); |
148 | | - |
149 | 156 | // Default output for normal printers: |
150 | 157 | if ( ( $outputmode != SMW_OUTPUT_FILE ) && // not in FILE context, |
151 | 158 | ( $results->getCount() == 0 ) && // no results, |
— | — | @@ -176,7 +183,7 @@ |
177 | 184 | $result = $this->getResultText( $results, $outputmode ); |
178 | 185 | |
179 | 186 | if ( $outputmode != SMW_OUTPUT_FILE ) { |
180 | | - $result = $this->handleNonFileResult( $result ); |
| 187 | + $result = $this->handleNonFileResult( $result, $results, $outputmode ); |
181 | 188 | } |
182 | 189 | |
183 | 190 | return $result; |
— | — | @@ -188,10 +195,12 @@ |
189 | 196 | * @since 1.6 |
190 | 197 | * |
191 | 198 | * @param string $result |
| 199 | + * @param SMWQueryResult $results |
| 200 | + * @param $outputmode |
192 | 201 | * |
193 | 202 | * @return string |
194 | 203 | */ |
195 | | - protected function handleNonFileResult( $result ) { |
| 204 | + protected function handleNonFileResult( $result, SMWQueryResult $results, $outputmode ) { |
196 | 205 | $result .= $this->getErrorString( $results ); // append errors |
197 | 206 | |
198 | 207 | if ( ( !$this->isHTML ) && ( $this->hasTemplates ) ) { // preprocess embedded templates if needed |
— | — | @@ -267,7 +276,7 @@ |
268 | 277 | * |
269 | 278 | * @return array |
270 | 279 | */ |
271 | | - protected function handleParameters( array $keyValuePairs ) { |
| 280 | + protected function handleRawParameters( array $keyValuePairs ) { |
272 | 281 | $validator = new Validator(); |
273 | 282 | $validator->setParameters( $keyValuePairs, $this->getParameters() ); |
274 | 283 | $validator->validateParameters(); |
— | — | @@ -277,6 +286,7 @@ |
278 | 287 | throw new Exception( 'Validator: fatal param validation error' ); |
279 | 288 | } |
280 | 289 | else { |
| 290 | + // TODO: keep track of non-fatal errors to display |
281 | 291 | return $validator->getParameterValues(); |
282 | 292 | } |
283 | 293 | } |
— | — | @@ -285,9 +295,57 @@ |
286 | 296 | * Read an array of parameter values given as key-value-pairs and |
287 | 297 | * initialise internal member fields accordingly. Possibly overwritten |
288 | 298 | * (extended) by subclasses. |
| 299 | + * |
| 300 | + * @since 1.6 |
| 301 | + * |
| 302 | + * @param array $params |
| 303 | + * @param $outputmode |
| 304 | + */ |
| 305 | + protected function handleParameters( array $params, $outputmode ) { |
| 306 | + $this->m_params = $params; |
| 307 | + |
| 308 | + if ( array_key_exists( 'intro', $params ) ) { $this->mIntro = $params['intro']; } |
| 309 | + if ( array_key_exists( 'outro', $params ) ) { $this->mOutro = $params['outro']; } |
| 310 | + |
| 311 | + if ( array_key_exists( 'searchlabel', $params ) ) { |
| 312 | + $this->mSearchlabel = $params['searchlabel'] === false ? null : $params['searchlabel']; |
| 313 | + } |
| 314 | + |
| 315 | + switch ( $params['link'] ) { |
| 316 | + case 'head': case 'subject': |
| 317 | + $this->mLinkFirst = true; |
| 318 | + $this->mLinkOthers = false; |
| 319 | + break; |
| 320 | + case 'all': |
| 321 | + $this->mLinkFirst = true; |
| 322 | + $this->mLinkOthers = true; |
| 323 | + break; |
| 324 | + case 'none': |
| 325 | + $this->mLinkFirst = false; |
| 326 | + $this->mLinkOthers = false; |
| 327 | + break; |
| 328 | + } |
| 329 | + |
| 330 | + if ( array_key_exists( 'default', $params ) ) { $this->mDefault = str_replace( '_', ' ', $params['default'] ); } |
| 331 | + |
| 332 | + if ( $params['headers'] == 'hide' ) { |
| 333 | + $this->mShowHeaders = SMW_HEADERS_HIDE; |
| 334 | + } elseif ( $params['headers'] == 'plain' ) { |
| 335 | + $this->mShowHeaders = SMW_HEADERS_PLAIN; |
| 336 | + } else { |
| 337 | + $this->mShowHeaders = SMW_HEADERS_SHOW; |
| 338 | + } |
| 339 | + } |
| 340 | + |
| 341 | + /** |
| 342 | + * Read an array of parameter values given as key-value-pairs and |
| 343 | + * initialise internal member fields accordingly. Possibly overwritten |
| 344 | + * (extended) by subclasses. |
289 | 345 | * |
290 | 346 | * @param array $params |
291 | 347 | * @param $outputmode |
| 348 | + * |
| 349 | + * @deprecated Use handleParameters instead |
292 | 350 | */ |
293 | 351 | protected function readParameters( /* array */ $params, $outputmode ) { |
294 | 352 | $this->m_params = $params; |
— | — | @@ -465,19 +523,22 @@ |
466 | 524 | * |
467 | 525 | * @since 1.5.0 |
468 | 526 | * |
469 | | - * @return array |
| 527 | + * @return array of Parameter |
470 | 528 | */ |
471 | 529 | protected function textDisplayParameters() { |
472 | 530 | $params = array(); |
473 | 531 | |
474 | 532 | $params['intro'] = new Parameter( 'intro' ); |
475 | 533 | $params['intro']->setDescription( wfMsg( 'smw_paramdesc_intro' ) ); |
476 | | - |
| 534 | + $params['intro']->setDefault( '' ); |
| 535 | + |
477 | 536 | $params['outro'] = new Parameter( 'outro' ); |
478 | 537 | $params['outro']->setDescription( wfMsg( 'smw_paramdesc_outro' ) ); |
| 538 | + $params['outro']->setDefault( '' ); |
479 | 539 | |
480 | 540 | $params['default'] = new Parameter( 'default' ); |
481 | 541 | $params['default']->setDescription( wfMsg( 'smw_paramdesc_default' ) ); |
| 542 | + $params['default']->setDefault( '' ); |
482 | 543 | |
483 | 544 | return $params; |
484 | 545 | } |
— | — | @@ -497,6 +558,7 @@ |
498 | 559 | |
499 | 560 | $params['searchlabel'] = new Parameter( 'searchlabel' ); |
500 | 561 | $params['searchlabel']->setDescription( wfMsg( 'smw_paramdesc_searchlabel' ) ); |
| 562 | + $params['searchlabel']->setDefault( false, false ); |
501 | 563 | |
502 | 564 | return $params; |
503 | 565 | } |
— | — | @@ -515,17 +577,21 @@ |
516 | 578 | |
517 | 579 | $params['limit'] = new Parameter( 'limit', Parameter::TYPE_INTEGER ); |
518 | 580 | $params['limit']->setDescription( wfMsg( 'smw_paramdesc_limit' ) ); |
| 581 | + $params['limit']->setDefault( 20 ); |
519 | 582 | |
520 | 583 | $params['headers'] = new Parameter( 'headers' ); |
521 | 584 | $params['headers']->setDescription( wfMsg( 'smw_paramdesc_headers' ) ); |
522 | 585 | $params['headers']->addCriteria( new CriterionInArray( 'show', 'hide', 'plain' ) ); |
| 586 | + $params['headers']->setDefault( 'show' ); |
523 | 587 | |
524 | 588 | $params['mainlabel'] = new Parameter( 'mainlabel' ); |
525 | 589 | $params['mainlabel']->setDescription( wfMsg( 'smw_paramdesc_mainlabel' ) ); |
| 590 | + $params['mainlabel']->setDefault( false, false ); |
526 | 591 | |
527 | 592 | $params['link'] = new Parameter( 'link' ); |
528 | 593 | $params['link']->setDescription( wfMsg( 'smw_paramdesc_link' ) ); |
529 | 594 | $params['link']->addCriteria( new CriterionInArray( 'all', 'subject', 'none' ) ); |
| 595 | + $params['link']->setDefault( 'all' ); |
530 | 596 | |
531 | 597 | return $params; |
532 | 598 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_CSV.php |
— | — | @@ -86,7 +86,7 @@ |
87 | 87 | $link->setParameter( 'csv', 'format' ); |
88 | 88 | $link->setParameter( $this->m_sep, 'sep' ); |
89 | 89 | |
90 | | - if ( array_key_exists( 'mainlabel', $this->m_params ) ) { |
| 90 | + if ( $this->m_params['mainlabel'] !== false ) { |
91 | 91 | $link->setParameter( $this->m_params['mainlabel'], 'mainlabel' ); |
92 | 92 | } |
93 | 93 | |
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_DSV.php |
— | — | @@ -160,7 +160,7 @@ |
161 | 161 | $link->setParameter( 'dsv', 'format' ); |
162 | 162 | $link->setParameter( $this->separator, 'sep' ); |
163 | 163 | |
164 | | - if ( array_key_exists( 'mainlabel', $this->m_params ) ) { |
| 164 | + if ( $this->m_params['mainlabel'] !== false ) { |
165 | 165 | $link->setParameter( $this->m_params['mainlabel'], 'mainlabel' ); |
166 | 166 | } |
167 | 167 | |
Index: trunk/extensions/SemanticMediaWiki/SemanticMediaWiki.php |
— | — | @@ -36,3 +36,6 @@ |
37 | 37 | 'url' => 'http://semantic-mediawiki.org', |
38 | 38 | 'descriptionmsg' => 'smw-desc' |
39 | 39 | ); |
| 40 | + |
| 41 | +// A flag used to indicate SMW supports Validator style parameter definitions and validation in the SMWResultPrinter class. |
| 42 | +define( 'SMW_SUPPORTS_VALIDATOR', true ); |