context: Use getRawVal instead of getVal for 'uselang' and 'useskin'
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 29 Jul 2019 22:57:43 +0000 (23:57 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 29 Jul 2019 23:02:52 +0000 (00:02 +0100)
Bug: T189966
Change-Id: I9db7b3f36f5457e80aa9b673bcb56deb83e47a18

includes/actions/RawAction.php
includes/api/ApiMain.php
includes/context/RequestContext.php
includes/resourceloader/ResourceLoaderContext.php

index f6c4472..abb8ff5 100644 (file)
@@ -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 == '' ) {
index 8389b24..554ab6a 100644 (file)
@@ -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' ) {
index 4393abb..23a6f68 100644 (file)
@@ -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' );
index 1f06ede..d929125 100644 (file)
@@ -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' );