MediaWiki  1.28.0
HTMLButtonField.php
Go to the documentation of this file.
1 <?php
2 
24  protected $buttonType = 'button';
25  protected $buttonLabel = null;
26 
28  protected $mFlags = [];
29 
30  public function __construct( $info ) {
31  $info['nodata'] = true;
32  if ( isset( $info['flags'] ) ) {
33  $this->mFlags = $info['flags'];
34  }
35 
36  # Generate the label from a message, if possible
37  if ( isset( $info['buttonlabel-message'] ) ) {
38  $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse();
39  } elseif ( isset( $info['buttonlabel'] ) ) {
40  if ( $info['buttonlabel'] === '&#160;' ) {
41  // Apparently some things set &nbsp directly and in an odd format
42  $this->buttonLabel = '&#160;';
43  } else {
44  $this->buttonLabel = htmlspecialchars( $info['buttonlabel'] );
45  }
46  } elseif ( isset( $info['buttonlabel-raw'] ) ) {
47  $this->buttonLabel = $info['buttonlabel-raw'];
48  }
49 
50  $this->setShowEmptyLabel( false );
51 
52  parent::__construct( $info );
53  }
54 
55  public function getInputHTML( $value ) {
56  $flags = '';
57  $prefix = 'mw-htmlform-';
58  if ( $this->mParent instanceof VFormHTMLForm ||
59  $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
60  ) {
61  $prefix = 'mw-ui-';
62  // add mw-ui-button separately, so the descriptor doesn't need to set it
63  $flags .= ' ' . $prefix . 'button';
64  }
65  foreach ( $this->mFlags as $flag ) {
66  $flags .= ' ' . $prefix . $flag;
67  }
68  $attr = [
69  'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
70  'id' => $this->mID,
71  'type' => $this->buttonType,
72  'name' => $this->mName,
73  'value' => $this->getDefault(),
74  ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
75 
76  if ( $this->isBadIE() ) {
77  return Html::element( 'input', $attr );
78  } else {
79  return Html::rawElement( 'button', $attr,
80  $this->buttonLabel ?: htmlspecialchars( $this->getDefault() ) );
81  }
82  }
83 
89  public function getInputOOUI( $value ) {
90  return new OOUI\ButtonInputWidget( [
91  'name' => $this->mName,
92  'value' => $this->getDefault(),
93  'label' => !$this->isBadIE() && $this->buttonLabel
94  ? new OOUI\HtmlSnippet( $this->buttonLabel )
95  : $this->getDefault(),
96  'type' => $this->buttonType,
97  'classes' => [ 'mw-htmlform-submit', $this->mClass ],
98  'id' => $this->mID,
99  'flags' => $this->mFlags,
100  'useInputTag' => $this->isBadIE(),
101  ] + OOUI\Element::configFromHtmlAttributes(
102  $this->getAttributes( [ 'disabled', 'tabindex' ] )
103  ) );
104  }
105 
106  protected function needsLabel() {
107  return false;
108  }
109 
118  public function validate( $value, $alldata ) {
119  return true;
120  }
121 
126  private function isBadIE() {
127  $request = $this->mParent
128  ? $this->mParent->getRequest()
129  : RequestContext::getMain()->getRequest();
130  return preg_match( '/MSIE [1-7]\./i', $request->getHeader( 'User-Agent' ) );
131  }
132 }
getInputOOUI($value)
Get the OOUI widget for this field.
getMessage($value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a name + parameters array) into a Message.
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:209
$value
setShowEmptyLabel($show)
Tell the field whether to generate a separate label element if its label is blank.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2703
isBadIE()
IE<8 has bugs with
getRequest()
Get the WebRequest object.
static getMain()
Static methods.
Adds a generic button inline to the form.
getConfig()
Get the Config object.
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
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
Compact stacked vertical format for forms.
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2573
The parent class to generate form fields.
getAttributes(array $list)
Returns the given attributes from the parameters.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:229
validate($value, $alldata)
Button cannot be invalid.