14 protected $mLabel; # String label,
as HTML. Set
on construction.
78 $args = func_get_args();
80 if ( $this->mParent ) {
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;
164 $op = array_shift( $params );
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' )->parse();
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'] ) ) {
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'] ) ) {
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[
'flatlist'] ) ) {
459 $this->mClass .=
' mw-htmlform-flatlist';
462 if ( isset(
$params[
'hidelabel'] ) ) {
463 $this->mShowEmptyLabels =
false;
466 if ( isset(
$params[
'hide-if'] ) ) {
467 $this->mHideIf =
$params[
'hide-if'];
482 $fieldType = get_class( $this );
484 $cellAttributes = [];
488 if ( !empty( $this->mParams[
'vertical-label'] ) ) {
489 $cellAttributes[
'colspan'] = 2;
490 $verticalLabel =
true;
492 $verticalLabel =
false;
499 [
'class' =>
'mw-input' ] + $cellAttributes,
500 $inputHtml .
"\n$errors"
503 if ( $this->mHideIf ) {
505 $rowClasses .=
' mw-htmlform-hide-if';
508 if ( $verticalLabel ) {
510 $rowAttributes + [
'class' =>
"mw-htmlform-vertical-label $rowClasses" ], $label );
513 'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
520 'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $rowClasses"
525 return $html . $helptext;
540 $fieldType = get_class( $this );
542 $cellAttributes = [];
547 'mw-htmlform-nolabel' => ( $label ===
'' )
550 $horizontalLabel = isset( $this->mParams[
'horizontal-label'] )
551 ? $this->mParams[
'horizontal-label'] :
false;
553 if ( $horizontalLabel ) {
554 $field =
' ' . $inputHtml .
"\n$errors";
558 [
'class' => $outerDivClass ] + $cellAttributes,
559 $inputHtml .
"\n$errors"
562 $divCssClasses = [
"mw-htmlform-field-$fieldType",
565 $wrapperAttributes = [
566 'class' => $divCssClasses,
568 if ( $this->mHideIf ) {
570 $wrapperAttributes[
'class'][] =
' mw-htmlform-hide-if';
589 if ( !$inputField ) {
594 new OOUI\Widget( [
'content' =>
new OOUI\HtmlSnippet( $this->
getDiv(
$value ) ) ] ),
595 [
'infusable' =>
false,
'align' =>
'top' ]
600 if ( is_string( $inputField ) ) {
604 $inputField =
new OOUI\Widget( [
'content' =>
new OOUI\HtmlSnippet( $inputField ) ] );
608 $fieldType = get_class( $this );
611 foreach ( $errors
as &$error ) {
612 $error =
new OOUI\HtmlSnippet( $error );
616 foreach ( $notices
as &$notice ) {
617 $notice =
new OOUI\HtmlSnippet( $notice );
621 'classes' => [
"mw-htmlform-field-$fieldType",
$this->mClass ],
623 'help' => $helpText !== null ?
new OOUI\HtmlSnippet( $helpText ) : null,
625 'notices' => $notices,
626 'infusable' => $infusable,
632 $config[
'label'] =
new OOUI\HtmlSnippet( $label );
651 if ( isset( $this->mClassWithButton ) ) {
652 $buttonWidget = $this->mClassWithButton->getInputOOUI(
'' );
653 return new OOUI\ActionFieldLayout( $inputField, $buttonWidget, $config );
655 return new OOUI\FieldLayout( $inputField, $config );
671 $cellAttributes = [];
692 $this->mVFormClass =
' mw-ui-vform-field';
706 $cellAttributes = [];
709 $html =
"\n" . $errors .
725 if ( is_null( $helptext ) ) {
730 if ( $this->mHideIf ) {
732 $rowAttributes[
'class'] =
'mw-htmlform-hide-if';
735 $tdClasses = [
'htmlform-tip' ];
736 if ( $this->mHelpClass !==
false ) {
739 $row =
Html::rawElement(
'td', [
'colspan' => 2,
'class' => $tdClasses ], $helptext );
754 if ( is_null( $helptext ) ) {
758 $wrapperAttributes = [
759 'class' =>
'htmlform-tip',
761 if ( $this->mHelpClass !==
false ) {
762 $wrapperAttributes[
'class'] .=
" {$this->mHelpClass}";
764 if ( $this->mHideIf ) {
766 $wrapperAttributes[
'class'] .=
' mw-htmlform-hide-if';
792 if ( isset( $this->mParams[
'help-message'] ) ) {
793 $this->mParams[
'help-messages'] = [ $this->mParams[
'help-message'] ];
796 if ( isset( $this->mParams[
'help-messages'] ) ) {
797 foreach ( $this->mParams[
'help-messages']
as $msg ) {
800 if ( $msg->exists() ) {
801 if ( is_null( $helptext ) ) {
804 $helptext .= $this->
msg(
'word-separator' )->escaped();
806 $helptext .= $msg->parse();
809 } elseif ( isset( $this->mParams[
'help'] ) ) {
810 $helptext = $this->mParams[
'help'];
826 if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
830 $errors = self::formatErrors( $errors );
831 $errorClass =
'mw-htmlform-invalid-input';
834 return [ $errors, $errorClass ];
847 if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
851 if ( !is_array( $errors ) ) {
852 $errors = [ $errors ];
854 foreach ( $errors
as &$error ) {
855 if ( $error instanceof
Message ) {
856 $error = $error->parse();
872 if ( isset( $this->mParams[
'notice-message'] ) ) {
873 $notices[] = $this->
getMessage( $this->mParams[
'notice-message'] )->parse();
876 if ( isset( $this->mParams[
'notice-messages'] ) ) {
877 foreach ( $this->mParams[
'notice-messages']
as $msg ) {
878 $notices[] = $this->
getMessage( $msg )->parse();
880 } elseif ( isset( $this->mParams[
'notice'] ) ) {
881 $notices[] = $this->mParams[
'notice'];
895 # Don't output a for= attribute for labels with no associated input.
896 # Kind of hacky here, possibly we don't want these to be <label>s at all.
903 $labelValue = trim( $this->
getLabel() );
905 if ( $labelValue !==
' ' && $labelValue !==
'' ) {
909 $displayFormat = $this->mParent->getDisplayFormat();
911 $horizontalLabel = isset( $this->mParams[
'horizontal-label'] )
912 ? $this->mParams[
'horizontal-label'] :
false;
914 if ( $displayFormat ===
'table' ) {
917 [
'class' =>
'mw-label' ] + $cellAttributes,
919 } elseif ( $hasLabel || $this->mShowEmptyLabels ) {
920 if ( $displayFormat ===
'div' && !$horizontalLabel ) {
923 [
'class' =>
'mw-label' ] + $cellAttributes,
934 if ( isset( $this->mDefault ) ) {
947 if ( empty( $this->mParams[
'tooltip'] ) ) {
961 static $boolAttribs = [
'disabled',
'required',
'autofocus',
'multiple',
'readonly' ];
964 foreach ( $list
as $key ) {
965 if ( in_array( $key, $boolAttribs ) ) {
966 if ( !empty( $this->mParams[$key] ) ) {
969 } elseif ( isset( $this->mParams[$key] ) ) {
970 $ret[$key] = $this->mParams[$key];
987 $key = $this->
msg( $key )->plain();
1003 if ( is_array( $array ) ) {
1004 return array_map( [ __CLASS__,
'forceToStringRecursive' ], $array );
1006 return strval( $array );
1017 if ( $this->mOptions ===
false ) {
1018 if ( array_key_exists(
'options-messages', $this->mParams ) ) {
1019 $this->mOptions = $this->
lookupOptionsKeys( $this->mParams[
'options-messages'] );
1020 } elseif ( array_key_exists(
'options', $this->mParams ) ) {
1021 $this->mOptionsLabelsNotFromMessage =
true;
1022 $this->mOptions = self::forceToStringRecursive( $this->mParams[
'options'] );
1023 } elseif ( array_key_exists(
'options-message', $this->mParams ) ) {
1025 $message = $this->
getMessage( $this->mParams[
'options-message'] )->inContentLanguage()->plain();
1028 $this->mOptions = [];
1029 foreach ( explode(
"\n", $message )
as $option ) {
1030 $value = trim( $option );
1033 } elseif ( substr(
$value, 0, 1 ) ==
'*' && substr(
$value, 1, 1 ) !=
'*' ) {
1034 # A new group is starting...
1037 } elseif ( substr(
$value, 0, 2 ) ==
'**' ) {
1039 $opt = trim( substr(
$value, 2 ) );
1040 if ( $optgroup ===
false ) {
1041 $this->mOptions[$opt] = $opt;
1043 $this->mOptions[$optgroup][$opt] = $opt;
1046 # groupless reason list
1048 $this->mOptions[$option] = $option;
1052 $this->mOptions = null;
1066 if ( $oldoptions === null ) {
1072 foreach ( $oldoptions
as $text => $data ) {
1075 'label' => (
string)$text,
1093 if ( is_array( $value ) ) {
1094 $flatOpts = array_merge( $flatOpts, self::flattenOptions( $value ) );
1111 if ( is_array( $errors ) && count( $errors ) === 1 ) {
1112 $errors = array_shift( $errors );
1115 if ( is_array( $errors ) ) {
1117 foreach ( $errors
as $error ) {
1118 if ( $error instanceof
Message ) {
1127 if ( $errors instanceof
Message ) {
1128 $errors = $errors->parse();
1144 if ( $this->mParent ) {
1145 $message->setContext( $this->mParent );
1158 return !empty( $this->mParams[
'nodata'] );
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
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
the array() calling protocol came about after MediaWiki 1.4rc1.
The Message class provides methods which fulfil two basic services:
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
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
static tooltipAndAccesskeyAttribs($name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
getCheck($name)
Return true if the named value is set in the input, whatever that value is (even "0").
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
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
static escapeId($id, $options=[])
Given a value, escape it so that it can be used in an id attribute and return it. ...
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
error also a ContextSource you ll probably need to make sure the header is varied on $request
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
Allows to change the fields on the form that will be generated $name
static newFromSpecifier($value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...