Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/263800
Change subject: Filter data type registrations with disabledDataTypes setting ...................................................................... Filter data type registrations with disabledDataTypes setting Removed the old (unused) dataTypes setting from lib and introduced a new 'disabledDataTypes' setting in client + repo. The disabledDataTypes setting can be used to define which data types are disabled for a wiki. Added documentation for the setting. The new data types registration system wasn't considering the dataTypes setting. We now have a hook to allow other extensions to add data types (e.g. math), so a setting that lists enabled types doesn't work so nicely with that. A setting that does the inverse can work for this. At least for Wikidata, we sometimes need to set this explicitly so we can deploy new data types in a more controlled way. The ability to enable only certain types might also be desired by some third party users. Bug: T123447 Change-Id: I07abc6bb5a785e2331bdc98412cf45a7160c5b9a --- M client/config/WikibaseClient.default.php M client/includes/WikibaseClient.php M docs/options.wiki M lib/config/WikibaseLib.default.php M lib/includes/DataTypeDefinitions.php M lib/tests/phpunit/DataTypeDefinitionsTest.php M repo/config/Wikibase.default.php M repo/includes/WikibaseRepo.php 8 files changed, 95 insertions(+), 28 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/00/263800/3 diff --git a/client/config/WikibaseClient.default.php b/client/config/WikibaseClient.default.php index 49c0dde..7c68e48 100644 --- a/client/config/WikibaseClient.default.php +++ b/client/config/WikibaseClient.default.php @@ -77,6 +77,18 @@ */ 'sharedCacheDuration' => 60 * 60, + /** + * List of data types (by data type id) not enabled on the wiki. + * This setting is intended to aid with deployment of new data types + * or on new Wikibase installs without items and properties yet. + * + * This setting should be consistent with the corresponding setting on the repo. + * + * WARNING: Disabling a data type after it is in use is dangerous + * and might break items. + */ + 'disabledDataTypes' => array(), + // The type of object cache to use. Use CACHE_XXX constants. // This is both a repo and client setting, and should be set to the same value in // repo and clients for multiwiki setups. diff --git a/client/includes/WikibaseClient.php b/client/includes/WikibaseClient.php index c8ec0ab..29eb79f 100644 --- a/client/includes/WikibaseClient.php +++ b/client/includes/WikibaseClient.php @@ -485,10 +485,15 @@ $dataTypeDefinitions = $wgWBClientDataTypes; Hooks::run( 'WikibaseClientDataTypes', array( &$dataTypeDefinitions ) ); + $settings = new SettingsArray( $wgWBClientSettings ); + return new self( - new SettingsArray( $wgWBClientSettings ), + $settings, $wgContLang, - new DataTypeDefinitions( $dataTypeDefinitions ) + new DataTypeDefinitions( + $dataTypeDefinitions, + $settings->getSetting( 'disabledDataTypes' ) + ) ); } diff --git a/docs/options.wiki b/docs/options.wiki index aacf5d6..f574822 100644 --- a/docs/options.wiki +++ b/docs/options.wiki @@ -30,12 +30,10 @@ :'''Warning:''' do not change this if you already have Wikibase entities in your database, since they may become unreadable! ;useChangesTable: Whether to record changes in the database, so they can be pushed to clients. Boolean, defaults to <code>true</code>. May be set to false in situations where there are no clients to notify, to preserve space. '''Note''' that if this is true, the <code>pruneChanges.php</code> script should be run periodically to remove old changes from the database table. ;changeHandlers: Array mapping change type IDs to handler classes. May be used by extensions to register additional change classes. -;dataTypes: Array listing the available data types that can be used in snaks (and thus in claims and statements). The relevant data type identifiers are defined by the DataType extension. Default: +;disabledDataTypes: Array listing of disabled data types on a wiki. This setting is intended to be used a new Wikibase install without items yet, or to control deployment of new data types. This setting should be set the same in the client and repo settings. +Default: <poem> - array( - 'wikibase-item', - 'commonsMedia', - ) + array() </poem> ;maxSerializedEntitySize: The maximum serialized size of entities, in KB. Loading and storing will fail if this size is exceeded. This is intended as a hard limit that prevents very large chunks of data being stored or processed due to abuse or erroneous code. Defaults to MediaWiki core's $wgMaxArticleSize setting. diff --git a/lib/config/WikibaseLib.default.php b/lib/config/WikibaseLib.default.php index de19c74..b530ff1 100644 --- a/lib/config/WikibaseLib.default.php +++ b/lib/config/WikibaseLib.default.php @@ -60,19 +60,6 @@ 'wikibase-query~restore' => 'Wikibase\EntityChange', ), - 'dataTypes' => array( - 'commonsMedia', - 'globe-coordinate', - 'quantity', - 'monolingualtext', - 'string', - 'time', - 'url', - 'external-id', - 'wikibase-item', - 'wikibase-property', - ), - 'maxSerializedEntitySize' => $GLOBALS['wgMaxArticleSize'], ); diff --git a/lib/includes/DataTypeDefinitions.php b/lib/includes/DataTypeDefinitions.php index fa1766c..efa04e5 100644 --- a/lib/includes/DataTypeDefinitions.php +++ b/lib/includes/DataTypeDefinitions.php @@ -53,9 +53,16 @@ * (with the prefix "PT:") and value types (with the prefix "VT:") to data type definitions. * Each data type definitions are associative arrays, refer to the class level documentation * for details. + * @param string[] $disabledDataTypes Array of disabled data types. */ - public function __construct( $dataTypeDefinitions = array() ) { - Assert::parameterElementType( 'array', $dataTypeDefinitions, '$dataTypeDefinitions' ); + public function __construct( + array $dataTypeDefinitions = array(), + array $disabledDataTypes = array() + ) { + $dataTypeDefinitions = $this->filterDisabledDataTypes( + $dataTypeDefinitions, + $disabledDataTypes + ); $this->registerDataTypes( $dataTypeDefinitions ); } @@ -74,7 +81,11 @@ Assert::parameterElementType( 'array', $dataTypeDefinitions, '$dataTypeDefinitions' ); foreach ( $dataTypeDefinitions as $id => $def ) { - Assert::parameter( strpos( $id, ':' ), "\$dataTypeDefinitions[$id]", 'Key must start with a prefix like "PT:" or "VT:".' ); + Assert::parameter( + strpos( $id, ':' ), + "\$dataTypeDefinitions[$id]", + 'Key must start with a prefix like "PT:" or "VT:".' + ); if ( isset( $this->dataTypeDefinitions[$id] ) ) { $this->dataTypeDefinitions[$id] = array_merge( @@ -88,6 +99,24 @@ } /** + * @param array[] $dataTypeDefinitions Associative array of data types and definitions. + * @param string[] $disabledTypes List of disabled data types + * + * @return array[] Filtered data type definitions + */ + private function filterDisabledDataTypes( array $dataTypeDefinitions, array $disabledTypes ) { + foreach ( $dataTypeDefinitions as $id => $def ) { + if ( 0 === strpos( $id, 'PT' ) ) { + if ( in_array( substr( $id, 3 ), $disabledTypes ) ) { + unset( $dataTypeDefinitions[$id] ); + } + } + } + + return $dataTypeDefinitions; + } + + /** * @param array $map * @param string $prefix * diff --git a/lib/tests/phpunit/DataTypeDefinitionsTest.php b/lib/tests/phpunit/DataTypeDefinitionsTest.php index 569dfb4..c4aed4e 100644 --- a/lib/tests/phpunit/DataTypeDefinitionsTest.php +++ b/lib/tests/phpunit/DataTypeDefinitionsTest.php @@ -16,8 +16,8 @@ */ class DataTypeDefinitionsTest extends \MediaWikiTestCase { - private function getDataTypeDefinitions() { - $definitions = array( + private function getDefinitions() { + return array( 'VT:FOO' => array( 'formatter-factory-callback' => 'DataTypeDefinitionsTest::getFooValueFormatter', 'parser-factory-callback' => 'DataTypeDefinitionsTest::getFooValueParser', @@ -34,8 +34,10 @@ 'formatter-factory-callback' => 'DataTypeDefinitionsTest::getBarFormatter', ) ); + } - return new DataTypeDefinitions( $definitions ); + private function getDataTypeDefinitions() { + return new DataTypeDefinitions( $this->getDefinitions() ); } public function testTypeIds() { @@ -129,4 +131,21 @@ ); } + public function testDataTypeDefinitions_onlySomeDataTypesEnabled() { + $definitions = $this->getDefinitions(); + $defs = new DataTypeDefinitions( $definitions, array( 'bar' ) ); + + $this->assertSame( + array( 'foo' ), + $defs->getTypeIds(), + 'data type ids' + ); + + $this->assertSame( + array( 'VT:FOO' => 'DataTypeDefinitionsTest::getFooValueFormatter' ), + $defs->getFormatterFactoryCallbacks( DataTypeDefinitions::PREFIXED_MODE ), + 'formatter factory callbacks, prefixed mode' + ); + } + } diff --git a/repo/config/Wikibase.default.php b/repo/config/Wikibase.default.php index 8bc11c5..5fc6239 100644 --- a/repo/config/Wikibase.default.php +++ b/repo/config/Wikibase.default.php @@ -123,6 +123,18 @@ // repo and clients for multiwiki setups. 'sharedCacheType' => $GLOBALS['wgMainCacheType'], + /** + * List of data types (by data type id) not enabled on the wiki. + * This setting is intended to aid with deployment of new data types + * or on new Wikibase installs without items and properties yet. + * + * This setting should be consistent with the corresponding setting on the client. + * + * WARNING: Disabling a data type after it is in use is dangerous + * and might break items. + */ + 'disabledDataTypes' => array(), + // Special non-canonical languages and their BCP 47 mappings // Based on: https://meta.wikimedia.org/wiki/Special_language_codes 'canonicalLanguageCodes' => array( diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index 8e9e0b7..b90f1e3 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -241,9 +241,14 @@ Hooks::run( 'WikibaseRepoDataTypes', array( &$dataTypeDefinitions ) ); if ( $instance === null ) { + $settings = new SettingsArray( $wgWBRepoSettings ); + $instance = new self( - new SettingsArray( $wgWBRepoSettings ), - new DataTypeDefinitions( $dataTypeDefinitions ), + $settings, + new DataTypeDefinitions( + $dataTypeDefinitions, + $settings->getSetting( 'disabledDataTypes' ) + ), $wgContLang ); } -- To view, visit https://gerrit.wikimedia.org/r/263800 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I07abc6bb5a785e2331bdc98412cf45a7160c5b9a Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <aude.w...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits