http://www.mediawiki.org/wiki/Special:Code/MediaWiki/71871

Revision: 71871
Author:   jeroendedauw
Date:     2010-08-29 05:46:04 +0000 (Sun, 29 Aug 2010)

Log Message:
-----------
Changes for 0.7 - Added tag support for geodistance and changed the way the 
parser hooks are included

Modified Paths:
--------------
    trunk/extensions/Maps/Maps.php
    trunk/extensions/Maps/Maps_Settings.php
    trunk/extensions/Maps/ParserHooks/Maps_Coordinates.php
    trunk/extensions/Maps/ParserHooks/Maps_Distance.php
    trunk/extensions/Maps/ParserHooks/Maps_GeoFunctions.php

Modified: trunk/extensions/Maps/Maps.php
===================================================================
--- trunk/extensions/Maps/Maps.php      2010-08-29 05:18:32 UTC (rev 71870)
+++ trunk/extensions/Maps/Maps.php      2010-08-29 05:46:04 UTC (rev 71871)
@@ -89,11 +89,16 @@
        global $egMapsDefaultService, $egMapsAvailableServices;
        global $egMapsDir, $egMapsUseMinJs, $egMapsJsExt;
 
-       // Autoload the "includes/" classes.
+       // Autoload the "Includes/" classes.
        $wgAutoloadClasses['MapsMapper']                                = 
$egMapsDir . 'Includes/Maps_Mapper.php';
        $wgAutoloadClasses['MapsCoordinateParser']              = $egMapsDir . 
'Includes/Maps_CoordinateParser.php';
        $wgAutoloadClasses['MapsDistanceParser']                = $egMapsDir . 
'Includes/Maps_DistanceParser.php';
        
+       // Autoload the "ParserHooks/" classes.
+       $wgAutoloadClasses['MapsCoordinates']                   = $egMapsDir . 
'ParserHooks/Maps_Coordinates.php';
+       $wgAutoloadClasses['MapsDistance']                              = 
$egMapsDir . 'ParserHooks/Maps_Distance.php';
+       $wgAutoloadClasses['MapsGeodistance']                   = $egMapsDir . 
'ParserHooks/Maps_Geodistance.php';
+       
        // This function has been deprecated in 1.16, but needed for earlier 
versions.
        // It's present in 1.16 as a stub, but lets check if it exists in case 
