From a2c1d8c0431ad111126f6cc22a51e7ecf2a45a1b Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Mon, 11 Mar 2019 09:40:36 +0100 Subject: [PATCH] Use the WebRequest::getCheck() shortcut where possible This is inspired by Ib117e05. As far as I can tell this is functionally identical. Even arrays should behave the same, as both the getVal() and getCheck() methods do have a special case that returns the `null` default in case the user tried to pass multiple values instead of a single scalar. Change-Id: Id4e4ec91f39d3c39461bd41673bdafc3bde11737 --- includes/EditPage.php | 4 ++-- includes/MediaWiki.php | 2 +- includes/api/ApiMain.php | 2 +- includes/htmlform/fields/HTMLCheckField.php | 2 +- includes/specials/SpecialSearch.php | 7 ++----- mw-config/index.php | 2 +- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 2048b87dd5..4d40d22024 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -869,7 +869,7 @@ class EditPage { } elseif ( $this->section == 'new' ) { // Nothing *to* preview for new sections return false; - } elseif ( ( $request->getVal( 'preload' ) !== null || $this->mTitle->exists() ) + } elseif ( ( $request->getCheck( 'preload' ) || $this->mTitle->exists() ) && $this->context->getUser()->getOption( 'previewonfirst' ) ) { // Standard preference behavior @@ -975,7 +975,7 @@ class EditPage { $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' ); - if ( $this->textbox1 === '' && $request->getVal( 'wpTextbox1' ) === null ) { + if ( $this->textbox1 === '' && !$request->getCheck( 'wpTextbox1' ) ) { // wpTextbox1 field is missing, possibly due to being "too big" // according to some filter rules such as Suhosin's setting for // suhosin.request.max_value_length (d'oh) diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 43512e1223..8cb9152daa 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -330,7 +330,7 @@ class MediaWiki { if ( $request->getVal( 'action', 'view' ) != 'view' || $request->wasPosted() - || ( $request->getVal( 'title' ) !== null + || ( $request->getCheck( 'title' ) && $title->getPrefixedDBkey() == $request->getVal( 'title' ) ) || count( $request->getValueNames( [ 'action', 'title' ] ) ) || !Hooks::run( 'TestCanonicalRedirect', [ $request, $title, $output ] ) diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index a233368156..31b82c1169 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -321,7 +321,7 @@ class ApiMain extends ApiBase { $request = $this->getRequest(); // JSONP mode - if ( $request->getVal( 'callback' ) !== null ) { + if ( $request->getCheck( 'callback' ) ) { $this->lacksSameOriginSecurity = true; return true; } diff --git a/includes/htmlform/fields/HTMLCheckField.php b/includes/htmlform/fields/HTMLCheckField.php index aad9f6e9d2..0a1024c4b1 100644 --- a/includes/htmlform/fields/HTMLCheckField.php +++ b/includes/htmlform/fields/HTMLCheckField.php @@ -119,7 +119,7 @@ class HTMLCheckField extends HTMLFormField { // Fetch the value in either one of the two following case: // - we have a valid submit attempt (form was just submitted) // - we have a value (an URL manually built by the user, or GET form with no wpFormIdentifier) - if ( $this->isSubmitAttempt( $request ) || $request->getVal( $this->mName ) !== null ) { + if ( $this->isSubmitAttempt( $request ) || $request->getCheck( $this->mName ) ) { return $invert ? !$request->getBool( $this->mName ) : $request->getBool( $this->mName ); diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index e6d06329ad..e2114a1155 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -129,7 +129,7 @@ class SpecialSearch extends SpecialPage { $this->load(); // TODO: This performs database actions on GET request, which is going to // be a problem for our multi-datacenter work. - if ( !is_null( $request->getVal( 'nsRemember' ) ) ) { + if ( $request->getCheck( 'nsRemember' ) ) { $this->saveNamespaces(); // Remove the token from the URL to prevent the user from inadvertently // exposing it (e.g. by pasting it into a public wiki page) or undoing @@ -141,10 +141,7 @@ class SpecialSearch extends SpecialPage { } $this->searchEngineType = $request->getVal( 'srbackend' ); - if ( - !$request->getVal( 'fulltext' ) && - $request->getVal( 'offset' ) === null - ) { + if ( !$request->getVal( 'fulltext' ) && !$request->getCheck( 'offset' ) ) { $url = $this->goResult( $term ); if ( $url !== null ) { // successful 'go' diff --git a/mw-config/index.php b/mw-config/index.php index df3f6e5500..b625c96002 100644 --- a/mw-config/index.php +++ b/mw-config/index.php @@ -63,7 +63,7 @@ function wfInstallerMain() { $session = array(); } - if ( $request->getVal( 'uselang' ) !== null ) { + if ( $request->getCheck( 'uselang' ) ) { $langCode = $request->getVal( 'uselang' ); } elseif ( isset( $session['settings']['_UserLang'] ) ) { $langCode = $session['settings']['_UserLang']; -- 2.20.1