HTMLTitleTextField: Remove incorrect check for unsubmitted GET forms
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 17 Jul 2018 23:35:45 +0000 (01:35 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 17 Jul 2018 23:35:45 +0000 (01:35 +0200)
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
includes/htmlform/fields/HTMLUserTextField.php

index 0ad41d4..b76684d 100644 (file)
@@ -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 = '';
index d672314..ccf0d12 100644 (file)
@@ -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"