| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Xml; |
| 24 |
|
| 25 |
use MediaWiki\Html\Html; |
| 26 |
use MediaWiki\Languages\LanguageNameUtils; |
| 27 |
use MediaWiki\MainConfigNames; |
| 28 |
use MediaWiki\MediaWikiServices; |
| 29 |
use MediaWiki\Message\Message; |
| 30 |
use MediaWiki\Parser\Sanitizer; |
| 31 |
use MediaWiki\Utils\MWTimestamp; |
| 32 |
use UtfNormal\Validator; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
class Xml { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static function element( $element, $attribs = null, $contents = '', |
| 55 |
$allowShortTag = true |
| 56 |
) { |
| 57 |
$out = '<' . $element; |
| 58 |
if ( $attribs !== null ) { |
| 59 |
$out .= self::expandAttributes( $attribs ); |
| 60 |
} |
| 61 |
if ( $contents === null ) { |
| 62 |
$out .= '>'; |
| 63 |
} elseif ( $allowShortTag && $contents === '' ) { |
| 64 |
$out .= ' />'; |
| 65 |
} else { |
| 66 |
$out .= '>' . htmlspecialchars( $contents, ENT_NOQUOTES ) . "</$element>"; |
| 67 |
} |
| 68 |
return $out; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public static function expandAttributes( ?array $attribs ) { |
| 80 |
if ( $attribs === null ) { |
| 81 |
return null; |
| 82 |
} |
| 83 |
$out = ''; |
| 84 |
foreach ( $attribs as $name => $val ) { |
| 85 |
$out .= " {$name}=\"" . Sanitizer::encodeAttribute( $val ) . '"'; |
| 86 |
} |
| 87 |
return $out; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public static function elementClean( $element, $attribs = [], $contents = '' ) { |
| 102 |
if ( $attribs ) { |
| 103 |
$attribs = array_map( [ Validator::class, 'cleanUp' ], $attribs ); |
| 104 |
} |
| 105 |
if ( $contents ) { |
| 106 |
$contents = |
| 107 |
MediaWikiServices::getInstance()->getContentLanguage()->normalize( $contents ); |
| 108 |
} |
| 109 |
return self::element( $element, $attribs, $contents ); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public static function openElement( $element, $attribs = null ) { |
| 120 |
return '<' . $element . self::expandAttributes( $attribs ) . '>'; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public static function closeElement( $element ) { |
| 129 |
return "</$element>"; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public static function tags( $element, $attribs, $contents ) { |
| 146 |
return self::openElement( $element, $attribs ) . $contents . "</$element>"; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
public static function monthSelector( $selected = '', $allmonths = null, $id = 'month' ) { |
| 161 |
wfDeprecated( __METHOD__, '1.42' ); |
| 162 |
|
| 163 |
global $wgLang; |
| 164 |
$options = []; |
| 165 |
|
| 166 |
$data = new XmlSelect( 'month', $id, $selected ?? '' ); |
| 167 |
|
| 168 |
if ( $allmonths !== null ) { |
| 169 |
$options[wfMessage( 'monthsall' )->text()] = $allmonths; |
| 170 |
} |
| 171 |
for ( $i = 1; $i < 13; $i++ ) { |
| 172 |
$options[$wgLang->getMonthName( $i )] = $i; |
| 173 |
} |
| 174 |
$data->addOptions( $options ); |
| 175 |
$data->setAttribute( 'class', 'mw-month-selector' ); |
| 176 |
return $data->getHTML(); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
public static function dateMenu( $year, $month ) { |
| 188 |
wfDeprecated( __METHOD__, '1.42' ); |
| 189 |
|
| 190 |
if ( $month && $month !== -1 ) { |
| 191 |
$encMonth = intval( $month ); |
| 192 |
} else { |
| 193 |
$encMonth = ''; |
| 194 |
} |
| 195 |
if ( $year ) { |
| 196 |
$encYear = intval( $year ); |
| 197 |
} elseif ( $encMonth ) { |
| 198 |
$timestamp = MWTimestamp::getInstance(); |
| 199 |
$thisMonth = intval( $timestamp->format( 'n' ) ); |
| 200 |
$thisYear = intval( $timestamp->format( 'Y' ) ); |
| 201 |
if ( $encMonth > $thisMonth ) { |
| 202 |
$thisYear--; |
| 203 |
} |
| 204 |
$encYear = $thisYear; |
| 205 |
} else { |
| 206 |
$encYear = ''; |
| 207 |
} |
| 208 |
$inputAttribs = [ 'id' => 'year', 'maxlength' => 4, 'size' => 7 ]; |
| 209 |
return self::label( wfMessage( 'year' )->text(), 'year' ) . ' ' . |
| 210 |
Html::input( 'year', $encYear, 'number', $inputAttribs ) . ' ' . |
| 211 |
self::label( wfMessage( 'month' )->text(), 'month' ) . ' ' . |
| 212 |
self::monthSelector( $encMonth, '-1' ); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
public static function languageSelector( $selected, $customisedOnly = true, |
| 228 |
$inLanguage = null, $overrideAttrs = [], ?Message $msg = null |
| 229 |
) { |
| 230 |
wfDeprecated( __METHOD__, '1.42' ); |
| 231 |
$languageCode = MediaWikiServices::getInstance()->getMainConfig() |
| 232 |
->get( MainConfigNames::LanguageCode ); |
| 233 |
|
| 234 |
$include = $customisedOnly ? LanguageNameUtils::SUPPORTED : LanguageNameUtils::DEFINED; |
| 235 |
$languages = MediaWikiServices::getInstance() |
| 236 |
->getLanguageNameUtils() |
| 237 |
->getLanguageNames( $inLanguage, $include ); |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
if ( !array_key_exists( $languageCode, $languages ) ) { |
| 242 |
$languages[$languageCode] = $languageCode; |
| 243 |
|
| 244 |
ksort( $languages ); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
$selected = isset( $languages[$selected] ) ? $selected : $languageCode; |
| 253 |
$options = "\n"; |
| 254 |
foreach ( $languages as $code => $name ) { |
| 255 |
$options .= self::option( "$code - $name", $code, $code == $selected ) . "\n"; |
| 256 |
} |
| 257 |
|
| 258 |
$attrs = [ 'id' => 'wpUserLanguage', 'name' => 'wpUserLanguage' ]; |
| 259 |
$attrs = array_merge( $attrs, $overrideAttrs ); |
| 260 |
|
| 261 |
$msg ??= wfMessage( 'yourlanguage' ); |
| 262 |
return [ |
| 263 |
self::label( $msg->text(), $attrs['id'] ), |
| 264 |
self::tags( 'select', $attrs, $options ) |
| 265 |
]; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
public static function span( $text, $class, $attribs = [] ) { |
| 278 |
return self::element( 'span', [ 'class' => $class ] + $attribs, $text ); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public static function wrapClass( $text, $class, $tag = 'span', $attribs = [] ) { |
| 293 |
wfDeprecated( __METHOD__, '1.42' ); |
| 294 |
return self::tags( $tag, [ 'class' => $class ] + $attribs, $text ); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
public static function input( $name, $size = false, $value = false, $attribs = [] ) { |
| 308 |
$attributes = [ 'name' => $name ]; |
| 309 |
|
| 310 |
if ( $size ) { |
| 311 |
$attributes['size'] = $size; |
| 312 |
} |
| 313 |
|
| 314 |
if ( $value !== false ) { |
| 315 |
$attributes['value'] = $value; |
| 316 |
} |
| 317 |
|
| 318 |
return self::element( 'input', $attributes + $attribs ); |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
public static function password( $name, $size = false, $value = false, |
| 332 |
$attribs = [] |
| 333 |
) { |
| 334 |
return self::input( $name, $size, $value, |
| 335 |
array_merge( $attribs, [ 'type' => 'password' ] ) ); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
public static function attrib( $name, $present = true ) { |
| 349 |
return $present ? [ $name => $name ] : []; |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
public static function check( $name, $checked = false, $attribs = [] ) { |
| 362 |
return self::element( 'input', array_merge( |
| 363 |
[ |
| 364 |
'name' => $name, |
| 365 |
'type' => 'checkbox', |
| 366 |
'value' => 1 ], |
| 367 |
self::attrib( 'checked', $checked ), |
| 368 |
$attribs ) ); |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
public static function radio( $name, $value, $checked = false, $attribs = [] ) { |
| 382 |
return self::element( 'input', [ |
| 383 |
'name' => $name, |
| 384 |
'type' => 'radio', |
| 385 |
'value' => $value ] + self::attrib( 'checked', $checked ) + $attribs ); |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
public static function label( $label, $id, $attribs = [] ) { |
| 401 |
$a = [ 'for' => $id ]; |
| 402 |
|
| 403 |
foreach ( [ 'class', 'title' ] as $attr ) { |
| 404 |
if ( isset( $attribs[$attr] ) ) { |
| 405 |
$a[$attr] = $attribs[$attr]; |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
return self::element( 'label', $a, $label ); |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
public static function inputLabel( $label, $name, $id, $size = false, |
| 425 |
$value = false, $attribs = [] |
| 426 |
) { |
| 427 |
[ $label, $input ] = self::inputLabelSep( $label, $name, $id, $size, $value, $attribs ); |
| 428 |
return $label . "\u{00A0}" . $input; |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
public static function inputLabelSep( $label, $name, $id, $size = false, |
| 445 |
$value = false, $attribs = [] |
| 446 |
) { |
| 447 |
return [ |
| 448 |
self::label( $label, $id, $attribs ), |
| 449 |
self::input( $name, $size, $value, [ 'id' => $id ] + $attribs ) |
| 450 |
]; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
public static function checkLabel( $label, $name, $id, $checked = false, $attribs = [] ) { |
| 466 |
return self::check( $name, $checked, [ 'id' => $id ] + $attribs ) . |
| 467 |
"\u{00A0}" . |
| 468 |
self::label( $label, $id, $attribs ); |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
public static function radioLabel( $label, $name, $value, $id, |
| 485 |
$checked = false, $attribs = [] |
| 486 |
) { |
| 487 |
return self::radio( $name, $value, $checked, [ 'id' => $id ] + $attribs ) . |
| 488 |
"\u{00A0}" . |
| 489 |
self::label( $label, $id, $attribs ); |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
public static function submitButton( $value, $attribs = [] ) { |
| 502 |
$attribs += [ |
| 503 |
'type' => 'submit', |
| 504 |
'value' => $value, |
| 505 |
]; |
| 506 |
return Html::element( 'input', $attribs ); |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
public static function option( $text, $value = null, $selected = false, |
| 520 |
$attribs = [] ) { |
| 521 |
if ( $value !== null ) { |
| 522 |
$attribs['value'] = $value; |
| 523 |
} |
| 524 |
if ( $selected ) { |
| 525 |
$attribs['selected'] = 'selected'; |
| 526 |
} |
| 527 |
return Html::element( 'option', $attribs, $text ); |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
public static function listDropdown( $name = '', $list = '', $other = '', |
| 546 |
$selected = '', $class = '', $tabindex = null |
| 547 |
) { |
| 548 |
$options = self::listDropdownOptions( $list, [ 'other' => $other ] ); |
| 549 |
|
| 550 |
$xmlSelect = new XmlSelect( $name, $name, $selected ); |
| 551 |
$xmlSelect->addOptions( $options ); |
| 552 |
|
| 553 |
if ( $class ) { |
| 554 |
$xmlSelect->setAttribute( 'class', $class ); |
| 555 |
} |
| 556 |
if ( $tabindex ) { |
| 557 |
$xmlSelect->setAttribute( 'tabindex', $tabindex ); |
| 558 |
} |
| 559 |
|
| 560 |
return $xmlSelect->getHTML(); |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
public static function listDropdownOptions( $list, $params = [] ) { |
| 579 |
$options = []; |
| 580 |
|
| 581 |
if ( isset( $params['other'] ) ) { |
| 582 |
$options[ $params['other'] ] = 'other'; |
| 583 |
} |
| 584 |
|
| 585 |
$optgroup = false; |
| 586 |
foreach ( explode( "\n", $list ) as $option ) { |
| 587 |
$value = trim( $option ); |
| 588 |
if ( $value == '' ) { |
| 589 |
continue; |
| 590 |
} |
| 591 |
if ( substr( $value, 0, 1 ) == '*' && substr( $value, 1, 1 ) != '*' ) { |
| 592 |
|
| 593 |
$value = trim( substr( $value, 1 ) ); |
| 594 |
if ( $value !== '' && |
| 595 |
|
| 596 |
( !isset( $params['other'] ) || $value !== $params['other'] ) |
| 597 |
) { |
| 598 |
$optgroup = $value; |
| 599 |
} else { |
| 600 |
$optgroup = false; |
| 601 |
} |
| 602 |
} elseif ( substr( $value, 0, 2 ) == '**' ) { |
| 603 |
|
| 604 |
$opt = trim( substr( $value, 2 ) ); |
| 605 |
if ( $optgroup === false ) { |
| 606 |
$options[$opt] = $opt; |
| 607 |
} else { |
| 608 |
$options[$optgroup][$opt] = $opt; |
| 609 |
} |
| 610 |
} else { |
| 611 |
|
| 612 |
$optgroup = false; |
| 613 |
$options[$option] = $option; |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
return $options; |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
public static function listDropdownOptionsOoui( $options ) { |
| 631 |
$optionsOoui = []; |
| 632 |
|
| 633 |
foreach ( $options as $text => $value ) { |
| 634 |
if ( is_array( $value ) ) { |
| 635 |
$optionsOoui[] = [ 'optgroup' => (string)$text ]; |
| 636 |
foreach ( $value as $text2 => $value2 ) { |
| 637 |
$optionsOoui[] = [ 'data' => (string)$value2, 'label' => (string)$text2 ]; |
| 638 |
} |
| 639 |
} else { |
| 640 |
$optionsOoui[] = [ 'data' => (string)$value, 'label' => (string)$text ]; |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
return $optionsOoui; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
public static function fieldset( $legend = false, $content = false, $attribs = [] ) { |
| 660 |
$s = self::openElement( 'fieldset', $attribs ) . "\n"; |
| 661 |
|
| 662 |
if ( $legend ) { |
| 663 |
$s .= self::element( 'legend', null, $legend ) . "\n"; |
| 664 |
} |
| 665 |
|
| 666 |
if ( $content !== false ) { |
| 667 |
$s .= $content . "\n"; |
| 668 |
$s .= self::closeElement( 'fieldset' ) . "\n"; |
| 669 |
} |
| 670 |
|
| 671 |
return $s; |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
public static function textarea( $name, $content, $cols = 40, $rows = 5, $attribs = [] ) { |
| 687 |
return self::element( 'textarea', |
| 688 |
[ |
| 689 |
'name' => $name, |
| 690 |
'id' => $name, |
| 691 |
'cols' => $cols, |
| 692 |
'rows' => $rows |
| 693 |
] + $attribs, |
| 694 |
$content, false ); |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
public static function encodeJsVar( $value, $pretty = false ) { |
| 713 |
return Html::encodeJsVar( $value, $pretty ); |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
public static function encodeJsCall( $name, $args, $pretty = false ) { |
| 733 |
return Html::encodeJsCall( $name, $args, $pretty ); |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
private static function isWellFormed( $text ) { |
| 748 |
$parser = xml_parser_create( "UTF-8" ); |
| 749 |
|
| 750 |
|
| 751 |
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); |
| 752 |
|
| 753 |
if ( !xml_parse( $parser, $text, true ) ) { |
| 754 |
return false; |
| 755 |
} |
| 756 |
|
| 757 |
return true; |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
public static function isWellFormedXmlFragment( $text ) { |
| 769 |
$html = |
| 770 |
Sanitizer::hackDocType() . |
| 771 |
'<html>' . |
| 772 |
$text . |
| 773 |
'</html>'; |
| 774 |
|
| 775 |
return self::isWellFormed( $html ); |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
public static function escapeTagsOnly( $in ) { |
| 786 |
return str_replace( |
| 787 |
[ '"', '>', '<' ], |
| 788 |
[ '"', '>', '<' ], |
| 789 |
$in ); |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
public static function buildForm( $fields, $submitLabel = null, $submitAttribs = [] ) { |
| 806 |
$form = ''; |
| 807 |
$form .= "<table><tbody>"; |
| 808 |
|
| 809 |
foreach ( $fields as $labelmsg => $input ) { |
| 810 |
$id = "mw-$labelmsg"; |
| 811 |
$form .= self::openElement( 'tr', [ 'id' => $id ] ); |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
$form .= self::tags( 'td', [ 'class' => 'mw-label' ], wfMessage( $labelmsg )->parse() ); |
| 818 |
$form .= self::openElement( 'td', [ 'class' => 'mw-input' ] ) |
| 819 |
. $input . self::closeElement( 'td' ); |
| 820 |
$form .= self::closeElement( 'tr' ); |
| 821 |
} |
| 822 |
|
| 823 |
if ( $submitLabel ) { |
| 824 |
$form .= self::openElement( 'tr' ); |
| 825 |
$form .= self::tags( 'td', [], '' ); |
| 826 |
$form .= self::openElement( 'td', [ 'class' => 'mw-submit' ] ) |
| 827 |
. self::submitButton( wfMessage( $submitLabel )->text(), $submitAttribs ) |
| 828 |
. self::closeElement( 'td' ); |
| 829 |
$form .= self::closeElement( 'tr' ); |
| 830 |
} |
| 831 |
|
| 832 |
$form .= "</tbody></table>"; |
| 833 |
|
| 834 |
return $form; |
| 835 |
} |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
public static function buildTable( $rows, $attribs = [], $headers = null ) { |
| 846 |
$s = self::openElement( 'table', $attribs ); |
| 847 |
|
| 848 |
if ( is_array( $headers ) ) { |
| 849 |
$s .= self::openElement( 'thead', $attribs ); |
| 850 |
|
| 851 |
foreach ( $headers as $id => $header ) { |
| 852 |
$attribs = []; |
| 853 |
|
| 854 |
if ( is_string( $id ) ) { |
| 855 |
$attribs['id'] = $id; |
| 856 |
} |
| 857 |
|
| 858 |
$s .= self::element( 'th', $attribs, $header ); |
| 859 |
} |
| 860 |
$s .= self::closeElement( 'thead' ); |
| 861 |
} |
| 862 |
|
| 863 |
foreach ( $rows as $id => $row ) { |
| 864 |
$attribs = []; |
| 865 |
|
| 866 |
if ( is_string( $id ) ) { |
| 867 |
$attribs['id'] = $id; |
| 868 |
} |
| 869 |
|
| 870 |
$s .= self::buildTableRow( $attribs, $row ); |
| 871 |
} |
| 872 |
|
| 873 |
$s .= self::closeElement( 'table' ); |
| 874 |
|
| 875 |
return $s; |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
public static function buildTableRow( $attribs, $cells ) { |
| 887 |
$s = self::openElement( 'tr', $attribs ); |
| 888 |
|
| 889 |
foreach ( $cells as $id => $cell ) { |
| 890 |
$attribs = []; |
| 891 |
|
| 892 |
if ( is_string( $id ) ) { |
| 893 |
$attribs['id'] = $id; |
| 894 |
} |
| 895 |
|
| 896 |
$s .= self::element( 'td', $attribs, $cell ); |
| 897 |
} |
| 898 |
|
| 899 |
$s .= self::closeElement( 'tr' ); |
| 900 |
|
| 901 |
return $s; |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
class_alias( Xml::class, 'Xml' ); |