Movatterモバイル変換


[0]ホーム

URL:


MediaWiki master
Html.php
Go to the documentation of this file.
1<?php
12namespaceMediaWiki\Html;
13
14useMediaWiki\Json\FormatJson;
15useMediaWiki\MainConfigNames;
16useMediaWiki\MediaWikiServices;
17useMediaWiki\Parser\Sanitizer;
18useMediaWiki\Request\ContentSecurityPolicy;
19use UnexpectedValueException;
20
43classHtml {
45privatestatic $voidElements = [
46'area' =>true,
47'base' =>true,
48'br' =>true,
49'col' =>true,
50'embed' =>true,
51'hr' =>true,
52'img' =>true,
53'input' =>true,
54'keygen' =>true,
55'link' =>true,
56'meta' =>true,
57'param' =>true,
58'source' =>true,
59'track' =>true,
60'wbr' =>true,
61 ];
62
68privatestatic $boolAttribs = [
69'async' =>true,
70'autofocus' =>true,
71'autoplay' =>true,
72'checked' =>true,
73'controls' =>true,
74'default' =>true,
75'defer' =>true,
76'disabled' =>true,
77'formnovalidate' =>true,
78'hidden' =>true,
79'ismap' =>true,
80'itemscope' =>true,
81'loop' =>true,
82'multiple' =>true,
83'muted' =>true,
84'novalidate' =>true,
85'open' =>true,
86'pubdate' =>true,
87'readonly' =>true,
88'required' =>true,
89'reversed' =>true,
90'scoped' =>true,
91'seamless' =>true,
92'selected' =>true,
93'truespeed' =>true,
94'typemustmatch' =>true,
95 ];
96
105publicstaticfunctionbuttonAttributes( array $attrs, array $modifiers = [] ) {
106wfDeprecated( __METHOD__,'1.42' );
107return $attrs;
108 }
109
117publicstaticfunctiongetTextInputAttributes( array $attrs ) {
118wfDeprecated( __METHOD__,'1.42' );
119return $attrs;
120 }
121
132publicstaticfunctionaddClass( &$classes,string $class ): void {
133 $classes = (array)$classes;
134// Detect mistakes where $attrs is passed as $classes instead of $attrs['class']
135foreach ( $classes as $key => $val ) {
136if (
137 ( is_int( $key ) && is_string( $val ) ) ||
138 ( is_string( $key ) && is_bool( $val ) )
139 ) {
140// Valid formats for class array entries
141continue;
142 }
143wfWarn( __METHOD__ .": Argument doesn't look like a class array: " . var_export( $classes,true ) );
144break;
145 }
146 $classes[] = $class;
147 }
148
159publicstaticfunctionlinkButton( $text, array $attrs, array $modifiers = [] ) {
160returnself::element(
161'a',
162 $attrs,
163 $text
164 );
165 }
166
177publicstaticfunctionsubmitButton( $contents, array $attrs = [], array $modifiers = [] ) {
178 $attrs['type'] ='submit';
179 $attrs['value'] = $contents;
180returnself::element('input', $attrs );
181 }
182
205publicstaticfunctionrawElement( $element, $attribs = [], $contents ='' ) {
206 $start = self::openElement( $element, $attribs );
207if ( isset( self::$voidElements[$element] ) ) {
208return $start;
209 }else {
210 $contents = Sanitizer::escapeCombiningChar( $contents ??'' );
211return $start . $contents . self::closeElement( $element );
212 }
213 }
214
231publicstaticfunctionelement( $element, $attribs = [], $contents ='' ) {
232return self::rawElement(
233 $element,
234 $attribs,
235 strtr( $contents ??'', [
236// There's no point in escaping quotes, >, etc. in the contents of
237// elements.
238'&' =>'&amp;',
239'<' =>'&lt;',
240 ] )
241 );
242 }
243
255publicstaticfunctionopenElement( $element, $attribs = [] ) {
256 $attribs = (array)$attribs;
257// This is not required in HTML5, but let's do it anyway, for
258// consistency and better compression.
259 $element = strtolower( $element );
260
261// Some people were abusing this by passing things like
262// 'h1 id="foo" to $element, which we don't want.
263if ( str_contains( $element,' ' ) ) {
264wfWarn( __METHOD__ ." given element name with space '$element'" );
265 }
266
267// Remove invalid input types
268if ( $element =='input' ) {
269 $validTypes = [
270'hidden' =>true,
271'text' =>true,
272'password' =>true,
273'checkbox' =>true,
274'radio' =>true,
275'file' =>true,
276'submit' =>true,
277'image' =>true,
278'reset' =>true,
279'button' =>true,
280
281// HTML input types
282'datetime' =>true,
283'datetime-local' =>true,
284'date' =>true,
285'month' =>true,
286'time' =>true,
287'week' =>true,
288'number' =>true,
289'range' =>true,
290'email' =>true,
291'url' =>true,
292'search' =>true,
293'tel' =>true,
294'color' =>true,
295 ];
296if ( isset( $attribs['type'] ) && !isset( $validTypes[$attribs['type']] ) ) {
297 unset( $attribs['type'] );
298 }
299 }
300
301// According to standard the default type for <button> elements is "submit".
302// Depending on compatibility mode IE might use "button", instead.
303// We enforce the standard "submit".
304if ( $element =='button' && !isset( $attribs['type'] ) ) {
305 $attribs['type'] ='submit';
306 }
307
308return"<$element" . self::expandAttributes(
309 self::dropDefaults( $element, $attribs ) ) .'>';
310 }
311
319publicstaticfunctioncloseElement( $element ) {
320 $element = strtolower( $element );
321
322return"</$element>";
323 }
324
342privatestaticfunction dropDefaults( $element, array $attribs ) {
343// Whenever altering this array, please provide a covering test case
344// in HtmlTest::provideElementsWithAttributesHavingDefaultValues
345static $attribDefaults = [
346'area' => ['shape' =>'rect' ],
347'button' => [
348'formaction' =>'GET',
349'formenctype' =>'application/x-www-form-urlencoded',
350 ],
351'canvas' => [
352'height' =>'150',
353'width' =>'300',
354 ],
355'form' => [
356'action' =>'GET',
357'autocomplete' =>'on',
358'enctype' =>'application/x-www-form-urlencoded',
359 ],
360'input' => [
361'formaction' =>'GET',
362'type' =>'text',
363 ],
364'keygen' => ['keytype' =>'rsa' ],
365'link' => ['media' =>'all' ],
366'menu' => ['type' =>'list' ],
367'script' => ['type' =>'text/javascript' ],
368'style' => [
369'media' =>'all',
370'type' =>'text/css',
371 ],
372'textarea' => ['wrap' =>'soft' ],
373 ];
374
375foreach ( $attribs as $attrib => $value ) {
376if ( $attrib ==='class' ) {
377if ( $value ==='' || $value === [] || $value === ['' ] ) {
378 unset( $attribs[$attrib] );
379 }
380 } elseif ( isset( $attribDefaults[$element][$attrib] ) ) {
381if ( is_array( $value ) ) {
382 $value = implode(' ', $value );
383 }else {
384 $value = strval( $value );
385 }
386if ( $attribDefaults[$element][$attrib] == $value ) {
387 unset( $attribs[$attrib] );
388 }
389 }
390 }
391
392// More subtle checks
393if ( $element ==='link'
394 && isset( $attribs['type'] ) && strval( $attribs['type'] ) =='text/css'
395 ) {
396 unset( $attribs['type'] );
397 }
398if ( $element ==='input' ) {
399 $type = $attribs['type'] ??null;
400 $value = $attribs['value'] ??null;
401if ( $type ==='checkbox' || $type ==='radio' ) {
402// The default value for checkboxes and radio buttons is 'on'
403// not ''. By stripping value="" we break radio boxes that
404// actually wants empty values.
405if ( $value ==='on' ) {
406 unset( $attribs['value'] );
407 }
408 } elseif ( $type ==='submit' ) {
409// The default value for submit appears to be "Submit" but
410// let's not bother stripping out localized text that matches
411// that.
412 }else {
413// The default value for nearly every other field type is ''
414// The 'range' and 'color' types use different defaults but
415// stripping a value="" does not hurt them.
416if ( $value ==='' ) {
417 unset( $attribs['value'] );
418 }
419 }
420 }
421if ( $element ==='select' && isset( $attribs['size'] ) ) {
422 $multiple = ( $attribs['multiple'] ?? false ) !==false ||
423 in_array('multiple', $attribs );
424 $default = $multiple ? 4 : 1;
425if ( (int)$attribs['size'] === $default ) {
426 unset( $attribs['size'] );
427 }
428 }
429
430return $attribs;
431 }
432
443publicstaticfunctionexpandClassList( $classes ): string {
444// Convert into correct array. Array can contain space-separated
445// values. Implode/explode to get those into the main array as well.
446if ( is_array( $classes ) ) {
447// If input wasn't an array, we can skip this step
448 $arrayValue = [];
449foreach ( $classes as $k => $v ) {
450if ( is_string( $v ) ) {
451// String values should be normal `[ 'foo' ]`
452// Just append them
453if ( !isset( $classes[$v] ) ) {
454// As a special case don't set 'foo' if a
455// separate 'foo' => true/false exists in the array
456// keys should be authoritative
457foreach ( explode(' ', $v ) as $part ) {
458// Normalize spacing by fixing up cases where people used
459// more than 1 space and/or a trailing/leading space
460if ( $part !=='' && $part !==' ' ) {
461 $arrayValue[] = $part;
462 }
463 }
464 }
465 } elseif ( $v ) {
466// If the value is truthy but not a string this is likely
467// an [ 'foo' => true ], falsy values don't add strings
468 $arrayValue[] = $k;
469 }
470 }
471 }else {
472 $arrayValue = explode(' ', $classes );
473// Normalize spacing by fixing up cases where people used
474// more than 1 space and/or a trailing/leading space
475 $arrayValue = array_diff( $arrayValue, ['',' ' ] );
476 }
477
478// Remove duplicates and create the string
479return implode(' ', array_unique( $arrayValue ) );
480 }
481
520publicstaticfunctionexpandAttributes( array $attribs ) {
521 $ret ='';
522foreach ( $attribs as $key => $value ) {
523// Support intuitive [ 'checked' => true/false ] form
524if ( $value ===false || $value ===null ) {
525continue;
526 }
527
528// For boolean attributes, support [ 'foo' ] instead of
529// requiring [ 'foo' => 'meaningless' ].
530if ( is_int( $key ) && isset( self::$boolAttribs[strtolower( $value )] ) ) {
531 $key = $value;
532 }
533
534// Not technically required in HTML5 but we'd like consistency
535// and better compression anyway.
536 $key = strtolower( $key );
537
538// https://www.w3.org/TR/html401/index/attributes.html ("space-separated")
539// https://www.w3.org/TR/html5/index.html#attributes-1 ("space-separated")
540 $spaceSeparatedListAttributes = [
541'class' =>true,// html4, html5
542'accesskey' =>true,// as of html5, multiple space-separated values allowed
543// html4-spec doesn't document rel= as space-separated
544// but has been used like that and is now documented as such
545// in the html5-spec.
546'rel' =>true,
547 ];
548
549// Specific features for attributes that allow a list of space-separated values
550if ( isset( $spaceSeparatedListAttributes[$key] ) ) {
551// Apply some normalization and remove duplicates
552 $value = self::expandClassList( $value );
553
554// Optimization: Skip below boolAttribs check and jump straight
555// to its `else` block. The current $spaceSeparatedListAttributes
556// block is mutually exclusive with $boolAttribs.
557// phpcs:ignore Generic.PHP.DiscourageGoto
558goto not_bool;// NOSONAR
559 } elseif ( is_array( $value ) ) {
560thrownew UnexpectedValueException("HTML attribute $key can not contain a list of values" );
561 }
562
563if ( isset( self::$boolAttribs[$key] ) ) {
564 $ret .=" $key=\"\"";
565 }else {
566// phpcs:ignore Generic.PHP.DiscourageGoto
567 not_bool:
568// Inlined from Sanitizer::encodeAttribute() for improved performance
569 $encValue = htmlspecialchars( $value, ENT_QUOTES );
570// Whitespace is normalized during attribute decoding,
571// so if we've been passed non-spaces we must encode them
572// ahead of time or they won't be preserved.
573 $encValue = strtr( $encValue, [
574"\n" =>'&#10;',
575"\r" =>'&#13;',
576"\t" =>'&#9;',
577 ] );
578 $ret .=" $key=\"$encValue\"";
579 }
580 }
581return $ret;
582 }
583
597publicstaticfunctioninlineScript( $contents, $nonce =null ) {
598if ( preg_match('/<\/?script/i', $contents ) ) {
599wfLogWarning( __METHOD__ .': Illegal character sequence found in inline script.' );
600 $contents ='/* ERROR: Invalid script */';
601 }
602
603return self::rawElement('script', [], $contents );
604 }
605
614publicstaticfunctionlinkedScript($url, $nonce =null ) {
615 $attrs = ['src' =>$url ];
616if ( $nonce !==null ) {
617 $attrs['nonce'] = $nonce;
618 } elseif ( ContentSecurityPolicy::isNonceRequired( MediaWikiServices::getInstance()->getMainConfig() ) ) {
619wfWarn("no nonce set on script. CSP will break it" );
620 }
621
622return self::element('script', $attrs );
623 }
624
637publicstaticfunctioninlineStyle( $contents, $media ='all', $attribs = [] ) {
638// Don't escape '>' since that is used
639// as direct child selector.
640// Remember, in css, there is no "x" for hexadecimal escapes, and
641// the space immediately after an escape sequence is swallowed.
642 $contents = strtr( $contents, [
643'<' =>'\3C ',
644// CDATA end tag for good measure, but the main security
645// is from escaping the '<'.
646']]>' =>'\5D\5D\3E '
647 ] );
648
649if ( preg_match('/[<&]/', $contents ) ) {
650 $contents ="/*<![CDATA[*/$contents/*]]>*/";
651 }
652
653return self::rawElement('style', [
654'media' => $media,
655 ] + $attribs, $contents );
656 }
657
666publicstaticfunctionlinkedStyle($url, $media ='all' ) {
667return self::element('link', [
668'rel' =>'stylesheet',
669'href' =>$url,
670'media' => $media,
671 ] );
672 }
673
685publicstaticfunctioninput( $name, $value ='', $type ='text', array $attribs = [] ) {
686 $attribs['type'] = $type;
687 $attribs['value'] = $value;
688 $attribs['name'] = $name;
689return self::element('input', $attribs );
690 }
691
700publicstaticfunctioncheck( $name, $checked =false, array $attribs = [] ) {
701 $value = $attribs['value'] ?? 1;
702 unset( $attribs['value'] );
703return self::element('input', [
704 ...$attribs,
705'checked' => (bool)$checked,
706'type' =>'checkbox',
707'value' => $value,
708'name' => $name,
709 ] );
710 }
711
722privatestaticfunction messageBox( $html, $className, $heading ='', $iconClassName ='' ) {
723if ( $heading !=='' ) {
724 $html = self::element('h2', [], $heading ) . $html;
725 }
726 self::addClass( $className,'cdx-message' );
727 self::addClass( $className,'cdx-message--block' );
728return self::rawElement('div', ['class' => $className ],
729 self::element('span', ['class' => [
730'cdx-message__icon',
731 $iconClassName
732 ] ] ) .
733 self::rawElement('div', [
734'class' =>'cdx-message__content'
735 ], $html )
736 );
737 }
738
754publicstaticfunctionnoticeBox( $html, $className ='', $heading ='', $iconClassName ='' ) {
755return self::messageBox( $html, [
756'cdx-message--notice',
757 $className
758 ], $heading, $iconClassName );
759 }
760
775publicstaticfunctionwarningBox( $html, $className ='' ) {
776return self::messageBox( $html, [
777'cdx-message--warning', $className ] );
778 }
779
795publicstaticfunctionerrorBox( $html, $heading ='', $className ='' ) {
796return self::messageBox( $html, [
797'cdx-message--error', $className ], $heading );
798 }
799
814publicstaticfunctionsuccessBox( $html, $className ='' ) {
815return self::messageBox( $html, [
816'cdx-message--success', $className ] );
817 }
818
827publicstaticfunctionradio( $name, $checked =false, array $attribs = [] ) {
828 $value = $attribs['value'] ?? 1;
829 unset( $attribs['value'] );
830return self::element('input', [
831 ...$attribs,
832'checked' => (bool)$checked,
833'type' =>'radio',
834'value' => $value,
835'name' => $name,
836 ] );
837 }
838
847publicstaticfunctionlabel( $label, $id, array $attribs = [] ) {
848 $attribs += [
849'for' => $id,
850 ];
851return self::element('label', $attribs, $label );
852 }
853
863publicstaticfunctionhidden( $name, $value, array $attribs = [] ) {
864return self::element('input', [
865 ...$attribs,
866'type' =>'hidden',
867'value' => $value,
868'name' => $name,
869 ] );
870 }
871
884publicstaticfunctiontextarea( $name, $value ='', array $attribs = [] ) {
885 $attribs['name'] = $name;
886
887if ( str_starts_with( $value ??'',"\n" ) ) {
888// Workaround for T14130: browsers eat the initial newline
889// assuming that it's just for show, but they do keep the later
890// newlines, which we may want to preserve during editing.
891// Prepending a single newline
892 $spacedValue ="\n" . $value;
893 }else {
894 $spacedValue = $value;
895 }
896return self::element('textarea', $attribs, $spacedValue );
897 }
898
904publicstaticfunctionnamespaceSelectorOptions( array $params = [] ) {
905if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
906 $params['exclude'] = [];
907 }
908
909if ( $params['in-user-lang'] ??false ) {
910 global$wgLang;
911 $lang =$wgLang;
912 }else {
913 $lang = MediaWikiServices::getInstance()->getContentLanguage();
914 }
915
916 $optionsOut = [];
917if ( isset( $params['all'] ) ) {
918// add an option that would let the user select all namespaces.
919// Value is provided by user, the name shown is localized for the user.
920 $optionsOut[$params['all']] =wfMessage('namespacesall' )->text();
921 }
922// Add all namespaces as options
923 $options = $lang->getFormattedNamespaces();
924// Filter out namespaces below 0 and massage labels
925foreach ( $options as $nsId => $nsName ) {
926if ( $nsId <NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
927continue;
928 }
929if (
930 isset( $params['include'] ) &&
931 is_array( $params['include'] ) &&
932 !in_array( $nsId, $params['include'] )
933 ) {
934continue;
935 }
936
937if ( $nsId ===NS_MAIN ) {
938// For other namespaces use the namespace prefix as label, but for
939// main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
940 $nsName =wfMessage('blanknamespace' )->text();
941 } elseif ( is_int( $nsId ) ) {
942 $converter = MediaWikiServices::getInstance()->getLanguageConverterFactory()
943 ->getLanguageConverter( $lang );
944 $nsName = $converter->convertNamespace( $nsId );
945 }
946 $optionsOut[$nsId] = $nsName;
947 }
948
949return $optionsOut;
950 }
951
968publicstaticfunctionnamespaceSelector(
969 array $params = [],
970 array $selectAttribs = []
971 ) {
972 ksort( $selectAttribs );
973
974// Is a namespace selected?
975if ( isset( $params['selected'] ) ) {
976// If string only contains digits, convert to clean int. Selected could also
977// be "all" or "" etc. which needs to be left untouched.
978if ( !is_int( $params['selected'] ) && ctype_digit( (string)$params['selected'] ) ) {
979 $params['selected'] = (int)$params['selected'];
980 }
981// else: leaves it untouched for later processing
982 }else {
983 $params['selected'] ='';
984 }
985
986if ( !isset( $params['disable'] ) || !is_array( $params['disable'] ) ) {
987 $params['disable'] = [];
988 }
989
990// Associative array between option-values and option-labels
991 $options = self::namespaceSelectorOptions( $params );
992
993// Convert $options to HTML
994 $optionsHtml = [];
995foreach ( $options as $nsId => $nsName ) {
996 $optionsHtml[] = self::element(
997'option',
998 [
999'disabled' => in_array( $nsId, $params['disable'] ),
1000'value' => $nsId,
1001'selected' => $nsId === $params['selected'],
1002 ],
1003 $nsName
1004 );
1005 }
1006
1007 $selectAttribs['id'] ??='namespace';
1008 $selectAttribs['name'] ??='namespace';
1009
1010 $ret ='';
1011if ( isset( $params['label'] ) ) {
1012 $ret .= self::element(
1013'label', [
1014'for' => $selectAttribs['id'],
1015 ], $params['label']
1016 ) ."\u{00A0}";
1017 }
1018
1019// Wrap options in a <select>
1020 $ret .= self::openElement('select', $selectAttribs )
1021 ."\n"
1022 . implode("\n", $optionsHtml )
1023 ."\n"
1024 . self::closeElement('select' );
1025
1026return $ret;
1027 }
1028
1037publicstaticfunctionhtmlHeader( array $attribs = [] ) {
1038 $ret ='';
1039 $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
1040 $html5Version = $mainConfig->get( MainConfigNames::Html5Version );
1041 $mimeType = $mainConfig->get( MainConfigNames::MimeType );
1042 $xhtmlNamespaces = $mainConfig->get( MainConfigNames::XhtmlNamespaces );
1043
1044 $isXHTML = self::isXmlMimeType( $mimeType );
1045
1046if ( $isXHTML ) {// XHTML5
1047// XML MIME-typed markup should have an xml header.
1048// However a DOCTYPE is not needed.
1049 $ret .="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
1050
1051// Add the standard xmlns
1052 $attribs['xmlns'] ='http://www.w3.org/1999/xhtml';
1053
1054// And support custom namespaces
1055foreach ( $xhtmlNamespaces as $tag => $ns ) {
1056 $attribs["xmlns:$tag"] = $ns;
1057 }
1058 }else {// HTML5
1059 $ret .="<!DOCTYPE html>\n";
1060 }
1061
1062if ( $html5Version ) {
1063 $attribs['version'] = $html5Version;
1064 }
1065
1066 $ret .= self::openElement('html', $attribs );
1067
1068return $ret;
1069 }
1070
1077publicstaticfunctionisXmlMimeType( $mimetype ) {
1078 # https://html.spec.whatwg.org/multipage/infrastructure.html#xml-mime-type
1079 # * text/xml
1080 # * application/xml
1081 # * Any MIME type with a subtype ending in +xml (this implicitly includes application/xhtml+xml)
1082return (bool)preg_match('!^(text|application)/xml$|^.+/.+\+xml$!', $mimetype );
1083 }
1084
1108publicstaticfunctionsrcSet( array $urls ) {
1109 $candidates = [];
1110foreach ( $urls as $density =>$url ) {
1111// Cast density to float to strip 'x', then back to string to serve
1112// as array index.
1113 $density = (string)(float)$density;
1114 $candidates[$density] =$url;
1115 }
1116
1117// Remove duplicates that are the same as a smaller value
1118 ksort( $candidates, SORT_NUMERIC );
1119 $candidates = array_unique( $candidates );
1120
1121// Append density info to the url
1122foreach ( $candidates as $density =>$url ) {
1123 $candidates[$density] =$url .' ' . $density .'x';
1124 }
1125
1126return implode(", ", $candidates );
1127 }
1128
1143publicstaticfunctionencodeJsVar( $value, $pretty =false ) {
1144if ( $value instanceofHtmlJsCode ) {
1145return $value->value;
1146 }
1147return FormatJson::encode( $value, $pretty, FormatJson::UTF8_OK );
1148 }
1149
1164publicstaticfunctionencodeJsCall( $name, $args, $pretty =false ) {
1165 $encodedArgs = self::encodeJsList( $args, $pretty );
1166if ( $encodedArgs ===false ) {
1167returnfalse;
1168 }
1169return"$name($encodedArgs);";
1170 }
1171
1181publicstaticfunctionencodeJsList( $args, $pretty =false ) {
1182foreach ( $args as &$arg ) {
1183 $arg = self::encodeJsVar( $arg, $pretty );
1184if ( $arg ===false ) {
1185returnfalse;
1186 }
1187 }
1188if ( $pretty ) {
1189return' ' . implode(', ', $args ) .' ';
1190 }else {
1191return implode(',', $args );
1192 }
1193 }
1194
1208publicstaticfunctionlistDropdownOptions( $list, $params = [] ) {
1209 $options = [];
1210
1211if ( isset( $params['other'] ) ) {
1212 $options[ $params['other'] ] ='other';
1213 }
1214
1215 $optgroup =false;
1216foreach ( explode("\n", $list ) as $option ) {
1217 $value = trim( $option );
1218if ( $value =='' ) {
1219continue;
1220 }
1221if ( str_starts_with( $value,'*' ) && !str_starts_with( $value,'**' ) ) {
1222 # A new group is starting...
1223 $value = trim( substr( $value, 1 ) );
1224if ( $value !=='' &&
1225// Do not use the value for 'other' as option group - T251351
1226 ( !isset( $params['other'] ) || $value !== $params['other'] )
1227 ) {
1228 $optgroup = $value;
1229 }else {
1230 $optgroup =false;
1231 }
1232 } elseif ( str_starts_with( $value,'**' ) ) {
1233 # groupmember
1234 $opt = trim( substr( $value, 2 ) );
1235if ( $optgroup ===false ) {
1236 $options[$opt] = $opt;
1237 }else {
1238 $options[$optgroup][$opt] = $opt;
1239 }
1240 }else {
1241 # groupless reason list
1242 $optgroup =false;
1243 $options[$option] = $option;
1244 }
1245 }
1246
1247return $options;
1248 }
1249
1258publicstaticfunctionlistDropdownOptionsOoui( $options ) {
1259 $optionsOoui = [];
1260
1261foreach ( $options as $text => $value ) {
1262if ( is_array( $value ) ) {
1263 $optionsOoui[] = ['optgroup' => (string)$text ];
1264foreach ( $value as $text2 => $value2 ) {
1265 $optionsOoui[] = ['data' => (string)$value2,'label' => (string)$text2 ];
1266 }
1267 }else {
1268 $optionsOoui[] = ['data' => (string)$value,'label' => (string)$text ];
1269 }
1270 }
1271
1272return $optionsOoui;
1273 }
1274
1283publicstaticfunctionlistDropdownOptionsCodex( $options ) {
1284 $optionsCodex = [];
1285
1286foreach ( $options as $text => $value ) {
1287if ( is_array( $value ) ) {
1288 $optionsCodex[] = [
1289'label' => (string)$text,
1290'items' => array_map(staticfunction ( $text2, $value2 ) {
1291return ['label' => (string)$text2,'value' => (string)$value2 ];
1292 }, array_keys( $value ), $value )
1293 ];
1294 }else {
1295 $optionsCodex[] = ['label' => (string)$text,'value' => (string)$value ];
1296 }
1297 }
1298return $optionsCodex;
1299 }
1300}
NS_MAIN
const NS_MAIN
DefinitionDefines.php:51
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
DefinitionGlobalFunctions.php:781
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
DefinitionGlobalFunctions.php:794
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
DefinitionGlobalFunctions.php:820
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
DefinitionGlobalFunctions.php:735
$wgLang
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
DefinitionSetup.php:551
if
if(!defined('MW_SETUP_CALLBACK'))
DefinitionWebStart.php:68
MediaWiki\Html\HtmlJsCode
A wrapper class which causes Html::encodeJsVar() and Html::encodeJsCall() (as well as their Xml::* co...
DefinitionHtmlJsCode.php:28
MediaWiki\Html\Html
This class is a collection of static functions that serve two purposes:
DefinitionHtml.php:43
MediaWiki\Html\Html\linkedScript
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
DefinitionHtml.php:614
MediaWiki\Html\Html\listDropdownOptionsOoui
static listDropdownOptionsOoui( $options)
Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc.
DefinitionHtml.php:1258
MediaWiki\Html\Html\namespaceSelector
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
DefinitionHtml.php:968
MediaWiki\Html\Html\warningBox
static warningBox( $html, $className='')
Return a warning box.
DefinitionHtml.php:775
MediaWiki\Html\Html\check
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
DefinitionHtml.php:700
MediaWiki\Html\Html\encodeJsVar
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
DefinitionHtml.php:1143
MediaWiki\Html\Html\listDropdownOptionsCodex
static listDropdownOptionsCodex( $options)
Convert options for a drop-down box into a format accepted by OOUI\DropdownInputWidget etc.
DefinitionHtml.php:1283
MediaWiki\Html\Html\label
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
DefinitionHtml.php:847
MediaWiki\Html\Html\expandAttributes
static expandAttributes(array $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
DefinitionHtml.php:520
MediaWiki\Html\Html\srcSet
static srcSet(array $urls)
Generate a srcset attribute value.
DefinitionHtml.php:1108
MediaWiki\Html\Html\noticeBox
static noticeBox( $html, $className='', $heading='', $iconClassName='')
Return the HTML for a notice message box.
DefinitionHtml.php:754
MediaWiki\Html\Html\successBox
static successBox( $html, $className='')
Return a success box.
DefinitionHtml.php:814
MediaWiki\Html\Html\buttonAttributes
static buttonAttributes(array $attrs, array $modifiers=[])
Modifies a set of attributes meant for button elements.
DefinitionHtml.php:105
MediaWiki\Html\Html\encodeJsCall
static encodeJsCall( $name, $args, $pretty=false)
Create a call to a JavaScript function.
DefinitionHtml.php:1164
MediaWiki\Html\Html\htmlHeader
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
DefinitionHtml.php:1037
MediaWiki\Html\Html\errorBox
static errorBox( $html, $heading='', $className='')
Return an error box.
DefinitionHtml.php:795
MediaWiki\Html\Html\inlineScript
static inlineScript( $contents, $nonce=null)
Output an HTML script tag with the given contents.
DefinitionHtml.php:597
MediaWiki\Html\Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
DefinitionHtml.php:255
MediaWiki\Html\Html\radio
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
DefinitionHtml.php:827
MediaWiki\Html\Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
DefinitionHtml.php:205
MediaWiki\Html\Html\isXmlMimeType
static isXmlMimeType( $mimetype)
Determines if the given MIME type is xml.
DefinitionHtml.php:1077
MediaWiki\Html\Html\getTextInputAttributes
static getTextInputAttributes(array $attrs)
Modifies a set of attributes meant for text input elements.
DefinitionHtml.php:117
MediaWiki\Html\Html\expandClassList
static expandClassList( $classes)
Convert a value for a 'class' attribute in a format accepted by Html::element() and similar methods t...
DefinitionHtml.php:443
MediaWiki\Html\Html\input
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an <input> element.
DefinitionHtml.php:685
MediaWiki\Html\Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
DefinitionHtml.php:863
MediaWiki\Html\Html\textarea
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
DefinitionHtml.php:884
MediaWiki\Html\Html\namespaceSelectorOptions
static namespaceSelectorOptions(array $params=[])
Helper for Html::namespaceSelector().
DefinitionHtml.php:904
MediaWiki\Html\Html\inlineStyle
static inlineStyle( $contents, $media='all', $attribs=[])
Output a "<style>" tag with the given contents for the given media type (if any).
DefinitionHtml.php:637
MediaWiki\Html\Html\closeElement
static closeElement( $element)
Returns "</$element>".
DefinitionHtml.php:319
MediaWiki\Html\Html\linkButton
static linkButton( $text, array $attrs, array $modifiers=[])
Returns an HTML link element in a string.
DefinitionHtml.php:159
MediaWiki\Html\Html\submitButton
static submitButton( $contents, array $attrs=[], array $modifiers=[])
Returns an HTML input element in a string.
DefinitionHtml.php:177
MediaWiki\Html\Html\encodeJsList
static encodeJsList( $args, $pretty=false)
Encode a JavaScript comma-separated list.
DefinitionHtml.php:1181
MediaWiki\Html\Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
DefinitionHtml.php:231
MediaWiki\Html\Html\listDropdownOptions
static listDropdownOptions( $list, $params=[])
Build options for a drop-down box from a textual list.
DefinitionHtml.php:1208
MediaWiki\Html\Html\linkedStyle
static linkedStyle( $url, $media='all')
Output a "<link rel=stylesheet>" linking to the given URL for the given media type (if any).
DefinitionHtml.php:666
MediaWiki\Html\Html\addClass
static addClass(&$classes, string $class)
Add a class to a 'class' attribute in a format accepted by Html::element().
DefinitionHtml.php:132
MediaWiki\Json\FormatJson
JSON formatter wrapper class.
DefinitionFormatJson.php:16
MediaWiki\MainConfigNames
A class containing constants representing the names of configuration variables.
DefinitionMainConfigNames.php:22
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
DefinitionMediaWikiServices.php:256
MediaWiki\Parser\Sanitizer
HTML sanitizer for MediaWiki.
DefinitionSanitizer.php:32
MediaWiki\Request\ContentSecurityPolicy
Handle sending Content-Security-Policy headers.
DefinitionContentSecurityPolicy.php:23
MediaWiki\Html
DefinitionFormOptions.php:15
MediaWiki\Html\element
element(SerializerNode $parent, SerializerNode $node, $contents)
DefinitionHtmlHelperTrait.php:38
$url
$url
Definitionopensearch_desc.php:23

[8]ページ先頭

©2009-2025 Movatter.jp