Merge "Do not require titles on Special:ComparePages"
[lhc/web/wiklou.git] / includes / htmlform / fields / HTMLTitleTextField.php
index a15b90e..602ddee 100644 (file)
@@ -25,6 +25,8 @@ class HTMLTitleTextField extends HTMLTextField {
                        'relative' => false,
                        'creatable' => false,
                        'exists' => false,
+                       // This overrides the default from HTMLFormField
+                       'required' => true,
                ];
 
                parent::__construct( $params );
@@ -34,8 +36,16 @@ class HTMLTitleTextField extends HTMLTextField {
                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 );
                }
+
+               if ( !$this->mParams['required'] && $value === '' ) {
+                       // If this field is not required and the value is empty, that's okay, skip validation
+                       return parent::validate( $value, $alldata );
+               }
+
                try {
                        if ( !$this->mParams['relative'] ) {
                                $title = Title::newFromTextThrow( $value );
@@ -51,22 +61,22 @@ class HTMLTitleTextField extends HTMLTextField {
                        if ( $params ) {
                                $msg->params( $params );
                        }
-                       return $msg->parse();
+                       return $msg;
                }
 
                $text = $title->getPrefixedText();
                if ( $this->mParams['namespace'] !== false &&
                        !$title->inNamespace( $this->mParams['namespace'] )
                ) {
-                       return $this->msg( 'htmlform-title-badnamespace', $this->mParams['namespace'], $text )->parse();
+                       return $this->msg( 'htmlform-title-badnamespace', $this->mParams['namespace'], $text );
                }
 
                if ( $this->mParams['creatable'] && !$title->canExist() ) {
-                       return $this->msg( 'htmlform-title-not-creatable', $text )->escaped();
+                       return $this->msg( 'htmlform-title-not-creatable', $text );
                }
 
                if ( $this->mParams['exists'] && !$title->exists() ) {
-                       return $this->msg( 'htmlform-title-not-exists', $text )->parse();
+                       return $this->msg( 'htmlform-title-not-exists', $text );
                }
 
                return parent::validate( $value, $alldata );