Page MenuHomePhabricator

NS_MODULE not defined in LocalSettings.php
Closed, DeclinedPublicBUG REPORT

Description

MW 1.34.0, Scribunto https://gerrit.wikimedia.org/g/mediawiki/extensions/Scribunto/+/f7bc2e34e7d3b29e470eb7c28e4081572b73ad95 (September 30, 2019), PHP 7.4.3.

For some reason, after wfLoadExtension ('Scribunto');, NS_MODULE is not defined.

Event Timeline

DannyS712 changed the subtype of this task from "Task" to "Bug Report".Mar 14 2020, 1:00 AM

Not defined where?

In LocalSettings.php, so that $wgNamespaceProtection [NS_MODULE] = ['editmodule']; restricts write access to the main namespace rather than to Module:.

NS_MODULE is a non canonical namespace, you must use the numerical constant

$wgNamespaceProtection[ 828 ] = [ 'editmodule' ];

NS_MODULE is a non canonical namespace, you must use the numerical constant

$wgNamespaceProtection[ 828 ] = [ 'editmodule' ];

That's what I did; however NS_NODULE is mentioned here: https://www.mediawiki.org/wiki/Extension_default_namespaces#Scribunto.

That's what I did;

No, you used $wgNamespaceProtection [NS_MODULE] = ['editmodule']; that's not the same thing with what I said.

howere NS_NODULE is mentioned here: https://www.mediawiki.org/wiki/Extension_default_namespaces#Scribunto.

Yes, it's still not canonical MW namespace.

That's what I did;

No, you used $wgNamespaceProtection [NS_MODULE] = ['editmodule']; that's not the same thing with what I said.

No, when I found out the absence of NS_MODULE, I had to switch to:

if (defined ('NS_MODULE')) {
	$wgNamespaceProtection [NS_MODULE] = ['editmodule'];
} else {
	$wgNamespaceProtection [828] = ['editmodule'];
}

So, I eventually had to do basically what you said.

@alex-mashin: Instead of having to ask several times due to byte-size information, it would be welcome if you followed https://www.mediawiki.org/wiki/How_to_report_a_bug and provide complete and clear steps to reproduce your setup, which leave no room for interpretation. Thanks.

So, I eventually had to do basically what you said.

No you did something different again; You should use $wgNamespaceProtection [828] = ['editmodule']; as it's all you need. You needn't to 'basically' use something else. NS_MODULE is meant to be used internally in the extension code.

If you must use it then you've to explicitly redefine it for yourself before loading the extension.

define( 'NS_MODULE', 828 );
wfLoadExtension( "Scribunto" );
$wgNamespaceProtection[NS_MODULE] = ['editmodule'];

But that's pretty pointless as it's the same thing with what has been already repeated above.

If you're wondering why $wgNamespaceProtection[NS_CATEGORY] = ['editcat']; works on the fly but $wgNamespaceProtection[NS_MODULE] = ['editmodule']; does not; it is because of this.

No you did something different again; You should use $wgNamespaceProtection [828] = ['editmodule']; as it's all you need. You needn't to 'basically' use something else. NS_MODULE is meant to be used internally in the extension code.

I did it in the hope that this issue would be resolved. The code fragment to which you referred still doesn't explain to me why namespace constants defined in some extensions are not available in LocalSettings.php while others are (like SMW_NS_PROPERTY).

I did it in the hope that this issue would be resolved.

Actually there's no issue to solve here as this report is invalid.

The code fragment to which you referred still doesn't explain to me why namespace constants defined in some extensions are not available in

The constants defined in the extension.json are not available by the time LocalSettings.php is setup because wfLoadExtension() is executed later, I believe.

... while others are (like SMW_NS_PROPERTY).

You did not ask why SMW_NS_PROPERTY works. Semantic MediaWiki is a sort of specialized extension here. That's why the extension is peculiarly enabled with enableSemantics( url ) function instead of loading through conventional wfLoadExtension( ) function or require_once statement used by majority of extensions.

enableSemantics() function is the mechanism through which the constants get defined in your LocalSettings.php. That's not currently available with wfLoadExtension().

If you load Semantic MediaWiki with wfLoadExtension( SemanticMediaWiki ) function (similar to how you currently load 'Scribunto' ), you'll get the same PHP warning as soon as you attempt to use SMW_NS_PROPERTY or any other of its namespace constants in LocalSettings.php

Anomie moved this task from Backlog to External on the Scribunto board.
Anomie subscribed.

When extensions were loaded via requiring a PHP file like Scribunto.php, that PHP file was able to define constants and so they could be used later in LocalSettings.php.

The switch to extension registration broke this: extension.json can declare namespace constants to be defined, but since extension.json isn't processed until after LocalSettings.php is done those constants don't get defined in time to be used within LocalSettings.php. See also T152294 and T141223.

while others are (like SMW_NS_PROPERTY).

It looks like SMW doesn't directly use MediaWiki's standard extension loading mechanism. Its instructions say to activate it by calling "enableSemantics()" instead, which does a bunch of extra stuff including defining that constant.

Krinkle renamed this task from NS_MODULE not defined to NS_MODULE not defined in LocalSettings.php.Mar 16 2020, 9:18 PM
Anomie removed a project: Platform Engineering.

Untagging Platform Engineering: We've reviewed this and decided that the workaround is sufficient for now. If someone else wants to try to make ExtensionRegistry be able to define the namespace constants at wfLoadExtension() time, feel free to re-tag us to review your patch.

Legoktm subscribed.

This is intentional as a side-effect of the extension.json migration. There is some loss of functionality, I admit that NS_MODULE can't be used in LocalSettings.php which was nice for readability. There is a plus side though, that extension namespace numbers are no longer hardcoded (e.g. doing define( 'NS_MODULE', 123 ); changes the internal NS number for Scribunto).

Maybe we could use string keys as aliases or something? That would require post-processing every namespace global...which isn't terrible. But that should probably be scoped to a different task that justifies why it's worth it (I currently dont think it is).