aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--includes/htmlform/CollapsibleFieldsetLayout.php2
-rw-r--r--includes/htmlform/HTMLForm.php48
-rw-r--r--includes/htmlform/HTMLFormField.php143
-rw-r--r--includes/htmlform/OOUIHTMLForm.php39
-rw-r--r--includes/htmlform/VFormHTMLForm.php5
5 files changed, 77 insertions, 160 deletions
diff --git a/includes/htmlform/CollapsibleFieldsetLayout.php b/includes/htmlform/CollapsibleFieldsetLayout.php
index f55711f18829..99c04a2a9f89 100644
--- a/includes/htmlform/CollapsibleFieldsetLayout.php
+++ b/includes/htmlform/CollapsibleFieldsetLayout.php
@@ -12,7 +12,7 @@ class CollapsibleFieldsetLayout extends OOUI\FieldsetLayout {
parent::__construct( $config );
$this->addClasses( [ 'mw-collapsibleFieldsetLayout', 'mw-collapsible' ] );
- if ( isset( $config[ 'collapsed' ] ) && $config[ 'collapsed' ] ) {
+ if ( $config['collapsed'] ?? false ) {
$this->addClasses( [ 'mw-collapsed' ] );
}
$this->header->addClasses( [ 'mw-collapsible-toggle' ] );
diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php
index 056de9343955..3f7afc565755 100644
--- a/includes/htmlform/HTMLForm.php
+++ b/includes/htmlform/HTMLForm.php
@@ -409,7 +409,6 @@ class HTMLForm extends ContextSource {
$loadedDescriptor = [];
foreach ( $descriptor as $fieldname => $info ) {
-
$section = $info['section'] ?? '';
if ( isset( $info['type'] ) && $info['type'] === 'file' ) {
@@ -421,10 +420,7 @@ class HTMLForm extends ContextSource {
$setSection =& $loadedDescriptor;
if ( $section ) {
foreach ( explode( '/', $section ) as $newName ) {
- if ( !isset( $setSection[$newName] ) ) {
- $setSection[$newName] = [];
- }
-
+ $setSection[$newName] ??= [];
$setSection =& $setSection[$newName];
}
}
@@ -901,9 +897,7 @@ class HTMLForm extends ContextSource {
if ( $section === null ) {
$this->mHeader .= $html;
} else {
- if ( !isset( $this->mSectionHeaders[$section] ) ) {
- $this->mSectionHeaders[$section] = '';
- }
+ $this->mSectionHeaders[$section] ??= '';
$this->mSectionHeaders[$section] .= $html;
}
@@ -938,11 +932,7 @@ class HTMLForm extends ContextSource {
* @return string HTML
*/
public function getHeaderHtml( $section = null ) {
- if ( $section === null ) {
- return $this->mHeader;
- } else {
- return $this->mSectionHeaders[$section] ?? '';
- }
+ return $section ? $this->mSectionHeaders[$section] ?? '' : $this->mHeader;
}
/**
@@ -998,9 +988,7 @@ class HTMLForm extends ContextSource {
if ( $section === null ) {
$this->mFooter .= $html;
} else {
- if ( !isset( $this->mSectionFooters[$section] ) ) {
- $this->mSectionFooters[$section] = '';
- }
+ $this->mSectionFooters[$section] ??= '';
$this->mSectionFooters[$section] .= $html;
}
@@ -1034,11 +1022,7 @@ class HTMLForm extends ContextSource {
* @return string
*/
public function getFooterHtml( $section = null ) {
- if ( $section === null ) {
- return $this->mFooter;
- } else {
- return $this->mSectionFooters[$section] ?? '';
- }
+ return $section ? $this->mSectionFooters[$section] ?? '' : $this->mFooter;
}
/**
@@ -1313,8 +1297,7 @@ class HTMLForm extends ContextSource {
$this->getOutput()->addModules( 'jquery.makeCollapsible' );
}
- $html = ''
- . $this->getErrorsOrWarnings( $submitResult, 'error' )
+ $html = $this->getErrorsOrWarnings( $submitResult, 'error' )
. $this->getErrorsOrWarnings( $submitResult, 'warning' )
. $this->getHeaderText()
. $this->getHiddenTitle()
@@ -1323,9 +1306,7 @@ class HTMLForm extends ContextSource {
. $this->getButtons()
. $this->getFooterText();
- $html = $this->wrapForm( $html );
-
- return '' . $this->mPre . $html . $this->mPost;
+ return $this->mPre . $this->wrapForm( $html ) . $this->mPost;
}
/**
@@ -1514,7 +1495,7 @@ class HTMLForm extends ContextSource {
}
if ( $useMediaWikiUIEverywhere ) {
- $attrs['class'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : [];
+ $attrs['class'] = (array)( $attrs['class'] ?? [] );
$attrs['class'][] = 'mw-ui-button';
}
@@ -1599,9 +1580,7 @@ class HTMLForm extends ContextSource {
);
}
- $errorstr = Html::rawElement( 'ul', [], $errorstr );
-
- return $errorstr;
+ return Html::rawElement( 'ul', [], $errorstr );
}
/**
@@ -2049,13 +2028,8 @@ class HTMLForm extends ContextSource {
return $html;
}
- $classes = [];
-
- if ( !$anyFieldHasLabel ) { // Avoid strange spacing when no labels exist
- $classes[] = 'mw-htmlform-nolabel';
- }
-
- $attribs = [ 'class' => $classes ];
+ // Avoid strange spacing when no labels exist
+ $attribs = $anyFieldHasLabel ? [] : [ 'class' => 'mw-htmlform-nolabel' ];
if ( $sectionName ) {
$attribs['id'] = Sanitizer::escapeIdForAttribute( $sectionName );
diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php
index bd984c72f0c9..201b1243dc1c 100644
--- a/includes/htmlform/HTMLFormField.php
+++ b/includes/htmlform/HTMLFormField.php
@@ -343,11 +343,8 @@ abstract class HTMLFormField {
* @return bool
*/
public function isHidden( $alldata ) {
- if ( !( $this->mCondState && isset( $this->mCondState['hide'] ) ) ) {
- return false;
- }
-
- return $this->checkStateRecurse( $alldata, $this->mCondState['hide'] );
+ return isset( $this->mCondState['hide'] ) &&
+ $this->checkStateRecurse( $alldata, $this->mCondState['hide'] );
}
/**
@@ -359,15 +356,10 @@ abstract class HTMLFormField {
* @return bool
*/
public function isDisabled( $alldata ) {
- if ( $this->mParams['disabled'] ?? false ) {
- return true;
- }
- $hidden = $this->isHidden( $alldata );
- if ( !$this->mCondState || !isset( $this->mCondState['disable'] ) ) {
- return $hidden;
- }
-
- return $hidden || $this->checkStateRecurse( $alldata, $this->mCondState['disable'] );
+ return ( $this->mParams['disabled'] ?? false ) ||
+ $this->isHidden( $alldata ) ||
+ isset( $this->mCondState['disable'] ) &&
+ $this->checkStateRecurse( $alldata, $this->mCondState['disable'] );
}
/**
@@ -527,10 +519,7 @@ abstract class HTMLFormField {
$this->mLabel = $params['label-raw'];
}
- $this->mName = "wp{$params['fieldname']}";
- if ( isset( $params['name'] ) ) {
- $this->mName = $params['name'];
- }
+ $this->mName = $params['name'] ?? 'wp' . $params['fieldname'];
if ( isset( $params['dir'] ) ) {
$this->mDir = $params['dir'];
@@ -675,20 +664,19 @@ abstract class HTMLFormField {
$inputHtml . "\n$errors"
);
}
- $divCssClasses = [ "mw-htmlform-field-$fieldType",
- $this->mClass, $this->mVFormClass, $errorClass ];
- $wrapperAttributes = [
- 'class' => $divCssClasses,
- ];
+ $wrapperAttributes = [ 'class' => [
+ "mw-htmlform-field-$fieldType",
+ $this->mClass,
+ $this->mVFormClass,
+ $errorClass,
+ ] ];
if ( $this->mCondState ) {
$wrapperAttributes['data-cond-state'] = FormatJson::encode( $this->parseCondStateForClient() );
$wrapperAttributes['class'] = array_merge( $wrapperAttributes['class'], $this->mCondStateClass );
}
- $html = Html::rawElement( 'div', $wrapperAttributes, $label . $field );
- $html .= $helptext;
-
- return $html;
+ return Html::rawElement( 'div', $wrapperAttributes, $label . $field ) .
+ $helptext;
}
/**
@@ -840,17 +828,10 @@ abstract class HTMLFormField {
*/
public function getRaw( $value ) {
[ $errors, ] = $this->getErrorsAndErrorClass( $value );
- $inputHtml = $this->getInputHTML( $value );
- $helptext = $this->getHelpTextHtmlRaw( $this->getHelpText() );
- $cellAttributes = [];
- $label = $this->getLabelHtml( $cellAttributes );
-
- $html = "\n$errors";
- $html .= $label;
- $html .= $inputHtml;
- $html .= $helptext;
-
- return $html;
+ return "\n" . $errors .
+ $this->getLabelHtml() .
+ $this->getInputHTML( $value ) .
+ $this->getHelpTextHtmlRaw( $this->getHelpText() );
}
/**
@@ -877,17 +858,11 @@ abstract class HTMLFormField {
*/
public function getInline( $value ) {
[ $errors, ] = $this->getErrorsAndErrorClass( $value );
- $inputHtml = $this->getInputHTML( $value );
- $helptext = $this->getHelpTextHtmlDiv( $this->getHelpText() );
- $cellAttributes = [];
- $label = $this->getLabelHtml( $cellAttributes );
-
- $html = "\n" . $errors .
- $label . "\u{00A0}" .
- $inputHtml .
- $helptext;
-
- return $html;
+ return "\n" . $errors .
+ $this->getLabelHtml() .
+ "\u{00A0}" .
+ $this->getInputHTML( $value ) .
+ $this->getHelpTextHtmlDiv( $this->getHelpText() );
}
/**
@@ -912,10 +887,9 @@ abstract class HTMLFormField {
if ( $this->mHelpClass !== false ) {
$tdClasses[] = $this->mHelpClass;
}
- $row = Html::rawElement( 'td', [ 'colspan' => 2, 'class' => $tdClasses ], $helptext );
- $row = Html::rawElement( 'tr', $rowAttributes, $row );
-
- return $row;
+ return Html::rawElement( 'tr', $rowAttributes,
+ Html::rawElement( 'td', [ 'colspan' => 2, 'class' => $tdClasses ], $helptext )
+ );
}
/**
@@ -941,9 +915,7 @@ abstract class HTMLFormField {
$wrapperAttributes['data-cond-state'] = FormatJson::encode( $this->parseCondStateForClient() );
$wrapperAttributes['class'] = array_merge( $wrapperAttributes['class'], $this->mCondStateClass );
}
- $div = Html::rawElement( 'div', $wrapperAttributes, $helptext );
-
- return $div;
+ return Html::rawElement( 'div', $wrapperAttributes, $helptext );
}
/**
@@ -1020,14 +992,10 @@ abstract class HTMLFormField {
$errors = $this->validate( $value, $this->mParent->mFieldData );
if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
- $errors = '';
- $errorClass = '';
- } else {
- $errors = self::formatErrors( $errors );
- $errorClass = 'mw-htmlform-invalid-input';
+ return [ '', '' ];
}
- return [ $errors, $errorClass ];
+ return [ self::formatErrors( $errors ), 'mw-htmlform-invalid-input' ];
}
/**
@@ -1041,7 +1009,7 @@ abstract class HTMLFormField {
$errors = $this->validate( $value, $this->mParent->mFieldData );
if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
- $errors = [];
+ return [];
}
if ( !is_array( $errors ) ) {
@@ -1073,39 +1041,29 @@ abstract class HTMLFormField {
public function getLabelHtml( $cellAttributes = [] ) {
# Don't output a for= attribute for labels with no associated input.
# Kind of hacky here, possibly we don't want these to be <label>s at all.
- $for = [];
-
- if ( $this->needsLabel() ) {
- $for['for'] = $this->mID;
- }
+ $for = $this->needsLabel() ? [ 'for' => $this->mID ] : [];
$labelValue = trim( $this->getLabel() );
- $hasLabel = false;
- if ( $labelValue !== "\u{00A0}" && $labelValue !== '&#160;' && $labelValue !== '' ) {
- $hasLabel = true;
- }
+ $hasLabel = $labelValue !== '' && $labelValue !== "\u{00A0}" && $labelValue !== '&#160;';
$displayFormat = $this->mParent->getDisplayFormat();
- $html = '';
$horizontalLabel = $this->mParams['horizontal-label'] ?? false;
if ( $displayFormat === 'table' ) {
- $html =
- Html::rawElement( 'td',
+ return Html::rawElement( 'td',
[ 'class' => 'mw-label' ] + $cellAttributes,
Html::rawElement( 'label', $for, $labelValue ) );
} elseif ( $hasLabel || $this->mShowEmptyLabels ) {
if ( $displayFormat === 'div' && !$horizontalLabel ) {
- $html =
- Html::rawElement( 'div',
+ return Html::rawElement( 'div',
[ 'class' => 'mw-label' ] + $cellAttributes,
Html::rawElement( 'label', $for, $labelValue ) );
} else {
- $html = Html::rawElement( 'label', $for, $labelValue );
+ return Html::rawElement( 'label', $for, $labelValue );
}
}
- return $html;
+ return '';
}
/**
@@ -1288,20 +1246,14 @@ abstract class HTMLFormField {
}
if ( is_array( $errors ) ) {
- $lines = [];
- foreach ( $errors as $error ) {
- if ( $error instanceof Message ) {
- $lines[] = Html::rawElement( 'li', [], $error->parse() );
- } else {
- $lines[] = Html::rawElement( 'li', [], $error );
- }
- }
-
- $errors = Html::rawElement( 'ul', [], implode( "\n", $lines ) );
- } else {
- if ( $errors instanceof Message ) {
- $errors = $errors->parse();
+ foreach ( $errors as &$error ) {
+ $error = Html::rawElement( 'li', [],
+ $error instanceof Message ? $error->parse() : $error
+ );
}
+ $errors = Html::rawElement( 'ul', [], implode( "\n", $errors ) );
+ } elseif ( $errors instanceof Message ) {
+ $errors = $errors->parse();
}
return Html::errorBox( $errors );
@@ -1342,10 +1294,7 @@ abstract class HTMLFormField {
* @since 1.29
*/
public function needsJSForHtml5FormValidation() {
- if ( $this->mCondState ) {
- // This is probably more restrictive than it needs to be, but better safe than sorry
- return true;
- }
- return false;
+ // This is probably more restrictive than it needs to be, but better safe than sorry
+ return (bool)$this->mCondState;
}
}
diff --git a/includes/htmlform/OOUIHTMLForm.php b/includes/htmlform/OOUIHTMLForm.php
index 260c8743c285..5377aaec0b14 100644
--- a/includes/htmlform/OOUIHTMLForm.php
+++ b/includes/htmlform/OOUIHTMLForm.php
@@ -61,7 +61,14 @@ class OOUIHTMLForm extends HTMLForm {
$buttons = '';
if ( $this->mShowSubmit ) {
- $attribs = [ 'infusable' => true ];
+ $attribs = [
+ 'infusable' => true,
+ 'classes' => [ 'mw-htmlform-submit' ],
+ 'type' => 'submit',
+ 'label' => $this->getSubmitText(),
+ 'value' => $this->getSubmitText(),
+ 'flags' => $this->mSubmitFlags,
+ ];
if ( isset( $this->mSubmitID ) ) {
$attribs['id'] = $this->mSubmitID;
@@ -78,12 +85,6 @@ class OOUIHTMLForm extends HTMLForm {
];
}
- $attribs['classes'] = [ 'mw-htmlform-submit' ];
- $attribs['type'] = 'submit';
- $attribs['label'] = $this->getSubmitText();
- $attribs['value'] = $this->getSubmitText();
- $attribs['flags'] = $this->mSubmitFlags;
-
$buttons .= new OOUI\ButtonInputWidget( $attribs );
}
@@ -95,10 +96,9 @@ class OOUIHTMLForm extends HTMLForm {
}
if ( $this->mShowCancel ) {
- $target = $this->getCancelTargetURL();
$buttons .= new OOUI\ButtonWidget( [
'label' => $this->msg( 'cancel' )->text(),
- 'href' => $target,
+ 'href' => $this->getCancelTargetURL(),
] );
}
@@ -189,7 +189,7 @@ class OOUIHTMLForm extends HTMLForm {
$html = implode( '', $fieldsHtml );
if ( $sectionName ) {
- $html = Html::rawElement(
+ return Html::rawElement(
'div',
[ 'id' => Sanitizer::escapeIdForAttribute( $sectionName ) ],
$html
@@ -258,13 +258,11 @@ class OOUIHTMLForm extends HTMLForm {
if ( !( $this->mHeader || $this->oouiErrors || $this->oouiWarnings ) ) {
return '';
}
- $classes = [ 'mw-htmlform-ooui-header' ];
- if ( $this->oouiErrors ) {
- $classes[] = 'mw-htmlform-ooui-header-errors';
- }
- if ( $this->oouiWarnings ) {
- $classes[] = 'mw-htmlform-ooui-header-warnings';
- }
+ $classes = [
+ 'mw-htmlform-ooui-header',
+ ...$this->oouiErrors ? [ 'mw-htmlform-ooui-header-errors' ] : [],
+ ...$this->oouiWarnings ? [ 'mw-htmlform-ooui-header-warnings' ] : [],
+ ];
// if there's no header, don't create an (empty) LabelWidget, simply use a placeholder
if ( $this->mHeader ) {
$element = new OOUI\LabelWidget( [ 'label' => new OOUI\HtmlSnippet( $this->mHeader ) ] );
@@ -283,9 +281,7 @@ class OOUIHTMLForm extends HTMLForm {
}
public function getBody() {
- $html = parent::getBody();
- $html = $this->formatFormHeader() . $html;
- return $html;
+ return $this->formatFormHeader() . parent::getBody();
}
public function wrapForm( $html ) {
@@ -304,9 +300,8 @@ class OOUIHTMLForm extends HTMLForm {
$content = new OOUI\HtmlSnippet( $html );
}
- $classes = [ 'mw-htmlform', 'mw-htmlform-ooui' ];
$form = new OOUI\FormLayout( $this->getFormAttributes() + [
- 'classes' => $classes,
+ 'classes' => [ 'mw-htmlform', 'mw-htmlform-ooui' ],
'content' => $content,
] );
diff --git a/includes/htmlform/VFormHTMLForm.php b/includes/htmlform/VFormHTMLForm.php
index ca8256b9b0c0..0bf117de7478 100644
--- a/includes/htmlform/VFormHTMLForm.php
+++ b/includes/htmlform/VFormHTMLForm.php
@@ -65,9 +65,8 @@ class VFormHTMLForm extends HTMLForm {
}
protected function getFormAttributes() {
- $attribs = parent::getFormAttributes();
- $attribs['class'] = [ 'mw-htmlform', 'mw-ui-vform', 'mw-ui-container' ];
- return $attribs;
+ return [ 'class' => [ 'mw-htmlform', 'mw-ui-vform', 'mw-ui-container' ] ] +
+ parent::getFormAttributes();
}
public function wrapForm( $html ) {