Jeroen De Dauw has uploaded a new change for review.

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


Change subject: Match EntityId changes in DataModel [DO NOT MERGE, DRAFT]
......................................................................

Match EntityId changes in DataModel [DO NOT MERGE, DRAFT]

Change-Id: I8fba1e700fe435c96618c2ab75e3bebe5363561e
---
M lib/WikibaseLib.php
M lib/includes/parsers/EntityIdParser.php
M lib/tests/phpunit/ReferencedEntitiesFinderTest.php
3 files changed, 33 insertions(+), 154 deletions(-)


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

diff --git a/lib/WikibaseLib.php b/lib/WikibaseLib.php
index 10350b8..d00747f 100644
--- a/lib/WikibaseLib.php
+++ b/lib/WikibaseLib.php
@@ -133,7 +133,7 @@
        $wgExtensionMessagesFiles['WikibaseLib'] = __DIR__ . 
'/WikibaseLib.i18n.php';
 
        $wgValueParsers['wikibase-entityid'] = 'Wikibase\Lib\EntityIdParser';
-       $wgDataValues['wikibase-entityid'] = 'Wikibase\EntityId';
+       $wgDataValues['wikibase-entityid'] = 
'Wikibase\DataModel\Entity\EntityIdValue';
        $wgJobClasses['ChangeNotification'] = 'Wikibase\ChangeNotificationJob';
        $wgJobClasses['UpdateRepoOnMove'] = 'Wikibase\UpdateRepoOnMoveJob';
 
@@ -199,7 +199,7 @@
        // Resource Loader Modules:
        $wgResourceModules = array_merge( $wgResourceModules, include( __DIR__ 
. "/resources/Resources.php" ) );
 
