Page MenuHomePhabricator

enableSemantics() without $namespace causing fatal error
Closed, ResolvedPublic

Description

function enableSemantics( $namespace = null, $complete = false ) without $namespace will cause an fatal error since wfWarn() is called in line 57 (as of r97000).
In since enableSemantics most likely is called during LocalSettings.php, before parser initialization, global wiki functions are not available as well.

Perhaps it would be cleaner to setup SMW like any normal extension with help of $wgHooks['ParserFirstCallInit'][]


Version: unspecified
Severity: minor

Details

Reference
bz30897

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 21 2014, 11:56 PM
bzimport set Reference to bz30897.
bzimport added a subscriber: Unknown Object (MLST).

As explained in INSTALL, the method enableSemantics() should not be called with null but with a namespace string. It is okay if it creates an error if called with the wrong kind of parameters. We could make the error less fatal but the very purpose of the current design is to prevent the use of SMW without fixing some reasonable namespace. This is so since we do not know of any method for obtaining a stable namespace in PHP. We need a namespace and this is our way of enforcing it. We could change it to require some variable to be set and throw an error if this is missing, but this would just be a syntactic issue. I guess this is not what bug report was aiming at (if it was, then it can of course be reopened).

In any case I don't see a problem with setting a namespace. It can simply be one of the URL bases of your wiki. Just pick the one that you like most.

Sorry, I misread the report to mean that no error should be created at all. Of course you are right that this call to wfWarn is not good if it fails at this stage. Maybe we could throw a PHP error instead or indeed use MW hooks to do the check later on.

I changed it to use die() in r97089. This seems more appropriate then throwing an error, as errors are often not shown, and in some cases come with a backtrace, which is not relevant.

In the original code there was only a warning and I think the code kept running pretty well.
So I would suggest making $namespace not an optional parameter because when it is optional, the wiki shouldn't just die without any further message, this could make searching for the cause quite hard if you're not into SMW.

Or if $namespace really is intended to be optional but should throw at least a warning as intended in the original code design, then only registering another function for $wgHooks['ParserFirstCallInit'][] and doing all the stuff done in enableSemantics() there at the right time when global functions are loaded (the clean way in my opinion anyway)
Or you could make enableSemantics() obsolete at all and introduce another config var to define the namespace, of course all of this depends on whats happening in enableSemantics(), didn't look into that too deep.

I just saw that you pass a message along with die( '...' ) so everybody who's not blind as me could see what's wrong anyway.