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
This commit is contained in:
parent
f47014c996
commit
f805387f62
1 changed files with 6 additions and 20 deletions
|
|
@ -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 );
|
||||
|
|
|
|||
Loading…
Reference in a new issue