r114405 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114404‎ | r114405 | r114406 >
Date:20:39, 21 March 2012
Author:foxtrott
Status:deferred
Tags:
Comment:
filtered format: register resources for distance filter; printout parameter 'distance filter property'; printout parameter 'hide'
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Distance.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/SRF_Resources.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Distance.php
@@ -46,6 +46,15 @@
4747 $this->mUnit = MapsDistanceParser::getValidUnit();
4848 }
4949
 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+
5059 $targetLabel = $printRequest->getLabel();
5160
5261 foreach ( $this->getQueryResults() as $id => $filteredItem ) {
@@ -68,8 +77,41 @@
6978 if ( $dataValue !== false ) {
7079
7180 $posText = $dataValue->getShortText( SMW_OUTPUT_WIKI, false );
72 - $pos = MapsGeocoders::attemptToGeocode( $posText );
7381
 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+
74116 if ( is_array( $pos ) ){
75117 $distance = round( MapsGeoFunctions::calculateDistance( $origin, $pos ) / MapsDistanceParser::getUnitRatio( $this->mUnit ) );
76118
Index: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php
@@ -118,13 +118,21 @@
119119 $wikitext = '';
120120
121121 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;
124129
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+ }
129137 }
130138 }
131139
@@ -138,28 +146,35 @@
139147 foreach ( $row as $field ) {
140148 $first_value = true;
141149
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+ }
151165
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;
154168
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+ }
157172 }
158 - }
159173
160 - $result .= $text; // actual output value
 174+ $result .= $text; // actual output value
161175 }
162 -
163 - $first_col = false;
 176+ }
 177+
 178+ $first_col = false;
164179 }
165180
166181 if ( $found_values ) $result .= ')';
Index: trunk/extensions/SemanticResultFormats/SRF_Resources.php
@@ -158,4 +158,17 @@
159159 ),
160160 );
161161
 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+
162175 unset( $moduleTemplate );

Status & tagging log