From c014e6b06077d65030ed291b7bc4fba550c58668 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Wed, 16 Jan 2013 09:47:06 +0000 Subject: [PATCH] (bug 44010) Pass context to UserGetLanguageObject Only way to avoid messing with wrong request contexts. Had to add recursion guard too. Change-Id: Idc11b54752450321e01d92004e08fc95fb6170e6 --- docs/hooks.txt | 1 + includes/context/RequestContext.php | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 8905d7eec4..e182a5a73e 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2473,6 +2473,7 @@ $user: User object 'UserGetLanguageObject': Called when getting user's interface language object. $user: User object &$code: Langauge code that will be used to create the object +$context: RequestContext object 'UserGetReservedNames': Allows to modify $wgReservedUsernames at run time. &$reservedUsernames: $wgReservedUsernames diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index c1ce7515a4..96d27b001f 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -270,21 +270,29 @@ class RequestContext implements IContextSource { } /** - * Get the Language object + * Get the Language object. + * Initialization of user or request objects can depend on this. * * @return Language * @since 1.19 */ public function getLanguage() { + if ( isset( $this->recursion ) ) { + throw new MWException( 'Recursion detected' ); + } + if ( $this->lang === null ) { + $this->recursion = true; + global $wgLanguageCode, $wgContLang; - $code = $this->getRequest()->getVal( - 'uselang', - $this->getUser()->getOption( 'language' ) - ); + + $request = $this->getRequest(); + $user = $this->getUser(); + + $code = $request->getVal( 'uselang', $user->getOption( 'language' ) ); $code = self::sanitizeLangCode( $code ); - wfRunHooks( 'UserGetLanguageObject', array( $this->getUser(), &$code ) ); + wfRunHooks( 'UserGetLanguageObject', array( $user, &$code, $this ) ); if ( $code === $wgLanguageCode ) { $this->lang = $wgContLang; @@ -292,7 +300,10 @@ class RequestContext implements IContextSource { $obj = Language::factory( $code ); $this->lang = $obj; } + + unset( $this->recursion ); } + return $this->lang; } @@ -388,7 +399,7 @@ class RequestContext implements IContextSource { * - Skin will be based on the anonymous user, should be the wiki's default skin * * @param Title $title Title to use for the extraneous request - * @param mixed $request A WebRequest or data to use for a FauxRequest + * @param WebRequest|array $request A WebRequest or data to use for a FauxRequest * @return RequestContext */ public static function newExtraneousContext( Title $title, $request = array() ) { -- 2.20.1