Index: trunk/extensions/SemanticMaps/SemanticMaps.php |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | |
40 | 40 | // Only initialize the extension when all dependencies are present. |
41 | 41 | if ( defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' ) ) { |
42 | | - define( 'SM_VERSION', '0.7.3 alpha' ); |
| 42 | + define( 'SM_VERSION', '0.7.3 a2' ); |
43 | 43 | |
44 | 44 | $useExtensionPath = version_compare( $wgVersion, '1.16', '>=' ) && isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath; |
45 | 45 | $smgScriptPath = ( $useExtensionPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/SemanticMaps'; |
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_KMLPrinter.php |
— | — | @@ -0,0 +1,106 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * SMWResultPrinter class for printing a query result as KML. |
| 6 | + * |
| 7 | + * @since 0.7.3 |
| 8 | + * |
| 9 | + * @file SM_KMLPrinter.php |
| 10 | + * @ingroup SemanticMaps |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw |
| 13 | + */ |
| 14 | +class SMKMLPrinter extends SMWResultPrinter { |
| 15 | + |
| 16 | + /** |
| 17 | + * Handler of the print request. |
| 18 | + * |
| 19 | + * @since 0.7.3 |
| 20 | + * |
| 21 | + * @param SMWQueryResult $res |
| 22 | + * @param $outputmode |
| 23 | + * |
| 24 | + * @return array |
| 25 | + */ |
| 26 | + public function getResultText( /* SMWQueryResult */ $res, $outputmode ) { |
| 27 | + return $outputmode == SMW_OUTPUT_FILE ? $this->getKML( $res, $outputmode ) : $this->getLink( $res, $outputmode ); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Returns the KML for the query result. |
| 32 | + * |
| 33 | + * @since 0.7.3 |
| 34 | + * |
| 35 | + * @param SMWQueryResult $res |
| 36 | + * @param integer $outputmode |
| 37 | + * |
| 38 | + * @return string |
| 39 | + */ |
| 40 | + protected function getKML( SMWQueryResult $res, $outputmode ) { |
| 41 | + $queryHandler = new SMQueryHandler( $res, $outputmode ); |
| 42 | + $locations = $queryHandler->getLocations(); |
| 43 | + |
| 44 | + $formatter = new MapsKMLFormatter(); |
| 45 | + $formatter->addPlacemarks( $locations ); |
| 46 | + |
| 47 | + return $formatter->getKML(); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns a link (HTML) pointing to a query that returns the actual KML file. |
| 52 | + * |
| 53 | + * @since 0.7.3 |
| 54 | + * |
| 55 | + * @param SMWQueryResult $res |
| 56 | + * @param integer $outputmode |
| 57 | + * |
| 58 | + * @return string |
| 59 | + */ |
| 60 | + protected function getLink( SMWQueryResult $res, $outputmode ) { |
| 61 | + $searchLabel = $this->getSearchLabel( $outputmode ); |
| 62 | + $link = $res->getQueryLink( $searchLabel ? $searchLabel : wfMsgForContent( 'semanticmaps-kml-link' ) ); |
| 63 | + $link->setParameter( 'kml', 'format' ); |
| 64 | + |
| 65 | + /* |
| 66 | + if ( $this->m_title !== '' ) { |
| 67 | + $link->setParameter( $this->m_title, 'title' ); |
| 68 | + } |
| 69 | + |
| 70 | + if ( $this->m_description !== '' ) { |
| 71 | + $link->setParameter( $this->m_description, 'description' ); |
| 72 | + } |
| 73 | + */ |
| 74 | + if ( array_key_exists( 'limit', $this->m_params ) ) { |
| 75 | + $link->setParameter( $this->m_params['limit'], 'limit' ); |
| 76 | + } else { // Use a reasonable default limit. |
| 77 | + $link->setParameter( 20, 'limit' ); |
| 78 | + } |
| 79 | + |
| 80 | + $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); |
| 81 | + |
| 82 | + return $link->getText( $outputmode, $this->mLinker ); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @see SMWResultPrinter::getMimeType() |
| 87 | + */ |
| 88 | + public function getMimeType( $res ) { |
| 89 | + return 'application/vnd.google-earth.kml+xml'; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @see SMWResultPrinter::getFileName() |
| 94 | + */ |
| 95 | + public function getFileName( $res ) { |
| 96 | + // TODO |
| 97 | + return 'kml.kml'; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @see SMWResultPrinter::getName() |
| 102 | + */ |
| 103 | + public final function getName() { |
| 104 | + return wfMsg( 'semanticmaps-kml' ); |
| 105 | + } |
| 106 | + |
| 107 | +} |
Property changes on: trunk/extensions/SemanticMaps/includes/queryprinters/SM_KMLPrinter.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 108 | + native |
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_QueryPrinters.php |
— | — | @@ -23,9 +23,13 @@ |
24 | 24 | public static function initialize() { |
25 | 25 | global $smgDir, $wgAutoloadClasses; |
26 | 26 | |
27 | | - $wgAutoloadClasses['SMMapper'] = dirname( __FILE__ ) . '/SM_Mapper.php'; |
28 | | - $wgAutoloadClasses['SMMapPrinter'] = dirname( __FILE__ ) . '/SM_MapPrinter.php'; |
| 27 | + $wgAutoloadClasses['SMQueryHandler'] = dirname( __FILE__ ) . '/SM_QueryHandler.php'; |
| 28 | + $wgAutoloadClasses['SMMapper'] = dirname( __FILE__ ) . '/SM_Mapper.php'; |
| 29 | + $wgAutoloadClasses['SMMapPrinter'] = dirname( __FILE__ ) . '/SM_MapPrinter.php'; |
| 30 | + $wgAutoloadClasses['SMKMLPrinter'] = dirname( __FILE__ ) . '/SM_KMLPrinter.php'; |
29 | 31 | |
| 32 | + self::initFormat( 'kml', 'SMKMLPrinter' ); |
| 33 | + |
30 | 34 | $hasQueryPrinters = false; |
31 | 35 | |
32 | 36 | foreach ( MapsMappingServices::getServiceIdentifiers() as $serviceIdentifier ) { |
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_MapPrinter.php |
— | — | @@ -3,6 +3,9 @@ |
4 | 4 | /** |
5 | 5 | * Abstract class that provides the common functionality for all map query printers. |
6 | 6 | * |
| 7 | + * TODO: make use of SMQueryHandler |
| 8 | + * TODO: make use of new-style Validator parameter handling |
| 9 | + * |
7 | 10 | * @file SM_MapPrinter.php |
8 | 11 | * @ingroup SemanticMaps |
9 | 12 | * |
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_QueryHandler.php |
— | — | @@ -0,0 +1,214 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class for handling geographical SMW queries. |
| 6 | + * |
| 7 | + * @since 0.7.3 |
| 8 | + * |
| 9 | + * @ingroup SemanticMaps |
| 10 | + * @file SM_QueryHandler.php |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw |
| 13 | + */ |
| 14 | +class SMQueryHandler { |
| 15 | + |
| 16 | + protected $queryResult; |
| 17 | + protected $outputmode; |
| 18 | + |
| 19 | + protected $locations = false; |
| 20 | + |
| 21 | + // TODO: add system to properly handle query parameters |
| 22 | + public $template = false; |
| 23 | + public $icon = ''; |
| 24 | + public $makeLinks = false; |
| 25 | + |
| 26 | + /** |
| 27 | + * Constructor. |
| 28 | + * |
| 29 | + * @since 0.7.3 |
| 30 | + * |
| 31 | + * @param SMWQueryResult $queryResult |
| 32 | + * @param integer $outputmode |
| 33 | + */ |
| 34 | + public function __construct( SMWQueryResult $queryResult, $outputmode ) { |
| 35 | + $this->queryResult = $queryResult; |
| 36 | + $this->outputmode = $outputmode; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Gets the query result as a list of locations. |
| 41 | + * |
| 42 | + * @since 0.7.3 |
| 43 | + * |
| 44 | + * @return array of MapsLocation |
| 45 | + */ |
| 46 | + public function getLocations() { |
| 47 | + if ( $this->locations === false ) { |
| 48 | + $this->locations = $this->findLocations(); |
| 49 | + } |
| 50 | + |
| 51 | + return $this->locations; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Gets the query result as a list of locations. |
| 56 | + * |
| 57 | + * @since 0.7.3 |
| 58 | + * |
| 59 | + * @return array of MapsLocation |
| 60 | + */ |
| 61 | + protected function findLocations() { |
| 62 | + $locations = array(); |
| 63 | + |
| 64 | + while ( ( $row = $this->queryResult->getNext() ) !== false ) { |
| 65 | + $locations = array_merge( $locations, $this->handleResultRow( $row ) ); |
| 66 | + } |
| 67 | + |
| 68 | + return $locations; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Returns the locations found in the provided result row. |
| 73 | + * |
| 74 | + * TODO: split up this method if possible |
| 75 | + * |
| 76 | + * @since 0.7.3 |
| 77 | + * |
| 78 | + * @param array $row Array of SMWResultArray |
| 79 | + * |
| 80 | + * @return array of MapsLocation |
| 81 | + */ |
| 82 | + protected function handleResultRow( array /* of SMWResultArray */ $row ) { |
| 83 | + global $wgUser, $smgUseSpatialExtensions, $wgTitle; |
| 84 | + |
| 85 | + $locations = array(); |
| 86 | + |
| 87 | + $skin = $wgUser->getSkin(); |
| 88 | + |
| 89 | + $title = ''; |
| 90 | + $titleForTemplate = ''; |
| 91 | + $text = ''; |
| 92 | + $lat = ''; |
| 93 | + $lon = ''; |
| 94 | + |
| 95 | + $coords = array(); |
| 96 | + $label = array(); |
| 97 | + |
| 98 | + // Loop throught all fields of the record. |
| 99 | + foreach ( $row as $i => $resultArray ) { |
| 100 | + /* SMWPrintRequest */ $printRequest = $resultArray->getPrintRequest(); |
| 101 | + |
| 102 | + // Loop throught all the parts of the field value. |
| 103 | + while ( ( /* SMWDataValue */ $object = $resultArray->getNextObject() ) !== false ) { |
| 104 | + if ( $object->getTypeID() == '_wpg' && $i == 0 ) { |
| 105 | + $title = $object->getLongText( $this->outputmode, $this->makeLinks ? $skin : NULL ); |
| 106 | + $titleForTemplate = $object->getLongText( $this->outputmode, NULL ); |
| 107 | + } |
| 108 | + |
| 109 | + if ( $object->getTypeID() != '_geo' && $i != 0 ) { |
| 110 | + if ( $this->template ) { |
| 111 | + if ( $object instanceof SMWWikiPageValue ) { |
| 112 | + $label[] = $object->getTitle()->getPrefixedText(); |
| 113 | + } else { |
| 114 | + $label[] = $object->getLongText( $this->outputmode, $this->makeLinks ? $skin : NULL ); |
| 115 | + } |
| 116 | + } |
| 117 | + else { |
| 118 | + $propertyName = $printRequest->getHTMLText( $this->makeLinks ? $skin : NULL ); |
| 119 | + if ( $propertyName != '' ) $propertyName .= ': '; |
| 120 | + $text .= $propertyName . $object->getLongText( $this->outputmode, $this->makeLinks ? $skin : NULL ) . '<br />'; |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + if ( $printRequest->getMode() == SMWPrintRequest::PRINT_PROP && $printRequest->getTypeID() == '_geo' ) { |
| 125 | + $coords[] = $object->getDBkeys(); |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + if ( $this->template ) { |
| 131 | + // New parser object to render the templates with. |
| 132 | + $parser = new Parser(); |
| 133 | + } |
| 134 | + |
| 135 | + foreach ( $coords as $coord ) { |
| 136 | + if ( count( $coord ) >= 2 ) { |
| 137 | + if ( $smgUseSpatialExtensions ) { |
| 138 | + // TODO |
| 139 | + } |
| 140 | + else { |
| 141 | + list( $lat, $lon ) = $coord; |
| 142 | + } |
| 143 | + |
| 144 | + if ( $lat != '' && $lon != '' ) { |
| 145 | + $icon = $this->getLocationIcon( $row ); |
| 146 | + |
| 147 | + if ( $this->template ) { |
| 148 | + $segments = array_merge( |
| 149 | + array( $this->template, 'title=' . $titleForTemplate, 'latitude=' . $lat, 'longitude=' . $lon ), |
| 150 | + $label |
| 151 | + ); |
| 152 | + |
| 153 | + $text = $parser->parse( '{{' . implode( '|', $segments ) . '}}', $wgTitle, new ParserOptions() )->getText(); |
| 154 | + } |
| 155 | + |
| 156 | + $location = new MapsLocation(); |
| 157 | + |
| 158 | + $location->setCoordinates( array( $lat, $lon ) ); |
| 159 | + |
| 160 | + if ( $location->isValid() ) { |
| 161 | + $location->setTitle( $title ); |
| 162 | + $location->setText( $text ); |
| 163 | + $location->setIcon( $icon ); |
| 164 | + |
| 165 | + $locations[] = $location; |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + return $locations; |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Get the icon for a row. |
| 176 | + * |
| 177 | + * @since 0.7.3 |
| 178 | + * |
| 179 | + * @param array $row |
| 180 | + * |
| 181 | + * @return string |
| 182 | + */ |
| 183 | + protected function getLocationIcon( array $row ) { |
| 184 | + $icon = ''; |
| 185 | + $legend_labels = array(); |
| 186 | + |
| 187 | + // Look for display_options field, which can be set by Semantic Compound Queries |
| 188 | + // the location of this field changed in SMW 1.5 |
| 189 | + $display_location = method_exists( $row[0], 'getResultSubject' ) ? $row[0]->getResultSubject() : $row[0]; |
| 190 | + |
| 191 | + if ( property_exists( $display_location, 'display_options' ) && is_array( $display_location->display_options ) ) { |
| 192 | + $display_options = $display_location->display_options; |
| 193 | + if ( array_key_exists( 'icon', $display_options ) ) { |
| 194 | + $icon = $display_options['icon']; |
| 195 | + |
| 196 | + // This is somewhat of a hack - if a legend label has been set, we're getting it for every point, instead of just once per icon |
| 197 | + if ( array_key_exists( 'legend label', $display_options ) ) { |
| 198 | + |
| 199 | + $legend_label = $display_options['legend label']; |
| 200 | + |
| 201 | + if ( ! array_key_exists( $icon, $legend_labels ) ) { |
| 202 | + $legend_labels[$icon] = $legend_label; |
| 203 | + } |
| 204 | + } |
| 205 | + } |
| 206 | + } // Icon can be set even for regular, non-compound queries If it is, though, we have to translate the name into a URL here |
| 207 | + elseif ( $this->icon != '' ) { |
| 208 | + $icon_image_page = new ImagePage( Title::newFromText( $this->icon ) ); |
| 209 | + $icon = $icon_image_page->getDisplayedFile()->getURL(); |
| 210 | + } |
| 211 | + |
| 212 | + return $icon; |
| 213 | + } |
| 214 | + |
| 215 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticMaps/includes/queryprinters/SM_QueryHandler.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 216 | + native |
Index: trunk/extensions/SemanticMaps/SemanticMaps.i18n.php |
— | — | @@ -21,6 +21,8 @@ |
22 | 22 | 'semanticmaps_desc' => "Provides the ability to view and edit coordinate data stored through the Semantic MediaWiki extension ([http://mapping.referata.com/wiki/Semantic_Maps_examples demo's]). |
23 | 23 | Available mapping services: $1", |
24 | 24 | 'semanticmaps-unrecognizeddistance' => 'The value $1 is not a valid distance.', |
| 25 | + 'semanticmaps-kml-link' => 'View the KML file', |
| 26 | + 'semanticmaps-kml' => 'KML', |
25 | 27 | |
26 | 28 | // Forms |
27 | 29 | 'semanticmaps_lookupcoordinates' => 'Look up coordinates', |