-       $wgValueFormatters[ \Wikibase\EntityId::getType() ] = 
'Wikibase\Lib\EntityIdFormatter';
+       $wgValueFormatters['wikibase-entityid'] = 
'Wikibase\Lib\EntityIdFormatter';
 
        if ( defined( 'WB_EXPERIMENTAL_FEATURES' ) && WB_EXPERIMENTAL_FEATURES 
) {
                include_once( __DIR__ . '/config/WikibaseLib.experimental.php' 
);
diff --git a/lib/includes/parsers/EntityIdParser.php 
b/lib/includes/parsers/EntityIdParser.php
index df2d5ef..ae568f2 100644
--- a/lib/includes/parsers/EntityIdParser.php
+++ b/lib/includes/parsers/EntityIdParser.php
@@ -1,28 +1,15 @@
 <?php
 
 namespace Wikibase\Lib;
+
 use ValueParsers\ParseException;
 use ValueParsers\StringValueParser;
-use ValueParsers\ParserOptions;
-use Wikibase\EntityId;
+use Wikibase\DataModel\Entity\BasicEntityIdParser;
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\EntityIdParsingException;
 
 /**
  * Parser that parses entity id strings into EntityId objects.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
  *
  * @since 0.4
  *
@@ -36,61 +23,9 @@
 class EntityIdParser extends StringValueParser {
 
        /**
-        * Option name for the required prefixmap option.
-        * The value of this option should be an array of
-        * prefixes (string) pointing to the entity type
-        * (string) they map to.
-        *
-        * @since 0.4
+        * @deprecated
         */
        const OPT_PREFIX_MAP = 'prefixmap';
-
-       /**
-        * Cache field that holds the regex used by @see getIdParts
-        *
-        * Note that this caching does not get invalidated when changing the 
options!
-        *
-        * @since 0.4
-        *
-        * @var string|boolean false
-        */
-       protected $regex = false;
-
-       private $prefixMap = null;
-
-       /**
-        * @since 0.4
-        *
-        * @param ParserOptions|null $options
-        *
-        * The OPT_PREFIX_MAP option MUST be set, and prefixes MUST be lower 
case.
-        *
-        * @todo: make this case insensitive
-        */
-       public function __construct( ParserOptions $options = null ) {
-               parent::__construct( $options );
-
-               $this->requireOption( self::OPT_PREFIX_MAP );
-       }
-
-       /**
-        * Returns a prefix map with lower case keys. The map is constructed 
from
-        * the OPT_PREFIX_MAP option from the ParserOptions passed to the 
provider.
-        *
-        * @return array A mapping from prefixes to type IDs.
-        */
-       protected function getPrefixMap() {
-               if ( $this->prefixMap === null ) {
-                       $this->prefixMap = array();
-
-                       foreach ( $this->getOption( self::OPT_PREFIX_MAP ) as 
$prefix => $type ) {
-                               $prefix = strtolower( $prefix );
-                               $this->prefixMap[$prefix] = $type;
-                       }
-               }
-
-               return $this->prefixMap;
-       }
 
        /**
         * @see StringValueParser::stringParse
@@ -103,58 +38,19 @@
         * @throws ParseException
         */
        protected function stringParse( $value ) {
-               $idParts = $this->getIdParts( $value );
+               $idBuilders = BasicEntityIdParser::getBuilders();
 
-               if ( count( $idParts ) < 3 || !ctype_digit( $idParts[2] ) ) {
-                       throw new ParseException( 'Not an EntityId' );
+               // TODO: extensions need to be able to add builders.
+               // The construction of the actual id parser will thus need to 
be moved out.
+
+               $parser = new \Wikibase\DataModel\Entity\EntityIdParser( 
$idBuilders );
+
+               try {
+                       return $parser->parse( $value );
                }
-
-               $entityType = $this->getEntityTypeForPrefix( $idParts[1] );
-
-               if ( $entityType === null ) {
-                       throw new ParseException( 'EntityId has an invalid 
prefix' );
+               catch ( EntityIdParsingException $ex ) {
+                       throw new ParseException( '', 0, $ex );
                }
-
-               return new EntityId( $entityType, (int)$idParts[2] );
-       }
-
-       /**
-        * @since 0.4
-        *
-        * @param string $prefix the prefix to look up
-        *
-        * @return string|null
-        */
-       protected function getEntityTypeForPrefix( $prefix ) {
-               $prefix = strtolower( $prefix );
-               $prefixMap = $this->getPrefixMap();
-               return array_key_exists( $prefix, $prefixMap ) ? 
$prefixMap[$prefix] : null;
-       }
-
-       /**
-        * Get individual parts of an id. All results are converted to lower 
case.
-        *
-        * @since 0.4
-        *
-        * @param string $id
-        *
-        * @return array The actual id broken up in prefix, number, hash and 
fragment and fragment alone
-        */
-       protected function getIdParts( $id ) {
-               if ( $this->regex === false ) {
-                       $prefixes = array();
-                       $prefixMap = $this->getPrefixMap();
-
-                       foreach ( array_keys( $prefixMap ) as $prefix ) {
-                               $prefixes[] = preg_quote( $prefix );
-                       }
-
-                       $this->regex = '/^(' . implode( '|', $prefixes ) . 
'|)(\d+)(#.*|)$/';
-               }
-
-               preg_match( $this->regex, strtolower( $id ), $matches );
-
-               return $matches;
        }
 
 }
diff --git a/lib/tests/phpunit/ReferencedEntitiesFinderTest.php 
b/lib/tests/phpunit/ReferencedEntitiesFinderTest.php
index c4ab41f..0fdf4a3 100644
--- a/lib/tests/phpunit/ReferencedEntitiesFinderTest.php
+++ b/lib/tests/phpunit/ReferencedEntitiesFinderTest.php
@@ -1,43 +1,26 @@
 <?php
 
 namespace Wikibase\Lib\Test;
+
 use DataTypes\DataType;
 use DataTypes\DataTypeFactory;
-use Wikibase\Claims;
-use Wikibase\ReferencedEntitiesFinder;
+use DataValues\StringValue;
 use Wikibase\Claim;
-use Wikibase\Statement;
+use Wikibase\DataModel\Entity\EntityIdValue;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\EntityId;
+use Wikibase\Item;
+use Wikibase\LibRegistry;
+use Wikibase\Property;
 use Wikibase\PropertyNoValueSnak;
 use Wikibase\PropertySomeValueSnak;
 use Wikibase\PropertyValueSnak;
-use Wikibase\EntityId;
-use Wikibase\Property;
-use Wikibase\Item;
-use Wikibase\SnakList;
+use Wikibase\ReferencedEntitiesFinder;
 use Wikibase\Snak;
-use DataValues\StringValue;
-use Wikibase\LibRegistry;
-use Wikibase\Settings;
-use Wikibase\ReferenceList;
-use Wikibase\Reference;
 
 /**
- * Tests for the Wikibase\ReferencedEntitiesFinder class.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
+ * @covers Wikibase\ReferencedEntitiesFinder
  *
  * @file
  * @since 0.4
@@ -58,12 +41,12 @@
        public function snaksProvider() {
                $argLists = array();
 
-               $p11 = new EntityId( Property::ENTITY_TYPE, 11 );
-               $p27 = new EntityId( Property::ENTITY_TYPE, 27 );
-               $p44 = new EntityId( Property::ENTITY_TYPE, 44 );
+               $p11 = new EntityIdValue( new PropertyId( 'p11' ) );
+               $p27 = new EntityIdValue( new PropertyId( 'p27' ) );
+               $p44 = new EntityIdValue( new PropertyId( 'p44' ) );
 
-               $q23 = new EntityId( Item::ENTITY_TYPE, 23 );
-               $q24 = new EntityId( Item::ENTITY_TYPE, 24 );
+               $q23 = new EntityIdValue( new ItemId( 'q23' ) );
+               $q24 = new EntityIdValue( new ItemId( 'q24' ) );
 
                $argLists[] = array(
                        array(),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8fba1e700fe435c96618c2ab75e3bebe5363561e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

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

Reply via email to