it gets removed at some point.
        if ( function_exists( 'wfLoadExtensionMessages' ) ) {

Modified: trunk/extensions/Maps/Maps_Settings.php
===================================================================
--- trunk/extensions/Maps/Maps_Settings.php     2010-08-29 05:18:32 UTC (rev 
71870)
+++ trunk/extensions/Maps/Maps_Settings.php     2010-08-29 05:46:04 UTC (rev 
71871)
@@ -39,12 +39,19 @@
                include_once $egMapsDir . 'Geocoders/Maps_Geocoders.php';
                # Geocoding parser functions: #geocode, #geocodelat, 
#geocodelon.
                include_once $egMapsDir . 
'ParserHooks/Maps_GeocodeFunctions.php';
+               
+               # Geographic functions
+               include_once $egMapsDir . 'ParserHooks/Maps_GeoFunctions.php';
+               
                # Required for #coordinates.
-               include_once $egMapsDir . 'ParserHooks/Maps_Coordinates.php';
+               $wgHooks['ParserFirstCallInit'][] = 
'MapsCoordinates::staticInit';
+               $wgHooks['LanguageGetMagic'][] = 
'MapsCoordinates::staticMagic';                
                # Required for #distance.
-               include_once $egMapsDir . 'ParserHooks/Maps_Distance.php';      
        
-               # Geographic parser functions: #geodistance, #finddestination
-               include_once $egMapsDir . 'ParserHooks/Maps_GeoFunctions.php';
+               $wgHooks['ParserFirstCallInit'][] = 'MapsDistance::staticInit';
+               $wgHooks['LanguageGetMagic'][] = 'MapsDistance::staticMagic';
+               # Required for #geodistance.
+               $wgHooks['ParserFirstCallInit'][] = 
'MapsGeodistance::staticInit';
+               $wgHooks['LanguageGetMagic'][] = 
'MapsGeodistance::staticMagic';                        
 
                
                

Modified: trunk/extensions/Maps/ParserHooks/Maps_Coordinates.php
===================================================================
--- trunk/extensions/Maps/ParserHooks/Maps_Coordinates.php      2010-08-29 
05:18:32 UTC (rev 71870)
+++ trunk/extensions/Maps/ParserHooks/Maps_Coordinates.php      2010-08-29 
05:46:04 UTC (rev 71871)
@@ -1,10 +1,5 @@
 <?php
 
-$wgAutoloadClasses['MapsCoordinates'] = dirname( __FILE__ ) . 
'/Maps_Coordinates.php';
-
-$wgHooks['ParserFirstCallInit'][] = 'MapsCoordinates::staticInit';
-$wgHooks['LanguageGetMagic'][] = 'MapsCoordinates::staticMagic';
-
 /**
  * Class for the 'coordinates' parser hooks, 
  * which can transform the notation of a set of coordinates.
@@ -112,6 +107,7 @@
                if ( $parsedCoords ) {
                        $output = MapsCoordinateParser::formatCoordinates( 
$parsedCoords, $parameters['format'], $parameters['directional'] );
                } else {
+                       // TODO: use ParserHook class methods to handle errors
                        $output = htmlspecialchars( wfMsgExt( 
'maps-invalid-coordinates', 'parsemag', $parameters['location'] ) );
                }
                

Modified: trunk/extensions/Maps/ParserHooks/Maps_Distance.php
===================================================================
--- trunk/extensions/Maps/ParserHooks/Maps_Distance.php 2010-08-29 05:18:32 UTC 
(rev 71870)
+++ trunk/extensions/Maps/ParserHooks/Maps_Distance.php 2010-08-29 05:46:04 UTC 
(rev 71871)
@@ -1,17 +1,12 @@
 <?php
 
-$wgAutoloadClasses['MapsMapsDistance'] = dirname( __FILE__ ) . 
'/Maps_MapsDistance.php';
-
-$wgHooks['ParserFirstCallInit'][] = 'MapsDistance::staticInit';
-$wgHooks['LanguageGetMagic'][] = 'MapsDistance::staticMagic';
-
 /**
  * Class for the 'distance' parser hooks, 
  * which can transform the notation of a distance.
  * 
  * @since 0.7
  * 
- * @file Maps_Coordinates.php
+ * @file Maps_Distance.php
  * @ingroup Maps
  * 
  * @author Jeroen De Dauw
@@ -106,6 +101,7 @@
                if ( $distanceInMeters ) {
                        $output = MapsDistanceParser::formatDistance( 
$distanceInMeters, $parameters['unit'], $parameters['decimals'] );
                } else {
+                       // TODO: use ParserHook class methods to handle errors
                        $output = wfMsgExt( 'maps_invalid_distance', 
'parsemag', '<b>' . $parameters['distance'] . '</b>' );
                }
 

Modified: trunk/extensions/Maps/ParserHooks/Maps_GeoFunctions.php
===================================================================
--- trunk/extensions/Maps/ParserHooks/Maps_GeoFunctions.php     2010-08-29 
05:18:32 UTC (rev 71870)
+++ trunk/extensions/Maps/ParserHooks/Maps_GeoFunctions.php     2010-08-29 
05:46:04 UTC (rev 71871)
@@ -39,7 +39,6 @@
  */
 function efMapsGeoFunctions( &$wgParser ) {
        // Hooks to enable the geocoding parser functions.
-       $wgParser->setFunctionHook( 'geodistance', array( 'MapsGeoFunctions', 
'renderGeoDistance' ) );
        $wgParser->setFunctionHook( 'finddestination', array( 
'MapsGeoFunctions', 'renderFindDestination' ) );
        
        return true;
@@ -48,102 +47,6 @@
 final class MapsGeoFunctions {
        
        /**
-        * Handler for the #geodistance parser function. 
-        * See http://mapping.referata.com/wiki/Geodistance
-        * 
-        * @since 0.6
-        * 
-        * @param Parser $parser
-        */
-       public static function renderGeoDistance( Parser &$parser ) {
-               global $egMapsDistanceUnit, $egMapsDistanceDecimals;
-               
-               $args = func_get_args();
-               
-               // We already know the $parser.
-               array_shift( $args );
-               
-               $manager = new ValidatorManager();
-               
-               $doCalculation = $manager->manageParameters(
-                       $args,
-                       array(
-                               'location1' => array(
-                                       'required' => true,
-                                       'tolower' => false
-                               ),
-                               'location2' => array(
-                                       'required' => true,
-                                       'tolower' => false
-                               ),
-                               'unit' => array(
-                                       'criteria' => array(
-                                               'in_array' => 
MapsDistanceParser::getUnits()
-                                       ),
-                                       'default' => $egMapsDistanceUnit
-                               ),
-                               'decimals' => array(
-                                       'type' => 'integer',
-                                       'default' => $egMapsDistanceDecimals
-                               )                               
-                       ),
-                       array( 'location1', 'location2', 'unit', 'decimals' )
-               );
-               
-               if ( $doCalculation ) {
-                       $parameters = $manager->getParameters( false );
-                       
-                       $canGeocode = MapsMapper::geocoderIsAvailable();
-                       
-                       if ( $canGeocode ) {
-                               $start = MapsGeocoder::attemptToGeocode( 
$parameters['location1'] );
-                               $end = MapsGeocoder::attemptToGeocode( 
$parameters['location2'] );
-                       } else {
-                               $start = 
MapsCoordinateParser::parseCoordinates( $parameters['location1'] );
-                               $end = MapsCoordinateParser::parseCoordinates( 
$parameters['location2'] );
-                       }
-                       
-                       if ( $start && $end ) {
-                               $output = MapsDistanceParser::formatDistance( 
self::calculateDistance( $start, $end ), $parameters['unit'], 
$parameters['decimals'] );
-                               $errorList = $manager->getErrorList();
-                               
-                               if ( $errorList != '' ) {
-                                       $output .= '<br />' . $errorList;
-                               }
-                       } else {
-                               global $egValidatorFatalLevel;
-                               
-                               $fails = array();
-                               if ( !$start ) $fails[] = 
$parameters['location1'];
-                               if ( !$end ) $fails[] = 
$parameters['location2'];
-                               
-                               switch ( $egValidatorFatalLevel ) {
-                                       case Validator_ERRORS_NONE:
-                                               $output = '';
-                                               break;
-                                       case Validator_ERRORS_WARN:
-                                               $output = '<b>' . 
htmlspecialchars( wfMsgExt( 'validator_warning_parameters', array( 'parsemag' 
), count( $fails ) ) ) . '</b>';
-                                               break;
-                                       case Validator_ERRORS_SHOW: default:
-                                               global $wgLang;
-                                               
-                                               if ( $canGeocode ) {
-                                                       $output = 
htmlspecialchars( wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), 
$wgLang->listToText( $fails ), count( $fails ) ) );
-                                               } else {
-                                                       $output = 
htmlspecialchars( wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), 
$wgLang->listToText( $fails ), count( $fails ) ) );
-                                               }
-                                               break;
-                               }
-                       }
-               } else {
-                       // One of the parameters is not provided, so display an 
error message.
-                       $output = $manager->getErrorList();
-               }
-        
-               return $output;
-       }
-       
-       /**
         * Handler for the #finddestination parser function. 
         * See http://mapping.referata.com/wiki/Finddestination
         * 



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

Reply via email to