jenkins-bot has submitted this change and it was merged. Change subject: (bug 47610) Keep default settings out of globals. ......................................................................
(bug 47610) Keep default settings out of globals. This change allows for using $wgWBClientSettings resp $wgWBRepoSettings for all settings, while staying compatible with sites using $wgWBSettings for everything. Special care has been taken to make sure default values never override explicit configuration, and repo/client settings override "generic" settings. CAVEAT: This breaks B/C in cases where a values is *added* to a setting that is an array. Doing something like $wgWBClientSettings['foo']['x'] will no longer add 'x' to the 'foo' setting, but *set* the 'foo' setting to an array containing just the 'x' field. Change-Id: I14422cd85a3cf0200ea89953251b78b6b8d813cb --- M DataModel/DataModel/Entity/EntityId.php M Query/WikibaseQuery.php M client/WikibaseClient.php M client/config/WikibaseClient.default.php M lib/WikibaseLib.php M lib/config/WikibaseLib.default.php M lib/config/WikibaseLib.experimental.php M lib/includes/Settings.php M repo/Wikibase.php M repo/config/Wikibase.default.php M repo/includes/content/EntityHandler.php M repo/tests/phpunit/includes/content/EntityHandlerTest.php 12 files changed, 333 insertions(+), 266 deletions(-) Approvals: Jeroen De Dauw: Looks good to me, approved jenkins-bot: Verified diff --git a/DataModel/DataModel/Entity/EntityId.php b/DataModel/DataModel/Entity/EntityId.php index d7f4a46..3dcd8d9 100644 --- a/DataModel/DataModel/Entity/EntityId.php +++ b/DataModel/DataModel/Entity/EntityId.php @@ -88,7 +88,8 @@ // TODO: fix dependency on global state // Either the prefix or the needed option should be passe din the constructor. - foreach ( Settings::get( 'entityPrefixes' ) as $prefix => $type ) { + $prefixes = Settings::get( 'entityPrefixes' ); + foreach ( $prefixes as $prefix => $type ) { $prefixMap[$type] = $prefix; } } diff --git a/Query/WikibaseQuery.php b/Query/WikibaseQuery.php index 73535b9..6349f98 100644 --- a/Query/WikibaseQuery.php +++ b/Query/WikibaseQuery.php @@ -94,7 +94,13 @@ // @codeCoverageIgnoreEnd }; -$wgWBSettings['entityPrefixes']['y'] = 'query'; +$wgHooks['WikibaseDefaultSettings'][] = function( array &$settings ) { + $settings['entityPrefixes']['y'] = 'query'; + $settings['entityNamespaces'][CONTENT_MODEL_WIKIBASE_QUERY] = WB_NS_QUERY; + + return true; +}; + define( 'CONTENT_MODEL_WIKIBASE_QUERY', "wikibase-query" ); @@ -104,9 +110,6 @@ $wgExtraNamespaces[WB_NS_QUERY] = 'Query'; $wgExtraNamespaces[WB_NS_QUERY_TALK] = 'Query_talk'; - -$wgWBRepoSettings['entityNamespaces'][CONTENT_MODEL_WIKIBASE_QUERY] = WB_NS_QUERY; - $wgAutoloadClasses['Wikibase\HistoryQueryAction'] = __DIR__ . '/Query/HistoryQueryAction.php'; $wgAutoloadClasses['Wikibase\EditQueryAction'] = __DIR__ . '/Query/EditQueryAction.php'; diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php index ba013d1..9dff8f7 100644 --- a/client/WikibaseClient.php +++ b/client/WikibaseClient.php @@ -39,6 +39,8 @@ define( 'WBC_VERSION', '0.4 alpha' . ( defined( 'WB_EXPERIMENTAL_FEATURES' ) && WB_EXPERIMENTAL_FEATURES ? '/experimental' : '' ) ); +define( 'WBC_DIR', __DIR__ ); + $wgExtensionCredits['wikibase'][] = array( 'path' => __DIR__, 'name' => 'Wikibase Client', @@ -144,7 +146,7 @@ $wgWBClientStores['DirectSqlStore'] = 'Wikibase\DirectSqlStore'; -include_once( $dir . 'config/WikibaseClient.default.php' ); +$wgWBClientSettings = array(); if ( defined( 'WB_EXPERIMENTAL_FEATURES' ) && WB_EXPERIMENTAL_FEATURES ) { include_once( $dir . 'config/WikibaseClient.experimental.php' ); diff --git a/client/config/WikibaseClient.default.php b/client/config/WikibaseClient.default.php index 617979e..5494f38 100644 --- a/client/config/WikibaseClient.default.php +++ b/client/config/WikibaseClient.default.php @@ -29,156 +29,157 @@ * @licence GNU GPL v2+ */ -if ( !defined( 'WBC_VERSION' ) ) { - die( 'Not an entry point.' ); -} -global $wgScriptPath, $wgArticlePath, $wgLanguageCode, $wgDBname; +return call_user_func( function() { + global $wgScriptPath, $wgArticlePath, $wgLanguageCode, $wgDBname; -$wgWBClientSettings = array( - 'namespaces' => array(), // by default, include all namespaces; deprecated as of 0.4 - 'excludeNamespaces' => array(), - 'repoUrl' => '//www.wikidata.org', - 'repoScriptPath' => $wgScriptPath, - 'repoArticlePath' => $wgArticlePath, - 'sort' => 'code', - 'sortPrepend' => array(), - 'alwaysSort' => false, - 'siteGlobalID' => $wgDBname, - // @todo would be great to just get this from the sites stuff - // but we will need to make sure the caching works good enough - 'siteLocalID' => $wgLanguageCode, - 'siteGroup' => 'wikipedia', - 'injectRecentChanges' => true, - 'showExternalRecentChanges' => true, - 'defaultClientStore' => null, - 'repoDatabase' => null, // note: "false" means "local"! - // default for repo items in main namespace - 'repoNamespaces' => array( - 'wikibase-item' => '', - 'wikibase-property' => 'Property' - ), - 'allowDataTransclusion' => true, - 'enableSiteLinkWidget' => false, -); + $defaults = array( + 'namespaces' => array(), // by default, include all namespaces; deprecated as of 0.4 + 'excludeNamespaces' => array(), + 'repoUrl' => '//www.wikidata.org', + 'repoScriptPath' => $wgScriptPath, + 'repoArticlePath' => $wgArticlePath, + 'sort' => 'code', + 'sortPrepend' => array(), + 'alwaysSort' => false, + 'siteGlobalID' => $wgDBname, + // @todo would be great to just get this from the sites stuff + // but we will need to make sure the caching works good enough + 'siteLocalID' => $wgLanguageCode, + 'siteGroup' => 'wikipedia', + 'injectRecentChanges' => true, + 'showExternalRecentChanges' => true, + 'defaultClientStore' => null, + 'repoDatabase' => null, // note: "false" means "local"! + // default for repo items in main namespace + 'repoNamespaces' => array( + 'wikibase-item' => '', + 'wikibase-property' => 'Property' + ), + 'allowDataTransclusion' => true, + 'enableSiteLinkWidget' => false, -/** - * @todo this is a bit wikimedia-specific and need to find a better place for this stuff, - * such as mediawiki-config, mediawiki messages for custom orders, or somewhere. - * - * alphabetic and alphabetic revised come from: - * http://meta.wikimedia.org/w/index.php?title=MediaWiki:Interwiki_config-sorting_order-native-languagename - * http://meta.wikimedia.org/w/index.php?title=MediaWiki:Interwiki_config-sorting_order-native-languagename-firstword (revised) - * and from pywikipedia for alphabetic_sr - */ -$wgWBClientSettings['interwikiSortOrders'] = array( - 'alphabetic' => array( - 'ace', 'kbd', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc', - 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bm', 'bn', 'bjn', - 'zh-min-nan', 'nan', 'map-bms', 'ba', 'be', 'be-x-old', 'bh', 'bcl', 'bi', - 'bg', 'bar', 'bo', 'bs', 'br', 'bxr', 'ca', 'cv', 'ceb', 'cs', 'ch', - 'cbk-zam', 'ny', 'sn', 'tum', 'cho', 'co', 'cy', 'da', 'dk', 'pdc', 'de', - 'dv', 'nv', 'dsb', 'dz', 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo', - 'ext', 'eu', 'ee', 'fa', 'hif', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', 'gv', - 'gag', 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', 'got', 'hak', 'xal', 'ko', 'ha', - 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig', 'ilo', 'bpy', 'id', 'ia', - 'ie', 'iu', 'ik', 'os', 'xh', 'zu', 'is', 'it', 'he', 'jv', 'kl', 'kn', 'kr', - 'pam', 'krc', 'ka', 'ks', 'csb', 'kk', 'kw', 'rw', 'rn', 'sw', 'kv', 'kg', - 'ht', 'ku', 'kj', 'ky', 'mrj', 'lad', 'lbe', 'lez', 'lo', 'ltg', 'la', 'lv', - 'lb', 'lt', 'lij', 'li', 'ln', 'jbo', 'lg', 'lmo', 'hu', 'mk', 'mg', 'ml', - 'mt', 'mi', 'mr', 'xmf', 'arz', 'mzn', 'ms', 'min', 'cdo', 'mwl', 'mdf', 'mo', - 'mn', 'mus', 'my', 'nah', 'na', 'fj', 'nl', 'nds-nl', 'cr', 'ne', 'new', 'ja', - 'nap', 'ce', 'frr', 'pih', 'no', 'nb', 'nn', 'nrm', 'nov', 'ii', 'oc', 'mhr', - 'or', 'om', 'ng', 'hz', 'uz', 'pa', 'pi', 'pfl', 'pag', 'pnb', 'pap', 'ps', - 'koi', 'km', 'pcd', 'pms', 'tpi', 'nds', 'pl', 'tokipona', 'tp', 'pnt', 'pt', - 'aa', 'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy', 'rm', 'qu', 'rue', 'ru', 'sah', - 'se', 'sm', 'sa', 'sg', 'sc', 'sco', 'stq', 'st', 'nso', 'tn', 'sq', 'scn', - 'si', 'simple', 'sd', 'ss', 'sk', 'sl', 'cu', 'szl', 'so', 'ckb', 'srn', 'sr', - 'sh', 'su', 'fi', 'sv', 'tl', 'ta', 'shi', 'kab', 'roa-tara', 'tt', 'te', 'tet', - 'th', 'ti', 'tg', 'to', 'chr', 'chy', 've', 'tr', 'tk', 'tw', 'udm', 'bug', - 'uk', 'ur', 'ug', 'za', 'vec', 'vep', 'vi', 'vo', 'fiu-vro', 'wa', 'zh-classical', - 'vls', 'war', 'wo', 'wuu', 'ts', 'yi', 'yo', 'zh-yue', 'diq', 'zea', 'bat-smg', - 'zh', 'zh-tw', 'zh-cn' - ), - 'alphabetic_revised' => array( - 'ace', 'kbd', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc', 'roa-rup', - 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bjn', 'id', 'ms', 'bm', 'bn', - 'zh-min-nan', 'nan', 'map-bms', 'jv', 'su', 'ba', 'min', 'be', 'be-x-old', 'bh', - 'bcl', 'bi', 'bar', 'bo', 'bs', 'br', 'bug', 'bg', 'bxr', 'ca', 'ceb', 'cv', 'cs', - 'ch', 'cbk-zam', 'ny', 'sn', 'tum', 'cho', 'co', 'cy', 'da', 'dk', 'pdc', 'de', - 'dv', 'nv', 'dsb', 'na', 'dz', 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo', - 'ext', 'eu', 'ee', 'fa', 'hif', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', 'gv', 'sm', - 'gag', 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', 'got', 'hak', 'xal', 'ko', 'ha', 'haw', - 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig', 'ilo', 'bpy', 'ia', 'ie', 'iu', 'ik', - 'os', 'xh', 'zu', 'is', 'it', 'he', 'kl', 'kn', 'kr', 'pam', 'ka', 'ks', 'csb', - 'kk', 'kw', 'rw', 'ky', 'rn', 'mrj', 'sw', 'kv', 'kg', 'ht', 'ku', 'kj', 'lad', - 'lbe', 'lez', 'lo', 'la', 'ltg', 'lv', 'to', 'lb', 'lt', 'lij', 'li', 'ln', 'jbo', - 'lg', 'lmo', 'hu', 'mk', 'mg', 'ml', 'krc', 'mt', 'mi', 'mr', 'xmf', 'arz', 'mzn', - 'cdo', 'mwl', 'koi', 'mdf', 'mo', 'mn', 'mus', 'my', 'nah', 'fj', 'nl', 'nds-nl', - 'cr', 'ne', 'new', 'ja', 'nap', 'ce', 'frr', 'pih', 'no', 'nb', 'nn', 'nrm', 'nov', - 'ii', 'oc', 'mhr', 'or', 'om', 'ng', 'hz', 'uz', 'pa', 'pi', 'pfl', 'pag', 'pnb', - 'pap', 'ps', 'km', 'pcd', 'pms', 'nds', 'pl', 'pnt', 'pt', 'aa', 'kaa', 'crh', 'ty', - 'ksh', 'ro', 'rmy', 'rm', 'qu', 'ru', 'rue', 'sah', 'se', 'sa', 'sg', 'sc', 'sco', - 'stq', 'st', 'nso', 'tn', 'sq', 'scn', 'si', 'simple', 'sd', 'ss', 'sk', 'sl', - 'cu', 'szl', 'so', 'ckb', 'srn', 'sr', 'sh', 'fi', 'sv', 'tl', 'ta', 'shi', - 'kab', 'roa-tara', 'tt', 'te', 'tet', 'th', 'vi', 'ti', 'tg', 'tpi', 'tokipona', - 'tp', 'chr', 'chy', 've', 'tr', 'tk', 'tw', 'udm', 'uk', 'ur', 'ug', 'za', - 'vec', 'vep', 'vo', 'fiu-vro', 'wa', 'zh-classical', 'vls', 'war', 'wo', 'wuu', - 'ts', 'yi', 'yo', 'zh-yue', 'diq', 'zea', 'bat-smg', 'zh', 'zh-tw', 'zh-cn' - ), - 'alphabetic_sr' => array( - 'ace', 'kbd', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc', - 'roa-rup', 'frp', 'arz', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bjn', 'id', - 'ms', 'bg', 'bm', 'zh-min-nan', 'nan', 'map-bms', 'jv', 'su', 'ba', 'be', - 'be-x-old', 'bh', 'bcl', 'bi', 'bn', 'bo', 'bar', 'bs', 'bpy', 'br', 'bug', - 'bxr', 'ca', 'ceb', 'ch', 'cbk-zam', 'sn', 'tum', 'ny', 'cho', 'chr', 'co', - 'cy', 'cv', 'cs', 'da', 'dk', 'pdc', 'de', 'nv', 'dsb', 'na', 'dv', 'dz', - 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo', 'ext', 'eu', 'ee', 'fa', - 'hif', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', 'gv', 'sm', 'gag', 'gd', 'gl', - 'gan', 'ki', 'glk', 'got', 'gu', 'ha', 'hak', 'xal', 'haw', 'he', 'hi', 'ho', - 'hsb', 'hr', 'hy', 'io', 'ig', 'ii', 'ilo', 'ia', 'ie', 'iu', 'ik', 'os', - 'xh', 'zu', 'is', 'it', 'ja', 'ka', 'kl', 'kr', 'pam', 'krc', 'csb', 'kk', - 'kw', 'rw', 'ky', 'mrj', 'rn', 'sw', 'km', 'kn', 'ko', 'kv', 'kg', 'ht', - 'ks', 'ku', 'kj', 'lad', 'lbe', 'la', 'ltg', 'lv', 'to', 'lb', 'lez', 'lt', - 'lij', 'li', 'ln', 'lo', 'jbo', 'lg', 'lmo', 'hu', 'mk', 'mg', 'mt', 'mi', - 'min', 'cdo', 'mwl', 'ml', 'mdf', 'mo', 'mn', 'mr', 'mus', 'my', 'mzn', 'nah', - 'fj', 'ne', 'nl', 'nds-nl', 'cr', 'new', 'nap', 'ce', 'frr', 'pih', 'no', 'nb', - 'nn', 'nrm', 'nov', 'oc', 'mhr', 'or', 'om', 'ng', 'hz', 'uz', 'pa', 'pfl', - 'pag', 'pap', 'koi', 'pi', 'pcd', 'pms', 'nds', 'pnb', 'pl', 'pt', 'pnt', - 'ps', 'aa', 'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy', 'rm', 'qu', 'ru', 'rue', - 'sa', 'sah', 'se', 'sg', 'sc', 'sco', 'sd', 'stq', 'st', 'nso', 'tn', 'sq', - 'si', 'scn', 'simple', 'ss', 'sk', 'sl', 'cu', 'szl', 'so', 'ckb', 'srn', - 'sr', 'sh', 'fi', 'sv', 'ta', 'shi', 'tl', 'kab', 'roa-tara', 'tt', 'te', - 'tet', 'th', 'ti', 'vi', 'tg', 'tokipona', 'tp', 'tpi', 'chy', 've', 'tr', - 'tk', 'tw', 'udm', 'uk', 'ur', 'ug', 'za', 'vec', 'vep', 'vo', 'fiu-vro', - 'wa', 'vls', 'war', 'wo', 'wuu', 'ts', 'xmf', 'yi', 'yo', 'diq', 'zea', 'zh', - 'zh-tw', 'zh-cn', 'zh-classical', 'zh-yue', 'bat-smg' - ), - 'alphabetic_fy' => array( - 'aa', 'ab', 'ace', 'af', 'ay', 'ak', 'als', 'am', 'an', 'ang', 'ar', 'arc', - 'arz', 'as', 'ast', 'av', 'az', 'ba', 'bar', 'bat-smg', 'bcl', 'be', 'be-x-old', - 'bg', 'bh', 'bi', 'bjn', 'bm', 'bn', 'bo', 'bpy', 'br', 'bs', 'bug', 'bxr', - 'ca', 'cbk-zam', 'cdo', 'ce', 'ceb', 'ch', 'chy', 'cho', 'chr', 'cy', 'ckb', - 'co', 'cr', 'crh', 'cs', 'csb', 'cu', 'cv', 'da', 'de', 'diq', 'dk', 'dsb', 'dv', - 'dz', 'ee', 'el', 'eml', 'en', 'eo', 'es', 'et', 'eu', 'ext', 'fa', 'ff', 'fi', - 'fy', 'fiu-vro', 'fj', 'fo', 'fr', 'frp', 'frr', 'fur', 'ga', 'gag', 'gan', 'gd', - 'gl', 'glk', 'gn', 'got', 'gu', 'gv', 'ha', 'hak', 'haw', 'he', 'hi', 'hy', - 'hif', 'ho', 'hr', 'hsb', 'ht', 'hu', 'hz', 'ia', 'id', 'ie', 'ig', 'ii', 'yi', - 'ik', 'ilo', 'io', 'yo', 'is', 'it', 'iu', 'ja', 'jbo', 'jv', 'ka', 'kaa', 'kab', - 'kbd', 'kg', 'ki', 'ky', 'kj', 'kk', 'kl', 'km', 'kn', 'ko', 'koi', 'kr', 'krc', - 'ks', 'ksh', 'ku', 'kv', 'kw', 'la', 'lad', 'lb', 'lbe', 'lez', 'lg', 'li', - 'lij', 'lmo', 'ln', 'lo', 'lt', 'ltg', 'lv', 'map-bms', 'mdf', 'mg', 'mh', 'mhr', - 'mi', 'my', 'min', 'myv', 'mk', 'ml', 'mn', 'mo', 'mr', 'mrj', 'ms', 'mt', 'mus', - 'mwl', 'mzn', 'na', 'nah', 'nan', 'nap', 'nds', 'nds-nl', 'ne', 'new', 'ng', 'ny', - 'nl', 'nn', 'no', 'nov', 'nrm', 'nso', 'nv', 'oc', 'om', 'or', 'os', 'pa', 'pag', - 'pam', 'pap', 'pcd', 'pdc', 'pfl', 'pi', 'pih', 'pl', 'pms', 'pnb', 'pnt', 'ps', - 'pt', 'qu', 'rm', 'rmy', 'rn', 'ro', 'roa-rup', 'roa-tara', 'ru', 'rue', 'rw', - 'sa', 'sah', 'sc', 'scn', 'sco', 'sd', 'se', 'sg', 'sh', 'shi', 'si', 'simple', - 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'srn', 'ss', 'st', 'stq', 'su', 'sv', - 'sw', 'szl', 'ta', 'te', 'tet', 'tg', 'th', 'ti', 'ty', 'tk', 'tl', 'tn', 'to', - 'tokipona', 'tp', 'tpi', 'tr', 'ts', 'tt', 'tum', 'tw', 'udm', 'ug', 'uk', 'ur', - 'uz', 've', 'vec', 'vep', 'vi', 'vls', 'vo', 'wa', 'war', 'wo', 'wuu', 'xal', - 'xh', 'xmf', 'za', 'zea', 'zh', 'zh-classical', 'zh-cn', 'zh-yue', 'zh-min-nan', - 'zh-tw', 'zu' - ), -); + /** + * @todo this is a bit wikimedia-specific and need to find a better place for this stuff, + * such as mediawiki-config, mediawiki messages for custom orders, or somewhere. + * + * alphabetic and alphabetic revised come from: + * http://meta.wikimedia.org/w/index.php?title=MediaWiki:Interwiki_config-sorting_order-native-languagename + * http://meta.wikimedia.org/w/index.php?title=MediaWiki:Interwiki_config-sorting_order-native-languagename-firstword (revised) + * and from pywikipedia for alphabetic_sr + */ + 'interwikiSortOrders' => array( + 'alphabetic' => array( + 'ace', 'kbd', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc', + 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bm', 'bn', 'bjn', + 'zh-min-nan', 'nan', 'map-bms', 'ba', 'be', 'be-x-old', 'bh', 'bcl', 'bi', + 'bg', 'bar', 'bo', 'bs', 'br', 'bxr', 'ca', 'cv', 'ceb', 'cs', 'ch', + 'cbk-zam', 'ny', 'sn', 'tum', 'cho', 'co', 'cy', 'da', 'dk', 'pdc', 'de', + 'dv', 'nv', 'dsb', 'dz', 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo', + 'ext', 'eu', 'ee', 'fa', 'hif', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', 'gv', + 'gag', 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', 'got', 'hak', 'xal', 'ko', 'ha', + 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig', 'ilo', 'bpy', 'id', 'ia', + 'ie', 'iu', 'ik', 'os', 'xh', 'zu', 'is', 'it', 'he', 'jv', 'kl', 'kn', 'kr', + 'pam', 'krc', 'ka', 'ks', 'csb', 'kk', 'kw', 'rw', 'rn', 'sw', 'kv', 'kg', + 'ht', 'ku', 'kj', 'ky', 'mrj', 'lad', 'lbe', 'lez', 'lo', 'ltg', 'la', 'lv', + 'lb', 'lt', 'lij', 'li', 'ln', 'jbo', 'lg', 'lmo', 'hu', 'mk', 'mg', 'ml', + 'mt', 'mi', 'mr', 'xmf', 'arz', 'mzn', 'ms', 'min', 'cdo', 'mwl', 'mdf', 'mo', + 'mn', 'mus', 'my', 'nah', 'na', 'fj', 'nl', 'nds-nl', 'cr', 'ne', 'new', 'ja', + 'nap', 'ce', 'frr', 'pih', 'no', 'nb', 'nn', 'nrm', 'nov', 'ii', 'oc', 'mhr', + 'or', 'om', 'ng', 'hz', 'uz', 'pa', 'pi', 'pfl', 'pag', 'pnb', 'pap', 'ps', + 'koi', 'km', 'pcd', 'pms', 'tpi', 'nds', 'pl', 'tokipona', 'tp', 'pnt', 'pt', + 'aa', 'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy', 'rm', 'qu', 'rue', 'ru', 'sah', + 'se', 'sm', 'sa', 'sg', 'sc', 'sco', 'stq', 'st', 'nso', 'tn', 'sq', 'scn', + 'si', 'simple', 'sd', 'ss', 'sk', 'sl', 'cu', 'szl', 'so', 'ckb', 'srn', 'sr', + 'sh', 'su', 'fi', 'sv', 'tl', 'ta', 'shi', 'kab', 'roa-tara', 'tt', 'te', 'tet', + 'th', 'ti', 'tg', 'to', 'chr', 'chy', 've', 'tr', 'tk', 'tw', 'udm', 'bug', + 'uk', 'ur', 'ug', 'za', 'vec', 'vep', 'vi', 'vo', 'fiu-vro', 'wa', 'zh-classical', + 'vls', 'war', 'wo', 'wuu', 'ts', 'yi', 'yo', 'zh-yue', 'diq', 'zea', 'bat-smg', + 'zh', 'zh-tw', 'zh-cn' + ), + 'alphabetic_revised' => array( + 'ace', 'kbd', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc', 'roa-rup', + 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bjn', 'id', 'ms', 'bm', 'bn', + 'zh-min-nan', 'nan', 'map-bms', 'jv', 'su', 'ba', 'min', 'be', 'be-x-old', 'bh', + 'bcl', 'bi', 'bar', 'bo', 'bs', 'br', 'bug', 'bg', 'bxr', 'ca', 'ceb', 'cv', 'cs', + 'ch', 'cbk-zam', 'ny', 'sn', 'tum', 'cho', 'co', 'cy', 'da', 'dk', 'pdc', 'de', + 'dv', 'nv', 'dsb', 'na', 'dz', 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo', + 'ext', 'eu', 'ee', 'fa', 'hif', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', 'gv', 'sm', + 'gag', 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', 'got', 'hak', 'xal', 'ko', 'ha', 'haw', + 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig', 'ilo', 'bpy', 'ia', 'ie', 'iu', 'ik', + 'os', 'xh', 'zu', 'is', 'it', 'he', 'kl', 'kn', 'kr', 'pam', 'ka', 'ks', 'csb', + 'kk', 'kw', 'rw', 'ky', 'rn', 'mrj', 'sw', 'kv', 'kg', 'ht', 'ku', 'kj', 'lad', + 'lbe', 'lez', 'lo', 'la', 'ltg', 'lv', 'to', 'lb', 'lt', 'lij', 'li', 'ln', 'jbo', + 'lg', 'lmo', 'hu', 'mk', 'mg', 'ml', 'krc', 'mt', 'mi', 'mr', 'xmf', 'arz', 'mzn', + 'cdo', 'mwl', 'koi', 'mdf', 'mo', 'mn', 'mus', 'my', 'nah', 'fj', 'nl', 'nds-nl', + 'cr', 'ne', 'new', 'ja', 'nap', 'ce', 'frr', 'pih', 'no', 'nb', 'nn', 'nrm', 'nov', + 'ii', 'oc', 'mhr', 'or', 'om', 'ng', 'hz', 'uz', 'pa', 'pi', 'pfl', 'pag', 'pnb', + 'pap', 'ps', 'km', 'pcd', 'pms', 'nds', 'pl', 'pnt', 'pt', 'aa', 'kaa', 'crh', 'ty', + 'ksh', 'ro', 'rmy', 'rm', 'qu', 'ru', 'rue', 'sah', 'se', 'sa', 'sg', 'sc', 'sco', + 'stq', 'st', 'nso', 'tn', 'sq', 'scn', 'si', 'simple', 'sd', 'ss', 'sk', 'sl', + 'cu', 'szl', 'so', 'ckb', 'srn', 'sr', 'sh', 'fi', 'sv', 'tl', 'ta', 'shi', + 'kab', 'roa-tara', 'tt', 'te', 'tet', 'th', 'vi', 'ti', 'tg', 'tpi', 'tokipona', + 'tp', 'chr', 'chy', 've', 'tr', 'tk', 'tw', 'udm', 'uk', 'ur', 'ug', 'za', + 'vec', 'vep', 'vo', 'fiu-vro', 'wa', 'zh-classical', 'vls', 'war', 'wo', 'wuu', + 'ts', 'yi', 'yo', 'zh-yue', 'diq', 'zea', 'bat-smg', 'zh', 'zh-tw', 'zh-cn' + ), + 'alphabetic_sr' => array( + 'ace', 'kbd', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc', + 'roa-rup', 'frp', 'arz', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bjn', 'id', + 'ms', 'bg', 'bm', 'zh-min-nan', 'nan', 'map-bms', 'jv', 'su', 'ba', 'be', + 'be-x-old', 'bh', 'bcl', 'bi', 'bn', 'bo', 'bar', 'bs', 'bpy', 'br', 'bug', + 'bxr', 'ca', 'ceb', 'ch', 'cbk-zam', 'sn', 'tum', 'ny', 'cho', 'chr', 'co', + 'cy', 'cv', 'cs', 'da', 'dk', 'pdc', 'de', 'nv', 'dsb', 'na', 'dv', 'dz', + 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo', 'ext', 'eu', 'ee', 'fa', + 'hif', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', 'gv', 'sm', 'gag', 'gd', 'gl', + 'gan', 'ki', 'glk', 'got', 'gu', 'ha', 'hak', 'xal', 'haw', 'he', 'hi', 'ho', + 'hsb', 'hr', 'hy', 'io', 'ig', 'ii', 'ilo', 'ia', 'ie', 'iu', 'ik', 'os', + 'xh', 'zu', 'is', 'it', 'ja', 'ka', 'kl', 'kr', 'pam', 'krc', 'csb', 'kk', + 'kw', 'rw', 'ky', 'mrj', 'rn', 'sw', 'km', 'kn', 'ko', 'kv', 'kg', 'ht', + 'ks', 'ku', 'kj', 'lad', 'lbe', 'la', 'ltg', 'lv', 'to', 'lb', 'lez', 'lt', + 'lij', 'li', 'ln', 'lo', 'jbo', 'lg', 'lmo', 'hu', 'mk', 'mg', 'mt', 'mi', + 'min', 'cdo', 'mwl', 'ml', 'mdf', 'mo', 'mn', 'mr', 'mus', 'my', 'mzn', 'nah', + 'fj', 'ne', 'nl', 'nds-nl', 'cr', 'new', 'nap', 'ce', 'frr', 'pih', 'no', 'nb', + 'nn', 'nrm', 'nov', 'oc', 'mhr', 'or', 'om', 'ng', 'hz', 'uz', 'pa', 'pfl', + 'pag', 'pap', 'koi', 'pi', 'pcd', 'pms', 'nds', 'pnb', 'pl', 'pt', 'pnt', + 'ps', 'aa', 'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy', 'rm', 'qu', 'ru', 'rue', + 'sa', 'sah', 'se', 'sg', 'sc', 'sco', 'sd', 'stq', 'st', 'nso', 'tn', 'sq', + 'si', 'scn', 'simple', 'ss', 'sk', 'sl', 'cu', 'szl', 'so', 'ckb', 'srn', + 'sr', 'sh', 'fi', 'sv', 'ta', 'shi', 'tl', 'kab', 'roa-tara', 'tt', 'te', + 'tet', 'th', 'ti', 'vi', 'tg', 'tokipona', 'tp', 'tpi', 'chy', 've', 'tr', + 'tk', 'tw', 'udm', 'uk', 'ur', 'ug', 'za', 'vec', 'vep', 'vo', 'fiu-vro', + 'wa', 'vls', 'war', 'wo', 'wuu', 'ts', 'xmf', 'yi', 'yo', 'diq', 'zea', 'zh', + 'zh-tw', 'zh-cn', 'zh-classical', 'zh-yue', 'bat-smg' + ), + 'alphabetic_fy' => array( + 'aa', 'ab', 'ace', 'af', 'ay', 'ak', 'als', 'am', 'an', 'ang', 'ar', 'arc', + 'arz', 'as', 'ast', 'av', 'az', 'ba', 'bar', 'bat-smg', 'bcl', 'be', 'be-x-old', + 'bg', 'bh', 'bi', 'bjn', 'bm', 'bn', 'bo', 'bpy', 'br', 'bs', 'bug', 'bxr', + 'ca', 'cbk-zam', 'cdo', 'ce', 'ceb', 'ch', 'chy', 'cho', 'chr', 'cy', 'ckb', + 'co', 'cr', 'crh', 'cs', 'csb', 'cu', 'cv', 'da', 'de', 'diq', 'dk', 'dsb', 'dv', + 'dz', 'ee', 'el', 'eml', 'en', 'eo', 'es', 'et', 'eu', 'ext', 'fa', 'ff', 'fi', + 'fy', 'fiu-vro', 'fj', 'fo', 'fr', 'frp', 'frr', 'fur', 'ga', 'gag', 'gan', 'gd', + 'gl', 'glk', 'gn', 'got', 'gu', 'gv', 'ha', 'hak', 'haw', 'he', 'hi', 'hy', + 'hif', 'ho', 'hr', 'hsb', 'ht', 'hu', 'hz', 'ia', 'id', 'ie', 'ig', 'ii', 'yi', + 'ik', 'ilo', 'io', 'yo', 'is', 'it', 'iu', 'ja', 'jbo', 'jv', 'ka', 'kaa', 'kab', + 'kbd', 'kg', 'ki', 'ky', 'kj', 'kk', 'kl', 'km', 'kn', 'ko', 'koi', 'kr', 'krc', + 'ks', 'ksh', 'ku', 'kv', 'kw', 'la', 'lad', 'lb', 'lbe', 'lez', 'lg', 'li', + 'lij', 'lmo', 'ln', 'lo', 'lt', 'ltg', 'lv', 'map-bms', 'mdf', 'mg', 'mh', 'mhr', + 'mi', 'my', 'min', 'myv', 'mk', 'ml', 'mn', 'mo', 'mr', 'mrj', 'ms', 'mt', 'mus', + 'mwl', 'mzn', 'na', 'nah', 'nan', 'nap', 'nds', 'nds-nl', 'ne', 'new', 'ng', 'ny', + 'nl', 'nn', 'no', 'nov', 'nrm', 'nso', 'nv', 'oc', 'om', 'or', 'os', 'pa', 'pag', + 'pam', 'pap', 'pcd', 'pdc', 'pfl', 'pi', 'pih', 'pl', 'pms', 'pnb', 'pnt', 'ps', + 'pt', 'qu', 'rm', 'rmy', 'rn', 'ro', 'roa-rup', 'roa-tara', 'ru', 'rue', 'rw', + 'sa', 'sah', 'sc', 'scn', 'sco', 'sd', 'se', 'sg', 'sh', 'shi', 'si', 'simple', + 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'srn', 'ss', 'st', 'stq', 'su', 'sv', + 'sw', 'szl', 'ta', 'te', 'tet', 'tg', 'th', 'ti', 'ty', 'tk', 'tl', 'tn', 'to', + 'tokipona', 'tp', 'tpi', 'tr', 'ts', 'tt', 'tum', 'tw', 'udm', 'ug', 'uk', 'ur', + 'uz', 've', 'vec', 'vep', 'vi', 'vls', 'vo', 'wa', 'war', 'wo', 'wuu', 'xal', + 'xh', 'xmf', 'za', 'zea', 'zh', 'zh-classical', 'zh-cn', 'zh-yue', 'zh-min-nan', + 'zh-tw', 'zu' + ), + ), + ); + + return $defaults; +} ); diff --git a/lib/WikibaseLib.php b/lib/WikibaseLib.php index a1f75b4..9b6a18b 100644 --- a/lib/WikibaseLib.php +++ b/lib/WikibaseLib.php @@ -79,6 +79,8 @@ define( 'WBL_VERSION', '0.4 alpha' . ( defined( 'WB_EXPERIMENTAL_FEATURES' ) && WB_EXPERIMENTAL_FEATURES ? '/experimental' : '' ) ); +define( 'WBL_DIR', __DIR__ ); + $wgExtensionCredits['wikibase'][] = array( 'path' => __DIR__, 'name' => 'WikibaseLib', @@ -167,8 +169,9 @@ // Resource Loader Modules: $wgResourceModules = array_merge( $wgResourceModules, include( __DIR__ . "/resources/Resources.php" ) ); +$wgWBSettings = array(); -include_once( __DIR__ . '/config/WikibaseLib.default.php' ); +$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/config/WikibaseLib.default.php b/lib/config/WikibaseLib.default.php index 7ec0fa5..6a4aa3a 100644 --- a/lib/config/WikibaseLib.default.php +++ b/lib/config/WikibaseLib.default.php @@ -29,65 +29,65 @@ * @licence GNU GPL v2+ */ -if ( !defined( 'WBL_VERSION' ) ) { - die( 'Not an entry point.' ); -} +return call_user_func( function() { -$wgWBSettings = array(); + $defaults = array( -// alternative: application/vnd.php.serialized -$wgWBSettings['serializationFormat'] = CONTENT_FORMAT_JSON; + // alternative: application/vnd.php.serialized + 'serializationFormat' => CONTENT_FORMAT_JSON, -// whether changes get recorded to wb_changes -$wgWBSettings['useChangesTable'] = true; + // whether changes get recorded to wb_changes + 'useChangesTable' => true, -$wgWBSettings['entityPrefixes'] = array( - 'q' => \Wikibase\Item::ENTITY_TYPE, - 'p' => \Wikibase\Property::ENTITY_TYPE, -); + 'entityPrefixes' => array( + 'q' => \Wikibase\Item::ENTITY_TYPE, + 'p' => \Wikibase\Property::ENTITY_TYPE, + ), -$wgWBSettings['siteLinkGroup'] = 'wikipedia'; + 'siteLinkGroup' => 'wikipedia', -// local by default. Set to something LBFactory understands. -$wgWBSettings['changesDatabase'] = false; + // local by default. Set to something LBFactory understands. + 'changesDatabase' => false, -// JSON is more robust against version differences between repo and client, -// but only once the client can cope with the JSON form of the change. -$wgWBSettings['changesAsJson'] = true; + // JSON is more robust against version differences between repo and client, + // but only once the client can cope with the JSON form of the change. + 'changesAsJson' => true, -// list of logical database names of local client wikis. -// may contain mappings from site-id to db-name. -$wgWBSettings['localClientDatabases'] = array(); + // list of logical database names of local client wikis. + // may contain mappings from site-id to db-name. + 'localClientDatabases' => array(), -$wgWBSettings['dispatchBatchChunkFactor'] = 3; -$wgWBSettings['dispatchBatchCacheFactor'] = 3; + 'dispatchBatchChunkFactor' => 3, + 'dispatchBatchCacheFactor' => 3, -$wgWBSettings['changeHandlers'] = array( - 'wikibase-item~add' => 'Wikibase\ItemChange', - 'wikibase-property~add' => 'Wikibase\EntityChange', - 'wikibase-query~add' => 'Wikibase\EntityChange', + 'changeHandlers' => array( + 'wikibase-item~add' => 'Wikibase\ItemChange', + 'wikibase-property~add' => 'Wikibase\EntityChange', + 'wikibase-query~add' => 'Wikibase\EntityChange', - 'wikibase-item~update' => 'Wikibase\ItemChange', - 'wikibase-property~update' => 'Wikibase\EntityChange', - 'wikibase-query~update' => 'Wikibase\EntityChange', + 'wikibase-item~update' => 'Wikibase\ItemChange', + 'wikibase-property~update' => 'Wikibase\EntityChange', + 'wikibase-query~update' => 'Wikibase\EntityChange', - 'wikibase-item~remove' => 'Wikibase\ItemChange', - 'wikibase-property~remove' => 'Wikibase\EntityChange', - 'wikibase-query~remove' => 'Wikibase\EntityChange', + 'wikibase-item~remove' => 'Wikibase\ItemChange', + 'wikibase-property~remove' => 'Wikibase\EntityChange', + 'wikibase-query~remove' => 'Wikibase\EntityChange', - 'wikibase-item~refresh' => 'Wikibase\ItemChange', - 'wikibase-property~refresh' => 'Wikibase\EntityChange', - 'wikibase-query~refresh' => 'Wikibase\EntityChange', + 'wikibase-item~refresh' => 'Wikibase\ItemChange', + 'wikibase-property~refresh' => 'Wikibase\EntityChange', + 'wikibase-query~refresh' => 'Wikibase\EntityChange', - 'wikibase-item~restore' => 'Wikibase\ItemChange', - 'wikibase-property~restore' => 'Wikibase\EntityChange', - 'wikibase-query~restore' => 'Wikibase\EntityChange', -); + 'wikibase-item~restore' => 'Wikibase\ItemChange', + 'wikibase-property~restore' => 'Wikibase\EntityChange', + 'wikibase-query~restore' => 'Wikibase\EntityChange', + ), -$wgWBSettings['dataTypes'] = array( - 'wikibase-item', - 'commonsMedia', - 'string', -); + 'dataTypes' => array( + 'wikibase-item', + 'commonsMedia', + 'string', + ), + ); -$wgValueFormatters['wikibase-entityid'] = 'Wikibase\Lib\EntityIdFormatter'; \ No newline at end of file + return $defaults; +} ); diff --git a/lib/config/WikibaseLib.experimental.php b/lib/config/WikibaseLib.experimental.php index cd8c6ef..7a237c6 100644 --- a/lib/config/WikibaseLib.experimental.php +++ b/lib/config/WikibaseLib.experimental.php @@ -33,16 +33,19 @@ die( 'Not an entry point.' ); } -global $wgWBSettings, $wgAutoloadClasses, $wgHooks; +global $wgHooks; -$wgWBSettings['dataTypes'] = array_merge( $wgWBSettings['dataTypes'], array( - 'geo-coordinate', - 'quantity', - 'monolingual-text', - 'multilingual-text', - 'time', -) ); +$wgHooks['WikibaseDefaultSettings'][] = function( array &$settings ) { + $settings['dataTypes'] = array_merge( $settings['dataTypes'], array( + 'geo-coordinate', + 'quantity', + 'monolingual-text', + 'multilingual-text', + 'time', + ) ); + return true; +}; $wgHooks['UnitTestsList'][] = function( array &$files ) { // @codeCoverageIgnoreStart diff --git a/lib/includes/Settings.php b/lib/includes/Settings.php index 35de02a..b306b1e 100644 --- a/lib/includes/Settings.php +++ b/lib/includes/Settings.php @@ -30,6 +30,7 @@ * * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > + * @author Daniel Kinzler */ class Settings extends SettingsArray { @@ -44,24 +45,67 @@ static $instance = null; if ( $instance === null ) { - $settings = array(); - - if ( defined( 'WB_VERSION' ) ) { - $settings = array_merge( $settings, $GLOBALS['wgWBRepoSettings'] ); - } - - if ( defined( 'WBC_VERSION' ) ) { - $settings = array_merge( $settings, $GLOBALS['wgWBClientSettings'] ); - } - - $settings = array_merge( $settings, $GLOBALS['wgWBSettings'] ); - - $instance = new static( $settings ); + $instance = new static(); + $instance->initFromGlobals(); } return $instance; } + protected static function loadDefaults( $path ) { + $defaults = include( $path ); + + if ( !is_array( $defaults ) ) { + throw new \MWException( "Defaults file not found: $path" ); + } + + return $defaults; + } + + /** + * Initializes this Settings object from the global configuration variables. + * Default settings are loaded from the appropriate files. + * The hook WikibaseDefaultSettings can be used to manipulate the defaults. + * + * @since 0.4 + */ + public function initFromGlobals() { + $settings = array(); + + // load appropriate defaults ------------------- + if ( defined( 'WBL_VERSION' ) ) { + $settings = array_merge( $settings, self::loadDefaults( WBL_DIR . '/config/WikibaseLib.default.php' ) ); + } + + if ( defined( 'WB_VERSION' ) ) { + $settings = array_merge( $settings, self::loadDefaults( WB_DIR . '/config/Wikibase.default.php' ) ); + } + + if ( defined( 'WBC_VERSION' ) ) { + $settings = array_merge( $settings, self::loadDefaults( WBC_DIR . '/config/WikibaseClient.default.php' ) ); + } + + wfRunHooks( 'WikibaseDefaultSettings', array( &$settings ) ); + + // merge appropriate settings ------------------- + if ( defined( 'WBL_VERSION' ) ) { + $settings = array_merge( $settings, $GLOBALS['wgWBSettings'] ); + } + + if ( defined( 'WB_VERSION' ) ) { + $settings = array_merge( $settings, $GLOBALS['wgWBRepoSettings'] ); + } + + if ( defined( 'WBC_VERSION' ) ) { + $settings = array_merge( $settings, $GLOBALS['wgWBClientSettings'] ); + } + + // store + foreach ( $settings as $key => $value ) { + $this[$key] = $value; + } + } + /** * Shortcut to ::singleton()->getSetting * diff --git a/repo/Wikibase.php b/repo/Wikibase.php index 1a6e586..2d4f3eb 100755 --- a/repo/Wikibase.php +++ b/repo/Wikibase.php @@ -50,6 +50,8 @@ define( 'WB_VERSION', '0.4 alpha' . ( defined( 'WB_EXPERIMENTAL_FEATURES' ) && WB_EXPERIMENTAL_FEATURES ? '/experimental' : '' ) ); +define( 'WB_DIR', __DIR__ ); + $wgExtensionCredits['wikibase'][] = array( 'path' => __DIR__, 'name' => 'Wikibase Repository', @@ -141,7 +143,6 @@ // Hooks $wgHooks['BeforePageDisplay'][] = 'Wikibase\RepoHooks::onBeforePageDisplay'; -$wgHooks['WikibaseDefaultSettings'][] = 'Wikibase\RepoHooks::onWikibaseDefaultSettings'; $wgHooks['LoadExtensionSchemaUpdates'][] = 'Wikibase\RepoHooks::onSchemaUpdate'; $wgHooks['UnitTestsList'][] = 'Wikibase\RepoHooks::registerUnitTests'; $wgHooks['NamespaceIsMovable'][] = 'Wikibase\RepoHooks::onNamespaceIsMovable'; @@ -176,7 +177,7 @@ $wgWBStores['sqlstore'] = 'Wikibase\SqlStore'; -include_once( __DIR__ . '/config/Wikibase.default.php' ); +$wgWBRepoSettings = array(); if ( defined( 'WB_EXPERIMENTAL_FEATURES' ) && WB_EXPERIMENTAL_FEATURES ) { include_once( __DIR__ . '/config/Wikibase.experimental.php' ); diff --git a/repo/config/Wikibase.default.php b/repo/config/Wikibase.default.php index ffb2828..da4768c 100644 --- a/repo/config/Wikibase.default.php +++ b/repo/config/Wikibase.default.php @@ -29,50 +29,50 @@ * @licence GNU GPL v2+ */ -if ( !defined( 'WB_VERSION' ) ) { - die( 'Not an entry point.' ); -} +return call_user_func( function() { -$dir = __DIR__ . '/'; + $defaults = array( -$wgWBRepoSettings = array(); + // Set API in debug mode + // do not turn on in production! + 'apiInDebug' => false, -// Set API in debug mode -// do not turn on in production! -$wgWBRepoSettings['apiInDebug'] = false; + // Additional settings for API when debugging is on to + // facilitate testing. + 'apiDebugWithPost' => false, + 'apiDebugWithRights' => false, + 'apiDebugWithTokens' => false, -// Additional settings for API when debugging is on to -// facilitate testing. -$wgWBRepoSettings['apiDebugWithPost'] = false; -$wgWBRepoSettings['apiDebugWithRights'] = false; -$wgWBRepoSettings['apiDebugWithTokens'] = false; + 'defaultStore' => 'sqlstore', -$wgWBRepoSettings['defaultStore'] = 'sqlstore'; + 'idBlacklist' => array( + 1, + 23, + 42, + 1337, + 9001, + 31337, + 720101010, + ), -$wgWBRepoSettings['idBlacklist'] = array( - 1, - 23, - 42, - 1337, - 9001, - 31337, - 720101010, -); + // Allow the TermIndex table to work without the term_search_key field, + // for sites that can not easily roll out schema changes on large tables. + // This means that all searches will use exact matching + // (depending on the database's collation). + 'withoutTermSearchKey' => false, -// Allow the TermIndex table to work without the term_search_key field, -// for sites that can not easily roll out schema changes on large tables. -// This means that all searches will use exact matching -// (depending on the database's collation). -$wgWBRepoSettings['withoutTermSearchKey'] = false; + 'entityNamespaces' => array(), -$wgWBRepoSettings['entityNamespaces'] = array(); + // These are used for multilanguage strings that should have a soft length constraint + 'multilang-limits' => array( + 'length' => 250, + ), -// These are used for multilanguage strings that should have a soft length constraint -$wgWBRepoSettings['multilang-limits'] = array( - 'length' => 250, -); + 'multilang-truncate-length' => 32, -$wgWBRepoSettings['multilang-truncate-length'] = 32; + // Should the page names (titles) be normalized against the external site + 'normalizeItemByTitlePageNames' => false, + ); -// Should the page names (titles) be normalized against the external site -$wgWBRepoSettings['normalizeItemByTitlePageNames'] = false; + return $defaults; +} ); diff --git a/repo/includes/content/EntityHandler.php b/repo/includes/content/EntityHandler.php index 3f9bf0d..f8fa10a 100644 --- a/repo/includes/content/EntityHandler.php +++ b/repo/includes/content/EntityHandler.php @@ -139,10 +139,16 @@ * * @since 0.1 * - * @return integer + * @return int */ final public function getEntityNamespace() { - return NamespaceUtils::getEntityNamespace( $this->getModelID() ); + $ns = NamespaceUtils::getEntityNamespace( $this->getModelID() ); + + if ( $ns === false ) { + throw new MWException( "No namespace found for entity model " . $this->getModelID() ); + } + + return $ns; } /** diff --git a/repo/tests/phpunit/includes/content/EntityHandlerTest.php b/repo/tests/phpunit/includes/content/EntityHandlerTest.php index f6f7f6c..fb085a2 100644 --- a/repo/tests/phpunit/includes/content/EntityHandlerTest.php +++ b/repo/tests/phpunit/includes/content/EntityHandlerTest.php @@ -118,11 +118,14 @@ public function testCanBeUsedOn() { $handler = $this->getHandler(); - $this->assertTrue( $handler->canBeUsedOn( \Title::makeTitle( $handler->getEntityNamespace(), "1234" ) ), + $ns = $handler->getEntityNamespace(); + $title = \Title::makeTitle( $ns, "1234" ); + $this->assertTrue( $handler->canBeUsedOn( $title ), 'It should be possible to create this kind of entity in the respective entity namespace!' ); - $this->assertFalse( $handler->canBeUsedOn( \Title::makeTitle( NS_MEDIAWIKI, "Foo" ) ), + $title = \Title::makeTitle( NS_MEDIAWIKI, "Foo" ); + $this->assertFalse( $handler->canBeUsedOn( $title ), 'It should be impossible to create an entity outside the respective entity namespace!' ); } -- To view, visit https://gerrit.wikimedia.org/r/62815 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I14422cd85a3cf0200ea89953251b78b6b8d813cb Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Denny Vrandecic <denny.vrande...@wikimedia.de> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits