Daniel Kinzler has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/66129


Change subject: Make EntityIdParser be case insensitive.
......................................................................

Make EntityIdParser be case insensitive.

Change-Id: Id669a6b47151c3efd7668bcb5f2fd17975c7f756
---
M lib/includes/parsers/EntityIdParser.php
M lib/tests/phpunit/parsers/EntityIdParserTest.php
2 files changed, 15 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/29/66129/1

diff --git a/lib/includes/parsers/EntityIdParser.php 
b/lib/includes/parsers/EntityIdParser.php
index 699059b..9a0c955 100644
--- a/lib/includes/parsers/EntityIdParser.php
+++ b/lib/includes/parsers/EntityIdParser.php
@@ -31,6 +31,7 @@
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
+ * @author Daniel Kinzler
  */
 class EntityIdParser extends StringValueParser {
 
@@ -55,6 +56,8 @@
         */
        protected $regex = false;
 
+       protected $prefixMap;
+
        /**
         * @since 0.4
         *
@@ -64,6 +67,11 @@
                parent::__construct( $options );
 
                $this->requireOption( self::OPT_PREFIX_MAP );
+
+               foreach ( $this->getOption( self::OPT_PREFIX_MAP ) as $prefix 
=> $type ) {
+                       $prefix = strtolower( $prefix );
+                       $this->prefixMap[$prefix] = $type;
+               }
        }
 
        /**
@@ -95,19 +103,17 @@
        /**
         * @since 0.4
         *
-        * @param string $prefix
-        *
-        * @todo: prefixes should be case insensitive
+        * @param string $prefix the prefix to look up
         *
         * @return string|null
         */
        protected function getEntityTypeForPrefix( $prefix ) {
-               $typeMap = $this->getOption( self::OPT_PREFIX_MAP );
-               return array_key_exists( $prefix, $typeMap ) ? 
$typeMap[$prefix] : null;
+               $prefix = strtolower( $prefix );
+               return array_key_exists( $prefix, $this->prefixMap ) ? 
$this->prefixMap[$prefix] : null;
        }
 
        /**
-        * Get individual parts of an id.
+        * Get individual parts of an id. All results are converted to lower 
case.
         *
         * @since 0.4
         *
@@ -119,7 +125,7 @@
                if ( $this->regex === false ) {
                        $prefixes = array();
 
-                       foreach ( array_keys( $this->getOption( 
self::OPT_PREFIX_MAP ) ) as $prefix ) {
+                       foreach ( array_keys( $this->prefixMap ) as $prefix ) {
                                $prefixes[] = preg_quote( $prefix );
                        }
 
diff --git a/lib/tests/phpunit/parsers/EntityIdParserTest.php 
b/lib/tests/phpunit/parsers/EntityIdParserTest.php
index bbf7eec..913a775 100644
--- a/lib/tests/phpunit/parsers/EntityIdParserTest.php
+++ b/lib/tests/phpunit/parsers/EntityIdParserTest.php
@@ -50,8 +50,8 @@
                        EntityIdParser::OPT_PREFIX_MAP => array(
                                'a' => 'entity-type-a',
                                'b' => 'entity-type-b',
-                               'x' => 'entity-type-a',
-                               'dd' => 'entity-type-d',
+                               'X' => 'entity-type-a',
+                               'DD' => 'entity-type-d',
                                '' => 'entity-type-e',
                                '-' => 'entity-type-f',
                                '|' => 'entity-type-f',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id669a6b47151c3efd7668bcb5f2fd17975c7f756
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

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

Reply via email to