Add setFormIdentifier to prevent validation errors

Used the setFormIdentifier to add a additional
parameter to the url, allowing prefilled requests
to be distinguished and thus preventing validation
errors. Also, updated the url parameters at
CiteThisPageHooks.php.

Bug: T238467
Change-Id: Ic1d0612bb4d4a40bc1ce0588c65782e33c09c3ca
This commit is contained in:
Sohom Datta 2019-11-16 23:14:17 +05:30
parent a145b85841
commit ca97c3fb06
2 changed files with 4 additions and 3 deletions

View file

@ -19,7 +19,8 @@ class CiteThisPageHooks {
$nav_urls['citethispage'] = [
'text' => $skintemplate->msg( 'citethispage-link' )->text(),
'href' => SpecialPage::getTitleFor( 'CiteThisPage' )
->getLocalURL( [ 'page' => $title->getPrefixedDBkey(), 'id' => $revid ] ),
->getLocalURL( [ 'page' => $title->getPrefixedDBkey(), 'id' => $revid,
'wpFormIdentifier' => 'titleform' ] ),
'id' => 't-cite',
# Used message keys: 'tooltip-citethispage', 'accesskey-citethispage'
'single-id' => 'citethispage',

View file

@ -33,6 +33,7 @@ class SpecialCiteThisPage extends FormSpecialPage {
protected function alterForm( HTMLForm $form ) {
$form->setMethod( 'get' );
$form->setFormIdentifier( 'titleform' );
}
protected function getFormFields() {
@ -53,8 +54,7 @@ class SpecialCiteThisPage extends FormSpecialPage {
public function onSubmit( array $data ) {
// GET forms are "submitted" on every view, so check
// that some data was put in for page, as empty string
// will pass validation
// that some data was put in for page
if ( strlen( $data['page'] ) ) {
$this->title = Title::newFromText( $data['page'] );
}