r74342 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74341‎ | r74342 | r74343 >
Date:09:59, 6 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.7 - added parameter to add static locations on query maps in addition to the query results
Modified paths:
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)
  • /trunk/extensions/SemanticMaps/includes/queryprinters/SM_MapPrinter.php (modified) (history)
  • /trunk/extensions/SemanticMaps/includes/queryprinters/SM_QueryPrinters.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_QueryPrinters.php
@@ -66,6 +66,13 @@
6767
6868 $params = MapsMapper::getCommonParameters();
6969
 70+ $params['staticlocations'] = new ListParameter( 'staticlocations', ';' );
 71+ $params['staticlocations']->addAliases( 'locations' );
 72+ $params['staticlocations']->addCriteria( new CriterionIsLocation( '~' ) );
 73+ $params['staticlocations']->addManipulations( new MapsParamCoordSet( '~' ) );
 74+ $params['staticlocations']->lowerCaseValue = false;
 75+ $params['staticlocations']->setDefault( array() );
 76+
7077 $params['centre'] = new Parameter(
7178 'centre',
7279 Parameter::TYPE_STRING,
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_MapPrinter.php
@@ -247,12 +247,72 @@
248248 * @param SMWQueryResult $res
249249 * @param $outputmode
250250 */
251 - private function formatResultData( SMWQueryResult $res, $outputmode ) {
 251+ protected function formatResultData( SMWQueryResult $res, $outputmode ) {
 252+ $this->addStaticLocations();
 253+
252254 while ( ( $row = $res->getNext() ) !== false ) {
253255 $this->addResultRow( $outputmode, $row );
254256 }
255257 }
256258
 259+ protected function addStaticLocations() {
 260+ global $wgTitle;
 261+
 262+ // New parser object to render popup contents with.
 263+ $parser = new Parser();
 264+
 265+ $this->title = $parser->parse( $this->title, $wgTitle, new ParserOptions() )->getText();
 266+ $this->label = $parser->parse( $this->label, $wgTitle, new ParserOptions() )->getText();
 267+
 268+ // Each $location is an array containg the coordinate set as first element, possibly followed by meta data.
 269+ foreach ( $this->staticlocations as $location ) {
 270+ $markerData = MapsCoordinateParser::parseCoordinates( array_shift( $location ) );
 271+
 272+ if ( !$markerData ) continue;
 273+
 274+ if ( count( $location ) > 0 ) {
 275+ // Parse and add the point specific title if it's present.
 276+ $markerData['title'] = $parser->parse( $location[0], $wgTitle, new ParserOptions() )->getText();
 277+
 278+ if ( count( $location ) > 1 ) {
 279+ // Parse and add the point specific label if it's present.
 280+ $markerData['label'] = $parser->parse( $location[1], $wgTitle, new ParserOptions() )->getText();
 281+
 282+ if ( count( $location ) > 2 ) {
 283+ // Add the point specific icon if it's present.
 284+ $markerData['icon'] = $location[2];
 285+ }
 286+ }
 287+ }
 288+
 289+ // If there is no point specific icon, use the general icon parameter when available.
 290+ if ( !array_key_exists( 'icon', $markerData ) && $this->icon != '' ) {
 291+ $markerData['icon'] = $this->icon;
 292+ }
 293+
 294+ // Get the url for the icon when there is one, else set the icon to an empty string.
 295+ if ( array_key_exists( 'icon', $markerData ) ) {
 296+ $icon_image_page = new ImagePage( Title::newFromText( $markerData['icon'] ) );
 297+ $markerData['icon'] = $icon_image_page->getDisplayedFile()->getURL();
 298+ }
 299+ else {
 300+ $markerData['icon'] = '';
 301+ }
 302+
 303+ // Temporary fix, will refactor away later
 304+ // TODO
 305+ $markerData = array_values( $markerData );
 306+ if ( count( $markerData ) < 5 ) {
 307+ if ( count( $markerData ) < 4 ) {
 308+ $markerData[] = '';
 309+ }
 310+ $markerData[] = '';
 311+ }
 312+
 313+ $this->locations[] = $markerData;
 314+ }
 315+ }
 316+
257317 /**
258318 * This function will loop through all properties (fields) of one record (row),
259319 * and add the location data, title, label and icon to the m_locations array.
@@ -262,7 +322,7 @@
263323 * @param $outputmode
264324 * @param array $row The record you want to add data from
265325 */
266 - private function addResultRow( $outputmode, array $row ) {
 326+ protected function addResultRow( $outputmode, array $row ) {
267327 global $wgUser, $smgUseSpatialExtensions, $wgTitle;
268328
269329 $skin = $wgUser->getSkin();
Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -40,7 +40,7 @@
4141 if ( defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' ) ) {
4242 define( 'SM_VERSION', '0.7 alpha-7' );
4343
44 - $useExtensionPath = version_compare( $wgVersion, '1.16', '>=' ) && isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath;
 44+ $useExtensionPath = /*version_compare( $wgVersion, '1.16', '>=' ) &&*/ isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath;
4545 $smgScriptPath = ( $useExtensionPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/SemanticMaps';
4646 $smgDir = dirname( __FILE__ ) . '/';
4747 unset( $useExtensionPath );

Follow-up revisions

RevisionCommit summaryAuthorDate
r74372Follow up to r74342jeroendedauw17:45, 6 October 2010

Status & tagging log