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 if ( !is_array(
$data ) || !array_key_exists( $key,
$data ) ) {
169 if ( !is_array( $p ) ) {
171 "Expected array, found " . gettype( $p ) .
" at index $i"
182 if ( !is_array( $p ) ) {
184 "Expected array, found " . gettype( $p ) .
" at index $i"
195 if ( !is_array( $p ) ) {
197 "Expected array, found " . gettype( $p ) .
" at index $i"
208 if ( !is_array( $p ) ) {
210 "Expected array, found " . gettype( $p ) .
" at index $i"
220 if ( count(
$params ) !== 1 ) {
221 throw new MWException(
"NOT takes exactly one parameter" );
224 if ( !is_array( $p ) ) {
226 "Expected array, found " . gettype( $p ) .
" at index 0"
233 if ( count(
$params ) !== 2 ) {
234 throw new MWException(
"$op takes exactly two parameters" );
237 if ( !is_string( $field ) || !is_string(
$value ) ) {
238 throw new MWException(
"Parameters for $op must be strings" );
243 return (
$value === $testValue );
245 return (
$value !== $testValue );
251 }
catch ( Exception $ex ) {
253 "Invalid hide-if specification for $this->mName: " .
254 $ex->getMessage() .
" in " . var_export( $origParams,
true ),
269 if ( !$this->mHideIf ) {
302 if ( $this->
isHidden( $alldata ) ) {
306 if ( isset( $this->mParams[
'required'] )
307 && $this->mParams[
'required'] !==
false
310 return $this->
msg(
'htmlform-required' );
313 if ( isset( $this->mValidationCallback ) ) {
314 return ( $this->mValidationCallback )(
$value, $alldata, $this->mParent );
321 if ( isset( $this->mFilterCallback ) ) {
322 $value = ( $this->mFilterCallback )(
$value, $alldata, $this->mParent );
348 $this->mShowEmptyLabels = $show;
362 return $request->getCheck(
'wpEditToken' ) ||
$request->getCheck(
'wpFormIdentifier' );
373 if (
$request->getCheck( $this->mName ) ) {
374 return $request->getText( $this->mName );
392 $this->mParent =
$params[
'parent'];
395 # Generate the label from a message, if possible
396 if ( isset(
$params[
'label-message'] ) ) {
398 } elseif ( isset(
$params[
'label'] ) ) {
399 if (
$params[
'label'] ===
' ' ||
$params[
'label'] ===
"\u{00A0}" ) {
401 $this->mLabel =
"\u{00A0}";
403 $this->mLabel = htmlspecialchars(
$params[
'label'] );
405 } elseif ( isset(
$params[
'label-raw'] ) ) {
406 $this->mLabel =
$params[
'label-raw'];
409 $this->mName =
"wp{$params['fieldname']}";
410 if ( isset(
$params[
'name'] ) ) {
411 $this->mName =
$params[
'name'];
414 if ( isset(
$params[
'dir'] ) ) {
418 $validName = urlencode( $this->mName );
419 $validName = str_replace( [
'%5B',
'%5D' ], [
'[',
']' ], $validName );
420 if ( $this->mName != $validName && !isset(
$params[
'nodata'] ) ) {
421 throw new MWException(
"Invalid name '{$this->mName}' passed to " . __METHOD__ );
424 $this->mID =
"mw-input-{$this->mName}";
426 if ( isset(
$params[
'default'] ) ) {
427 $this->mDefault =
$params[
'default'];
430 if ( isset(
$params[
'id'] ) ) {
432 $validId = urlencode( $id );
434 if ( $id != $validId ) {
435 throw new MWException(
"Invalid id '$id' passed to " . __METHOD__ );
441 if ( isset(
$params[
'cssclass'] ) ) {
442 $this->mClass =
$params[
'cssclass'];
445 if ( isset(
$params[
'csshelpclass'] ) ) {
446 $this->mHelpClass =
$params[
'csshelpclass'];
449 if ( isset(
$params[
'validation-callback'] ) ) {
450 $this->mValidationCallback =
$params[
'validation-callback'];
453 if ( isset(
$params[
'filter-callback'] ) ) {
454 $this->mFilterCallback =
$params[
'filter-callback'];
457 if ( isset(
$params[
'hidelabel'] ) ) {
458 $this->mShowEmptyLabels =
false;
461 if ( isset(
$params[
'hide-if'] ) ) {
462 $this->mHideIf =
$params[
'hide-if'];
477 $fieldType = static::class;
479 $cellAttributes = [];
483 if ( !empty( $this->mParams[
'vertical-label'] ) ) {
484 $cellAttributes[
'colspan'] = 2;
485 $verticalLabel =
true;
487 $verticalLabel =
false;
492 $field = Html::rawElement(
494 [
'class' =>
'mw-input' ] + $cellAttributes,
495 $inputHtml .
"\n$errors"
498 if ( $this->mHideIf ) {
499 $rowAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
500 $rowClasses .=
' mw-htmlform-hide-if';
503 if ( $verticalLabel ) {
504 $html = Html::rawElement(
'tr',
505 $rowAttributes + [
'class' =>
"mw-htmlform-vertical-label $rowClasses" ], $label );
506 $html .= Html::rawElement(
'tr',
508 'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
513 Html::rawElement(
'tr',
515 'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
520 return $html . $helptext;
535 $fieldType = static::class;
537 $cellAttributes = [];
542 'mw-htmlform-nolabel' => ( $label ===
'' )
545 $horizontalLabel = $this->mParams[
'horizontal-label'] ??
false;
547 if ( $horizontalLabel ) {
548 $field =
"\u{00A0}" . $inputHtml .
"\n$errors";
550 $field = Html::rawElement(
552 [
'class' => $outerDivClass ] + $cellAttributes,
553 $inputHtml .
"\n$errors"
556 $divCssClasses = [
"mw-htmlform-field-$fieldType",
557 $this->mClass, $this->mVFormClass, $errorClass ];
559 $wrapperAttributes = [
560 'class' => $divCssClasses,
562 if ( $this->mHideIf ) {
563 $wrapperAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
564 $wrapperAttributes[
'class'][] =
' mw-htmlform-hide-if';
566 $html = Html::rawElement(
'div', $wrapperAttributes, $label . $field );
583 if ( !$inputField ) {
588 new OOUI\Widget( [
'content' =>
new OOUI\HtmlSnippet( $this->
getDiv(
$value ) ) ] ),
594 if ( is_string( $inputField ) ) {
598 $inputField =
new OOUI\Widget( [
'content' =>
new OOUI\HtmlSnippet( $inputField ) ] );
602 $fieldType = static::class;
605 foreach ( $errors
as &$error ) {
606 $error =
new OOUI\HtmlSnippet( $error );
610 'classes' => [
"mw-htmlform-field-$fieldType", $this->mClass ],
612 'help' => (
$help !==
null &&
$help !==
'' ) ?
new OOUI\HtmlSnippet(
$help ) :
null,
614 'infusable' => $infusable,
618 $preloadModules =
false;
621 $preloadModules =
true;
622 $config[
'classes'][] =
'mw-htmlform-field-autoinfuse';
627 if ( $label && $label !==
"\u{00A0}" && $label !==
' ' ) {
628 $config[
'label'] =
new OOUI\HtmlSnippet( $label );
631 if ( $this->mHideIf ) {
632 $preloadModules =
true;
633 $config[
'hideIf'] = $this->mHideIf;
638 if ( $preloadModules ) {
639 $this->mParent->getOutput()->addModules(
'mediawiki.htmlform.ooui' );
640 $this->mParent->getOutput()->addModules( $this->
getOOUIModules() );
661 if ( isset( $this->mClassWithButton ) ) {
662 $buttonWidget = $this->mClassWithButton->getInputOOUI(
'' );
703 $cellAttributes = [];
724 $this->mVFormClass =
' mw-ui-vform-field';
738 $cellAttributes = [];
741 $html =
"\n" . $errors .
742 $label .
"\u{00A0}" .
757 if ( is_null( $helptext ) ) {
762 if ( $this->mHideIf ) {
763 $rowAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
764 $rowAttributes[
'class'] =
'mw-htmlform-hide-if';
767 $tdClasses = [
'htmlform-tip' ];
768 if ( $this->mHelpClass !==
false ) {
769 $tdClasses[] = $this->mHelpClass;
771 $row = Html::rawElement(
'td', [
'colspan' => 2,
'class' => $tdClasses ], $helptext );
772 $row = Html::rawElement(
'tr', $rowAttributes, $row );
786 if ( is_null( $helptext ) ) {
790 $wrapperAttributes = [
791 'class' =>
'htmlform-tip',
793 if ( $this->mHelpClass !==
false ) {
794 $wrapperAttributes[
'class'] .=
" {$this->mHelpClass}";
796 if ( $this->mHideIf ) {
797 $wrapperAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
798 $wrapperAttributes[
'class'] .=
' mw-htmlform-hide-if';
800 $div = Html::rawElement(
'div', $wrapperAttributes, $helptext );
824 if ( isset( $this->mParams[
'help-message'] ) ) {
825 $this->mParams[
'help-messages'] = [ $this->mParams[
'help-message'] ];
828 if ( isset( $this->mParams[
'help-messages'] ) ) {
829 foreach ( $this->mParams[
'help-messages']
as $msg ) {
832 if ( $msg->exists() ) {
833 if ( is_null( $helptext ) ) {
836 $helptext .= $this->
msg(
'word-separator' )->escaped();
838 $helptext .= $msg->parse();
841 } elseif ( isset( $this->mParams[
'help'] ) ) {
842 $helptext = $this->mParams[
'help'];
857 return $this->mParams[
'help-inline'] ??
true;
875 if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
879 $errors = self::formatErrors( $errors );
880 $errorClass =
'mw-htmlform-invalid-input';
883 return [ $errors, $errorClass ];
896 if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
900 if ( !is_array( $errors ) ) {
901 $errors = [ $errors ];
903 foreach ( $errors
as &$error ) {
904 if ( $error instanceof
Message ) {
905 $error = $error->parse();
916 return $this->mLabel ??
'';
920 # Don't output a for= attribute for labels with no associated input.
921 # Kind of hacky here, possibly we don't want these to be <label>s at all.
925 $for[
'for'] = $this->mID;
928 $labelValue = trim( $this->
getLabel() );
930 if ( $labelValue !==
"\u{00A0}" && $labelValue !==
' ' && $labelValue !==
'' ) {
934 $displayFormat = $this->mParent->getDisplayFormat();
936 $horizontalLabel = $this->mParams[
'horizontal-label'] ??
false;
938 if ( $displayFormat ===
'table' ) {
940 Html::rawElement(
'td',
941 [
'class' =>
'mw-label' ] + $cellAttributes,
942 Html::rawElement(
'label', $for, $labelValue ) );
943 } elseif ( $hasLabel || $this->mShowEmptyLabels ) {
944 if ( $displayFormat ===
'div' && !$horizontalLabel ) {
946 Html::rawElement(
'div',
947 [
'class' =>
'mw-label' ] + $cellAttributes,
948 Html::rawElement(
'label', $for, $labelValue ) );
950 $html = Html::rawElement(
'label', $for, $labelValue );
958 return $this->mDefault ??
null;
967 if ( empty( $this->mParams[
'tooltip'] ) ) {
980 if ( empty( $this->mParams[
'tooltip'] ) ) {
997 static $boolAttribs = [
'disabled',
'required',
'autofocus',
'multiple',
'readonly' ];
1000 foreach ( $list
as $key ) {
1001 if ( in_array( $key, $boolAttribs ) ) {
1002 if ( !empty( $this->mParams[$key] ) ) {
1005 } elseif ( isset( $this->mParams[$key] ) ) {
1006 $ret[$key] = $this->mParams[$key];
1023 $key = $this->
msg( $key )->plain();
1039 if ( is_array( $array ) ) {
1040 return array_map( [ __CLASS__,
'forceToStringRecursive' ], $array );
1042 return strval( $array );
1053 if ( $this->mOptions ===
false ) {
1054 if ( array_key_exists(
'options-messages', $this->mParams ) ) {
1055 $this->mOptions = $this->
lookupOptionsKeys( $this->mParams[
'options-messages'] );
1056 } elseif ( array_key_exists(
'options', $this->mParams ) ) {
1057 $this->mOptionsLabelsNotFromMessage =
true;
1058 $this->mOptions = self::forceToStringRecursive( $this->mParams[
'options'] );
1059 } elseif ( array_key_exists(
'options-message', $this->mParams ) ) {
1060 $message = $this->
getMessage( $this->mParams[
'options-message'] )->inContentLanguage()->plain();
1061 $this->mOptions = Xml::listDropDownOptions( $message );
1063 $this->mOptions =
null;
1067 return $this->mOptions;
1077 if ( $oldoptions ===
null ) {
1081 return Xml::listDropDownOptionsOoui( $oldoptions );
1095 if ( is_array(
$value ) ) {
1096 $flatOpts = array_merge( $flatOpts, self::flattenOptions(
$value ) );
1122 if ( is_array( $errors ) && count( $errors ) === 1 ) {
1123 $errors = array_shift( $errors );
1126 if ( is_array( $errors ) ) {
1128 foreach ( $errors
as $error ) {
1129 if ( $error instanceof
Message ) {
1130 $lines[] = Html::rawElement(
'li', [], $error->parse() );
1132 $lines[] = Html::rawElement(
'li', [], $error );
1136 return Html::rawElement(
'ul', [
'class' =>
'error' ], implode(
"\n",
$lines ) );
1138 if ( $errors instanceof
Message ) {
1139 $errors = $errors->parse();
1142 return Html::rawElement(
'span', [
'class' =>
'error' ], $errors );
1153 $message = Message::newFromSpecifier(
$value );
1155 if ( $this->mParent ) {
1156 $message->setContext( $this->mParent );
1169 return !empty( $this->mParams[
'nodata'] );
1180 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
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
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
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
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going on
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
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))