14 protected $mLabel; # String label, as HTML. Set on construction.
80 public function msg() {
81 $args = func_get_args();
83 if ( $this->mParent ) {
84 return $this->mParent->msg( ...
$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 ( $this->mValidationCallback )(
$value, $alldata, $this->mParent );
322 if ( isset( $this->mFilterCallback ) ) {
323 $value = ( $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'] ===
' ' ||
$params[
'label'] ===
"\u{00A0}" ) {
402 $this->mLabel =
"\u{00A0}";
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'];
466 if ( isset( $this->mParams[
'notice-message'] ) ) {
467 wfDeprecated(
"'notice-message' parameter in HTMLForm",
'1.32' );
469 if ( isset( $this->mParams[
'notice-messages'] ) ) {
470 wfDeprecated(
"'notice-messages' parameter in HTMLForm",
'1.32' );
472 if ( isset( $this->mParams[
'notice'] ) ) {
473 wfDeprecated(
"'notice' parameter in HTMLForm",
'1.32' );
488 $fieldType = static::class;
490 $cellAttributes = [];
494 if ( !empty( $this->mParams[
'vertical-label'] ) ) {
495 $cellAttributes[
'colspan'] = 2;
496 $verticalLabel =
true;
498 $verticalLabel =
false;
503 $field = Html::rawElement(
505 [
'class' =>
'mw-input' ] + $cellAttributes,
506 $inputHtml .
"\n$errors"
509 if ( $this->mHideIf ) {
510 $rowAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
511 $rowClasses .=
' mw-htmlform-hide-if';
514 if ( $verticalLabel ) {
515 $html = Html::rawElement(
'tr',
516 $rowAttributes + [
'class' =>
"mw-htmlform-vertical-label $rowClasses" ], $label );
517 $html .= Html::rawElement(
'tr',
519 'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
524 Html::rawElement(
'tr',
526 'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
531 return $html . $helptext;
546 $fieldType = static::class;
548 $cellAttributes = [];
553 'mw-htmlform-nolabel' => ( $label ===
'' )
556 $horizontalLabel = $this->mParams[
'horizontal-label'] ??
false;
558 if ( $horizontalLabel ) {
559 $field =
"\u{00A0}" . $inputHtml .
"\n$errors";
561 $field = Html::rawElement(
563 [
'class' => $outerDivClass ] + $cellAttributes,
564 $inputHtml .
"\n$errors"
567 $divCssClasses = [
"mw-htmlform-field-$fieldType",
568 $this->mClass, $this->mVFormClass, $errorClass ];
570 $wrapperAttributes = [
571 'class' => $divCssClasses,
573 if ( $this->mHideIf ) {
574 $wrapperAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
575 $wrapperAttributes[
'class'][] =
' mw-htmlform-hide-if';
577 $html = Html::rawElement(
'div', $wrapperAttributes, $label . $field );
594 if ( !$inputField ) {
599 new OOUI\Widget( [
'content' =>
new OOUI\HtmlSnippet( $this->
getDiv(
$value ) ) ] ),
600 [
'infusable' =>
false,
'align' =>
'top' ]
605 if ( is_string( $inputField ) ) {
609 $inputField =
new OOUI\Widget( [
'content' =>
new OOUI\HtmlSnippet( $inputField ) ] );
613 $fieldType = static::class;
616 foreach ( $errors as &$error ) {
617 $error =
new OOUI\HtmlSnippet( $error );
620 $notices = $this->
getNotices(
'skip deprecation' );
621 foreach ( $notices as &$notice ) {
622 $notice =
new OOUI\HtmlSnippet( $notice );
626 'classes' => [
"mw-htmlform-field-$fieldType", $this->mClass ],
628 'help' => (
$help !==
null &&
$help !==
'' ) ?
new OOUI\HtmlSnippet(
$help ) :
null,
630 'notices' => $notices,
631 'infusable' => $infusable,
635 $preloadModules =
false;
638 $preloadModules =
true;
639 $config[
'classes'][] =
'mw-htmlform-field-autoinfuse';
644 if ( $label && $label !==
"\u{00A0}" && $label !==
' ' ) {
645 $config[
'label'] =
new OOUI\HtmlSnippet( $label );
648 if ( $this->mHideIf ) {
649 $preloadModules =
true;
650 $config[
'hideIf'] = $this->mHideIf;
655 if ( $preloadModules ) {
656 $this->mParent->getOutput()->addModules(
'mediawiki.htmlform.ooui' );
657 $this->mParent->getOutput()->addModules( $this->
getOOUIModules() );
678 if ( isset( $this->mClassWithButton ) ) {
679 $buttonWidget = $this->mClassWithButton->getInputOOUI(
'' );
720 $cellAttributes = [];
741 $this->mVFormClass =
' mw-ui-vform-field';
755 $cellAttributes = [];
758 $html =
"\n" . $errors .
759 $label .
"\u{00A0}" .
774 if ( is_null( $helptext ) ) {
779 if ( $this->mHideIf ) {
780 $rowAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
781 $rowAttributes[
'class'] =
'mw-htmlform-hide-if';
784 $tdClasses = [
'htmlform-tip' ];
785 if ( $this->mHelpClass !==
false ) {
786 $tdClasses[] = $this->mHelpClass;
788 $row = Html::rawElement(
'td', [
'colspan' => 2,
'class' => $tdClasses ], $helptext );
789 $row = Html::rawElement(
'tr', $rowAttributes, $row );
803 if ( is_null( $helptext ) ) {
807 $wrapperAttributes = [
808 'class' =>
'htmlform-tip',
810 if ( $this->mHelpClass !==
false ) {
811 $wrapperAttributes[
'class'] .=
" {$this->mHelpClass}";
813 if ( $this->mHideIf ) {
814 $wrapperAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
815 $wrapperAttributes[
'class'] .=
' mw-htmlform-hide-if';
817 $div = Html::rawElement(
'div', $wrapperAttributes, $helptext );
841 if ( isset( $this->mParams[
'help-message'] ) ) {
842 $this->mParams[
'help-messages'] = [ $this->mParams[
'help-message'] ];
845 if ( isset( $this->mParams[
'help-messages'] ) ) {
846 foreach ( $this->mParams[
'help-messages'] as $msg ) {
849 if ( $msg->exists() ) {
850 if ( is_null( $helptext ) ) {
853 $helptext .= $this->
msg(
'word-separator' )->escaped();
855 $helptext .= $msg->parse();
858 } elseif ( isset( $this->mParams[
'help'] ) ) {
859 $helptext = $this->mParams[
'help'];
874 return $this->mParams[
'help-inline'] ??
true;
892 if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
896 $errors = self::formatErrors( $errors );
897 $errorClass =
'mw-htmlform-invalid-input';
900 return [ $errors, $errorClass ];
913 if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
917 if ( !is_array( $errors ) ) {
918 $errors = [ $errors ];
920 foreach ( $errors as &$error ) {
921 if ( $error instanceof
Message ) {
922 $error = $error->parse();
939 if ( $skipDeprecation !==
'skip deprecation' ) {
945 if ( isset( $this->mParams[
'notice-message'] ) ) {
946 $notices[] = $this->
getMessage( $this->mParams[
'notice-message'] )->parse();
949 if ( isset( $this->mParams[
'notice-messages'] ) ) {
950 foreach ( $this->mParams[
'notice-messages'] as $msg ) {
951 $notices[] = $this->
getMessage( $msg )->parse();
953 } elseif ( isset( $this->mParams[
'notice'] ) ) {
954 $notices[] = $this->mParams[
'notice'];
964 return $this->mLabel ??
'';
968 # Don't output a for= attribute for labels with no associated input.
969 # Kind of hacky here, possibly we don't want these to be <label>s at all.
973 $for[
'for'] = $this->mID;
976 $labelValue = trim( $this->
getLabel() );
978 if ( $labelValue !==
"\u{00A0}" && $labelValue !==
' ' && $labelValue !==
'' ) {
982 $displayFormat = $this->mParent->getDisplayFormat();
984 $horizontalLabel = $this->mParams[
'horizontal-label'] ??
false;
986 if ( $displayFormat ===
'table' ) {
988 Html::rawElement(
'td',
989 [
'class' =>
'mw-label' ] + $cellAttributes,
990 Html::rawElement(
'label', $for, $labelValue ) );
991 } elseif ( $hasLabel || $this->mShowEmptyLabels ) {
992 if ( $displayFormat ===
'div' && !$horizontalLabel ) {
994 Html::rawElement(
'div',
995 [
'class' =>
'mw-label' ] + $cellAttributes,
996 Html::rawElement(
'label', $for, $labelValue ) );
998 $html = Html::rawElement(
'label', $for, $labelValue );
1006 return $this->mDefault ??
null;
1015 if ( empty( $this->mParams[
'tooltip'] ) ) {
1028 if ( empty( $this->mParams[
'tooltip'] ) ) {
1045 static $boolAttribs = [
'disabled',
'required',
'autofocus',
'multiple',
'readonly' ];
1048 foreach ( $list as $key ) {
1049 if ( in_array( $key, $boolAttribs ) ) {
1050 if ( !empty( $this->mParams[$key] ) ) {
1053 } elseif ( isset( $this->mParams[$key] ) ) {
1054 $ret[$key] = $this->mParams[$key];
1071 $key = $this->
msg( $key )->plain();
1087 if ( is_array( $array ) ) {
1088 return array_map( [ __CLASS__,
'forceToStringRecursive' ], $array );
1090 return strval( $array );
1101 if ( $this->mOptions ===
false ) {
1102 if ( array_key_exists(
'options-messages', $this->mParams ) ) {
1103 $this->mOptions = $this->
lookupOptionsKeys( $this->mParams[
'options-messages'] );
1104 } elseif ( array_key_exists(
'options', $this->mParams ) ) {
1105 $this->mOptionsLabelsNotFromMessage =
true;
1106 $this->mOptions = self::forceToStringRecursive( $this->mParams[
'options'] );
1107 } elseif ( array_key_exists(
'options-message', $this->mParams ) ) {
1108 $message = $this->
getMessage( $this->mParams[
'options-message'] )->inContentLanguage()->plain();
1109 $this->mOptions = Xml::listDropDownOptions( $message );
1111 $this->mOptions =
null;
1115 return $this->mOptions;
1125 if ( $oldoptions ===
null ) {
1129 return Xml::listDropDownOptionsOoui( $oldoptions );
1143 if ( is_array(
$value ) ) {
1144 $flatOpts = array_merge( $flatOpts, self::flattenOptions(
$value ) );
1170 if ( is_array( $errors ) && count( $errors ) === 1 ) {
1171 $errors = array_shift( $errors );
1174 if ( is_array( $errors ) ) {
1176 foreach ( $errors as $error ) {
1177 if ( $error instanceof
Message ) {
1178 $lines[] = Html::rawElement(
'li', [], $error->parse() );
1180 $lines[] = Html::rawElement(
'li', [], $error );
1184 return Html::rawElement(
'ul', [
'class' =>
'error' ], implode(
"\n",
$lines ) );
1186 if ( $errors instanceof
Message ) {
1187 $errors = $errors->parse();
1190 return Html::rawElement(
'span', [
'class' =>
'error' ], $errors );
1201 $message = Message::newFromSpecifier(
$value );
1203 if ( $this->mParent ) {
1204 $message->setContext( $this->mParent );
1217 return !empty( $this->mParams[
'nodata'] );
1228 if ( $this->mHideIf ) {
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
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
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))