Page MenuHomePhabricator

Warn if MediaWikiServices::getInstance() called prior to bootstrap completing
Closed, DuplicatePublic

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

@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 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-libs-Services 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.

Mainframe98 renamed this task from Warn if MediaWiki::getInstance() called prior to bootstrap completing to Warn if MediaWikiServices::getInstance() called prior to bootstrap completing .Apr 21 2021, 3:23 PM