This provides better mobile experiences on various pages and a more consistent UI across both mobile and desktop. It does this in two ways. 1) Forces HTMLForms to not use table based layouts so as not to interfere with responsive nature of mediawiki ui elements 2) Applies MediaWiki.UI classes to most pages If a page is created via Xml or Html classes it will use mediawiki ui Where possible I've added classes unconditionally, but for cases of buttons this is behind the $wgUseMediaWikiUIEverywhere global since button styling is enabled on pages by default and for checkboxes since it is changes HTML markup. 3) Adds all MediaWiki.UI styles to pages which can use it When enabled: * Apply these styles to all pages which use HTMLForms * Apply to EditPage * Apply to anything that uses certain elements outputted by the Xml or HTML helper classes * Apply to History page * Apply to protection page * Apply to move page * Apply to deletion page Currently kept behind a global to allow us time to finetune existing elements. After further testing we will look to kill the globals and make mediawiki.ui the default See: I430c0fbb79d2a33bb828b2427bda0ee01115d73f Change-Id: I47db5eab4569514d039261d11b6dedb0eeae17b5
122 lines
3.2 KiB
PHP
122 lines
3.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Multi-select field
|
|
*/
|
|
class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable {
|
|
function validate( $value, $alldata ) {
|
|
$p = parent::validate( $value, $alldata );
|
|
|
|
if ( $p !== true ) {
|
|
return $p;
|
|
}
|
|
|
|
if ( !is_array( $value ) ) {
|
|
return false;
|
|
}
|
|
|
|
# If all options are valid, array_intersect of the valid options
|
|
# and the provided options will return the provided options.
|
|
$validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
|
|
|
|
$validValues = array_intersect( $value, $validOptions );
|
|
if ( count( $validValues ) == count( $value ) ) {
|
|
return true;
|
|
} else {
|
|
return $this->msg( 'htmlform-select-badoption' )->parse();
|
|
}
|
|
}
|
|
|
|
function getInputHTML( $value ) {
|
|
$value = HTMLFormField::forceToStringRecursive( $value );
|
|
$html = $this->formatOptions( $this->getOptions(), $value );
|
|
|
|
return $html;
|
|
}
|
|
|
|
function formatOptions( $options, $value ) {
|
|
$html = '';
|
|
|
|
$attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
|
|
$elementFunc = array( 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' );
|
|
|
|
foreach ( $options as $label => $info ) {
|
|
if ( is_array( $info ) ) {
|
|
$html .= Html::rawElement( 'h1', array(), $label ) . "\n";
|
|
$html .= $this->formatOptions( $info, $value );
|
|
} else {
|
|
$thisAttribs = array( 'id' => "{$this->mID}-$info", 'value' => $info );
|
|
|
|
// @todo: Make this use checkLabel for consistency purposes
|
|
$checkbox = Xml::check(
|
|
$this->mName . '[]',
|
|
in_array( $info, $value, true ),
|
|
$attribs + $thisAttribs
|
|
);
|
|
$checkbox .= ' ' . call_user_func( $elementFunc,
|
|
'label',
|
|
array( 'for' => "{$this->mID}-$info" ),
|
|
$label
|
|
);
|
|
|
|
$html .= ' ' . Html::rawElement(
|
|
'div',
|
|
array( 'class' => 'mw-htmlform-flatlist-item' ),
|
|
$checkbox
|
|
);
|
|
}
|
|
}
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* @param WebRequest $request
|
|
*
|
|
* @return string
|
|
*/
|
|
function loadDataFromRequest( $request ) {
|
|
if ( $this->mParent->getMethod() == 'post' ) {
|
|
if ( $request->wasPosted() ) {
|
|
# Checkboxes are just not added to the request arrays if they're not checked,
|
|
# so it's perfectly possible for there not to be an entry at all
|
|
return $request->getArray( $this->mName, array() );
|
|
} else {
|
|
# That's ok, the user has not yet submitted the form, so show the defaults
|
|
return $this->getDefault();
|
|
}
|
|
} else {
|
|
# This is the impossible case: if we look at $_GET and see no data for our
|
|
# field, is it because the user has not yet submitted the form, or that they
|
|
# have submitted it with all the options unchecked? We will have to assume the
|
|
# latter, which basically means that you can't specify 'positive' defaults
|
|
# for GET forms.
|
|
# @todo FIXME...
|
|
return $request->getArray( $this->mName, array() );
|
|
}
|
|
}
|
|
|
|
function getDefault() {
|
|
if ( isset( $this->mDefault ) ) {
|
|
return $this->mDefault;
|
|
} else {
|
|
return array();
|
|
}
|
|
}
|
|
|
|
function filterDataForSubmit( $data ) {
|
|
$data = HTMLFormField::forceToStringRecursive( $data );
|
|
$options = HTMLFormField::flattenOptions( $this->getOptions() );
|
|
|
|
$res = array();
|
|
foreach ( $options as $opt ) {
|
|
$res["$opt"] = in_array( $opt, $data, true );
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
protected function needsLabel() {
|
|
return false;
|
|
}
|
|
}
|