MediaWiki  1.33.0
HTMLCheckField.php
Go to the documentation of this file.
1 <?php
2 
7  public function getInputHTML( $value ) {
9 
10  if ( !empty( $this->mParams['invert'] ) ) {
11  $value = !$value;
12  }
13 
14  $attr = $this->getTooltipAndAccessKey();
15  $attr['id'] = $this->mID;
16 
17  $attr += $this->getAttributes( [ 'disabled', 'tabindex' ] );
18 
19  if ( $this->mClass !== '' ) {
20  $attr['class'] = $this->mClass;
21  }
22 
23  $attrLabel = [ 'for' => $this->mID ];
24  if ( isset( $attr['title'] ) ) {
25  // propagate tooltip to label
26  $attrLabel['title'] = $attr['title'];
27  }
28 
29  $chkLabel = Xml::check( $this->mName, $value, $attr ) .
30  "\u{00A0}" .
31  Html::rawElement( 'label', $attrLabel, $this->mLabel );
32 
33  if ( $wgUseMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) {
34  $chkLabel = Html::rawElement(
35  'div',
36  [ 'class' => 'mw-ui-checkbox' ],
37  $chkLabel
38  );
39  }
40 
41  return $chkLabel;
42  }
43 
50  public function getInputOOUI( $value ) {
51  if ( !empty( $this->mParams['invert'] ) ) {
52  $value = !$value;
53  }
54 
55  $attr = $this->getTooltipAndAccessKeyOOUI();
56  $attr['id'] = $this->mID;
57  $attr['name'] = $this->mName;
58 
59  $attr += OOUI\Element::configFromHtmlAttributes(
60  $this->getAttributes( [ 'disabled', 'tabindex' ] )
61  );
62 
63  if ( $this->mClass !== '' ) {
64  $attr['classes'] = [ $this->mClass ];
65  }
66 
67  $attr['selected'] = $value;
68  $attr['value'] = '1'; // Nasty hack, but needed to make this work
69 
70  return new OOUI\CheckboxInputWidget( $attr );
71  }
72 
82  public function getLabel() {
83  if ( $this->mParent instanceof OOUIHTMLForm ) {
84  return $this->mLabel;
85  } elseif (
86  $this->mParent instanceof HTMLForm &&
87  $this->mParent->getDisplayFormat() === 'div'
88  ) {
89  return '';
90  } else {
91  return "\u{00A0}";
92  }
93  }
94 
99  protected function getLabelAlignOOUI() {
100  return 'inline';
101  }
102 
107  protected function needsLabel() {
108  return false;
109  }
110 
116  public function loadDataFromRequest( $request ) {
117  $invert = isset( $this->mParams['invert'] ) && $this->mParams['invert'];
118 
119  // Fetch the value in either one of the two following case:
120  // - we have a valid submit attempt (form was just submitted)
121  // - we have a value (an URL manually built by the user, or GET form with no wpFormIdentifier)
122  if ( $this->isSubmitAttempt( $request ) || $request->getCheck( $this->mName ) ) {
123  return $invert
124  ? !$request->getBool( $this->mName )
125  : $request->getBool( $this->mName );
126  } else {
127  return (bool)$this->getDefault();
128  }
129  }
130 }
HTMLCheckField\getLabel
getLabel()
For a checkbox, the label goes on the right hand side, and is added in getInputHTML(),...
Definition: HTMLCheckField.php:82
HTMLFormField\getTooltipAndAccessKeyOOUI
getTooltipAndAccessKeyOOUI()
Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
Definition: HTMLFormField.php:979
HTMLFormField\$mLabel
$mLabel
Definition: HTMLFormField.php:14
HTMLCheckField\getLabelAlignOOUI
getLabelAlignOOUI()
Get label alignment when generating field for OOUI.
Definition: HTMLCheckField.php:99
HTMLCheckField
A checkbox field.
Definition: HTMLCheckField.php:6
HTMLForm\getDisplayFormat
getDisplayFormat()
Getter for displayFormat.
Definition: HTMLForm.php:430
$wgUseMediaWikiUIEverywhere
$wgUseMediaWikiUIEverywhere
Temporary variable that applies MediaWiki UI wherever it can be supported.
Definition: DefaultSettings.php:3261
HTMLCheckField\getInputOOUI
getInputOOUI( $value)
Get the OOUI version of this field.
Definition: HTMLCheckField.php:50
VFormHTMLForm
Compact stacked vertical format for forms.
Definition: VFormHTMLForm.php:27
HTMLFormField\$mClass
$mClass
Definition: HTMLFormField.php:16
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
OOUIHTMLForm
Compact stacked vertical format for forms, implemented using OOUI widgets.
Definition: OOUIHTMLForm.php:27
HTMLFormField\$mName
$mName
Definition: HTMLFormField.php:12
Xml\check
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
Definition: Xml.php:323
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
HTMLCheckField\loadDataFromRequest
loadDataFromRequest( $request)
Definition: HTMLCheckField.php:116
HTMLCheckField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
Definition: HTMLCheckField.php:7
HTMLFormField\$mID
$mID
Definition: HTMLFormField.php:15
$request
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2636
$value
$value
Definition: styleTest.css.php:49
HTMLFormField\getDefault
getDefault()
Definition: HTMLFormField.php:957
HTMLCheckField\needsLabel
needsLabel()
checkboxes don't need a label.
Definition: HTMLCheckField.php:107
HTMLFormField\isSubmitAttempt
isSubmitAttempt(WebRequest $request)
Can we assume that the request is an attempt to submit a HTMLForm, as opposed to an attempt to just v...
Definition: HTMLFormField.php:361
HTMLFormField\getTooltipAndAccessKey
getTooltipAndAccessKey()
Returns the attributes required for the tooltip and accesskey, for Html::element() etc.
Definition: HTMLFormField.php:966
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:996
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:133