Page MenuHomePhabricator

Warn if MediaWiki::getInstance() called prior to bootstrap completing
Open, Needs TriagePublic

Description

MediaWikiServices should not be instantiated prior to the bootstrap process completing.
This is because after bootstrapping, the MediaWikiServices global instance is reset in Setup.php (MediaWikiServices::resetGlobalInstance()).

We should emit a warning to any class that calls MediaWikiServices::getInstance() prior to MW_SERVICE_BOOTSTRAP_COMPLETE being defined.

Event Timeline

nnikkhoui created this task.Apr 6 2020, 5:54 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 6 2020, 5:54 PM

@daniel pointed out that MW_SERVICE_BOOTSTRAP_COMPLETE comes after Session setup, which probably needs various services to work. We could still emit a warning if it's called before ExtensionRegistry->finish() though.

daniel added a comment.Apr 7 2020, 8:21 PM

@daniel pointed out that MW_SERVICE_BOOTSTRAP_COMPLETE comes after Session setup, which probably needs various services to work. We could still emit a warning if it's called before ExtensionRegistry->finish() though.

Looks like I was confused about that, MW_SERVICE_BOOTSTRAP_COMPLETE comes pretty early in Setup.php. So it would probably be ok to implement warnings for this, and just see what turns up. We could enable it just on beta at first.

@nnikkhoui: Assuming this task is about the MediaWiki-ServiceContainer code project, hence adding that project tag so other people who don't know or don't care about team tags can also find this task when searching via projects.