jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/256847 )

Change subject: Add handling for arrays, such as weekday_text
......................................................................


Add handling for arrays, such as weekday_text

Change-Id: I8ef8b052b77d11933bf95d2434d793f767d1623e
---
M GooglePlaces.hooks.php
M extension.json
2 files changed, 27 insertions(+), 5 deletions(-)

Approvals:
  jenkins-bot: Verified
  tosfos: Looks good to me, approved



diff --git a/GooglePlaces.hooks.php b/GooglePlaces.hooks.php
index cdbc4a0..59f1f0a 100644
--- a/GooglePlaces.hooks.php
+++ b/GooglePlaces.hooks.php
@@ -1,4 +1,5 @@
 <?php
+
 class GooglePlacesHooks {
 
        /**
@@ -12,6 +13,7 @@
 
        /**
         *
+        * @SuppressWarnings(PHPMD.UnusedFormalParameter)
         * @param Parser $parser
         * @param string $placeIDSent
         * @param string $resultPathSent
@@ -37,6 +39,10 @@
 
                $output = self::getArrayElementFromPath( $details['result'], 
$resultPath );
 
+               if ( is_array( $output ) ) {
+                       $output = self::htmlEscapeImplode( ';', $output );
+               }
+
                self::insertPoweredBy();
                $output .= self::getTOSRequiredHTML( $details );
 
@@ -45,6 +51,7 @@
 
        /**
         *
+        * @SuppressWarnings(PHPMD.UnusedFormalParameter)
         * @param Parser $parser
         * @param string $placeIDSent
         * @param string $typeSent
@@ -71,7 +78,8 @@
                        return '';
                }
 
-               $output = self::getArrayElementFromType( 
$details['result']['address_components'], $type, $field );
+               $output = self::getArrayElementFromType(
+                               $details['result']['address_components'], 
$type, $field );
 
                self::insertPoweredBy();
                $output .= self::getTOSRequiredHTML( $details );
@@ -192,7 +200,7 @@
                if ( $element !== '' ) {
                        return $element;
                } else {
-                       foreach ( $result as $key => $value ) {
+                       foreach ( $result as $value ) {
                                if ( is_array( $value ) ) {
                                        $element = 
self::getArrayElementFromType( $value, $type, $field );
                                        if ( $element !== '' ) {
@@ -210,7 +218,7 @@
         * If $element is unset, return the first value of that sibling array.
         *
         * @param array $array
-        * @param array $type
+        * @param array $types
         * @param string $element
         */
        private static function getElementWithMatchingType( array $array, 
$types, $element = '' ) {
@@ -220,7 +228,6 @@
                                return $return;
                        } else {
                                return $array[$element];
-
                        }
                } else {
                        return '';
@@ -255,4 +262,19 @@
                        $wgFooterIcons['poweredby']['googleplaces'] = 
self::getFooterIcon();
                }
        }
+
+       /**
+        * Implodes an array into a string, but also escapes instances of $glue 
into its HTML
+        * ampersand representation.
+        *
+        * @param string $glue
+        * @param array $pieces
+        * @return string
+        */
+       private static function htmlEscapeImplode( $glue, array $pieces ) {
+               foreach ( $pieces as &$piece ) {
+                       $piece = str_replace( $glue, '&#' . ord( $glue ) . ';', 
$piece );
+               }
+               return implode( $glue, $pieces );
+       }
 }
diff --git a/extension.json b/extension.json
index acff003..d0eb0da 100644
--- a/extension.json
+++ b/extension.json
@@ -3,7 +3,7 @@
        "author": "Ike Hecht",
        "url": "https://www.mediawiki.org/wiki/Extension:GooglePlaces";,
        "descriptionmsg": "googleplaces-desc",
-       "version": "1.0",
+       "version": "1.1",
        "type": "parserhook",
        "AutoloadClasses": {
                "GooglePlacesHooks": "GooglePlaces.hooks.php",

-- 
To view, visit https://gerrit.wikimedia.org/r/256847
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8ef8b052b77d11933bf95d2434d793f767d1623e
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/GooglePlaces
Gerrit-Branch: master
Gerrit-Owner: tosfos <tos...@yahoo.com>
Gerrit-Reviewer: Aklapper <aklap...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>
Gerrit-Reviewer: tosfos <tos...@yahoo.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to