From ba7acbe791317d313c0232210b01bc782251e74f Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Fri, 24 Jul 2015 18:18:49 -0700 Subject: [PATCH] Allow HTMLTitleTextField to work on GET forms Just skip validation if it is a GET form and the current input is an empty string. Callers will need to check that it is not the empty string though. Also make sure HTMLForm::mMethod is always lowercase. Change-Id: I605f32048fe97eebd7e04b6ffd799759aeb7f31e --- includes/htmlform/HTMLForm.php | 5 ++++- includes/htmlform/HTMLTitleTextField.php | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index 48cc828136..a56b398df3 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -1302,11 +1302,14 @@ class HTMLForm extends ContextSource { * @return HTMLForm $this for chaining calls (since 1.20) */ public function setMethod( $method = 'post' ) { - $this->mMethod = $method; + $this->mMethod = strtolower( $method ); return $this; } + /** + * @return string Always lowercase + */ public function getMethod() { return $this->mMethod; } diff --git a/includes/htmlform/HTMLTitleTextField.php b/includes/htmlform/HTMLTitleTextField.php index e1bc1a0cb3..2124bb1cf9 100644 --- a/includes/htmlform/HTMLTitleTextField.php +++ b/includes/htmlform/HTMLTitleTextField.php @@ -7,7 +7,8 @@ use MediaWiki\Widget\TitleInputWidget; * Automatically does validation that the title is valid, * as well as autocompletion if using the OOUI display format. * - * FIXME: Does not work for forms that support GET requests. + * 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 @@ -28,6 +29,11 @@ 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 + return parent::validate( $value, $alldata ); + } try { $title = Title::newFromTextThrow( $value ); } catch ( MalformedTitleException $e ) { -- 2.20.1