Index: trunk/extensions/SemanticExpressiveness/includes/SemExQueryPF.php |
— | — | @@ -20,27 +20,47 @@ |
21 | 21 | $smwgIQRunningNumber++; |
22 | 22 | |
23 | 23 | $params = func_get_args(); |
24 | | - array_shift( $params ); // remove $parser |
| 24 | + array_shift( $params ); // remove $parser |
| 25 | + $params = static::validateParams( $params ); |
25 | 26 | |
26 | | - $query = SemExShortQuery::newFromPFParams( |
27 | | - $params, |
28 | | - array( 'property', Validator::PARAM_UNNAMED ) |
29 | | - ); |
30 | | - $options = SemExShortQueryOutputOptions::newFromPFParams( $params ); |
| 27 | + $query = SemExShortQuery::newFromValidatedParams( $params ); |
| 28 | + $options = SemExShortQueryOutputOptions::newFromValidatedParams( $params ); |
31 | 29 | |
32 | 30 | if( ! $query || ! $options ) { |
33 | 31 | // @ToDo: real error message (anyway, in what case can this happen?) |
34 | 32 | return 'FALSE'; |
35 | 33 | } |
36 | 34 | |
37 | | - $result = SemExShortQueryProcessor::getResultFromQuery( $parser, $query, $options ); |
38 | | - } else { |
| 35 | + $result = SemExShortQueryProcessor::getResultFromQuery( $parser, $query, $options ); |
| 36 | + |
| 37 | + if( $result === '' ) { |
| 38 | + $result = $params['default']; |
| 39 | + } else { |
| 40 | + $result = // allow ' ' in form of '_' around the result |
| 41 | + preg_replace( '/_$/', ' ', $params['intro'] ) . |
| 42 | + $result . |
| 43 | + preg_replace( '/^_/', ' ', $params['outro'] ); |
| 44 | + } |
| 45 | + } |
| 46 | + else { |
39 | 47 | $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_iq_disabled' ) ) ); |
40 | 48 | } |
41 | 49 | |
42 | 50 | return $result; |
43 | 51 | } |
44 | 52 | |
| 53 | + protected static function validateParams( array $rawParams, &$validator = null ) { |
| 54 | + $validator = new Validator(); |
| 55 | + $validator->setFunctionParams( |
| 56 | + $rawParams, |
| 57 | + static::getParameters(), |
| 58 | + array( 'property', Validator::PARAM_UNNAMED ) // 'property' is parameter 1 |
| 59 | + ); |
| 60 | + $validator->validateParameters(); |
| 61 | + |
| 62 | + return $validator->getParameterValues(); |
| 63 | + } |
| 64 | + |
45 | 65 | /** |
46 | 66 | * Returns a description of all allowed function Parameters. |
47 | 67 | * |
— | — | @@ -50,8 +70,13 @@ |
51 | 71 | $params = array(); |
52 | 72 | |
53 | 73 | $params['intro'] = new Parameter( 'intro' ); |
| 74 | + $params['intro']->setDefault( '' ); |
| 75 | + |
54 | 76 | $params['outro'] = new Parameter( 'outro' ); |
| 77 | + $params['outro']->setDefault( '' ); |
| 78 | + |
55 | 79 | $params['default'] = new Parameter( 'default' ); |
| 80 | + $params['default']->setDefault( '' ); |
56 | 81 | |
57 | 82 | // add function parameters describing the querry and its options: |
58 | 83 | $params = array_merge( |
Index: trunk/extensions/SemanticExpressiveness/includes/SemExExpressiveStringPF.php |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | * @return array |
45 | 45 | */ |
46 | 46 | protected function getParameterInfo( $type ) { |
47 | | - $params = array(); |
| 47 | + $params = SemExExpressiveStringOutputOptions::getPFParams(); |
48 | 48 | |
49 | 49 | # input text. |
50 | 50 | # since 0.1 |
— | — | @@ -55,13 +55,11 @@ |
56 | 56 | |
57 | 57 | $params['detect'] = new ListParameter( 'detect' ); |
58 | 58 | $params['detect']->addCriteria( $pieceTypesCriteria ); |
59 | | - $params['detect']->setDefault( false, false ); |
| 59 | + $params['detect']->setDefault( array( '' ), false ); |
60 | 60 | |
61 | 61 | $params['ignore'] = new ListParameter( 'ignore' ); |
62 | 62 | $params['ignore']->addCriteria( $pieceTypesCriteria ); |
63 | 63 | $params['ignore']->setDefault( array(), false ); |
64 | | - |
65 | | - $params = array_merge( $params, SemExExpressiveStringOutputOptions::getPFParams() ); |
66 | 64 | |
67 | 65 | return $params; |
68 | 66 | } |
— | — | @@ -102,7 +100,7 @@ |
103 | 101 | // get all types that should be handled by this |
104 | 102 | $enabledTypes = array(); |
105 | 103 | |
106 | | - if( $parameters['detect'] !== false ) { |
| 104 | + if( implode( '', $parameters['detect'] ) !== '' ) { // '' counts as if parameter not set |
107 | 105 | foreach( $parameters['detect'] as $typeName ) { |
108 | 106 | $type = SemExExpressiveString::getRegisteredPieceTypeByName( $typeName ); |
109 | 107 | if( $type !== null ) { |
— | — | @@ -115,11 +113,13 @@ |
116 | 114 | $enabledTypes = SemExExpressiveString::getRegisteredPieceTypeNames(); |
117 | 115 | } |
118 | 116 | |
119 | | - $enabledTypes = array_flip( $enabledTypes ); |
120 | | - foreach( $parameters['ignore'] as $typeName ) { |
121 | | - unset( $enabledTypes[ SemExExpressiveString::getRegisteredPieceTypeByName( $typeName ) ] ); |
| 117 | + if( $enabledTypes !== null ) { |
| 118 | + $enabledTypes = array_flip( $enabledTypes ); |
| 119 | + foreach( $parameters['ignore'] as $typeName ) { |
| 120 | + unset( $enabledTypes[ SemExExpressiveString::getRegisteredPieceTypeByName( $typeName ) ] ); |
| 121 | + } |
| 122 | + $enabledTypes = array_flip( $enabledTypes ); |
122 | 123 | } |
123 | | - $enabledTypes = array_flip( $enabledTypes ); |
124 | 124 | |
125 | 125 | // build expressive string from input with enabled types: |
126 | 126 | $exprString = new SemExExpressiveString( $parameters['text'], $this->parser, $enabledTypes ); |