Index: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Distance.php |
— | — | @@ -46,6 +46,15 @@ |
47 | 47 | $this->mUnit = MapsDistanceParser::getValidUnit(); |
48 | 48 | } |
49 | 49 | |
| 50 | + // Is the real position stored in a property? |
| 51 | + if ( array_key_exists( 'distance filter property', $params ) ) { |
| 52 | + $property = trim( $params['distance filter property'] ); |
| 53 | + $locations = array(); |
| 54 | + } else { |
| 55 | + $property = null; |
| 56 | + $locations = null; |
| 57 | + } |
| 58 | + |
50 | 59 | $targetLabel = $printRequest->getLabel(); |
51 | 60 | |
52 | 61 | foreach ( $this->getQueryResults() as $id => $filteredItem ) { |
— | — | @@ -68,8 +77,41 @@ |
69 | 78 | if ( $dataValue !== false ) { |
70 | 79 | |
71 | 80 | $posText = $dataValue->getShortText( SMW_OUTPUT_WIKI, false ); |
72 | | - $pos = MapsGeocoders::attemptToGeocode( $posText ); |
73 | 81 | |
| 82 | + if ( $property === null ) { |
| 83 | + |
| 84 | + // position is directly given |
| 85 | + $pos = MapsGeocoders::attemptToGeocode( $posText ); |
| 86 | + |
| 87 | + } else { |
| 88 | + // position is given in a property of a page |
| 89 | + |
| 90 | + // if we used this page before, just look up the coordinates |
| 91 | + if ( array_key_exists( $posText, $locations ) ) { |
| 92 | + $pos = $locations[$posText]; |
| 93 | + } else { |
| 94 | + |
| 95 | + // query the position's page for the coordinates or address |
| 96 | + $posText = SMWQueryProcessor::getResultFromFunctionParams( |
| 97 | + array($posText, '?' . $property), |
| 98 | + SMW_OUTPUT_WIKI, |
| 99 | + SMWQueryProcessor::INLINE_QUERY, |
| 100 | + true |
| 101 | + ); |
| 102 | + |
| 103 | + // |
| 104 | + if ( $posText !== '' ) { |
| 105 | + // geocode |
| 106 | + $pos = MapsGeocoders::attemptToGeocode( $posText ); |
| 107 | + } else { |
| 108 | + $pos = array('lat' => '0', 'lon' => '0'); |
| 109 | + } |
| 110 | + |
| 111 | + // store coordinates in case we need them again |
| 112 | + $locations[$posText] = $pos; |
| 113 | + } |
| 114 | + } |
| 115 | + |
74 | 116 | if ( is_array( $pos ) ){ |
75 | 117 | $distance = round( MapsGeoFunctions::calculateDistance( $origin, $pos ) / MapsDistanceParser::getUnitRatio( $this->mUnit ) ); |
76 | 118 | |
Index: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php |
— | — | @@ -118,13 +118,21 @@ |
119 | 119 | $wikitext = ''; |
120 | 120 | |
121 | 121 | foreach ( $row as $i => $field ) { |
122 | | - $wikitext .= '|' . ( $this->mNamedArgs ? '?' . $field->getPrintRequest()->getLabel() : $i + 1 ) . '='; |
123 | | - $first_value = true; |
| 122 | + |
| 123 | + $printrequest = $field->getPrintRequest(); |
| 124 | + |
| 125 | + // only print value if not hidden |
| 126 | + if ( $printrequest->getParameter( 'hide' ) === false ) { |
| 127 | + $wikitext .= '|' . ( $this->mNamedArgs ? '?' . $printrequest->getLabel() : $i + 1 ) . '='; |
| 128 | + $first_value = true; |
124 | 129 | |
125 | | - $field->reset(); |
126 | | - while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $i == 0 ) ) ) !== false ) { |
127 | | - if ( $first_value ) $first_value = false; else $wikitext .= ', '; |
128 | | - $wikitext .= $text; |
| 130 | + $field->reset(); |
| 131 | + while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $i == 0 ) ) ) !== false ) { |
| 132 | + if ( $first_value ) |
| 133 | + $first_value = false; else |
| 134 | + $wikitext .= ', '; |
| 135 | + $wikitext .= $text; |
| 136 | + } |
129 | 137 | } |
130 | 138 | } |
131 | 139 | |
— | — | @@ -138,28 +146,35 @@ |
139 | 147 | foreach ( $row as $field ) { |
140 | 148 | $first_value = true; |
141 | 149 | |
142 | | - $field->reset(); |
143 | | - while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $first_col ) ) ) !== false ) { |
144 | | - if ( !$first_col && !$found_values ) { // first values after first column |
145 | | - $result .= ' ('; |
146 | | - $found_values = true; |
147 | | - } elseif ( $found_values || !$first_value ) { |
148 | | - // any value after '(' or non-first values on first column |
149 | | - $result .= "$listsep "; |
150 | | - } |
| 150 | + $printrequest = $field->getPrintRequest(); |
| 151 | + |
| 152 | + $field->reset(); |
| 153 | + while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $first_col ) ) ) !== false ) { |
| 154 | + |
| 155 | + // only print value if not hidden |
| 156 | + if ( $printrequest->getParameter( 'hide' ) === false ) { |
| 157 | + |
| 158 | + if ( !$first_col && !$found_values ) { // first values after first column |
| 159 | + $result .= ' ('; |
| 160 | + $found_values = true; |
| 161 | + } elseif ( $found_values || !$first_value ) { |
| 162 | + // any value after '(' or non-first values on first column |
| 163 | + $result .= "$listsep "; |
| 164 | + } |
151 | 165 | |
152 | | - if ( $first_value ) { // first value in any column, print header |
153 | | - $first_value = false; |
| 166 | + if ( $first_value ) { // first value in any column, print header |
| 167 | + $first_value = false; |
154 | 168 | |
155 | | - if ( ( $this->mShowHeaders != SMW_HEADERS_HIDE ) && ( $field->getPrintRequest()->getLabel() !== '' ) ) { |
156 | | - $result .= $field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, ( $this->mShowHeaders == SMW_HEADERS_PLAIN ? null:$this->getQueryPrinter()->getLinker( true, true ) ) ) . ' '; |
| 169 | + if ( ( $this->mShowHeaders != SMW_HEADERS_HIDE ) && ( $field->getPrintRequest()->getLabel() !== '' ) ) { |
| 170 | + $result .= $field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, ( $this->mShowHeaders == SMW_HEADERS_PLAIN ? null:$this->getQueryPrinter()->getLinker( true, true ) ) ) . ' '; |
| 171 | + } |
157 | 172 | } |
158 | | - } |
159 | 173 | |
160 | | - $result .= $text; // actual output value |
| 174 | + $result .= $text; // actual output value |
161 | 175 | } |
162 | | - |
163 | | - $first_col = false; |
| 176 | + } |
| 177 | + |
| 178 | + $first_col = false; |
164 | 179 | } |
165 | 180 | |
166 | 181 | if ( $found_values ) $result .= ')'; |
Index: trunk/extensions/SemanticResultFormats/SRF_Resources.php |
— | — | @@ -158,4 +158,17 @@ |
159 | 159 | ), |
160 | 160 | ); |
161 | 161 | |
| 162 | +$wgResourceModules['ext.srf.filtered.distance-filter'] = $moduleTemplate + array( |
| 163 | + 'scripts' => array( |
| 164 | + 'Filtered/libs/ext.srf.filtered.distance-filter.js', |
| 165 | + ), |
| 166 | + 'styles' => array( |
| 167 | + 'Filtered/skins/ext.srf.filtered.distance-filter.css', |
| 168 | + ), |
| 169 | + 'dependencies' => array( |
| 170 | + 'ext.srf.filtered', |
| 171 | + 'jquery.ui.slider' |
| 172 | + ), |
| 173 | +); |
| 174 | + |
162 | 175 | unset( $moduleTemplate ); |