MediaWiki  REL1_31
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  if ( isset( $info['flags'] ) ) {
38  $this->mFlags = $info['flags'];
39  }
40 
41  if ( isset( $info['formnovalidate'] ) ) {
42  $this->mFormnovalidate = $info['formnovalidate'];
43  }
44 
45  # Generate the label from a message, if possible
46  if ( isset( $info['buttonlabel-message'] ) ) {
47  $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse();
48  } elseif ( isset( $info['buttonlabel'] ) ) {
49  if ( $info['buttonlabel'] === '&#160;' ) {
50  // Apparently some things set &nbsp directly and in an odd format
51  $this->buttonLabel = '&#160;';
52  } else {
53  $this->buttonLabel = htmlspecialchars( $info['buttonlabel'] );
54  }
55  } elseif ( isset( $info['buttonlabel-raw'] ) ) {
56  $this->buttonLabel = $info['buttonlabel-raw'];
57  }
58 
59  $this->setShowEmptyLabel( false );
60 
61  parent::__construct( $info );
62  }
63 
64  public function getInputHTML( $value ) {
65  $flags = '';
66  $prefix = 'mw-htmlform-';
67  if ( $this->mParent instanceof VFormHTMLForm ||
68  $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
69  ) {
70  $prefix = 'mw-ui-';
71  // add mw-ui-button separately, so the descriptor doesn't need to set it
72  $flags .= ' ' . $prefix . 'button';
73  }
74  foreach ( $this->mFlags as $flag ) {
75  $flags .= ' ' . $prefix . $flag;
76  }
77  $attr = [
78  'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
79  'id' => $this->mID,
80  'type' => $this->buttonType,
81  'name' => $this->mName,
82  'value' => $this->getDefault(),
83  'formnovalidate' => $this->mFormnovalidate,
84  ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
85 
86  if ( $this->isBadIE() ) {
87  return Html::element( 'input', $attr );
88  } else {
89  return Html::rawElement( 'button', $attr,
90  $this->buttonLabel ?: htmlspecialchars( $this->getDefault() ) );
91  }
92  }
93 
99  public function getInputOOUI( $value ) {
100  return new OOUI\ButtonInputWidget( [
101  'name' => $this->mName,
102  'value' => $this->getDefault(),
103  'label' => !$this->isBadIE() && $this->buttonLabel
104  ? new OOUI\HtmlSnippet( $this->buttonLabel )
105  : $this->getDefault(),
106  'type' => $this->buttonType,
107  'classes' => [ 'mw-htmlform-submit', $this->mClass ],
108  'id' => $this->mID,
109  'flags' => $this->mFlags,
110  'useInputTag' => $this->isBadIE(),
111  ] + OOUI\Element::configFromHtmlAttributes(
112  $this->getAttributes( [ 'disabled', 'tabindex' ] )
113  ) );
114  }
115 
116  protected function needsLabel() {
117  return false;
118  }
119 
128  public function validate( $value, $alldata ) {
129  return true;
130  }
131 
136  private function isBadIE() {
137  $request = $this->mParent
138  ? $this->mParent->getRequest()
139  : RequestContext::getMain()->getRequest();
140  return (bool)preg_match( '/MSIE [1-7]\./i', $request->getHeader( 'User-Agent' ) );
141  }
142 }
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:116
HTMLButtonField\__construct
__construct( $info)
Initialise the object.
Definition: HTMLButtonField.php:35
HTMLButtonField\validate
validate( $value, $alldata)
Button cannot be invalid.
Definition: HTMLButtonField.php:128
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
HTMLButtonField\getInputOOUI
getInputOOUI( $value)
Get the OOUI widget for this field.
Definition: HTMLButtonField.php:99
HTMLFormField\setShowEmptyLabel
setShowEmptyLabel( $show)
Tell the field whether to generate a separate label element if its label is blank.
Definition: HTMLFormField.php:348
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:1177
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:37
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:136
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
HTMLFormField\$mID
$mID
Definition: HTMLFormField.php:15
$value
$value
Definition: styleTest.css.php:45
HTMLButtonField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
Definition: HTMLButtonField.php:64
HTMLFormField\getDefault
getDefault()
Definition: HTMLFormField.php:984
HTMLButtonField\$mFlags
$mFlags
Definition: HTMLButtonField.php:31
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:434
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:22
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
HTMLButtonField\$buttonType
$buttonType
Definition: HTMLButtonField.php:27
$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:2806
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:1027