From f805387f62e6f895c588aae73b4ca11bfbeadce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 14 Jun 2018 00:56:32 +0200 Subject: [PATCH] SpecialChangeContentModel: Always use POST method for both forms HTMLForm can't detect whether a GET form was submitted or just viewed, resulting in error messages about missing page title being shown on the initial page view. We were also doing some weird checks to distinguish the two forms by the GET/POST method. Instead, use setFormIdentifier() to do it, which avoids similar error messages about content model being shown before the user had a chance to fill in that field. Bug: T196514 Change-Id: Id007f2db5238ed2a8123c6cc309dce361b9220cb --- .../specials/SpecialChangeContentModel.php | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/includes/specials/SpecialChangeContentModel.php b/includes/specials/SpecialChangeContentModel.php index 5fecd42feb9..c81dbfd425b 100644 --- a/includes/specials/SpecialChangeContentModel.php +++ b/includes/specials/SpecialChangeContentModel.php @@ -68,12 +68,14 @@ class SpecialChangeContentModel extends FormSpecialPage { } protected function alterForm( HTMLForm $form ) { - if ( !$this->title ) { - $form->setMethod( 'GET' ); - } - $this->addHelpLink( 'Help:ChangeContentModel' ); + if ( $this->title ) { + $form->setFormIdentifier( 'modelform' ); + } else { + $form->setFormIdentifier( 'titleform' ); + } + // T120576 $form->setSubmitTextMsg( 'changecontentmodel-submit' ); @@ -83,11 +85,6 @@ class SpecialChangeContentModel extends FormSpecialPage { } public function validateTitle( $title ) { - if ( !$title ) { - // No form input yet - return true; - } - // Already validated by HTMLForm, but if not, throw // an exception instead of a fatal $titleObj = Title::newFromTextThrow( $title ); @@ -193,17 +190,6 @@ class SpecialChangeContentModel extends FormSpecialPage { } public function onSubmit( array $data ) { - if ( $data['pagetitle'] === '' ) { - // Initial form view of special page, pass - return false; - } - - // At this point, it has to be a POST request. This is enforced by HTMLForm, - // but lets be safe verify that. - if ( !$this->getRequest()->wasPosted() ) { - throw new RuntimeException( "Form submission was not POSTed" ); - } - $user = $this->getUser(); $this->title = Title::newFromText( $data['pagetitle'] ); $page = WikiPage::factory( $this->title );