Page MenuHomePhabricator

Stop using the global service locator in RevisionRecord::userCanBitfield
Closed, ResolvedPublic

Description

I see several TODO comments about that, but couldn't find a task.

RevisionRecord
public static function userCanBitfield( $bitfield, $field, User $user, Title $title = null ) {
	// ...

	// XXX: How can we avoid global scope here?
	//      Perhaps the audience check should be done in a callback.
	$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();

which also relates to

RevisionRecord
protected function userCan( $field, User $user ) {
	// TODO: use callback for permission checks, so we don't need to know a Title object!
	return self::userCanBitfield( $this->getVisibility(), $field, $user, $this->mTitle );
}

Using the global locator makes it impossible to use pure unit tests to cover any code that needs to check the visibility of a RevisionRecord.

Event Timeline

This fits very well with the work we are starting right now on introducing Authority, see T271458: RevisionRecord should use Authority for permission checks.