request = $request; $this->user = $user; $this->config = $config; } /** * Whether or not the legacy skin is being used. * * @return bool * @throws \ConfigException */ public function isLegacy(): bool { return $this->getVersion() === Constants::SKIN_VERSION_LEGACY; } /** * The skin version as a string. E.g., `Constants::SKIN_VERSION_LATEST`, * `Constants::SKIN_VERSION_LATEST`, or maybe 'beta'. Note: it's likely someone will put arbitrary * strings in the query parameter which means this function returns those strings as is. * * @return string * @throws \ConfigException */ public function getVersion(): string { // Obtain the skin version from the 1) `useskinversion` URL query parameter override, 2) the // user preference, 3) the configured default for logged in users, 4) or the site default. // // The latter two configurations cannot be set by `Hooks::onUserGetDefaultOptions()` as user // sessions are unavailable at that time so it's not possible to determine whether the // preference is for a logged in user or an anonymous user. Since new users are known to have // had their user preferences initialized in `Hooks::onLocalUserCreated()`, that means all // subsequent requests to `User->getOption()` that do not have a preference set are either // existing accounts or anonymous users. Login state makes the distinction. return (string)$this->request->getVal( Constants::QUERY_PARAM_SKIN_VERSION, $this->user->getOption( Constants::PREF_KEY_SKIN_VERSION, $this->config->get( $this->user->isLoggedIn() ? Constants::CONFIG_KEY_DEFAULT_SKIN_VERSION_FOR_EXISTING_ACCOUNTS : Constants::CONFIG_KEY_DEFAULT_SKIN_VERSION ) ) ); } }