From: Bartosz DziewoƄski Date: Sat, 30 Jul 2016 21:59:24 +0000 (+0200) Subject: Move HTMLFormField subclasses to a separate directory X-Git-Tag: 1.31.0-rc.0~6192^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=15692fa6d4f2d7d15e3c0df8937612d9bdda93bb;hp=3823c900f15d75a218286d227506ae8877e944ca;p=lhc%2Fweb%2Fwiklou.git Move HTMLFormField subclasses to a separate directory It's getting more difficult to navigate the files in includes/htmlform/ with every new field and every new helper class that is being added. Change-Id: I92ce2356baf6151f17b2440970d5abdf86503820 --- diff --git a/autoload.php b/autoload.php index 5808040e41..50d544c1f9 100644 --- a/autoload.php +++ b/autoload.php @@ -514,41 +514,41 @@ $wgAutoloadLocalClasses = [ 'GitInfo' => __DIR__ . '/includes/GitInfo.php', 'GlobalDependency' => __DIR__ . '/includes/cache/CacheDependency.php', 'GlobalVarConfig' => __DIR__ . '/includes/config/GlobalVarConfig.php', - 'HTMLApiField' => __DIR__ . '/includes/htmlform/HTMLApiField.php', - 'HTMLAutoCompleteSelectField' => __DIR__ . '/includes/htmlform/HTMLAutoCompleteSelectField.php', - 'HTMLButtonField' => __DIR__ . '/includes/htmlform/HTMLButtonField.php', + 'HTMLApiField' => __DIR__ . '/includes/htmlform/fields/HTMLApiField.php', + 'HTMLAutoCompleteSelectField' => __DIR__ . '/includes/htmlform/fields/HTMLAutoCompleteSelectField.php', + 'HTMLButtonField' => __DIR__ . '/includes/htmlform/fields/HTMLButtonField.php', 'HTMLCacheUpdate' => __DIR__ . '/includes/deferred/HTMLCacheUpdate.php', 'HTMLCacheUpdateJob' => __DIR__ . '/includes/jobqueue/jobs/HTMLCacheUpdateJob.php', - 'HTMLCheckField' => __DIR__ . '/includes/htmlform/HTMLCheckField.php', - 'HTMLCheckMatrix' => __DIR__ . '/includes/htmlform/HTMLCheckMatrix.php', - 'HTMLComboboxField' => __DIR__ . '/includes/htmlform/HTMLComboboxField.php', - 'HTMLEditTools' => __DIR__ . '/includes/htmlform/HTMLEditTools.php', + 'HTMLCheckField' => __DIR__ . '/includes/htmlform/fields/HTMLCheckField.php', + 'HTMLCheckMatrix' => __DIR__ . '/includes/htmlform/fields/HTMLCheckMatrix.php', + 'HTMLComboboxField' => __DIR__ . '/includes/htmlform/fields/HTMLComboboxField.php', + 'HTMLEditTools' => __DIR__ . '/includes/htmlform/fields/HTMLEditTools.php', 'HTMLFileCache' => __DIR__ . '/includes/cache/HTMLFileCache.php', - 'HTMLFloatField' => __DIR__ . '/includes/htmlform/HTMLFloatField.php', + 'HTMLFloatField' => __DIR__ . '/includes/htmlform/fields/HTMLFloatField.php', 'HTMLForm' => __DIR__ . '/includes/htmlform/HTMLForm.php', 'HTMLFormField' => __DIR__ . '/includes/htmlform/HTMLFormField.php', - 'HTMLFormFieldCloner' => __DIR__ . '/includes/htmlform/HTMLFormFieldCloner.php', + 'HTMLFormFieldCloner' => __DIR__ . '/includes/htmlform/fields/HTMLFormFieldCloner.php', 'HTMLFormFieldRequiredOptionsException' => __DIR__ . '/includes/htmlform/HTMLFormFieldRequiredOptionsException.php', - 'HTMLFormFieldWithButton' => __DIR__ . '/includes/htmlform/HTMLFormFieldWithButton.php', - 'HTMLHiddenField' => __DIR__ . '/includes/htmlform/HTMLHiddenField.php', - 'HTMLInfoField' => __DIR__ . '/includes/htmlform/HTMLInfoField.php', - 'HTMLIntField' => __DIR__ . '/includes/htmlform/HTMLIntField.php', - 'HTMLMultiSelectField' => __DIR__ . '/includes/htmlform/HTMLMultiSelectField.php', + 'HTMLFormFieldWithButton' => __DIR__ . '/includes/htmlform/fields/HTMLFormFieldWithButton.php', + 'HTMLHiddenField' => __DIR__ . '/includes/htmlform/fields/HTMLHiddenField.php', + 'HTMLInfoField' => __DIR__ . '/includes/htmlform/fields/HTMLInfoField.php', + 'HTMLIntField' => __DIR__ . '/includes/htmlform/fields/HTMLIntField.php', + 'HTMLMultiSelectField' => __DIR__ . '/includes/htmlform/fields/HTMLMultiSelectField.php', 'HTMLNestedFilterable' => __DIR__ . '/includes/htmlform/HTMLNestedFilterable.php', - 'HTMLRadioField' => __DIR__ . '/includes/htmlform/HTMLRadioField.php', - 'HTMLSelectAndOtherField' => __DIR__ . '/includes/htmlform/HTMLSelectAndOtherField.php', - 'HTMLSelectField' => __DIR__ . '/includes/htmlform/HTMLSelectField.php', - 'HTMLSelectLimitField' => __DIR__ . '/includes/htmlform/HTMLSelectLimitField.php', - 'HTMLSelectNamespace' => __DIR__ . '/includes/htmlform/HTMLSelectNamespace.php', - 'HTMLSelectNamespaceWithButton' => __DIR__ . '/includes/htmlform/HTMLSelectNamespaceWithButton.php', - 'HTMLSelectOrOtherField' => __DIR__ . '/includes/htmlform/HTMLSelectOrOtherField.php', - 'HTMLSubmitField' => __DIR__ . '/includes/htmlform/HTMLSubmitField.php', - 'HTMLTagFilter' => __DIR__ . '/includes/htmlform/HTMLTagFilter.php', - 'HTMLTextAreaField' => __DIR__ . '/includes/htmlform/HTMLTextAreaField.php', - 'HTMLTextField' => __DIR__ . '/includes/htmlform/HTMLTextField.php', - 'HTMLTextFieldWithButton' => __DIR__ . '/includes/htmlform/HTMLTextFieldWithButton.php', - 'HTMLTitleTextField' => __DIR__ . '/includes/htmlform/HTMLTitleTextField.php', - 'HTMLUserTextField' => __DIR__ . '/includes/htmlform/HTMLUserTextField.php', + 'HTMLRadioField' => __DIR__ . '/includes/htmlform/fields/HTMLRadioField.php', + 'HTMLSelectAndOtherField' => __DIR__ . '/includes/htmlform/fields/HTMLSelectAndOtherField.php', + 'HTMLSelectField' => __DIR__ . '/includes/htmlform/fields/HTMLSelectField.php', + 'HTMLSelectLimitField' => __DIR__ . '/includes/htmlform/fields/HTMLSelectLimitField.php', + 'HTMLSelectNamespace' => __DIR__ . '/includes/htmlform/fields/HTMLSelectNamespace.php', + 'HTMLSelectNamespaceWithButton' => __DIR__ . '/includes/htmlform/fields/HTMLSelectNamespaceWithButton.php', + 'HTMLSelectOrOtherField' => __DIR__ . '/includes/htmlform/fields/HTMLSelectOrOtherField.php', + 'HTMLSubmitField' => __DIR__ . '/includes/htmlform/fields/HTMLSubmitField.php', + 'HTMLTagFilter' => __DIR__ . '/includes/htmlform/fields/HTMLTagFilter.php', + 'HTMLTextAreaField' => __DIR__ . '/includes/htmlform/fields/HTMLTextAreaField.php', + 'HTMLTextField' => __DIR__ . '/includes/htmlform/fields/HTMLTextField.php', + 'HTMLTextFieldWithButton' => __DIR__ . '/includes/htmlform/fields/HTMLTextFieldWithButton.php', + 'HTMLTitleTextField' => __DIR__ . '/includes/htmlform/fields/HTMLTitleTextField.php', + 'HTMLUserTextField' => __DIR__ . '/includes/htmlform/fields/HTMLUserTextField.php', 'HWLDFWordAccumulator' => __DIR__ . '/includes/diff/DairikiDiff.php', 'HashBagOStuff' => __DIR__ . '/includes/libs/objectcache/HashBagOStuff.php', 'HashConfig' => __DIR__ . '/includes/config/HashConfig.php', diff --git a/includes/htmlform/HTMLApiField.php b/includes/htmlform/HTMLApiField.php deleted file mode 100644 index 24a253eddd..0000000000 --- a/includes/htmlform/HTMLApiField.php +++ /dev/null @@ -1,23 +0,0 @@ -getTableRow( $value ); - } - - public function getRaw( $value ) { - return $this->getTableRow( $value ); - } - - public function getInputHTML( $value ) { - return ''; - } - - public function hasVisibleOutput() { - return false; - } -} diff --git a/includes/htmlform/HTMLAutoCompleteSelectField.php b/includes/htmlform/HTMLAutoCompleteSelectField.php deleted file mode 100644 index 76a88d5121..0000000000 --- a/includes/htmlform/HTMLAutoCompleteSelectField.php +++ /dev/null @@ -1,177 +0,0 @@ - false, - ]; - - parent::__construct( $params ); - - if ( array_key_exists( 'autocomplete-messages', $this->mParams ) ) { - foreach ( $this->mParams['autocomplete-messages'] as $key => $value ) { - $key = $this->msg( $key )->plain(); - $this->autocomplete[$key] = strval( $value ); - } - } elseif ( array_key_exists( 'autocomplete', $this->mParams ) ) { - foreach ( $this->mParams['autocomplete'] as $key => $value ) { - $this->autocomplete[$key] = strval( $value ); - } - } - if ( !is_array( $this->autocomplete ) || !$this->autocomplete ) { - throw new MWException( 'HTMLAutoCompleteSelectField called without any autocompletions' ); - } - - $this->getOptions(); - if ( $this->mOptions && !in_array( 'other', $this->mOptions, true ) ) { - if ( isset( $params['other-message'] ) ) { - $msg = $this->getMessage( $params['other-message'] )->text(); - } elseif ( isset( $params['other'] ) ) { - $msg = $params['other']; - } else { - $msg = wfMessage( 'htmlform-selectorother-other' )->text(); - } - $this->mOptions[$msg] = 'other'; - } - } - - function loadDataFromRequest( $request ) { - if ( $request->getCheck( $this->mName ) ) { - $val = $request->getText( $this->mName . '-select', 'other' ); - - if ( $val === 'other' ) { - $val = $request->getText( $this->mName ); - if ( isset( $this->autocomplete[$val] ) ) { - $val = $this->autocomplete[$val]; - } - } - - return $val; - } else { - return $this->getDefault(); - } - } - - function validate( $value, $alldata ) { - $p = parent::validate( $value, $alldata ); - - if ( $p !== true ) { - return $p; - } - - $validOptions = HTMLFormField::flattenOptions( $this->getOptions() ); - - if ( in_array( strval( $value ), $validOptions, true ) ) { - return true; - } elseif ( in_array( strval( $value ), $this->autocomplete, true ) ) { - return true; - } elseif ( $this->mParams['require-match'] ) { - return $this->msg( 'htmlform-select-badoption' )->parse(); - } - - return true; - } - - // FIXME Ewww, this shouldn't be adding any attributes not requested in $list :( - public function getAttributes( array $list ) { - $attribs = [ - 'type' => 'text', - 'data-autocomplete' => FormatJson::encode( array_keys( $this->autocomplete ) ), - ] + parent::getAttributes( $list ); - - if ( $this->getOptions() ) { - $attribs['data-hide-if'] = FormatJson::encode( - [ '!==', $this->mName . '-select', 'other' ] - ); - } - - return $attribs; - } - - function getInputHTML( $value ) { - $oldClass = $this->mClass; - $this->mClass = (array)$this->mClass; - - $valInSelect = false; - $ret = ''; - - if ( $this->getOptions() ) { - if ( $value !== false ) { - $value = strval( $value ); - $valInSelect = in_array( - $value, HTMLFormField::flattenOptions( $this->getOptions() ), true - ); - } - - $selected = $valInSelect ? $value : 'other'; - $select = new XmlSelect( $this->mName . '-select', $this->mID . '-select', $selected ); - $select->addOptions( $this->getOptions() ); - $select->setAttribute( 'class', 'mw-htmlform-select-or-other' ); - - if ( !empty( $this->mParams['disabled'] ) ) { - $select->setAttribute( 'disabled', 'disabled' ); - } - - if ( isset( $this->mParams['tabindex'] ) ) { - $select->setAttribute( 'tabindex', $this->mParams['tabindex'] ); - } - - $ret = $select->getHTML() . "
\n"; - - $this->mClass[] = 'mw-htmlform-hide-if'; - } - - if ( $valInSelect ) { - $value = ''; - } else { - $key = array_search( strval( $value ), $this->autocomplete, true ); - if ( $key !== false ) { - $value = $key; - } - } - - $this->mClass[] = 'mw-htmlform-autocomplete'; - $ret .= parent::getInputHTML( $valInSelect ? '' : $value ); - $this->mClass = $oldClass; - - return $ret; - } - - /** - * Get the OOUI version of this input. - * @param string $value - * @return false - */ - function getInputOOUI( $value ) { - // To be implemented, for now override the function from HTMLTextField - return false; - } -} diff --git a/includes/htmlform/HTMLButtonField.php b/includes/htmlform/HTMLButtonField.php deleted file mode 100644 index 64fe7eda9b..0000000000 --- a/includes/htmlform/HTMLButtonField.php +++ /dev/null @@ -1,132 +0,0 @@ -mFlags = $info['flags']; - } - - # Generate the label from a message, if possible - if ( isset( $info['buttonlabel-message'] ) ) { - $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse(); - } elseif ( isset( $info['buttonlabel'] ) ) { - if ( $info['buttonlabel'] === ' ' ) { - // Apparently some things set   directly and in an odd format - $this->buttonLabel = ' '; - } else { - $this->buttonLabel = htmlspecialchars( $info['buttonlabel'] ); - } - } elseif ( isset( $info['buttonlabel-raw'] ) ) { - $this->buttonLabel = $info['buttonlabel-raw']; - } - - $this->setShowEmptyLabel( false ); - - parent::__construct( $info ); - } - - public function getInputHTML( $value ) { - $flags = ''; - $prefix = 'mw-htmlform-'; - if ( $this->mParent instanceof VFormHTMLForm || - $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' ) - ) { - $prefix = 'mw-ui-'; - // add mw-ui-button separately, so the descriptor doesn't need to set it - $flags .= ' ' . $prefix . 'button'; - } - foreach ( $this->mFlags as $flag ) { - $flags .= ' ' . $prefix . $flag; - } - $attr = [ - 'class' => 'mw-htmlform-submit ' . $this->mClass . $flags, - 'id' => $this->mID, - 'type' => $this->buttonType, - 'name' => $this->mName, - 'value' => $this->getDefault(), - ] + $this->getAttributes( [ 'disabled', 'tabindex' ] ); - - if ( $this->isBadIE() ) { - return Html::element( 'input', $attr ); - } else { - return Html::rawElement( 'button', $attr, - $this->buttonLabel ?: htmlspecialchars( $this->getDefault() ) ); - } - } - - /** - * Get the OOUI widget for this field. - * @param string $value - * @return OOUI\ButtonInputWidget - */ - public function getInputOOUI( $value ) { - return new OOUI\ButtonInputWidget( [ - 'name' => $this->mName, - 'value' => $this->getDefault(), - 'label' => !$this->isBadIE() && $this->buttonLabel - ? new OOUI\HtmlSnippet( $this->buttonLabel ) - : $this->getDefault(), - 'type' => $this->buttonType, - 'classes' => [ 'mw-htmlform-submit', $this->mClass ], - 'id' => $this->mID, - 'flags' => $this->mFlags, - 'useInputTag' => $this->isBadIE(), - ] + OOUI\Element::configFromHtmlAttributes( - $this->getAttributes( [ 'disabled', 'tabindex' ] ) - ) ); - } - - protected function needsLabel() { - return false; - } - - /** - * Button cannot be invalid - * - * @param string $value - * @param array $alldata - * - * @return bool - */ - public function validate( $value, $alldata ) { - return true; - } - - /** - * IE<8 has bugs with