jenkins-bot has submitted this change and it was merged.
Change subject: Automatic defaults for entityNamespaces and repoNamespaces.
......................................................................
Automatic defaults for entityNamespaces and repoNamespaces.
If the local wiki is a repo as well as a client, derive the client
settings entityNamespaces and repoNamespaces from the repository
settings.
This is motivated by repeated confusion while installing test systems.
The idea is that when enabling client functionality on a repo wiki,
no additional manual configuration should be needed, since all
necessary information is already present in the repo settings.
Change-Id: Ib8b111eefe3c595e80d91b3f6267ff30d42fda10
---
M client/config/WikibaseClient.default.php
M client/config/WikibaseClient.example.php
M client/includes/WikibaseClient.php
M client/tests/phpunit/ClientDefaultsTest.php
M client/tests/phpunit/includes/WikibaseClientTest.php
5 files changed, 102 insertions(+), 10 deletions(-)
Approvals:
Adrian Heine: Looks good to me, approved
jenkins-bot: Verified
diff --git a/client/config/WikibaseClient.default.php
b/client/config/WikibaseClient.default.php
index 6ca9a93..a691966 100644
--- a/client/config/WikibaseClient.default.php
+++ b/client/config/WikibaseClient.default.php
@@ -30,15 +30,6 @@
'languageLinkSiteGroup' => null,
'injectRecentChanges' => true,
'showExternalRecentChanges' => true,
- // default for repo items in main namespace
- 'repoNamespaces' => [
- 'wikibase-item' => '',
- 'wikibase-property' => 'Property'
- ],
- 'entityNamespaces' => [
- 'wikibase-item' => 0,
- 'wikibase-property' => 120
- ],
'allowDataTransclusion' => true,
'propagateChangesToRepo' => true,
'otherProjectsLinksByDefault' => false,
@@ -269,6 +260,39 @@
return $settings->getSetting( 'thisWikiIsTheRepo' ) ? false :
null;
};
+ $defaults['entityNamespaces'] = function ( SettingsArray $settings ) {
+ if ( $settings->getSetting( 'thisWikiIsTheRepo' ) ) {
+ // if this is the repo wiki, use the repo setting
+ $repoSettings =
WikibaseClient::getDefaultInstance()->getRepoSettings();
+ return $repoSettings->getSetting( 'entityNamespaces' );
+ } else {
+ // XXX: Default to having Items in the main namespace,
and properties in NS 120.
+ // That is the live setup at wikidata.org, it is NOT
consistent with the example settings!
+ return [
+ 'wikibase-item' => 0,
+ 'wikibase-property' => 120
+ ];
+ }
+ };
+
+ $defaults['repoNamespaces'] = function ( SettingsArray $settings ) {
+ if ( $settings->getSetting( 'thisWikiIsTheRepo' ) ) {
+ // if this is the repo wiki, look up the namespace
names based on the entityNamespaces setting
+ $namespaceNames = array_map(
+ 'MWNamespace::getCanonicalName',
+ $settings->getSetting( 'entityNamespaces' )
+ );
+ return $namespaceNames;
+ } else {
+ // XXX: Default to having Items in the main namespace,
and properties in the 'Property' namespace.
+ // That is the live setup at wikidata.org, it is NOT
consistent with the example settings!
+ return [
+ 'wikibase-item' => '',
+ 'wikibase-property' => 'Property'
+ ];
+ }
+ };
+
$defaults['changesDatabase'] = function ( SettingsArray $settings ) {
// Per default, the database for tracking changes is the repo's
database.
// Note that the value for the repoDatabase setting may be
calculated dynamically,
diff --git a/client/config/WikibaseClient.example.php
b/client/config/WikibaseClient.example.php
index 6376be3..afd7eb3 100644
--- a/client/config/WikibaseClient.example.php
+++ b/client/config/WikibaseClient.example.php
@@ -52,6 +52,15 @@
// This requires the given database name to be known to LBFactory, see
// $wgLBFactoryConf below.
$wgWBClientSettings['repoDatabase'] = "repo";
+
+ // Tell the client which namespace ID on the repo holds which type of
entity.
+ $baseRepoNs = 120;
+
+ define( 'WB_REPO_NS_ITEM', $baseRepoNs );
+ define( 'WB_REPO_NS_PROPERTY', $baseRepoNs + 2 );
+
+ $wgWBRepoSettings['entityNamespaces']['wikibase-item'] =
WB_REPO_NS_ITEM;
+ $wgWBRepoSettings['entityNamespaces']['wikibase-property'] =
WB_REPO_NS_PROPERTY;
}
// In order to access a remote repo using a different database server,
diff --git a/client/includes/WikibaseClient.php
b/client/includes/WikibaseClient.php
index ef164df..4f7e68e 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -521,6 +521,23 @@
}
/**
+ * Returns the repo's settings array IF the local wiki also acts as a
repository.
+ * If the local wiki is not a repository, this method returns null.
+ *
+ * This is intended to be used ONLY to allow client settings to default
to local repo
+ * settings in WikibaseClient.default.php.
+ *
+ * @return SettingsArray|null
+ */
+ public function getRepoSettings() {
+ if ( defined( 'WB_VERSION' ) ) {
+ return
\Wikibase\Repo\WikibaseRepo::getDefaultInstance()->getSettings();
+ } else {
+ return null;
+ }
+ }
+
+ /**
* Returns a new instance constructed from global settings.
* IMPORTANT: Use only when it is not feasible to inject an instance
properly.
*
diff --git a/client/tests/phpunit/ClientDefaultsTest.php
b/client/tests/phpunit/ClientDefaultsTest.php
index defa6ca..213fbc0 100644
--- a/client/tests/phpunit/ClientDefaultsTest.php
+++ b/client/tests/phpunit/ClientDefaultsTest.php
@@ -2,6 +2,7 @@
namespace Wikibase\Test;
+use Wikibase\Client\WikibaseClient;
use Wikibase\SettingsArray;
/**
@@ -16,7 +17,7 @@
class ClientDefaultsTest extends \MediaWikiTestCase {
public function settingsProvider() {
- return array(
+ $cases = array(
array( // #0: no local repo, all values set
array( // $settings
'repoUrl' => 'http://acme.com',
@@ -148,7 +149,38 @@
'sharedCacheKeyPrefix' =>
'wikibase_shared/wikidata_1_25wmf24',
)
),
+ array( // #6: derive repoNamespaces and entityNamespaces
+ array( // $settings
+ ),
+ array( // $wg
+ ),
+ false, // $repoIsLocal
+ array( // $expected
+ 'repoNamespaces' => [ 'wikibase-item'
=> '', 'wikibase-property' => 'Property' ],
+ 'entityNamespaces' => [ 'wikibase-item'
=> 0, 'wikibase-property' => 120 ],
+ )
+ ),
);
+
+ if ( defined( 'WB_VERSION' ) ) {
+ $repoSettings =
WikibaseClient::getDefaultInstance()->getRepoSettings();
+ $entityNamespaces = $repoSettings->getSetting(
'entityNamespaces' );
+ $namespaceNames = array_map(
'MWNamespace::getCanonicalName', $entityNamespaces );
+
+ $cases[] = array( // #7: default repoNamespaces and
entityNamespaces
+ array( // $settings
+ ),
+ array( // $wg
+ ),
+ true, // $repoIsLocal
+ array( // $expected
+ 'repoNamespaces' => $namespaceNames,
+ 'entityNamespaces' => $entityNamespaces,
+ )
+ );
+ }
+
+ return $cases;
}
/**
diff --git a/client/tests/phpunit/includes/WikibaseClientTest.php
b/client/tests/phpunit/includes/WikibaseClientTest.php
index 2d51789..e1071e7 100644
--- a/client/tests/phpunit/includes/WikibaseClientTest.php
+++ b/client/tests/phpunit/includes/WikibaseClientTest.php
@@ -129,6 +129,16 @@
$this->assertInstanceOf( SettingsArray::class, $returnValue );
}
+ public function testGetRepoSettingsReturnType() {
+ $returnValue = $this->getWikibaseClient()->getRepoSettings();
+
+ if ( defined( 'WB_VERSION' ) ) {
+ $this->assertInstanceOf( SettingsArray::class,
$returnValue );
+ } else {
+ $this->assertNull( $returnValue );
+ }
+ }
+
public function testGetSiteReturnType() {
$returnValue = $this->getWikibaseClient()->getSite();
$this->assertInstanceOf( Site::class, $returnValue );
--
To view, visit https://gerrit.wikimedia.org/r/290423
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib8b111eefe3c595e80d91b3f6267ff30d42fda10
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Adrian Heine <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Lucie Kaffee <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits