Pastakhov has uploaded a new change for review.
https://gerrit.wikimedia.org/r/49810
Change subject: fix issue with param service
......................................................................
fix issue with param service
Change-Id: I2bd66af9b8fd089e32b7f061abf70707db0232d5
---
M MultiMaps.body.php
M MultiMaps.i18n.php
M MultiMaps.php
M Settings.php
M includes/BaseService.php
M includes/Services.php
6 files changed, 44 insertions(+), 26 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultiMaps
refs/changes/10/49810/1
diff --git a/MultiMaps.body.php b/MultiMaps.body.php
index 2ac2fe5..0d6ec86 100644
--- a/MultiMaps.body.php
+++ b/MultiMaps.body.php
@@ -23,8 +23,8 @@
$nameService = null;
$matches = array();
foreach ($params as $value) {
- if( preg_match('/^\s*service\s*=(.+)$/si', $value,
&$matches) ) {
- $nameService = strtolower($matches[1]);
+ if( preg_match('/^\s*service\s*=\s*(.+)\s*$/si',
$value, &$matches) ) {
+ $nameService = $matches[1];
break;
}
}
@@ -37,7 +37,7 @@
throw new MWException(
'MultiMapsServices::getServiceInstance() must return an object
"\MultiMaps\BaseService" or a string describing the error.' );
}
}
- $service->parse($params);
+ $service->parse($params, false);
$service->addDependencies($parser);
return $service->render();
}
diff --git a/MultiMaps.i18n.php b/MultiMaps.i18n.php
index ae0b896..3661224 100644
--- a/MultiMaps.i18n.php
+++ b/MultiMaps.i18n.php
@@ -22,12 +22,12 @@
'multimaps-circle-radius-not-defined' => 'for the circle must be
defined radius',
'multimaps-circle-wrong-number-parameters' => 'for the circle should be
defined only two parameters, the coordinates of the center and the radius. But
specified {{PLURAL:$1|one parameter|$1 parameters}}',
'multimaps-marker-incorrect-icon' => 'For the icon marker provided an
incorrect file name "$1"',
+ 'multimaps-passed-unavailable-service' => 'Service name "$1" not found
in the list of available services ($2). Used default service "$3"',
'multimaps-square-wrong-number-points' => 'coordinates of the square
should contain only two points, but specified {{PLURAL:$1|one point|$1
points}}',
'multimaps-unable-create-element' => 'Map element "$1" can not be
created',
'multimaps-unable-parse-coordinates' => 'unable to parse the geographic
coordinates "$1"',
'multimaps-unable-parse-parameter' => 'unable to parse parameter "$1"
value is "$2"',
'multimaps-unable-parse-radius' => 'radius of the circle must be a
numeric value, but specified "$1"',
- 'multimaps-unknown-showmap-service' => 'Could not find available
service to display the map',
'multimaps-unknown-class-for-service' => 'The class "$1" that is
defined for the service cannot be found.',
'multimaps-unknown-parameter' => 'Unknown parameter: "$1"',
'multimaps-error-incorrect-class-for-service' => 'The class "$1" that
is defined for the service cannot be used.',
@@ -56,6 +56,10 @@
* $1 - number of passed parameters (always more than two)',
'multimaps-marker-incorrect-icon' => 'Error message, Parameters:
* $1 - user-specified value',
+ 'multimaps-passed-unavailable-service' => 'Informational message warns
that the specified service is not available and service is used by default.
Parameters:
+* $1 - user-specified service
+* $2 - comma separated list of available services
+* $3 - name of default service, which is currently in use',
'multimaps-square-wrong-number-points' => 'Error message, when for
square (map element) specified more or less than two parameters. Parameters:
* $1 - the number of user-specified coordinates for the square',
'multimaps-unable-create-element' => 'An error occurred while creating
the map element. $1 - the name of the element, such as a "marker", "line",
"polygon", etc.',
@@ -65,7 +69,6 @@
* $2 - its value',
'multimaps-unable-parse-radius' => 'Error message, Parameters:
* $1 - user-specified value',
- 'multimaps-unknown-showmap-service' => 'Error message when lack of
available services for the map display (For example there are no values in the
$egMultiMapsDefaultService_showmap)',
'multimaps-unknown-class-for-service' => 'An error that occurs when the
key in array $egMultiMapsServices_showmap is name of unknown class. Parameters:
* $1 - class name',
'multimaps-error-incorrect-class-for-service' => 'An error that occurs
when the key in array $egMultiMapsServices_showmap is name of class, which can
not be used to display the map. Parameters:
diff --git a/MultiMaps.php b/MultiMaps.php
index 3cc5f52..6067fe2 100644
--- a/MultiMaps.php
+++ b/MultiMaps.php
@@ -15,7 +15,7 @@
die( 'This file is an extension to MediaWiki and thus not a valid entry
point.' );
}
-define( 'MultiMaps_VERSION' , '0.2' );
+define( 'MultiMaps_VERSION' , '0.3' );
// Register this extension on Special:Version
$wgExtensionCredits['parserhook'][] = array(
diff --git a/Settings.php b/Settings.php
index 5a3568c..4913976 100644
--- a/Settings.php
+++ b/Settings.php
@@ -20,16 +20,13 @@
// Default settings
// Array of String. Array containing all the mapping services that will be
made available to the user.
-// Firs key - default service, which will be used if the service is not in the
parameters
-// format:
-// key - string, class name based on class \MultiMaps\BaseService
-// value - string or array, service name for using in parameters
+// Firs value - default service, which will be used if the service is not in
the parameters
+// Values may be a valid name of class based on class BaseService
$egMultiMapsServices_showmap = array(
- 'Leaflet' => 'leaflet',
- 'Google' => 'google',
- 'Yandex' => 'yandex',
+ 'Leaflet',
+ 'Google',
+ 'Yandex',
);
-
// Integer. The default zoom of a map. This value will only be used when the
// user does not provide one.
diff --git a/includes/BaseService.php b/includes/BaseService.php
index ef74879..71013d4 100644
--- a/includes/BaseService.php
+++ b/includes/BaseService.php
@@ -243,9 +243,12 @@
/**
* Parse params and fill map data
* @param array $param
+ * @param boolean $reset Reset service before parse data
*/
- public function parse(array $param) {
- $this->reset();
+ public function parse(array $param, $reset = true) {
+ if( $reset ) {
+ $this->reset();
+ }
$this->addElementMarker( array_shift($param) );
@@ -546,4 +549,12 @@
return $this->errormessages;
}
+ /**
+ * Push error message into error messages
+ * @param string $string
+ */
+ public function pushErrorMessage( $string ) {
+ $this->errormessages[] = $string;
+ }
+
}
\ No newline at end of file
diff --git a/includes/Services.php b/includes/Services.php
index 028294c..54a66b0 100644
--- a/includes/Services.php
+++ b/includes/Services.php
@@ -27,27 +27,34 @@
switch ($action) {
case 'showmap':
- $classname = MultiMaps::recursive_array_search(
$servicename, $egMultiMapsServices_showmap );
- if( $classname === false ) { // a
user-specified service can not be found
- if(
!reset($egMultiMapsServices_showmap) ) {
- throw new
MWException('$egMultiMapsServices_showmap must not be an empty array');
- }
- $showmap =
each($egMultiMapsServices_showmap);
- $classname = $showmap['key'];
+ if( is_array($egMultiMapsServices_showmap) ===
false || count($egMultiMapsServices_showmap) == 0 ) {
+ throw new
MWException('$egMultiMapsServices_showmap must not be an empty array');
}
- if( $classname === false ) { // default service
is not found
- return wfMessage(
'multimaps-unknown-showmap-service' )->escaped();
+ $errormessage = '';
+ $classkey =
array_search(strtolower($servicename),array_map('strtolower',$egMultiMapsServices_showmap));
+ if( $classkey === false ) { // a user-specified
service can not be found
+ $classname =
$egMultiMapsServices_showmap[0];
+ $errormessage = \wfMessage(
'multimaps-passed-unavailable-service', $servicename, implode(', ',
$egMultiMapsServices_showmap), $classname )->escaped();
+ } else {
+ $classname =
$egMultiMapsServices_showmap[$classkey];
}
$newclassname="MultiMaps\\$classname";
if( !class_exists($newclassname) ) {
- return wfMessage(
'multimaps-unknown-class-for-service', $newclassname )->escaped();
+ if ( $errormessage != '' ) {
+ $errormessage .= '<br />';
+ }
+ return $errormessage . wfMessage(
'multimaps-unknown-class-for-service', $newclassname )->escaped();
}
$returnservice = new $newclassname();
if( !($returnservice instanceof
\MultiMaps\BaseService) ) {
return wfMessage(
'multimaps-error-incorrect-class-for-service', $newclassname )->escaped();
}
+
+ if ( $errormessage != '' ) {
+ $returnservice->pushErrorMessage(
$errormessage );
+ }
break;
default:
--
To view, visit https://gerrit.wikimedia.org/r/49810
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2bd66af9b8fd089e32b7f061abf70707db0232d5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultiMaps
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits