2015-04-21 21:03:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* HTML form generation and submission handling, OOUI style.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compact stacked vertical format for forms, implemented using OOUI widgets.
|
|
|
|
|
*/
|
|
|
|
|
class OOUIHTMLForm extends HTMLForm {
|
|
|
|
|
public function __construct( $descriptor, $context = null, $messagePrefix = '' ) {
|
2015-05-28 06:02:58 +00:00
|
|
|
parent::__construct( $descriptor, $context, $messagePrefix );
|
2015-04-21 21:03:49 +00:00
|
|
|
$this->getOutput()->enableOOUI();
|
|
|
|
|
$this->getOutput()->addModuleStyles( 'mediawiki.htmlform.ooui.styles' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Symbolic display format name.
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $displayFormat = 'ooui';
|
|
|
|
|
|
|
|
|
|
public static function loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent = null ) {
|
|
|
|
|
$field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
|
|
|
|
|
$field->setShowEmptyLabel( false );
|
|
|
|
|
return $field;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getButtons() {
|
|
|
|
|
$buttons = '';
|
|
|
|
|
|
|
|
|
|
if ( $this->mShowSubmit ) {
|
2015-06-27 07:55:24 +00:00
|
|
|
$attribs = array( 'infusable' => true );
|
2015-04-21 21:03:49 +00:00
|
|
|
|
|
|
|
|
if ( isset( $this->mSubmitID ) ) {
|
|
|
|
|
$attribs['id'] = $this->mSubmitID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $this->mSubmitName ) ) {
|
|
|
|
|
$attribs['name'] = $this->mSubmitName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $this->mSubmitTooltip ) ) {
|
|
|
|
|
$attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-14 18:09:52 +00:00
|
|
|
$attribs['classes'] = array( 'mw-htmlform-submit' );
|
2015-04-21 21:03:49 +00:00
|
|
|
$attribs['type'] = 'submit';
|
|
|
|
|
$attribs['label'] = $this->getSubmitText();
|
|
|
|
|
$attribs['value'] = $this->getSubmitText();
|
2015-06-14 18:09:52 +00:00
|
|
|
$attribs['flags'] = array( $this->mSubmitFlag );
|
2015-04-21 21:03:49 +00:00
|
|
|
|
|
|
|
|
$buttons .= new OOUI\ButtonInputWidget( $attribs );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->mShowReset ) {
|
|
|
|
|
$buttons .= new OOUI\ButtonInputWidget( array(
|
|
|
|
|
'type' => 'reset',
|
|
|
|
|
'label' => $this->msg( 'htmlform-reset' )->text(),
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $this->mButtons as $button ) {
|
|
|
|
|
$attrs = array();
|
|
|
|
|
|
|
|
|
|
if ( $button['attribs'] ) {
|
|
|
|
|
$attrs += $button['attribs'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $button['id'] ) ) {
|
|
|
|
|
$attrs['id'] = $button['id'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$attrs['classes'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : array();
|
|
|
|
|
|
|
|
|
|
$buttons .= new OOUI\ButtonInputWidget( array(
|
|
|
|
|
'type' => 'submit',
|
|
|
|
|
'name' => $button['name'],
|
|
|
|
|
'value' => $button['value'],
|
|
|
|
|
'label' => $button['value'],
|
|
|
|
|
) + $attrs );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$html = Html::rawElement( 'div',
|
|
|
|
|
array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n";
|
|
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-11 16:46:05 +00:00
|
|
|
function getBody() {
|
|
|
|
|
$fieldset = parent::getBody();
|
|
|
|
|
// FIXME This only works for forms with no subsections
|
|
|
|
|
if ( $fieldset instanceof OOUI\FieldsetLayout ) {
|
|
|
|
|
$fieldset->group->prependContent( new OOUI\HtmlSnippet( $this->mHeader ) );
|
2015-04-21 21:03:49 +00:00
|
|
|
}
|
2015-07-11 16:46:05 +00:00
|
|
|
return $fieldset;
|
2015-04-21 21:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function wrapForm( $html ) {
|
2015-07-11 16:46:05 +00:00
|
|
|
$form = new OOUI\FormLayout( $this->getFormAttributes() + array(
|
|
|
|
|
'classes' => array( 'mw-htmlform-ooui' ),
|
|
|
|
|
'content' => new OOUI\HtmlSnippet( $html ),
|
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
// Include a wrapper for style, if requested.
|
|
|
|
|
$form = new OOUI\PanelLayout( array(
|
|
|
|
|
'classes' => array( 'mw-htmlform-ooui-wrapper' ),
|
|
|
|
|
'expanded' => false,
|
|
|
|
|
'padded' => $this->mWrapperLegend !== false,
|
|
|
|
|
'framed' => $this->mWrapperLegend !== false,
|
|
|
|
|
'content' => $form,
|
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
return $form;
|
2015-04-21 21:03:49 +00:00
|
|
|
}
|
|
|
|
|
}
|