*/
private static $instance = null;
+ /**
+ * Boolean flag to guard against recursion in getLanguage
+ * @var bool
+ */
+ private $languageRecursion = false;
+
/**
* @param Config $config
*/
* @since 1.19
*/
public function getLanguage() {
- if ( isset( $this->recursion ) ) {
+ if ( $this->languageRecursion === true ) {
trigger_error( "Recursion detected in " . __METHOD__, E_USER_WARNING );
$e = new Exception;
wfDebugLog( 'recursion-guard', "Recursion detected:\n" . $e->getTraceAsString() );
$code = $this->getConfig()->get( 'LanguageCode' ) ?: 'en';
$this->lang = Language::factory( $code );
} elseif ( $this->lang === null ) {
- $this->recursion = true;
+ $this->languageRecursion = true;
try {
$request = $this->getRequest();
$user = $this->getUser();
- $code = $request->getVal( 'uselang', 'user' );
+ // Optimisation: Avoid slow getVal(), this isn't user-generated content.
+ $code = $request->getRawVal( 'uselang', 'user' );
if ( $code === 'user' ) {
$code = $user->getOption( 'language' );
}
$this->lang = $obj;
}
} finally {
- unset( $this->recursion );
+ $this->languageRecursion = false;
}
}
Hooks::run( 'RequestContextCreateSkin', [ $this, &$skin ] );
$factory = MediaWikiServices::getInstance()->getSkinFactory();
- // If the hook worked try to set a skin from it
if ( $skin instanceof Skin ) {
+ // The hook provided a skin object
$this->skin = $skin;
} elseif ( is_string( $skin ) ) {
+ // The hook provided a skin name
// Normalize the key, just in case the hook did something weird.
$normalized = Skin::normalizeKey( $skin );
$this->skin = $factory->makeSkin( $normalized );
- }
-
- // If this is still null (the hook didn't run or didn't work)
- // then go through the normal processing to load a skin
- if ( $this->skin === null ) {
+ } else {
+ // No hook override, go through normal processing
if ( !in_array( 'skin', $this->getConfig()->get( 'HiddenPrefs' ) ) ) {
- # get the user skin
$userSkin = $this->getUser()->getOption( 'skin' );
- $userSkin = $this->getRequest()->getVal( 'useskin', $userSkin );
+ // Optimisation: Avoid slow getVal(), this isn't user-generated content.
+ $userSkin = $this->getRequest()->getRawVal( 'useskin', $userSkin );
} else {
- # if we're not allowing users to override, then use the default
$userSkin = $this->getConfig()->get( 'DefaultSkin' );
}
- // Normalize the key in case the user is passing gibberish
- // or has old preferences (T71566).
+ // Normalize the key in case the user is passing gibberish query params
+ // or has old user preferences (T71566).
+ // Skin::normalizeKey will also validate it, so makeSkin() won't throw.
$normalized = Skin::normalizeKey( $userSkin );
-
- // Skin::normalizeKey will also validate it, so
- // this won't throw an exception
$this->skin = $factory->makeSkin( $normalized );
}
* @param string|string[]|MessageSpecifier $key Message key, or array of keys,
* or a MessageSpecifier.
* @param mixed $args,...
+ * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847
* @return Message
*/
public function msg( $key ) {