14 protected $mLabel; # String label, as HTML. Set on construction.
77 public function msg() {
78 $args = func_get_args();
80 if ( $this->mParent ) {
81 $callback = [ $this->mParent,
'msg' ];
83 $callback =
'wfMessage';
86 return call_user_func_array( $callback,
$args );
115 while ( preg_match(
'/^(.+)\[([^\]]+)\]$/', $tmp, $m ) ) {
116 array_unshift( $thisKeys, $m[2] );
119 if ( substr( $tmp, 0, 2 ) ==
'wp' &&
120 !array_key_exists( $tmp, $alldata ) &&
121 array_key_exists( substr( $tmp, 2 ), $alldata )
124 $tmp = substr( $tmp, 2 );
126 array_unshift( $thisKeys, $tmp );
130 while ( preg_match(
'/^(.+)\[([^\]]+)\]$/', $tmp, $m ) ) {
131 array_unshift( $nameKeys, $m[2] );
134 array_unshift( $nameKeys, $tmp );
137 for ( $i = count( $thisKeys ) - 1; $i >= 0; $i-- ) {
138 $keys = array_merge( array_slice( $thisKeys, 0, $i ), $nameKeys );
141 $key = array_shift(
$keys );
142 if ( !is_array( $data ) || !array_key_exists( $key, $data ) ) {
147 $testValue = (
string)$data;
169 foreach (
$params as $i => $p ) {
170 if ( !is_array( $p ) ) {
172 "Expected array, found " . gettype( $p ) .
" at index $i"
182 foreach (
$params as $i => $p ) {
183 if ( !is_array( $p ) ) {
185 "Expected array, found " . gettype( $p ) .
" at index $i"
195 foreach (
$params as $i => $p ) {
196 if ( !is_array( $p ) ) {
198 "Expected array, found " . gettype( $p ) .
" at index $i"
208 foreach (
$params as $i => $p ) {
209 if ( !is_array( $p ) ) {
211 "Expected array, found " . gettype( $p ) .
" at index $i"
221 if ( count(
$params ) !== 1 ) {
222 throw new MWException(
"NOT takes exactly one parameter" );
225 if ( !is_array( $p ) ) {
227 "Expected array, found " . gettype( $p ) .
" at index 0"
234 if ( count(
$params ) !== 2 ) {
235 throw new MWException(
"$op takes exactly two parameters" );
238 if ( !is_string( $field ) || !is_string(
$value ) ) {
239 throw new MWException(
"Parameters for $op must be strings" );
244 return (
$value === $testValue );
246 return (
$value !== $testValue );
252 }
catch ( Exception $ex ) {
254 "Invalid hide-if specification for $this->mName: " .
255 $ex->getMessage() .
" in " . var_export( $origParams,
true ),
270 if ( !$this->mHideIf ) {
303 if ( $this->
isHidden( $alldata ) ) {
307 if ( isset( $this->mParams[
'required'] )
308 && $this->mParams[
'required'] !==
false
311 return $this->
msg(
'htmlform-required' );
314 if ( isset( $this->mValidationCallback ) ) {
315 return call_user_func( $this->mValidationCallback,
$value, $alldata, $this->mParent );
322 if ( isset( $this->mFilterCallback ) ) {
323 $value = call_user_func( $this->mFilterCallback,
$value, $alldata, $this->mParent );
349 $this->mShowEmptyLabels = $show;
363 return $request->getCheck(
'wpEditToken' ) ||
$request->getCheck(
'wpFormIdentifier' );
374 if (
$request->getCheck( $this->mName ) ) {
375 return $request->getText( $this->mName );
393 $this->mParent =
$params[
'parent'];
396 # Generate the label from a message, if possible
397 if ( isset(
$params[
'label-message'] ) ) {
399 } elseif ( isset(
$params[
'label'] ) ) {
400 if (
$params[
'label'] ===
' ' ) {
402 $this->mLabel =
' ';
404 $this->mLabel = htmlspecialchars(
$params[
'label'] );
406 } elseif ( isset(
$params[
'label-raw'] ) ) {
407 $this->mLabel =
$params[
'label-raw'];
410 $this->mName =
"wp{$params['fieldname']}";
411 if ( isset(
$params[
'name'] ) ) {
412 $this->mName =
$params[
'name'];
415 if ( isset(
$params[
'dir'] ) ) {
419 $validName = urlencode( $this->mName );
420 $validName = str_replace( [
'%5B',
'%5D' ], [
'[',
']' ], $validName );
421 if ( $this->mName != $validName && !isset(
$params[
'nodata'] ) ) {
422 throw new MWException(
"Invalid name '{$this->mName}' passed to " . __METHOD__ );
425 $this->mID =
"mw-input-{$this->mName}";
427 if ( isset(
$params[
'default'] ) ) {
428 $this->mDefault =
$params[
'default'];
431 if ( isset(
$params[
'id'] ) ) {
433 $validId = urlencode( $id );
435 if ( $id != $validId ) {
436 throw new MWException(
"Invalid id '$id' passed to " . __METHOD__ );
442 if ( isset(
$params[
'cssclass'] ) ) {
443 $this->mClass =
$params[
'cssclass'];
446 if ( isset(
$params[
'csshelpclass'] ) ) {
447 $this->mHelpClass =
$params[
'csshelpclass'];
450 if ( isset(
$params[
'validation-callback'] ) ) {
451 $this->mValidationCallback =
$params[
'validation-callback'];
454 if ( isset(
$params[
'filter-callback'] ) ) {
455 $this->mFilterCallback =
$params[
'filter-callback'];
458 if ( isset(
$params[
'hidelabel'] ) ) {
459 $this->mShowEmptyLabels =
false;
462 if ( isset(
$params[
'hide-if'] ) ) {
463 $this->mHideIf =
$params[
'hide-if'];
480 $cellAttributes = [];
484 if ( !empty( $this->mParams[
'vertical-label'] ) ) {
485 $cellAttributes[
'colspan'] = 2;
486 $verticalLabel =
true;
488 $verticalLabel =
false;
493 $field = Html::rawElement(
495 [
'class' =>
'mw-input' ] + $cellAttributes,
496 $inputHtml .
"\n$errors"
499 if ( $this->mHideIf ) {
500 $rowAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
501 $rowClasses .=
' mw-htmlform-hide-if';
504 if ( $verticalLabel ) {
505 $html = Html::rawElement(
'tr',
506 $rowAttributes + [
'class' =>
"mw-htmlform-vertical-label $rowClasses" ], $label );
507 $html .= Html::rawElement(
'tr',
509 'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
514 Html::rawElement(
'tr',
516 'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
521 return $html . $helptext;
538 $cellAttributes = [];
543 'mw-htmlform-nolabel' => ( $label ===
'' )
546 $horizontalLabel = isset( $this->mParams[
'horizontal-label'] )
547 ? $this->mParams[
'horizontal-label'] :
false;
549 if ( $horizontalLabel ) {
550 $field =
' ' . $inputHtml .
"\n$errors";
552 $field = Html::rawElement(
554 [
'class' => $outerDivClass ] + $cellAttributes,
555 $inputHtml .
"\n$errors"
558 $divCssClasses = [
"mw-htmlform-field-$fieldType",
559 $this->mClass, $this->mVFormClass, $errorClass ];
561 $wrapperAttributes = [
562 'class' => $divCssClasses,
564 if ( $this->mHideIf ) {
565 $wrapperAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
566 $wrapperAttributes[
'class'][] =
' mw-htmlform-hide-if';
568 $html = Html::rawElement(
'div', $wrapperAttributes, $label . $field );
585 if ( !$inputField ) {
590 new OOUI\Widget( [
'content' =>
new OOUI\HtmlSnippet( $this->
getDiv(
$value ) ) ] ),
591 [
'infusable' =>
false,
'align' =>
'top' ]
596 if ( is_string( $inputField ) ) {
600 $inputField =
new OOUI\Widget( [
'content' =>
new OOUI\HtmlSnippet( $inputField ) ] );
607 foreach ( $errors as &$error ) {
608 $error =
new OOUI\HtmlSnippet( $error );
612 foreach ( $notices as &$notice ) {
613 $notice =
new OOUI\HtmlSnippet( $notice );
617 'classes' => [
"mw-htmlform-field-$fieldType", $this->mClass ],
619 'help' => (
$help !==
null &&
$help !==
'' ) ?
new OOUI\HtmlSnippet(
$help ) :
null,
621 'notices' => $notices,
622 'infusable' => $infusable,
625 $preloadModules =
false;
628 $preloadModules =
true;
629 $config[
'classes'][] =
'mw-htmlform-field-autoinfuse';
634 if ( $label && $label !==
' ' ) {
635 $config[
'label'] =
new OOUI\HtmlSnippet( $label );
638 if ( $this->mHideIf ) {
639 $preloadModules =
true;
640 $config[
'hideIf'] = $this->mHideIf;
645 if ( $preloadModules ) {
646 $this->mParent->getOutput()->addModules(
'mediawiki.htmlform.ooui' );
647 $this->mParent->getOutput()->addModules( $this->
getOOUIModules() );
661 $name = explode(
'\\', static::class );
680 if ( isset( $this->mClassWithButton ) ) {
681 $buttonWidget = $this->mClassWithButton->getInputOOUI(
'' );
722 $cellAttributes = [];
743 $this->mVFormClass =
' mw-ui-vform-field';
757 $cellAttributes = [];
760 $html =
"\n" . $errors .
776 if ( is_null( $helptext ) ) {
781 if ( $this->mHideIf ) {
782 $rowAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
783 $rowAttributes[
'class'] =
'mw-htmlform-hide-if';
786 $tdClasses = [
'htmlform-tip' ];
787 if ( $this->mHelpClass !==
false ) {
788 $tdClasses[] = $this->mHelpClass;
790 $row = Html::rawElement(
'td', [
'colspan' => 2,
'class' => $tdClasses ], $helptext );
791 $row = Html::rawElement(
'tr', $rowAttributes, $row );
805 if ( is_null( $helptext ) ) {
809 $wrapperAttributes = [
810 'class' =>
'htmlform-tip',
812 if ( $this->mHelpClass !==
false ) {
813 $wrapperAttributes[
'class'] .=
" {$this->mHelpClass}";
815 if ( $this->mHideIf ) {
816 $wrapperAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
817 $wrapperAttributes[
'class'] .=
' mw-htmlform-hide-if';
819 $div = Html::rawElement(
'div', $wrapperAttributes, $helptext );
843 if ( isset( $this->mParams[
'help-message'] ) ) {
844 $this->mParams[
'help-messages'] = [ $this->mParams[
'help-message'] ];
847 if ( isset( $this->mParams[
'help-messages'] ) ) {
848 foreach ( $this->mParams[
'help-messages'] as $msg ) {
851 if ( $msg->exists() ) {
852 if ( is_null( $helptext ) ) {
855 $helptext .= $this->
msg(
'word-separator' )->escaped();
857 $helptext .= $msg->parse();
860 } elseif ( isset( $this->mParams[
'help'] ) ) {
861 $helptext = $this->mParams[
'help'];
877 if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
881 $errors = self::formatErrors( $errors );
882 $errorClass =
'mw-htmlform-invalid-input';
885 return [ $errors, $errorClass ];
898 if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
902 if ( !is_array( $errors ) ) {
903 $errors = [ $errors ];
905 foreach ( $errors as &$error ) {
906 if ( $error instanceof
Message ) {
907 $error = $error->parse();
923 if ( isset( $this->mParams[
'notice-message'] ) ) {
924 $notices[] = $this->
getMessage( $this->mParams[
'notice-message'] )->parse();
927 if ( isset( $this->mParams[
'notice-messages'] ) ) {
928 foreach ( $this->mParams[
'notice-messages'] as $msg ) {
929 $notices[] = $this->
getMessage( $msg )->parse();
931 } elseif ( isset( $this->mParams[
'notice'] ) ) {
932 $notices[] = $this->mParams[
'notice'];
942 return is_null( $this->mLabel ) ?
'' : $this->mLabel;
946 # Don't output a for= attribute for labels with no associated input.
947 # Kind of hacky here, possibly we don't want these to be <label>s at all.
951 $for[
'for'] = $this->mID;
954 $labelValue = trim( $this->
getLabel() );
956 if ( $labelValue !==
' ' && $labelValue !==
'' ) {
960 $displayFormat = $this->mParent->getDisplayFormat();
962 $horizontalLabel = isset( $this->mParams[
'horizontal-label'] )
963 ? $this->mParams[
'horizontal-label'] :
false;
965 if ( $displayFormat ===
'table' ) {
967 Html::rawElement(
'td',
968 [
'class' =>
'mw-label' ] + $cellAttributes,
969 Html::rawElement(
'label', $for, $labelValue ) );
970 } elseif ( $hasLabel || $this->mShowEmptyLabels ) {
971 if ( $displayFormat ===
'div' && !$horizontalLabel ) {
973 Html::rawElement(
'div',
974 [
'class' =>
'mw-label' ] + $cellAttributes,
975 Html::rawElement(
'label', $for, $labelValue ) );
977 $html = Html::rawElement(
'label', $for, $labelValue );
985 if ( isset( $this->mDefault ) ) {
986 return $this->mDefault;
998 if ( empty( $this->mParams[
'tooltip'] ) ) {
1011 if ( empty( $this->mParams[
'tooltip'] ) ) {
1028 static $boolAttribs = [
'disabled',
'required',
'autofocus',
'multiple',
'readonly' ];
1031 foreach ( $list as $key ) {
1032 if ( in_array( $key, $boolAttribs ) ) {
1033 if ( !empty( $this->mParams[$key] ) ) {
1036 } elseif ( isset( $this->mParams[$key] ) ) {
1037 $ret[$key] = $this->mParams[$key];
1054 $key = $this->
msg( $key )->plain();
1070 if ( is_array( $array ) ) {
1071 return array_map( [ __CLASS__,
'forceToStringRecursive' ], $array );
1073 return strval( $array );
1084 if ( $this->mOptions ===
false ) {
1085 if ( array_key_exists(
'options-messages', $this->mParams ) ) {
1086 $this->mOptions = $this->
lookupOptionsKeys( $this->mParams[
'options-messages'] );
1087 } elseif ( array_key_exists(
'options', $this->mParams ) ) {
1088 $this->mOptionsLabelsNotFromMessage =
true;
1089 $this->mOptions = self::forceToStringRecursive( $this->mParams[
'options'] );
1090 } elseif ( array_key_exists(
'options-message', $this->mParams ) ) {
1091 $message = $this->
getMessage( $this->mParams[
'options-message'] )->inContentLanguage()->plain();
1092 $this->mOptions = Xml::listDropDownOptions( $message );
1094 $this->mOptions =
null;
1098 return $this->mOptions;
1108 if ( $oldoptions ===
null ) {
1112 return Xml::listDropDownOptionsOoui( $oldoptions );
1126 if ( is_array(
$value ) ) {
1127 $flatOpts = array_merge( $flatOpts, self::flattenOptions(
$value ) );
1147 if ( is_array( $errors ) && count( $errors ) === 1 ) {
1148 $errors = array_shift( $errors );
1151 if ( is_array( $errors ) ) {
1153 foreach ( $errors as $error ) {
1154 if ( $error instanceof
Message ) {
1155 $lines[] = Html::rawElement(
'li', [], $error->parse() );
1157 $lines[] = Html::rawElement(
'li', [], $error );
1161 return Html::rawElement(
'ul', [
'class' =>
'error' ], implode(
"\n",
$lines ) );
1163 if ( $errors instanceof
Message ) {
1164 $errors = $errors->parse();
1167 return Html::rawElement(
'span', [
'class' =>
'error' ], $errors );
1178 $message = Message::newFromSpecifier(
$value );
1180 if ( $this->mParent ) {
1181 $message->setContext( $this->mParent );
1194 return !empty( $this->mParams[
'nodata'] );
1205 if ( $this->mHideIf ) {
static titleAttrib( $name, $options=null, array $msgParams=[])
Given the id of an interface element, constructs the appropriate title attribute from the system mess...
static accesskey( $name)
Given the id of an interface element, constructs the appropriate accesskey attribute from the system ...
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
The Message class provides methods which fulfil two basic services:
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
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
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Allows to change the fields on the form that will be generated $name