From: Timo Tijhof Date: Mon, 29 Jul 2019 22:57:43 +0000 (+0100) Subject: context: Use getRawVal instead of getVal for 'uselang' and 'useskin' X-Git-Tag: 1.34.0-rc.0~822^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=cad882954a084a87bae1f5026d5f30cef4d73ac5;p=lhc%2Fweb%2Fwiklou.git context: Use getRawVal instead of getVal for 'uselang' and 'useskin' Bug: T189966 Change-Id: I9db7b3f36f5457e80aa9b673bcb56deb83e47a18 --- diff --git a/includes/actions/RawAction.php b/includes/actions/RawAction.php index f6c4472f2a..abb8ff5b1f 100644 --- a/includes/actions/RawAction.php +++ b/includes/actions/RawAction.php @@ -269,9 +269,7 @@ class RawAction extends FormlessAction { * @return string */ public function getContentType() { - // Use getRawVal instead of getVal because we only - // need to match against known strings, there is no - // storing of localised content or other user input. + // Optimisation: Avoid slow getVal(), this isn't user-generated content. $ctype = $this->getRequest()->getRawVal( 'ctype' ); if ( $ctype == '' ) { diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 8389b24c9c..554ab6a285 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -238,7 +238,8 @@ class ApiMain extends ApiBase { // Setup uselang. This doesn't use $this->getParameter() // because we're not ready to handle errors yet. - $uselang = $request->getVal( 'uselang', self::API_DEFAULT_USELANG ); + // Optimisation: Avoid slow getVal(), this isn't user-generated content. + $uselang = $request->getRawVal( 'uselang', self::API_DEFAULT_USELANG ); if ( $uselang === 'user' ) { // Assume the parent context is going to return the user language // for uselang=user (see T85635). @@ -257,8 +258,9 @@ class ApiMain extends ApiBase { // Set up the error formatter. This doesn't use $this->getParameter() // because we're not ready to handle errors yet. - $errorFormat = $request->getVal( 'errorformat', 'bc' ); - $errorLangCode = $request->getVal( 'errorlang', 'uselang' ); + // Optimisation: Avoid slow getVal(), this isn't user-generated content. + $errorFormat = $request->getRawVal( 'errorformat', 'bc' ); + $errorLangCode = $request->getRawVal( 'errorlang', 'uselang' ); $errorsUseDB = $request->getCheck( 'errorsuselocal' ); if ( in_array( $errorFormat, [ 'plaintext', 'wikitext', 'html', 'raw', 'none' ], true ) ) { if ( $errorLangCode === 'uselang' ) { diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 4393abb23d..23a6f68d1a 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -332,7 +332,8 @@ class RequestContext implements IContextSource, MutableContext { $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' ); } @@ -386,7 +387,8 @@ class RequestContext implements IContextSource, MutableContext { 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' ); diff --git a/includes/resourceloader/ResourceLoaderContext.php b/includes/resourceloader/ResourceLoaderContext.php index 1f06ede1b7..d929125072 100644 --- a/includes/resourceloader/ResourceLoaderContext.php +++ b/includes/resourceloader/ResourceLoaderContext.php @@ -66,8 +66,8 @@ class ResourceLoaderContext implements MessageLocalizer { $this->request = $request; $this->logger = $resourceLoader->getLogger(); - // Future developers: Use WebRequest::getRawVal() instead of getVal(). - // The getVal() method performs slow Language+UTF logic. (f303bb9360) + // Optimisation: Use WebRequest::getRawVal() instead of getVal(). We don't + // need the slow Language+UTF logic meant for user input here. (f303bb9360) // List of modules $modules = $request->getRawVal( 'modules' );