MediaWiki  1.33.0
HTMLButtonField.php
Go to the documentation of this file.
1 <?php
2 
27  protected $buttonType = 'button';
28  protected $buttonLabel = null;
29 
31  protected $mFlags = [];
32 
33  protected $mFormnovalidate = false;
34 
35  public function __construct( $info ) {
36  $info['nodata'] = true;
37 
38  $this->setShowEmptyLabel( false );
39 
40  parent::__construct( $info );
41 
42  if ( isset( $info['flags'] ) ) {
43  $this->mFlags = $info['flags'];
44  }
45 
46  if ( isset( $info['formnovalidate'] ) ) {
47  $this->mFormnovalidate = $info['formnovalidate'];
48  }
49 
50  # Generate the label from a message, if possible
51  if ( isset( $info['buttonlabel-message'] ) ) {
52  $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse();
53  } elseif ( isset( $info['buttonlabel'] ) ) {
54  if ( $info['buttonlabel'] === '&#160;' || $info['buttonlabel'] === "\u{00A0}" ) {
55  // Apparently some things set &nbsp directly and in an odd format
56  $this->buttonLabel = "\u{00A0}";
57  } else {
58  $this->buttonLabel = htmlspecialchars( $info['buttonlabel'] );
59  }
60  } elseif ( isset( $info['buttonlabel-raw'] ) ) {
61  $this->buttonLabel = $info['buttonlabel-raw'];
62  }
63  }
64 
65  public function getInputHTML( $value ) {
66  $flags = '';
67  $prefix = 'mw-htmlform-';
68  if ( $this->mParent instanceof VFormHTMLForm ||
69  $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
70  ) {
71  $prefix = 'mw-ui-';
72  // add mw-ui-button separately, so the descriptor doesn't need to set it
73  $flags .= ' ' . $prefix . 'button';
74  }
75  foreach ( $this->mFlags as $flag ) {
76  $flags .= ' ' . $prefix . $flag;
77  }
78  $attr = [
79  'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
80  'id' => $this->mID,
81  'type' => $this->buttonType,
82  'name' => $this->mName,
83  'value' => $this->getDefault(),
84  'formnovalidate' => $this->mFormnovalidate,
85  ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
86 
87  if ( $this->isBadIE() ) {
88  return Html::element( 'input', $attr );
89  } else {
90  return Html::rawElement( 'button', $attr,
91  $this->buttonLabel ?: htmlspecialchars( $this->getDefault() ) );
92  }
93  }
94 
100  public function getInputOOUI( $value ) {
101  return new OOUI\ButtonInputWidget( [
102  'name' => $this->mName,
103  'value' => $this->getDefault(),
104  'label' => !$this->isBadIE() && $this->buttonLabel
105  ? new OOUI\HtmlSnippet( $this->buttonLabel )
106  : $this->getDefault(),
107  'type' => $this->buttonType,
108  'classes' => [ 'mw-htmlform-submit', $this->mClass ],
109  'id' => $this->mID,
110  'flags' => $this->mFlags,
111  'useInputTag' => $this->isBadIE(),
112  ] + OOUI\Element::configFromHtmlAttributes(
113  $this->getAttributes( [ 'disabled', 'tabindex' ] )
114  ) );
115  }
116 
117  protected function needsLabel() {
118  return false;
119  }
120 
129  public function validate( $value, $alldata ) {
130  return true;
131  }
132 
137  private function isBadIE() {
138  $request = $this->mParent
139  ? $this->mParent->getRequest()
140  : RequestContext::getMain()->getRequest();
141  return (bool)preg_match( '/MSIE [1-7]\./i', $request->getHeader( 'User-Agent' ) );
142  }
143 }
HTMLButtonField\needsLabel
needsLabel()
Should this field have a label, or is there no input element with the appropriate id for the label to...
Definition: HTMLButtonField.php:117
HTMLButtonField\__construct
__construct( $info)
Initialise the object.
Definition: HTMLButtonField.php:35
HTMLButtonField\validate
validate( $value, $alldata)
Button cannot be invalid.
Definition: HTMLButtonField.php:129
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
HTMLButtonField\getInputOOUI
getInputOOUI( $value)
Get the OOUI widget for this field.
Definition: HTMLButtonField.php:100
HTMLFormField\setShowEmptyLabel
setShowEmptyLabel( $show)
Tell the field whether to generate a separate label element if its label is blank.
Definition: HTMLFormField.php:347
HTMLButtonField\$mFormnovalidate
$mFormnovalidate
Definition: HTMLButtonField.php:33
VFormHTMLForm
Compact stacked vertical format for forms.
Definition: VFormHTMLForm.php:27
HTMLButtonField
Adds a generic button inline to the form.
Definition: HTMLButtonField.php:26
HTMLFormField\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition: HTMLFormField.php:1152
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
HTMLButtonField\$buttonLabel
$buttonLabel
Definition: HTMLButtonField.php:28
HTMLFormField\$mName
$mName
Definition: HTMLFormField.php:12
HTMLButtonField\isBadIE
isBadIE()
IE<8 has bugs with <button>, so we'll need to avoid them.
Definition: HTMLButtonField.php:137
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.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
HTMLButtonField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
Definition: HTMLButtonField.php:65
HTMLFormField\getDefault
getDefault()
Definition: HTMLFormField.php:957
HTMLButtonField\$mFlags
$mFlags
Definition: HTMLButtonField.php:31
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:430
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
HTMLButtonField\$buttonType
$buttonType
Definition: HTMLButtonField.php:27
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:996