Skip to content

Commit

Permalink
NamespaceManager avoid reset of user settings, refs 2439 (#2444)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed May 6, 2017
1 parent 80950d1 commit 8878300
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
33 changes: 18 additions & 15 deletions src/NamespaceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function init() {
}

$this->addNamespaceSettings();
$this->addExtraNamespaceSettings();
}

/**
Expand Down Expand Up @@ -188,19 +189,6 @@ public static function initCustomNamespace( &$globalVars ) {

protected function addNamespaceSettings() {

// Support subpages only for talk pages by default
$this->globalVars['wgNamespacesWithSubpages'] = $this->globalVars['wgNamespacesWithSubpages'] + array(
SMW_NS_PROPERTY_TALK => true,
SMW_NS_TYPE_TALK => true,
SMW_NS_CONCEPT_TALK => true,
);

// not modified for Semantic MediaWiki
/* $this->globalVars['wgNamespacesToBeSearchedDefault'] = array(
NS_MAIN => true,
);
*/

/**
* Default settings for the SMW specific NS which can only
* be defined after SMW_NS_PROPERTY is declared
Expand All @@ -226,6 +214,19 @@ protected function addNamespaceSettings() {
$smwNamespacesSettings,
$this->globalVars['smwgNamespacesWithSemanticLinks']
);
}

private function addExtraNamespaceSettings() {

/**
* Indicating which namespaces allow sub-pages
*
* @see https://www.mediawiki.org/wiki/Manual:$wgNamespacesWithSubpages
*/
$this->globalVars['wgNamespacesWithSubpages'] = $this->globalVars['wgNamespacesWithSubpages'] + array(
SMW_NS_PROPERTY_TALK => true,
SMW_NS_CONCEPT_TALK => true,
);

/**
* Allow custom namespaces to be acknowledged as containing useful content
Expand All @@ -242,8 +243,10 @@ protected function addNamespaceSettings() {
*
* @see https://www.mediawiki.org/wiki/Manual:$wgNamespacesToBeSearchedDefault
*/
$this->globalVars['wgNamespacesToBeSearchedDefault'][SMW_NS_PROPERTY] = true;
$this->globalVars['wgNamespacesToBeSearchedDefault'][SMW_NS_CONCEPT] = true;
$this->globalVars['wgNamespacesToBeSearchedDefault'] = $this->globalVars['wgNamespacesToBeSearchedDefault'] + array(
SMW_NS_PROPERTY => true,
SMW_NS_CONCEPT => true
);
}

protected function isDefinedConstant( $constant ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function testRunNamespaceManagerWithNoConstantsDefined() {
'wgExtraNamespaces' => array(),
'wgNamespaceAliases' => array(),
'wgContentNamespaces' => array(),
'wgNamespacesToBeSearchedDefault' => array(),
'wgLanguageCode' => 'en'
);

Expand Down
34 changes: 32 additions & 2 deletions tests/phpunit/Unit/NamespaceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testCanConstruct() {
);
}

public function testExecutionWithIncompleteConfiguration() {
public function testInitOnIncompleteConfiguration() {

$test = $this->default + array(
'wgExtraNamespaces' => '',
Expand Down Expand Up @@ -169,7 +169,7 @@ public function testNamespacesInitWithEmptySettings() {
);
}

public function testNamespacesInitToKeepPreInitSettings() {
public function testInitToKeepPreInitSettings() {

$this->testEnvironment->addConfiguration(
'smwgHistoricTypeNamespace',
Expand Down Expand Up @@ -201,6 +201,36 @@ public function testNamespacesInitToKeepPreInitSettings() {
);
}

public function testInitWithoutOverridingUserSettingsOnExtraNamespaceSettings() {

$test = array(
'wgNamespacesWithSubpages' => array(
SMW_NS_PROPERTY => false
),
'wgNamespacesToBeSearchedDefault' => array(
SMW_NS_PROPERTY => false
),
'wgContentNamespaces' => array(
SMW_NS_PROPERTY => false
)
) + $this->default;

$instance = new NamespaceManager( $test, $this->extraneousLanguage );
$instance->init();

$this->assertFalse(
$test['wgNamespacesWithSubpages'][SMW_NS_PROPERTY]
);

$this->assertFalse(
$test['wgNamespacesToBeSearchedDefault'][SMW_NS_PROPERTY]
);

$this->assertFalse(
$test['wgContentNamespaces'][SMW_NS_PROPERTY]
);
}

public function testInitCanonicalNamespacesWithForcedNsReset() {

$namespaces = array(
Expand Down

0 comments on commit 8878300

Please sign in to comment.