https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114405

Revision: 114405
Author:   foxtrott
Date:     2012-03-21 20:39:55 +0000 (Wed, 21 Mar 2012)
Log Message:
-----------
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
    trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php
    trunk/extensions/SemanticResultFormats/SRF_Resources.php

Modified: 
trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Distance.php
===================================================================
--- trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Distance.php 
2012-03-21 20:31:24 UTC (rev 114404)
+++ trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Distance.php 
2012-03-21 20:39:55 UTC (rev 114405)
@@ -46,6 +46,15 @@
                        $this->mUnit = MapsDistanceParser::getValidUnit();
                }
 
+               // Is the real position stored in a property?
+               if ( array_key_exists( 'distance filter property', $params ) ) {
+                       $property = trim( $params['distance filter property'] );
+                       $locations = array();
+               } else {
+                       $property = null;
+                       $locations = null;
+               }
+
                $targetLabel = $printRequest->getLabel();
                
                foreach ( $this->getQueryResults() as $id => $filteredItem ) {
@@ -68,8 +77,41 @@
                                        if ( $dataValue !== false ) {
                                                
                                                $posText = 
$dataValue->getShortText( SMW_OUTPUT_WIKI, false );
-                                               $pos = 
MapsGeocoders::attemptToGeocode( $posText );
                                                
+                                               if ( $property === null ) {
+                                                       
+                                                       // position is directly 
given
+                                                       $pos = 
MapsGeocoders::attemptToGeocode( $posText );
+                                                       
+                                               } else {
+                                                       // position is given in 
a property of a page
+                                                       
+                                                       // if we used this page 
before, just look up the coordinates
+                                                       if ( array_key_exists( 
$posText, $locations ) ) {
+                                                               $pos = 
$locations[$posText];
+                                                       } else {
+                                                               
+                                                               // query the 
position's page for the coordinates or address
+                                                               $posText = 
SMWQueryProcessor::getResultFromFunctionParams(
+                                                                       
array($posText, '?' . $property),
+                                                                       
SMW_OUTPUT_WIKI,
+                                                                       
SMWQueryProcessor::INLINE_QUERY,
+                                                                       true
+                                                               );
+                                                               
+                                                               // 
+                                                               if ( $posText 
!== '' ) {
+                                                                       // 
geocode 
+                                                                       $pos = 
MapsGeocoders::attemptToGeocode( $posText );
+                                                               } else {
+                                                                       $pos = 
array('lat' => '0', 'lon' => '0');
+                                                               }
+                                                               
+                                                               // store 
coordinates in case we need them again
+                                                               
$locations[$posText] = $pos;
+                                                       }
+                                               }
+
                                                if ( is_array( $pos ) ){
                                                        $distance = round( 
MapsGeoFunctions::calculateDistance( $origin, $pos ) / 
MapsDistanceParser::getUnitRatio( $this->mUnit ) );
                                                        

Modified: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php
===================================================================
--- trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php       
2012-03-21 20:31:24 UTC (rev 114404)
+++ trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php       
2012-03-21 20:39:55 UTC (rev 114405)
@@ -118,13 +118,21 @@
                        $wikitext = '';
 
                        foreach ( $row as $i => $field ) {
-                               $wikitext .= '|' . ( $this->mNamedArgs ? '?' . 
$field->getPrintRequest()->getLabel() : $i + 1 ) . '=';
-                               $first_value = true;
+                               
+                               $printrequest = $field->getPrintRequest();
+                               
+                               // only print value if not hidden
+                               if ( $printrequest->getParameter( 'hide' ) === 
false ) {
+                                       $wikitext .= '|' . ( $this->mNamedArgs 
? '?' . $printrequest->getLabel() : $i + 1 ) . '=';
+                                       $first_value = true;
 
-                               $field->reset();
-                               while ( ( $text = $field->getNextText( 
SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $i == 0 ) ) ) !== false ) 
{
-                                       if ( $first_value ) $first_value = 
false; else $wikitext .= ', ';
-                                       $wikitext .= $text;
+                                       $field->reset();
+                                       while ( ( $text = $field->getNextText( 
SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $i == 0 ) ) ) !== false ) 
{
+                                               if ( $first_value )
+                                                       $first_value = false; 
else
+                                                       $wikitext .= ', ';
+                                               $wikitext .= $text;
+                                       }
                                }
                        }
 
@@ -138,28 +146,35 @@
                        foreach ( $row as $field ) {
                                $first_value = true;
 
-                               $field->reset();
-                               while ( ( $text = $field->getNextText( 
SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $first_col ) ) ) !== 
false ) {
-                                       if ( !$first_col && !$found_values ) { 
// first values after first column
-                                               $result .= ' (';
-                                               $found_values = true;
-                                       } elseif ( $found_values || 
!$first_value ) {
-                                               // any value after '(' or 
non-first values on first column
-                                               $result .= "$listsep ";
-                                       }
+                               $printrequest = $field->getPrintRequest();
+                               
+                                       $field->reset();
+                                       while ( ( $text = $field->getNextText( 
SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $first_col ) ) ) !== 
false ) {
+                                               
+                               // only print value if not hidden
+                               if ( $printrequest->getParameter( 'hide' ) === 
false ) {
+                                       
+                                               if ( !$first_col && 
!$found_values ) { // first values after first column
+                                                       $result .= ' (';
+                                                       $found_values = true;
+                                               } elseif ( $found_values || 
!$first_value ) {
+                                                       // any value after '(' 
or non-first values on first column
+                                                       $result .= "$listsep ";
+                                               }
 
-                                       if ( $first_value ) { // first value in 
any column, print header
-                                               $first_value = false;
+                                               if ( $first_value ) { // first 
value in any column, print header
+                                                       $first_value = false;
 
-                                               if ( ( $this->mShowHeaders != 
SMW_HEADERS_HIDE ) && ( $field->getPrintRequest()->getLabel() !== '' ) ) {
-                                                       $result .= 
$field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, ( $this->mShowHeaders == 
SMW_HEADERS_PLAIN ? null:$this->getQueryPrinter()->getLinker( true, true ) ) ) 
. ' ';
+                                                       if ( ( 
$this->mShowHeaders != SMW_HEADERS_HIDE ) && ( 
$field->getPrintRequest()->getLabel() !== '' ) ) {
+                                                               $result .= 
$field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, ( $this->mShowHeaders == 
SMW_HEADERS_PLAIN ? null:$this->getQueryPrinter()->getLinker( true, true ) ) ) 
. ' ';
+                                                       }
                                                }
-                                       }
 
-                                       $result .= $text; // actual output value
+                                               $result .= $text; // actual 
output value
                                }
-
-                               $first_col = false;
+                                       }
+                                       
+                                       $first_col = false;
                        }
 
                        if ( $found_values ) $result .= ')';

Modified: trunk/extensions/SemanticResultFormats/SRF_Resources.php
===================================================================
--- trunk/extensions/SemanticResultFormats/SRF_Resources.php    2012-03-21 
20:31:24 UTC (rev 114404)
+++ trunk/extensions/SemanticResultFormats/SRF_Resources.php    2012-03-21 
20:39:55 UTC (rev 114405)
@@ -158,4 +158,17 @@
        ),
 );
 
+$wgResourceModules['ext.srf.filtered.distance-filter'] = $moduleTemplate + 
array(
+       'scripts' => array(
+               'Filtered/libs/ext.srf.filtered.distance-filter.js',
+       ),
+       'styles' => array(
+               'Filtered/skins/ext.srf.filtered.distance-filter.css',
+       ),
+       'dependencies' => array(
+               'ext.srf.filtered',
+               'jquery.ui.slider'
+       ),
+);
+
 unset( $moduleTemplate );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to