Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php |
— | — | @@ -19,7 +19,6 @@ |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @see MapsBaseMap::setMapSettings() |
23 | | - * |
24 | 23 | */ |
25 | 24 | protected function setMapSettings() { |
26 | 25 | global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix; |
— | — | @@ -30,7 +29,6 @@ |
31 | 30 | |
32 | 31 | /** |
33 | 32 | * @see MapsBaseMap::doMapServiceLoad() |
34 | | - * |
35 | 33 | */ |
36 | 34 | protected function doMapServiceLoad() { |
37 | 35 | global $egOpenLayersOnThisPage; |
— | — | @@ -43,7 +41,6 @@ |
44 | 42 | |
45 | 43 | /** |
46 | 44 | * @see MapsBaseMap::addSpecificMapHTML() |
47 | | - * |
48 | 45 | */ |
49 | 46 | public function addSpecificMapHTML( Parser $parser ) { |
50 | 47 | $layerItems = MapsOpenLayers::createLayersStringAndLoadDependencies( $this->output, $this->layers ); |
Index: trunk/extensions/Maps/Maps.i18n.magic.php |
— | — | @@ -3,13 +3,12 @@ |
4 | 4 | $magicWords = array(); |
5 | 5 | |
6 | 6 | $magicWords['en'] = array( |
| 7 | + 'display_map' => array( 0, 'display_map' ), |
7 | 8 | 'display_point' => array( 0, 'display_point' ), |
8 | 9 | 'display_points' => array( 0, 'display_points' ), |
9 | | - 'display_address' => array( 0, 'display_address' ), |
10 | | - 'display_addresses' => array( 0, 'display_addresses' ), |
11 | 10 | 'geocode' => array( 0, 'geocode' ), |
12 | 11 | 'geocodelat' => array( 0, 'geocodelat' ), |
13 | | - 'geocodelng' => array( 0, 'geocodelng' ), |
| 12 | + 'geocodelon' => array( 0, 'geocodelon' ), |
14 | 13 | ); |
15 | 14 | |
16 | 15 | $magicWords['ar'] = array( |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php |
— | — | @@ -16,7 +16,9 @@ |
17 | 17 | $wgAutoloadClasses['MapsDisplayPoint'] = $egMapsDir . 'ParserFunctions/DisplayPoint/Maps_DisplayPoint.php'; |
18 | 18 | $wgAutoloadClasses['MapsBasePointMap'] = $egMapsDir . 'ParserFunctions/DisplayPoint/Maps_BasePointMap.php'; |
19 | 19 | |
20 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic'; |
| 20 | +if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) { |
| 21 | + $wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic'; |
| 22 | +} |
21 | 23 | $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint'; |
22 | 24 | |
23 | 25 | $egMapsFeatures['pf'][] = 'MapsDisplayPoint::initialize'; |
— | — | @@ -52,7 +54,6 @@ |
53 | 55 | public static $parameters = array(); |
54 | 56 | |
55 | 57 | public static function initialize() { |
56 | | - self::initializeParams(); |
57 | 58 | } |
58 | 59 | |
59 | 60 | /** |
— | — | @@ -67,32 +68,4 @@ |
68 | 69 | return MapsParserFunctions::getMapHtml( $parser, $args, 'display_point' ); |
69 | 70 | } |
70 | 71 | |
71 | | - private static function initializeParams() { |
72 | | - global $egMapsDefaultCentre, $egMapsDefaultTitle, $egMapsDefaultLabel, $egMapsDefaultServices; |
73 | | - |
74 | | - self::$parameters = array_merge( |
75 | | - MapsParserFunctions::$parameters, |
76 | | - array( |
77 | | - 'service' => array( |
78 | | - 'default' => $egMapsDefaultServices['display_map'] |
79 | | - ), |
80 | | - 'centre' => array( |
81 | | - 'aliases' => array( 'center' ), |
82 | | - 'default' => $egMapsDefaultCentre |
83 | | - ), |
84 | | - 'title' => array( |
85 | | - 'default' => $egMapsDefaultTitle |
86 | | - ), |
87 | | - 'label' => array( |
88 | | - 'default' => $egMapsDefaultLabel |
89 | | - ), |
90 | | - 'icon' => array( |
91 | | - 'criteria' => array( |
92 | | - 'not_empty' => array() |
93 | | - ) |
94 | | - ), |
95 | | - ) |
96 | | - ); |
97 | | - } |
98 | | - |
99 | 72 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php |
— | — | @@ -22,12 +22,42 @@ |
23 | 23 | * |
24 | 24 | * @author Jeroen De Dauw |
25 | 25 | */ |
26 | | -abstract class MapsBasePointMap extends MapsMapFeature implements iDisplayFunction { |
| 26 | +abstract class MapsBasePointMap extends MapsMapFeature implements iDisplayFunction { |
27 | 27 | |
28 | 28 | private $markerData = array(); |
29 | 29 | protected $markerString; |
30 | 30 | |
31 | 31 | /** |
| 32 | + * @return array |
| 33 | + */ |
| 34 | + public function getFeatureParameters() { |
| 35 | + global $egMapsDefaultServices, $egMapsDefaultTitle, $egMapsDefaultLabel; |
| 36 | + |
| 37 | + return array_merge( |
| 38 | + parent::getFeatureParameters(), |
| 39 | + array( |
| 40 | + 'service' => array( |
| 41 | + 'default' => $egMapsDefaultServices['display_point'] |
| 42 | + ), |
| 43 | + 'centre' => array( |
| 44 | + 'aliases' => array( 'center' ), |
| 45 | + ), |
| 46 | + 'title' => array( |
| 47 | + 'default' => $egMapsDefaultTitle |
| 48 | + ), |
| 49 | + 'label' => array( |
| 50 | + 'default' => $egMapsDefaultLabel |
| 51 | + ), |
| 52 | + 'icon' => array( |
| 53 | + 'criteria' => array( |
| 54 | + 'not_empty' => array() |
| 55 | + ) |
| 56 | + ), |
| 57 | + ) |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
32 | 62 | * Handles the request from the parser hook by doing the work that's common for all |
33 | 63 | * mapping services, calling the specific methods and finally returning the resulting output. |
34 | 64 | * |
— | — | @@ -40,24 +70,24 @@ |
41 | 71 | $this->setMapSettings(); |
42 | 72 | |
43 | 73 | $this->featureParameters = MapsDisplayPoint::$parameters; |
44 | | - |
45 | | - if ( parent::manageMapProperties( $params, __CLASS__ ) ) { |
46 | | - $this->doMapServiceLoad(); |
47 | 74 | |
48 | | - $this->setMapName(); |
49 | | - |
50 | | - $this->setMarkerData( $parser ); |
51 | | - |
52 | | - $this->createMarkerString(); |
53 | | - |
54 | | - $this->setZoom(); |
55 | | - |
56 | | - $this->setCentre(); |
57 | | - |
58 | | - $this->addSpecificMapHTML( $parser ); |
59 | | - } |
| 75 | + $this->doMapServiceLoad(); |
| 76 | + |
| 77 | + parent::setMapProperties( $params, __CLASS__ ); |
60 | 78 | |
61 | | - return $this->output . $this->errorList; |
| 79 | + $this->setMapName(); |
| 80 | + |
| 81 | + $this->setMarkerData( $parser ); |
| 82 | + |
| 83 | + $this->createMarkerString(); |
| 84 | + |
| 85 | + $this->setZoom(); |
| 86 | + |
| 87 | + $this->setCentre(); |
| 88 | + |
| 89 | + $this->addSpecificMapHTML( $parser ); |
| 90 | + |
| 91 | + return $this->output; |
62 | 92 | } |
63 | 93 | |
64 | 94 | /** |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php |
— | — | @@ -16,7 +16,9 @@ |
17 | 17 | $wgAutoloadClasses['MapsDisplayMap'] = $egMapsDir . 'ParserFunctions/DisplayMap/Maps_DisplayMap.php'; |
18 | 18 | $wgAutoloadClasses['MapsBaseMap'] = $egMapsDir . 'ParserFunctions/DisplayMap/Maps_BaseMap.php'; |
19 | 19 | |
20 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic'; |
| 20 | +if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) { |
| 21 | + $wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic'; |
| 22 | +} |
21 | 23 | $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap'; |
22 | 24 | |
23 | 25 | $egMapsFeatures['pf'][] = 'MapsDisplayMap::initialize'; |
— | — | @@ -51,7 +53,6 @@ |
52 | 54 | public static $parameters = array(); |
53 | 55 | |
54 | 56 | public static function initialize() { |
55 | | - self::initializeParams(); |
56 | 57 | } |
57 | 58 | |
58 | 59 | /** |
— | — | @@ -65,18 +66,5 @@ |
66 | 67 | $args = func_get_args(); |
67 | 68 | return MapsParserFunctions::getMapHtml( $parser, $args, 'display_map' ); |
68 | 69 | } |
69 | | - |
70 | | - private static function initializeParams() { |
71 | | - global $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsDefaultServices; |
72 | | - |
73 | | - self::$parameters = array_merge( |
74 | | - MapsParserFunctions::$parameters, |
75 | | - array( |
76 | | - 'service' => array( |
77 | | - 'default' => $egMapsDefaultServices['display_map'] |
78 | | - ), |
79 | | - ) |
80 | | - ); |
81 | | - } |
82 | 70 | |
83 | 71 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php |
— | — | @@ -25,6 +25,22 @@ |
26 | 26 | abstract class MapsBaseMap extends MapsMapFeature implements iDisplayFunction { |
27 | 27 | |
28 | 28 | /** |
| 29 | + * @return array |
| 30 | + */ |
| 31 | + public function getFeatureParameters() { |
| 32 | + global $egMapsDefaultServices; |
| 33 | + |
| 34 | + return array_merge( |
| 35 | + parent::getFeatureParameters(), |
| 36 | + array( |
| 37 | + 'service' => array( |
| 38 | + 'default' => $egMapsDefaultServices['display_map'] |
| 39 | + ) |
| 40 | + ) |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
29 | 45 | * Handles the request from the parser hook by doing the work that's common for all |
30 | 46 | * mapping services, calling the specific methods and finally returning the resulting output. |
31 | 47 | * |
— | — | @@ -38,19 +54,19 @@ |
39 | 55 | |
40 | 56 | $this->featureParameters = MapsDisplayMap::$parameters; |
41 | 57 | |
42 | | - if ( parent::manageMapProperties( $params, __CLASS__ ) ) { |
43 | | - $this->doMapServiceLoad(); |
44 | | - |
45 | | - $this->setMapName(); |
46 | | - |
47 | | - $this->setZoom(); |
48 | | - |
49 | | - $this->setCentre(); |
50 | | - |
51 | | - $this->addSpecificMapHTML( $parser ); |
52 | | - } |
| 58 | + $this->doMapServiceLoad(); |
| 59 | + |
| 60 | + parent::setMapProperties( $params, __CLASS__ ); |
53 | 61 | |
54 | | - return $this->output . $this->errorList; |
| 62 | + $this->setMapName(); |
| 63 | + |
| 64 | + $this->setZoom(); |
| 65 | + |
| 66 | + $this->setCentre(); |
| 67 | + |
| 68 | + $this->addSpecificMapHTML( $parser ); |
| 69 | + |
| 70 | + return $this->output; |
55 | 71 | } |
56 | 72 | |
57 | 73 | /** |
— | — | @@ -81,7 +97,10 @@ |
82 | 98 | $this->centreLon = Xml::escapeJsString( $this->coordinates['lon'] ); |
83 | 99 | } |
84 | 100 | else { // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used. |
85 | | - $this->setCentreDefaults(); |
| 101 | + // TODO: Some warning this failed would be nice here. |
| 102 | + global $egMapsMapLat, $egMapsMapLon; |
| 103 | + $this->centreLat = $egMapsMapLat; |
| 104 | + $this->centreLon = $egMapsMapLon; |
86 | 105 | } |
87 | 106 | } |
88 | 107 | } |
Index: trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php |
— | — | @@ -19,7 +19,9 @@ |
20 | 20 | // The approximate radius of the earth in km. |
21 | 21 | define( 'Maps_EARTH_RADIUS', 20000 / M_PI ); |
22 | 22 | |
23 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionsMagic'; |
| 23 | +if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) { |
| 24 | + $wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionsMagic'; |
| 25 | +} |
24 | 26 | $wgHooks['ParserFirstCallInit'][] = 'efMapsGeoFunctions'; |
25 | 27 | |
26 | 28 | /** |
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php |
— | — | @@ -14,7 +14,9 @@ |
15 | 15 | die( 'Not an entry point.' ); |
16 | 16 | } |
17 | 17 | |
18 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionMagic'; |
| 18 | +if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) { |
| 19 | + $wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionMagic'; |
| 20 | +} |
19 | 21 | $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterGeoFunctions'; |
20 | 22 | |
21 | 23 | /** |
Index: trunk/extensions/Maps/ParserFunctions/Coordinates/Maps_Coordinates.php |
— | — | @@ -14,7 +14,9 @@ |
15 | 15 | die( 'Not an entry point.' ); |
16 | 16 | } |
17 | 17 | |
18 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsCoordinatesMagic'; |
| 18 | +if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) { |
| 19 | + $wgHooks['LanguageGetMagic'][] = 'efMapsCoordinatesMagic'; |
| 20 | +} |
19 | 21 | $wgHooks['ParserFirstCallInit'][] = 'efMapsCoordinatesFunction'; |
20 | 22 | |
21 | 23 | /** |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php |
— | — | @@ -7,8 +7,6 @@ |
8 | 8 | * @ingroup Maps |
9 | 9 | * |
10 | 10 | * @author Jeroen De Dauw |
11 | | - * |
12 | | - * TODO: clean up this stuff (goes together with refactoring MapsMapFeature and it's subclasses). |
13 | 11 | */ |
14 | 12 | |
15 | 13 | if ( !defined( 'MEDIAWIKI' ) ) { |
— | — | @@ -37,8 +35,6 @@ |
38 | 36 | |
39 | 37 | include_once $egMapsDir . 'ParserFunctions/Maps_iDisplayFunction.php'; |
40 | 38 | |
41 | | - self::initializeParams(); |
42 | | - |
43 | 39 | // This runs a small hook that enables parser functions to run initialization code. |
44 | 40 | foreach ( $egMapsFeatures['pf'] as $hook ) { |
45 | 41 | call_user_func( $hook ); |
— | — | @@ -49,23 +45,6 @@ |
50 | 46 | |
51 | 47 | private static function initializeParams() { |
52 | 48 | global $egMapsAvailableServices, $egMapsDefaultServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
53 | | - |
54 | | - self::$parameters = array( |
55 | | - 'service' => array( |
56 | | - 'criteria' => array( |
57 | | - 'in_array' => $egMapsAvailableServices |
58 | | - ), |
59 | | - ), |
60 | | - 'coordinates' => array( |
61 | | - 'aliases' => array( 'coords', 'location', 'locations' ), |
62 | | - ), |
63 | | - 'geoservice' => array( |
64 | | - 'criteria' => array( |
65 | | - 'in_array' => $egMapsAvailableGeoServices |
66 | | - ), |
67 | | - 'default' => $egMapsDefaultGeoService |
68 | | - ), |
69 | | - ); |
70 | 49 | } |
71 | 50 | |
72 | 51 | /** |
— | — | @@ -77,197 +56,68 @@ |
78 | 57 | * |
79 | 58 | * @return array |
80 | 59 | */ |
81 | | - public static function getMapHtml( Parser &$parser, array $params, $parserFunction ) { |
82 | | - global $wgLang, $egValidatorErrorLevel, $egValidatorFatalLevel; |
| 60 | + public static function getMapHtml( Parser &$parser, array $args, $parserFunction ) { |
| 61 | + global $wgLang, $egValidatorErrorLevel, $egValidatorFatalLevel, $egMapsServices; |
83 | 62 | |
84 | | - array_shift( $params ); // We already know the $parser. |
85 | | - |
86 | | - $map = array(); |
87 | | - $coordFails = array(); |
| 63 | + array_shift( $args ); // We already know the $parser. |
88 | 64 | |
89 | | - $paramInfo = array_merge( MapsMapper::getMainParams(), self::$parameters ); |
90 | | - |
91 | | - $geoFails = self::changeAddressesToCoords( $params, $paramInfo, $parserFunction ); |
| 65 | + $parameters = array(); |
| 66 | + $setService = false; |
92 | 67 | |
93 | | - // Go through all parameters, split their names and values, and put them in the $map array. |
94 | | - foreach ( $params as $param ) { |
95 | | - $split = explode( '=', $param ); |
96 | | - if ( count( $split ) > 1 ) { |
97 | | - $paramName = strtolower( trim( array_shift( $split ) ) ); |
98 | | - $paramValue = trim( implode( $split ) ); |
99 | | - if ( $paramName != '' && $paramValue != '' ) { |
100 | | - $map[$paramName] = $paramValue; |
101 | | - if ( self::inParamAliases( $paramName, 'coordinates', $paramInfo ) ) $coordFails = self::filterInvalidCoords( $map[$paramName] ); |
102 | | - } |
103 | | - } |
104 | | - else { // Default parameter (without name). |
105 | | - $split[0] = trim( $split[0] ); |
106 | | - if ( $split[0] != '' ) $map['coordinates'] = $split[0]; |
107 | | - } |
108 | | - } |
109 | | - |
110 | | - $coords = self::getParamValue( 'coordinates', $map, $paramInfo ); |
111 | | - |
112 | | - if ( $coords ) { |
113 | | - $mapClass = self::getParserClassInstance( $map['service'], $parserFunction ); |
114 | | - |
115 | | - // Call the function according to the map service to get the HTML output. |
116 | | - $output = $mapClass->displayMap( $parser, $map ); |
117 | | - |
118 | | - if ( $egValidatorErrorLevel >= Validator_ERRORS_WARN ) { |
119 | | - if ( count( $coordFails ) > 0 ) { |
120 | | - $output .= '<i>' . htmlspecialchars( wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) ) . '</i>'; |
121 | | - } |
122 | | - |
123 | | - if ( count( $geoFails ) > 0 ) { |
124 | | - $output .= '<i>' . htmlspecialchars( wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) ) . '</i>'; |
125 | | - } |
126 | | - } |
127 | | - } |
128 | | - elseif ( $egValidatorFatalLevel >= Validator_ERRORS_NONE ) { |
129 | | - if ( $coords == '' && ( count( $geoFails ) > 0 || count( $coordFails ) > 0 ) ) { |
130 | | - if ( count( $coordFails ) > 0 ) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
131 | | - if ( count( $geoFails ) > 0 ) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; |
132 | | - $output .= '<i>' . htmlspecialchars( wfMsg( 'maps_map_cannot_be_displayed' ) ) . '</i>'; |
133 | | - } |
134 | | - else { |
135 | | - $output = '<i>' . htmlspecialchars( wfMsg( 'maps_coordinates_missing' ) ) . '</i>'; |
136 | | - } |
137 | | - } |
138 | | - |
139 | | - // Return the result. |
140 | | - return array( $output, 'noparse' => true, 'isHTML' => true ); |
141 | | - } |
142 | | - |
143 | | - /** |
144 | | - * Filters all non coordinate valus from a coordinate string, |
145 | | - * and returns an array containing all filtered out values. |
146 | | - * |
147 | | - * @param string $coordList |
148 | | - * @param string $delimeter |
149 | | - * |
150 | | - * @return array |
151 | | - */ |
152 | | - public static function filterInvalidCoords( &$coordList, $delimeter = ';' ) { |
153 | | - $coordFails = array(); |
154 | | - $validCoordinates = array(); |
155 | | - $coordinateSets = explode( $delimeter, $coordList ); |
156 | | - |
157 | | - // Loop through all the provided coordinates. If they are valid, format their parsed values |
158 | | - // to non-directional floats, and add them to the valid array, else add them to the fails array. |
159 | | - foreach ( $coordinateSets as $coordinates ) { |
160 | | - $parsedCoords = MapsCoordinateParser::parseCoordinates( $coordinates ); |
161 | | - |
162 | | - if ( $parsedCoords ) { // Will be false when parsing failed. |
163 | | - $validCoordinates[] = MapsCoordinateParser::formatCoordinates( $parsedCoords, Maps_COORDS_FLOAT, false ); |
| 68 | + foreach( $args as $arg ) { |
| 69 | + $split = explode( '=', $arg ); |
| 70 | + $name = strtolower( trim( array_shift( $split ) ) ); |
| 71 | + if ( count( $split ) > 1 && self::inParamAliases( $name, 'service', self::$parameters ) ) { |
| 72 | + if ( !$setService ) { |
| 73 | + $service = implode( '=', $split ); |
| 74 | + $parameters = 'service=' . $service; |
| 75 | + $setService = true; |
| 76 | + } |
| 77 | + } else { |
| 78 | + $parameters[] = $arg; |
164 | 79 | } |
165 | | - else { |
166 | | - $coordFails[] = $coordinates; |
167 | | - } |
168 | 80 | } |
169 | 81 | |
170 | | - $coordList = implode( $delimeter, $validCoordinates ); |
171 | | - return $coordFails; |
172 | | - } |
173 | | - |
174 | | - /** |
175 | | - * Changes the values of the address or addresses parameter into coordinates |
176 | | - * in the provided array. Returns an array containing the addresses that |
177 | | - * could not be geocoded. |
178 | | - * |
179 | | - * Also ensures the service parameter is valid. |
180 | | - * |
181 | | - * @param array $params |
182 | | - * |
183 | | - * @return array |
184 | | - */ |
185 | | - private static function changeAddressesToCoords( &$params, array $paramInfo, $parserFunction ) { |
186 | | - global $egMapsDefaultService; |
187 | | - |
188 | | - $fails = array(); |
| 82 | + $service = MapsMapper::getValidService( $setService ? $service : '', $parserFunction ); |
189 | 83 | |
190 | | - // Get the service and geoservice from the parameters, since they are needed to geocode addresses. |
191 | | - for ( $i = 0; $i < count( $params ); $i++ ) { |
192 | | - $split = explode( '=', $params[$i] ); |
193 | | - if ( self::inParamAliases( strtolower( trim( $split[0] ) ), 'service', $paramInfo ) && count( $split ) > 1 ) { |
194 | | - $service = trim( $split[1] ); |
195 | | - } |
196 | | - else if ( strtolower( trim( $split[0] ) ) == 'geoservice' && count( $split ) > 1 ) { |
197 | | - $geoservice = trim( $split[1] ); |
198 | | - } |
199 | | - } |
200 | | - |
201 | | - // Make sure the service and geoservice are valid. |
202 | | - if ( !isset( $service ) ) $service = ''; |
203 | | - $service = MapsMapper::getValidService( $service, $parserFunction ); |
| 84 | + // TODO: hook into Validator for main parameter validation, geocoding and coordinate parsing |
204 | 85 | |
205 | | - if ( ! isset( $geoservice ) ) $geoservice = ''; |
| 86 | + $mapClass = new $egMapsServices[$service]['features'][$parserFunction](); |
206 | 87 | |
207 | | - $setService = false; |
| 88 | + $manager = new ValidatorManager(); |
208 | 89 | |
209 | | - // Go over all parameters. |
210 | | - for ( $i = 0; $i < count( $params ); $i++ ) { |
211 | | - $split = explode( '=', $params[$i] ); |
212 | | - $isAddress = ( strtolower( trim( $split[0] ) ) == 'address' || strtolower( trim( $split[0] ) ) == 'addresses' ) && count( $split ) > 1; |
213 | | - $isDefault = count( $split ) == 1; |
214 | | - |
215 | | - // If a parameter is either the default (no name), or an addresses list, extract all locations. |
216 | | - if ( $isAddress || $isDefault ) { |
217 | | - |
218 | | - $address_srting = $split[count( $split ) == 1 ? 0 : 1]; |
219 | | - $addresses = explode( ';', $address_srting ); |
220 | | - |
221 | | - $coordinates = array(); |
222 | | - |
223 | | - // Go over every location and attempt to geocode it. |
224 | | - foreach ( $addresses as $address ) { |
225 | | - $args = explode( '~', $address ); |
226 | | - $args[0] = trim( $args[0] ); |
227 | | - |
228 | | - if ( strlen( $args[0] ) > 0 ) { |
229 | | - $coords = MapsGeocoder::attemptToGeocodeToString( $args[0], $geoservice, $service, $isDefault ); |
230 | | - |
231 | | - if ( $coords ) { |
232 | | - $args[0] = $coords; |
233 | | - $coordinates[] = implode( '~', $args ); |
234 | | - } |
235 | | - else { |
236 | | - $fails[] = $args[0]; |
237 | | - } |
238 | | - } |
239 | | - } |
240 | | - |
241 | | - // Add the geocoded result back to the parameter list. |
242 | | - $params[$i] = implode( ';', $coordinates ); |
243 | | - |
244 | | - } else if ( self::inParamAliases( strtolower( trim( $split[0] ) ), 'service', $paramInfo ) && count( $split ) > 1 ) { |
245 | | - $params[$i] = "service=$service"; |
246 | | - $setService = true; |
247 | | - } |
248 | | - } |
249 | | - |
250 | | - if ( !$setService ) { |
251 | | - $params[] = "service=$service"; |
252 | | - } |
| 90 | + /* |
| 91 | + * Assembliy of the allowed parameters and their information. |
| 92 | + * The main parameters (the ones that are shared by everything) are overidden |
| 93 | + * by the feature parameters (the ones spesific to a feature). The result is then |
| 94 | + * again overidden by the service parameters (the ones spesific to the service), |
| 95 | + * and finally by the spesific parameters (the ones spesific to a service-feature combination). |
| 96 | + */ |
| 97 | + $parameterInfo = array_merge( MapsMapper::getMainParams(), self::$parameters ); |
| 98 | + $parameterInfo = array_merge( $parameterInfo, $mapClass->getFeatureParameters() ); |
| 99 | + $parameterInfo = array_merge( $parameterInfo, $egMapsServices[$service]['parameters'] ); |
| 100 | + $parameterInfo = array_merge( $parameterInfo, $mapClass->getSpecificParameterInfo() ); |
253 | 101 | |
254 | | - return $fails; |
| 102 | + $parameters = $manager->manageParameters( |
| 103 | + $parameters, |
| 104 | + $parameterInfo, |
| 105 | + array( 'coordinates' ) |
| 106 | + ); |
| 107 | + |
| 108 | + $displayMap = $parameters !== false; |
| 109 | + |
| 110 | + if ( $displayMap ) { |
| 111 | + // Call the function according to the map service to get the HTML output. |
| 112 | + $output = $mapClass->displayMap( $parser, $parameters ) . $manager->getErrorList(); |
| 113 | + } else { |
| 114 | + // TODO: add errors to output depending on validator fatal level |
| 115 | + } |
| 116 | + |
| 117 | + // Return the result. |
| 118 | + return array( $output, 'noparse' => true, 'isHTML' => true ); |
255 | 119 | } |
256 | 120 | |
257 | 121 | /** |
258 | | - * Returns an instance of the class supporting the spesified mapping service for |
259 | | - * the also spesified parser function. |
260 | | - * |
261 | | - * @param string $service |
262 | | - * @param string $parserFunction |
263 | | - * |
264 | | - * @return MapsMapFeature |
265 | | - */ |
266 | | - public static function getParserClassInstance( $service, $parserFunction ) { |
267 | | - global $egMapsServices; |
268 | | - return new $egMapsServices[$service]['features'][$parserFunction](); |
269 | | - } |
270 | | - |
271 | | - /** |
272 | 122 | * Gets if a provided name is present in the aliases array of a parameter |
273 | 123 | * name in the $mainParams array. |
274 | 124 | * |
— | — | @@ -287,59 +137,4 @@ |
288 | 138 | |
289 | 139 | return $equals; |
290 | 140 | } |
291 | | - |
292 | | - /** |
293 | | - * Gets if a parameter is present as key in the $stack. Also checks for |
294 | | - * the presence of aliases in the $mainParams array unless specified not to. |
295 | | - * |
296 | | - * @param string $paramName |
297 | | - * @param array $stack |
298 | | - * @param array $paramInfo Contains meta data, including aliases, of the possible parameters. |
299 | | - * @param boolean $checkForAliases |
300 | | - * |
301 | | - * @return boolean |
302 | | - */ |
303 | | - public static function paramIsPresent( $paramName, array $stack, array $paramInfo = array(), $checkForAliases = true ) { |
304 | | - $isPresent = array_key_exists( $paramName, $stack ); |
305 | | - |
306 | | - if ( !$isPresent && $checkForAliases && array_key_exists( 'aliases', $paramInfo[$paramName] ) ) { |
307 | | - foreach ( $paramInfo[$paramName]['aliases'] as $alias ) { |
308 | | - if ( array_key_exists( $alias, $stack ) ) { |
309 | | - $isPresent = true; |
310 | | - break; |
311 | | - } |
312 | | - } |
313 | | - } |
314 | | - |
315 | | - return $isPresent; |
316 | | - } |
317 | | - |
318 | | - /** |
319 | | - * Returns the value of a parameter represented as key in the $stack. |
320 | | - * Also checks for the presence of aliases in the $mainParams array |
321 | | - * and returns the value of the alies unless specified not to. When |
322 | | - * no array key name match is found, false will be returned. |
323 | | - * |
324 | | - * @param string $paramName |
325 | | - * @param array $stack The values to search through |
326 | | - * @param array $paramInfo Contains meta data, including aliases, of the possible parameters. |
327 | | - * @param boolean $checkForAliases |
328 | | - * |
329 | | - * @return the parameter value or false |
330 | | - */ |
331 | | - private static function getParamValue( $paramName, array $stack, array $paramInfo = array(), $checkForAliases = true ) { |
332 | | - $paramValue = false; |
333 | | - |
334 | | - if ( array_key_exists( $paramName, $stack ) ) $paramValue = $stack[$paramName]; |
335 | | - |
336 | | - if ( $checkForAliases ) { |
337 | | - foreach ( $paramInfo[$paramName]['aliases'] as $alias ) { |
338 | | - if ( array_key_exists( $alias, $stack ) ) $paramValue = $stack[$alias]; |
339 | | - break; |
340 | | - } |
341 | | - } |
342 | | - |
343 | | - return $paramValue; |
344 | | - } |
345 | | - |
346 | 141 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -62,8 +62,12 @@ |
63 | 63 | // Include the settings file. |
64 | 64 | require_once( $egMapsDir . 'Maps_Settings.php' ); |
65 | 65 | |
66 | | - $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php'; |
| 66 | + $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php'; |
67 | 67 | |
| 68 | + if( version_compare( $wgVersion, '1.16alpha', '>=' ) ) { |
| 69 | + $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.magic.php'; |
| 70 | + } |
| 71 | + |
68 | 72 | // Register the initialization function of Maps. |
69 | 73 | $wgExtensionFunctions[] = 'efMapsSetup'; |
70 | 74 | |
Index: trunk/extensions/Maps/Maps_Mapper.php |
— | — | @@ -14,22 +14,16 @@ |
15 | 15 | } |
16 | 16 | |
17 | 17 | final class MapsMapper { |
18 | | - |
19 | | - /** |
20 | | - * Array holding the parameters that are not spesific to a mapping service, |
21 | | - * their aliases, criteria and default value. |
22 | | - * |
23 | | - * @var array |
24 | | - */ |
25 | | - private static $mainParams; |
26 | 18 | |
| 19 | + private static $mainParams; |
| 20 | + |
27 | 21 | public static function initializeMainParams() { |
28 | 22 | global $egMapsSizeRestrictions, $egMapsMapWidth, $egMapsMapHeight; |
29 | 23 | |
30 | 24 | Validator::addOutputFormat( 'mapdimension', array( __CLASS__, 'setMapDimension' ) ); |
31 | | - Validator::addValidationFunction( 'is_map_dimension', array( __CLASS__, 'isMapDimension' ) ); |
32 | | - |
33 | | - self::$mainParams = array ( |
| 25 | + Validator::addValidationFunction( 'is_map_dimension', array( __CLASS__, 'isMapDimension' ) ); |
| 26 | + |
| 27 | + self::$mainParams = array( |
34 | 28 | 'zoom' => array( |
35 | 29 | 'type' => 'integer', |
36 | 30 | 'criteria' => array( |
— | — | @@ -49,10 +43,10 @@ |
50 | 44 | ), |
51 | 45 | 'default' => $egMapsMapHeight, |
52 | 46 | 'output-type' => array( 'mapdimension', 'height', $egMapsMapHeight ) |
53 | | - ), |
| 47 | + ), |
54 | 48 | ); |
55 | 49 | } |
56 | | - |
| 50 | + |
57 | 51 | /** |
58 | 52 | * Returns the main parameters array. |
59 | 53 | * |
— | — | @@ -60,7 +54,7 @@ |
61 | 55 | */ |
62 | 56 | public static function getMainParams() { |
63 | 57 | return self::$mainParams; |
64 | | - } |
| 58 | + } |
65 | 59 | |
66 | 60 | /** |
67 | 61 | * Returns a valid service. When an invalid service is provided, the default one will be returned. |
— | — | @@ -68,7 +62,6 @@ |
69 | 63 | * |
70 | 64 | * @param string $service |
71 | 65 | * @param string $feature |
72 | | - * @param string $subfeature |
73 | 66 | * |
74 | 67 | * @return string |
75 | 68 | */ |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php |
— | — | @@ -24,30 +24,33 @@ |
25 | 25 | |
26 | 26 | public $serviceName = MapsGoogleMaps::SERVICE_NAME; |
27 | 27 | |
28 | | - /** |
29 | | - * @see MapsBaseMap::setMapSettings() |
30 | | - * |
31 | | - */ |
32 | | - protected function setMapSettings() { |
33 | | - global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix, $egMapsGMapOverlays; |
34 | | - |
35 | | - $this->elementNamePrefix = $egMapsGoogleMapsPrefix; |
36 | | - $this->defaultZoom = $egMapsGoogleMapsZoom; |
37 | | - |
| 28 | + public function getSpecificParameterInfo() { |
| 29 | + global $egMapsGMapOverlays; |
| 30 | + // TODO: it'd be cool to have this static so it can be cheched in order to only init it once. |
38 | 31 | $this->spesificParameters = array( |
39 | 32 | 'overlays' => array( |
40 | 33 | 'type' => array( 'string', 'list' ), |
41 | 34 | 'criteria' => array( |
42 | 35 | 'is_google_overlay' => array() |
43 | | - ), |
| 36 | + ), |
44 | 37 | 'default' => $egMapsGMapOverlays, |
45 | | - ), |
| 38 | + ), |
46 | 39 | ); |
| 40 | + return $this->spesificParameters; |
47 | 41 | } |
48 | 42 | |
49 | 43 | /** |
| 44 | + * @see MapsBaseMap::setMapSettings() |
| 45 | + */ |
| 46 | + protected function setMapSettings() { |
| 47 | + global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix; |
| 48 | + |
| 49 | + $this->elementNamePrefix = $egMapsGoogleMapsPrefix; |
| 50 | + $this->defaultZoom = $egMapsGoogleMapsZoom; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
50 | 54 | * @see MapsBaseMap::doMapServiceLoad() |
51 | | - * |
52 | 55 | */ |
53 | 56 | protected function doMapServiceLoad() { |
54 | 57 | global $egGoogleMapsOnThisPage; |
— | — | @@ -60,7 +63,6 @@ |
61 | 64 | |
62 | 65 | /** |
63 | 66 | * @see MapsBaseMap::addSpecificMapHTML() |
64 | | - * |
65 | 67 | */ |
66 | 68 | public function addSpecificMapHTML( Parser $parser ) { |
67 | 69 | MapsGoogleMaps::addOverlayOutput( $this->output, $this->mapName, $this->overlays, $this->controls ); |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php |
— | — | @@ -24,27 +24,32 @@ |
25 | 25 | |
26 | 26 | public $serviceName = MapsGoogleMaps::SERVICE_NAME; |
27 | 27 | |
| 28 | + public function getSpecificParameterInfo() { |
| 29 | + global $egMapsGMapOverlays; |
| 30 | + // TODO: it'd be cool to have this static so it can be cheched in order to only init it once. |
| 31 | + $this->spesificParameters = array( |
| 32 | + 'overlays' => array( |
| 33 | + 'type' => array( 'string', 'list' ), |
| 34 | + 'criteria' => array( |
| 35 | + 'is_google_overlay' => array() |
| 36 | + ), |
| 37 | + 'default' => $egMapsGMapOverlays, |
| 38 | + ), |
| 39 | + ); |
| 40 | + return $this->spesificParameters; |
| 41 | + } |
| 42 | + |
28 | 43 | /** |
29 | 44 | * @see MapsBaseMap::setMapSettings() |
30 | 45 | * |
31 | 46 | */ |
32 | 47 | protected function setMapSettings() { |
33 | | - global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix, $egMapsGMapOverlays; |
| 48 | + global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix; |
34 | 49 | |
35 | 50 | $this->elementNamePrefix = $egMapsGoogleMapsPrefix; |
36 | 51 | $this->defaultZoom = $egMapsGoogleMapsZoom; |
37 | 52 | |
38 | 53 | $this->markerStringFormat = 'getGMarkerData(lat, lon, \'title\', \'label\', "icon")'; |
39 | | - |
40 | | - $this->spesificParameters = array( |
41 | | - 'overlays' => array( |
42 | | - 'type' => array( 'string', 'list' ), |
43 | | - 'criteria' => array( |
44 | | - 'is_google_overlay' => array() |
45 | | - ), |
46 | | - 'default' => $egMapsGMapOverlays, |
47 | | - ), |
48 | | - ); |
49 | 54 | } |
50 | 55 | |
51 | 56 | /** |
Index: trunk/extensions/Maps/Maps_MapFeature.php |
— | — | @@ -40,70 +40,32 @@ |
41 | 41 | protected abstract function addSpecificMapHTML( Parser $parser ); |
42 | 42 | |
43 | 43 | public $serviceName; |
44 | | - |
45 | | - protected $defaultZoom; |
46 | 44 | |
47 | 45 | protected $elementNr; |
48 | 46 | protected $elementNamePrefix; |
49 | 47 | |
50 | 48 | protected $mapName; |
51 | 49 | |
52 | | - protected $centreLat; |
53 | | - protected $centreLon; |
| 50 | + protected $centreLat, $centreLon; |
54 | 51 | |
55 | 52 | protected $output = ''; |
56 | | - protected $errorList; |
| 53 | + |
| 54 | + protected $spesificParameters = false; |
| 55 | + protected $featureParameters = false; |
57 | 56 | |
58 | | - protected $featureParameters = array(); |
59 | | - protected $spesificParameters = array(); |
60 | | - |
61 | 57 | /** |
62 | | - * Validates and corrects the provided map properties, and the sets them as class fields. |
63 | | - * |
64 | | - * @param array $mapProperties |
65 | | - * @param string $className |
66 | | - * |
67 | | - * @return boolean Indicates whether the map should be shown or not. |
68 | | - */ |
69 | | - protected final function manageMapProperties( array $mapProperties, $className ) { |
70 | | - global $egMapsServices; |
71 | | - |
72 | | - /* |
73 | | - * Assembliy of the allowed parameters and their information. |
74 | | - * The main parameters (the ones that are shared by everything) are overidden |
75 | | - * by the feature parameters (the ones spesific to a feature). The result is then |
76 | | - * again overidden by the service parameters (the ones spesific to the service), |
77 | | - * and finally by the spesific parameters (the ones spesific to a service-feature combination). |
78 | | - */ |
79 | | - $parameterInfo = array_merge( MapsMapper::getMainParams(), $this->featureParameters ); |
80 | | - $parameterInfo = array_merge( $parameterInfo, $egMapsServices[$this->serviceName]['parameters'] ); |
81 | | - $parameterInfo = array_merge( $parameterInfo, $this->spesificParameters ); |
82 | | - |
83 | | - $manager = new ValidatorManager(); |
84 | | - |
85 | | - $result = $manager->manageParameters( $mapProperties, $parameterInfo ); |
86 | | - |
87 | | - $showMap = $result !== false; |
88 | | - |
89 | | - if ( $showMap ) $this->setMapProperties( $result, $className ); |
90 | | - |
91 | | - $this->errorList = $manager->getErrorList(); |
92 | | - |
93 | | - return $showMap; |
94 | | - } |
95 | | - |
96 | | - /** |
97 | 58 | * Sets the map properties as class fields. |
98 | 59 | * |
99 | 60 | * @param array $mapProperties |
100 | 61 | * @param string $className |
101 | 62 | */ |
102 | | - private function setMapProperties( array $mapProperties, $className ) { |
| 63 | + protected function setMapProperties( array $mapProperties, $className ) { |
103 | 64 | foreach ( $mapProperties as $paramName => $paramValue ) { |
104 | | - if ( ! property_exists( $className, $paramName ) ) { |
| 65 | + if ( !property_exists( $className, $paramName ) ) { |
105 | 66 | $this-> { $paramName } = $paramValue; |
106 | 67 | } |
107 | 68 | else { |
| 69 | + // If this happens in any way, it could be a big vunerability, so throw an exception. |
108 | 70 | throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName ); |
109 | 71 | } |
110 | 72 | } |
— | — | @@ -116,4 +78,34 @@ |
117 | 79 | $this->mapName = $this->elementNamePrefix . '_' . $this->elementNr; |
118 | 80 | } |
119 | 81 | |
| 82 | + /** |
| 83 | + * @return array |
| 84 | + */ |
| 85 | + public function getSpecificParameterInfo() { |
| 86 | + return array(); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @return array |
| 91 | + */ |
| 92 | + public function getFeatureParameters() { |
| 93 | + global $egMapsAvailableServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
| 94 | + |
| 95 | + return array( |
| 96 | + 'service' => array( |
| 97 | + 'criteria' => array( |
| 98 | + 'in_array' => $egMapsAvailableServices |
| 99 | + ), |
| 100 | + ), |
| 101 | + 'coordinates' => array( |
| 102 | + 'aliases' => array( 'coords', 'location', 'locations' ), |
| 103 | + ), |
| 104 | + 'geoservice' => array( |
| 105 | + 'criteria' => array( |
| 106 | + 'in_array' => $egMapsAvailableGeoServices |
| 107 | + ), |
| 108 | + 'default' => $egMapsDefaultGeoService |
| 109 | + ), |
| 110 | + ); |
| 111 | + } |
120 | 112 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/Maps_Settings.php |
— | — | @@ -152,11 +152,6 @@ |
153 | 153 | $egMapsMapLat = '1'; |
154 | 154 | $egMapsMapLon = '1'; |
155 | 155 | |
156 | | -# String. The default centre for a map. Must be in floating point notation. |
157 | | -# This value will override the smart behaviour when multiple markers are present when set. |
158 | | -# This value will only be used when the user does not provide one. |
159 | | -$egMapsDefaultCentre = ''; |
160 | | - |
161 | 156 | # Strings. The default content for all pop-ups. This value will only be used when the user does not provide one. |
162 | 157 | $egMapsDefaultTitle = ''; |
163 | 158 | $egMapsDefaultLabel = ''; |