From 06c49e69dc0331f28dce61df2fc8d8fd59fb8e3c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 18 Jul 2018 01:35:45 +0200 Subject: [PATCH] HTMLTitleTextField: Remove incorrect check for unsubmitted GET forms MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This check was added in I605f32048fe97eebd7e04b6ffd799759aeb7f31e, to fix an issue on Special:ChangeContentModel that was pointed out in code review of I766da59e6cbf7ed8f887d1a684ea9e284e9cf67e. This code actually does nothing in most cases, because `$value` for unsubmitted forms comes from the getDefault() method, and it is `null` and not `''`, unless specifically overridden. As it happens, Special:ChangeContentModel overrides the default to `''`, so this worked there. However, this was a brittle hack, and another change recently broke Special:ChangeContentModel in the exact way this was supposed to avoid: T196514. There is a pending patch there to fix it properly. The proper way to avoid validation errors on initial view of a GET form is to call setFormIdentifier( … ) on the form, which allows HTMLForm code to detect whether the form was really submitted. Change-Id: Id6a449bfa313d470ae4c39455e58b36252dc6b43 --- includes/htmlform/fields/HTMLTitleTextField.php | 11 ----------- includes/htmlform/fields/HTMLUserTextField.php | 2 -- 2 files changed, 13 deletions(-) diff --git a/includes/htmlform/fields/HTMLTitleTextField.php b/includes/htmlform/fields/HTMLTitleTextField.php index 0ad41d43bd..b76684dfe5 100644 --- a/includes/htmlform/fields/HTMLTitleTextField.php +++ b/includes/htmlform/fields/HTMLTitleTextField.php @@ -7,9 +7,6 @@ use MediaWiki\Widget\TitleInputWidget; * Automatically does validation that the title is valid, * as well as autocompletion if using the OOUI display format. * - * Note: Forms using GET requests will need to make sure the title value is not - * an empty string. - * * Optional parameters: * 'namespace' - Namespace the page must be in * 'relative' - If true and 'namespace' given, strip/add the namespace from/to the title as needed @@ -33,14 +30,6 @@ class HTMLTitleTextField extends HTMLTextField { } public function validate( $value, $alldata ) { - if ( $this->mParent->getMethod() === 'get' && $value === '' ) { - // If the form is a GET form and has no value, assume it hasn't been - // submitted yet, and skip validation - // TODO This doesn't look right, we should be able to tell the difference - // between "not submitted" (null) and "submitted but empty" (empty string). - return parent::validate( $value, $alldata ); - } - // Default value (from getDefault()) is null, which breaks Title::newFromTextThrow() below if ( $value === null ) { $value = ''; diff --git a/includes/htmlform/fields/HTMLUserTextField.php b/includes/htmlform/fields/HTMLUserTextField.php index d6723144f5..ccf0d12df7 100644 --- a/includes/htmlform/fields/HTMLUserTextField.php +++ b/includes/htmlform/fields/HTMLUserTextField.php @@ -6,8 +6,6 @@ use MediaWiki\Widget\UserInputWidget; * Implements a text input field for user names. * Automatically auto-completes if using the OOUI display format. * - * FIXME: Does not work for forms that support GET requests. - * * Optional parameters: * 'exists' - Whether to validate that the user already exists * 'ipallowed' - Whether an IP adress is interpreted as "valid" -- 2.20.1