HTMLForm: Add title field if the action is overridden to script path

Some use cases like HistoryAction prefer the `index.php` form to keep
consistency, so they use setAction( wfScript() ) or something similar.
But the title is missing, so they hack it with manual addHiddenField()
or add a 'title' field in the descriptor. This is not good and prevents
us to warn the use of internal fields (title, wfEditToken).

Bug: T285464
Change-Id: Iaec81a2fb49162f2fc764f143f88e887572a3a0b
This commit is contained in:
Func 2022-03-20 20:06:28 +08:00
parent 96099ac63f
commit ef2e948d31
3 changed files with 8 additions and 13 deletions

View file

@ -241,11 +241,6 @@ class HistoryAction extends FormlessAction {
// Add the general form.
$fields = [
[
'name' => 'title',
'type' => 'hidden',
'default' => $this->getTitle()->getPrefixedDBkey(),
],
[
'name' => 'action',
'type' => 'hidden',

View file

@ -1357,11 +1357,10 @@ class HTMLForm extends ContextSource {
$this->getUser()->getEditToken( $this->mTokenSalt ),
[ 'id' => 'wpEditToken' ]
) . "\n";
$html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
}
$articlePath = $this->getConfig()->get( 'ArticlePath' );
if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
if ( $this->getMethod() === 'post' ||
$this->getAction() === $this->getConfig()->get( 'Script' )
) {
$html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
}
@ -2128,10 +2127,10 @@ class HTMLForm extends ContextSource {
// Check whether we are in GET mode and the ArticlePath contains a "?"
// meaning that getLocalURL() would return something like "index.php?title=...".
// As browser remove the query string before submitting GET forms,
// it means that the title would be lost. In such case use wfScript() instead
// it means that the title would be lost. In such case use script path instead
// and put title in an hidden field (see getHiddenFields()).
if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
return wfScript();
return $this->getConfig()->get( 'Script' );
}
return $this->getTitle()->getLocalURL();

View file

@ -642,7 +642,6 @@ class SpecialContributions extends IncludableSpecialPage {
* @return string HTML fragment
*/
protected function getForm( array $pagerOptions ) {
$this->opts['title'] = $this->getPageTitle()->getPrefixedText();
// Modules required only for the form
$this->getOutput()->addModules( [
'mediawiki.special.contributions',
@ -665,7 +664,8 @@ class SpecialContributions extends IncludableSpecialPage {
'newOnly',
'hideMinor',
'associated',
'tagfilter'
'tagfilter',
'title',
];
foreach ( $this->opts as $name => $value ) {
@ -808,6 +808,7 @@ class SpecialContributions extends IncludableSpecialPage {
$htmlForm = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
$htmlForm
->setMethod( 'get' )
->setTitle( $this->getPageTitle() )
// When offset is defined, the user is paging through results
// so we hide the form by default to allow users to focus on browsing
// rather than defining search parameters