Merge "HTMLTitleTextField: Remove incorrect check for unsubmitted GET forms"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 20 Sep 2019 22:45:24 +0000 (22:45 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 20 Sep 2019 22:45:24 +0000 (22:45 +0000)
1  2 
includes/htmlform/fields/HTMLTitleTextField.php
includes/htmlform/fields/HTMLUserTextField.php

@@@ -7,9 -7,6 +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 +30,6 @@@ class HTMLTitleTextField extends HTMLTe
        }
  
        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 = '';
                                $title = Title::newFromTextThrow( $value );
                        } else {
                                // Can't use Title::makeTitleSafe(), because it doesn't throw useful exceptions
 -                              global $wgContLang;
 -                              $namespaceName = $wgContLang->getNsText( $this->mParams['namespace'] );
 -                              $title = Title::newFromTextThrow( $namespaceName . ':' . $value );
 +                              $title = Title::newFromTextThrow( Title::makeName( $this->mParams['namespace'], $value ) );
                        }
                } catch ( MalformedTitleException $e ) {
 -                      $msg = $this->msg( $e->getErrorMessage() );
 -                      $params = $e->getErrorMessageParameters();
 -                      if ( $params ) {
 -                              $msg->params( $params );
 -                      }
 -                      return $msg;
 +                      return $this->msg( $e->getErrorMessage(), $e->getErrorMessageParameters() );
                }
  
                $text = $title->getPrefixedText();
                if ( $this->mParams['namespace'] !== false &&
                        !$title->inNamespace( $this->mParams['namespace'] )
                ) {
 -                      return $this->msg( 'htmlform-title-badnamespace', $this->mParams['namespace'], $text );
 +                      return $this->msg( 'htmlform-title-badnamespace', $text, $this->mParams['namespace'] );
                }
  
                if ( $this->mParams['creatable'] && !$title->canExist() ) {
@@@ -6,8 -6,6 +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"
@@@ -65,7 -63,7 +63,7 @@@ class HTMLUserTextField extends HTMLTex
        protected function isValidIPRange( $value ) {
                $cidrIPRanges = $this->mParams['iprangelimits'];
  
 -              if ( !IP::isValidBlock( $value ) ) {
 +              if ( !IP::isValidRange( $value ) ) {
                        return false;
                }