| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
namespace MediaWiki\Parser; |
| 25 |
|
| 26 |
use InvalidArgumentException; |
| 27 |
use LogicException; |
| 28 |
use MediaWiki\Content\Content; |
| 29 |
use MediaWiki\Context\IContextSource; |
| 30 |
use MediaWiki\HookContainer\HookRunner; |
| 31 |
use MediaWiki\Language\Language; |
| 32 |
use MediaWiki\MainConfigNames; |
| 33 |
use MediaWiki\MediaWikiServices; |
| 34 |
use MediaWiki\Revision\MutableRevisionRecord; |
| 35 |
use MediaWiki\Revision\SlotRecord; |
| 36 |
use MediaWiki\StubObject\StubObject; |
| 37 |
use MediaWiki\Title\Title; |
| 38 |
use MediaWiki\User\UserIdentity; |
| 39 |
use MediaWiki\User\UserIdentityValue; |
| 40 |
use MediaWiki\Utils\MWTimestamp; |
| 41 |
use ReflectionClass; |
| 42 |
use Wikimedia\IPUtils; |
| 43 |
use Wikimedia\ScopedCallback; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
class ParserOptions { |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
private static $defaults = null; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
private static $lazyOptions = null; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
private static $initialLazyOptions = [ |
| 80 |
'dateformat' => [ __CLASS__, 'initDateFormat' ], |
| 81 |
'speculativeRevId' => [ __CLASS__, 'initSpeculativeRevId' ], |
| 82 |
'speculativePageId' => [ __CLASS__, 'initSpeculativePageId' ], |
| 83 |
]; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
private static $cacheVaryingOptionsHash = null; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
private static $initialCacheVaryingOptionsHash = [ |
| 96 |
'dateformat' => true, |
| 97 |
'thumbsize' => true, |
| 98 |
'printable' => true, |
| 99 |
'userlang' => true, |
| 100 |
'useParsoid' => true, |
| 101 |
'suppressSectionEditLinks' => true, |
| 102 |
'collapsibleSections' => true, |
| 103 |
]; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
private static $callbacks = [ |
| 111 |
'currentRevisionRecordCallback' => true, |
| 112 |
'templateCallback' => true, |
| 113 |
'speculativeRevIdCallback' => true, |
| 114 |
'speculativePageIdCallback' => true, |
| 115 |
]; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
private $options; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
private $mTimestamp; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
private $mUser; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
private $onAccessCallback = null; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
private $redirectTarget = null; |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
private $mExtraKey = ''; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
private $renderReason = 'unknown'; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public function getOption( $name ) { |
| 171 |
if ( !array_key_exists( $name, $this->options ) ) { |
| 172 |
throw new InvalidArgumentException( "Unknown parser option $name" ); |
| 173 |
} |
| 174 |
|
| 175 |
$this->lazyLoadOption( $name ); |
| 176 |
$this->optionUsed( $name ); |
| 177 |
return $this->options[$name]; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
private function lazyLoadOption( $name ) { |
| 184 |
$lazyOptions = self::getLazyOptions(); |
| 185 |
if ( isset( $lazyOptions[$name] ) && $this->options[$name] === null ) { |
| 186 |
$this->options[$name] = call_user_func( $lazyOptions[$name], $this, $name ); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
private function nullifyLazyOption( array $options ): array { |
| 196 |
return array_fill_keys( array_keys( self::getLazyOptions() ), null ) + $options; |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public static function getLazyOptions(): array { |
| 211 |
|
| 212 |
|
| 213 |
if ( self::$lazyOptions === null ) { |
| 214 |
self::getDefaults(); |
| 215 |
} |
| 216 |
return self::$lazyOptions; |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
private static function getCacheVaryingOptionsHash(): array { |
| 228 |
|
| 229 |
|
| 230 |
if ( self::$cacheVaryingOptionsHash === null ) { |
| 231 |
self::getDefaults(); |
| 232 |
} |
| 233 |
return self::$cacheVaryingOptionsHash; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
public function setOption( $name, $value ) { |
| 245 |
if ( !array_key_exists( $name, $this->options ) ) { |
| 246 |
throw new InvalidArgumentException( "Unknown parser option $name" ); |
| 247 |
} |
| 248 |
$old = $this->options[$name]; |
| 249 |
$this->options[$name] = $value; |
| 250 |
return $old; |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
protected function setOptionLegacy( $name, $value ) { |
| 262 |
if ( !array_key_exists( $name, $this->options ) ) { |
| 263 |
throw new InvalidArgumentException( "Unknown parser option $name" ); |
| 264 |
} |
| 265 |
return wfSetVar( $this->options[$name], $value ); |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
public function getInterwikiMagic() { |
| 277 |
return $this->getOption( 'interwikiMagic' ); |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public function setInterwikiMagic( $x ) { |
| 286 |
return $this->setOptionLegacy( 'interwikiMagic', $x ); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
public function getAllowExternalImages() { |
| 294 |
return $this->getOption( 'allowExternalImages' ); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
public function getAllowExternalImagesFrom() { |
| 305 |
return $this->getOption( 'allowExternalImagesFrom' ); |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
public function getEnableImageWhitelist() { |
| 313 |
return $this->getOption( 'enableImageWhitelist' ); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
public function getAllowSpecialInclusion() { |
| 321 |
return $this->getOption( 'allowSpecialInclusion' ); |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
public function setAllowSpecialInclusion( $x ) { |
| 330 |
return $this->setOptionLegacy( 'allowSpecialInclusion', $x ); |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
public function getInterfaceMessage() { |
| 338 |
return $this->getOption( 'interfaceMessage' ); |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
public function setInterfaceMessage( $x ) { |
| 347 |
return $this->setOptionLegacy( 'interfaceMessage', $x ); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
public function getTargetLanguage() { |
| 355 |
return $this->getOption( 'targetLanguage' ); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
public function setTargetLanguage( $x ) { |
| 364 |
return $this->setOption( 'targetLanguage', $x ); |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
public function getMaxIncludeSize() { |
| 372 |
return $this->getOption( 'maxIncludeSize' ); |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
public function setMaxIncludeSize( $x ) { |
| 381 |
return $this->setOptionLegacy( 'maxIncludeSize', $x ); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
public function getMaxPPNodeCount() { |
| 389 |
return $this->getOption( 'maxPPNodeCount' ); |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
public function setMaxPPNodeCount( $x ) { |
| 398 |
return $this->setOptionLegacy( 'maxPPNodeCount', $x ); |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
public function getMaxPPExpandDepth() { |
| 406 |
return $this->getOption( 'maxPPExpandDepth' ); |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
public function getMaxTemplateDepth() { |
| 415 |
return $this->getOption( 'maxTemplateDepth' ); |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
public function setMaxTemplateDepth( $x ) { |
| 425 |
return $this->setOptionLegacy( 'maxTemplateDepth', $x ); |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
public function getExpensiveParserFunctionLimit() { |
| 434 |
return $this->getOption( 'expensiveParserFunctionLimit' ); |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
public function setExpensiveParserFunctionLimit( $x ) { |
| 444 |
return $this->setOptionLegacy( 'expensiveParserFunctionLimit', $x ); |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
public function getRemoveComments() { |
| 453 |
return $this->getOption( 'removeComments' ); |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
public function setRemoveComments( $x ) { |
| 463 |
return $this->setOptionLegacy( 'removeComments', $x ); |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
public function getEnableLimitReport() { |
| 474 |
return false; |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
public function enableLimitReport( $x = true ) { |
| 486 |
return false; |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
public function getCleanSignatures() { |
| 495 |
return $this->getOption( 'cleanSignatures' ); |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
public function setCleanSignatures( $x ) { |
| 505 |
return $this->setOptionLegacy( 'cleanSignatures', $x ); |
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
public function getExternalLinkTarget() { |
| 514 |
return $this->getOption( 'externalLinkTarget' ); |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
public function setExternalLinkTarget( $x ) { |
| 524 |
return $this->setOptionLegacy( 'externalLinkTarget', $x ); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
public function getDisableContentConversion() { |
| 532 |
return $this->getOption( 'disableContentConversion' ); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
public function disableContentConversion( $x = true ) { |
| 541 |
return $this->setOptionLegacy( 'disableContentConversion', $x ); |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
public function getDisableTitleConversion() { |
| 549 |
return $this->getOption( 'disableTitleConversion' ); |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
public function disableTitleConversion( $x = true ) { |
| 558 |
return $this->setOptionLegacy( 'disableTitleConversion', $x ); |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
public function getThumbSize() { |
| 566 |
return $this->getOption( 'thumbsize' ); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
public function setThumbSize( $x ) { |
| 575 |
return $this->setOptionLegacy( 'thumbsize', $x ); |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
public function getIsPreview() { |
| 583 |
return $this->getOption( 'isPreview' ); |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
public function setIsPreview( $x ) { |
| 592 |
return $this->setOptionLegacy( 'isPreview', $x ); |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
public function getIsSectionPreview() { |
| 600 |
return $this->getOption( 'isSectionPreview' ); |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
public function setIsSectionPreview( $x ) { |
| 609 |
return $this->setOptionLegacy( 'isSectionPreview', $x ); |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
public function getIsPrintable() { |
| 617 |
return $this->getOption( 'printable' ); |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
public function setIsPrintable( $x ) { |
| 626 |
return $this->setOptionLegacy( 'printable', $x ); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
public function getPreSaveTransform() { |
| 634 |
return $this->getOption( 'preSaveTransform' ); |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
public function setPreSaveTransform( $x ) { |
| 643 |
return $this->setOptionLegacy( 'preSaveTransform', $x ); |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
public function getUseParsoid(): bool { |
| 654 |
return $this->getOption( 'useParsoid' ); |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
public function setUseParsoid() { |
| 664 |
$this->setOption( 'useParsoid', true ); |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
public function getDateFormat() { |
| 672 |
return $this->getOption( 'dateformat' ); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
private static function initDateFormat( ParserOptions $popt ) { |
| 681 |
$userFactory = MediaWikiServices::getInstance()->getUserFactory(); |
| 682 |
return $userFactory->newFromUserIdentity( $popt->getUserIdentity() )->getDatePreference(); |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
public function setDateFormat( $x ) { |
| 691 |
return $this->setOptionLegacy( 'dateformat', $x ); |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
public function getUserLangObj() { |
| 712 |
return $this->getOption( 'userlang' ); |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
public function getUserLang() { |
| 728 |
return $this->getUserLangObj()->getCode(); |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
public function setUserLang( $x ) { |
| 737 |
if ( is_string( $x ) ) { |
| 738 |
$x = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $x ); |
| 739 |
} |
| 740 |
|
| 741 |
return $this->setOptionLegacy( 'userlang', $x ); |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
public function getMagicISBNLinks() { |
| 750 |
return $this->getOption( 'magicISBNLinks' ); |
| 751 |
} |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
public function getMagicPMIDLinks() { |
| 759 |
return $this->getOption( 'magicPMIDLinks' ); |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
public function getMagicRFCLinks() { |
| 768 |
return $this->getOption( 'magicRFCLinks' ); |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
public function getSuppressTOC() { |
| 781 |
return $this->getOption( 'suppressTOC' ); |
| 782 |
} |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
public function setSuppressTOC() { |
| 795 |
wfDeprecated( __METHOD__, '1.42' ); |
| 796 |
$this->setOption( 'suppressTOC', true ); |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
public function getSuppressSectionEditLinks() { |
| 807 |
return $this->getOption( 'suppressSectionEditLinks' ); |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
public function setSuppressSectionEditLinks() { |
| 817 |
$this->setOption( 'suppressSectionEditLinks', true ); |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
public function getCollapsibleSections(): bool { |
| 826 |
return $this->getOption( 'collapsibleSections' ); |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
public function setCollapsibleSections(): void { |
| 835 |
$this->setOption( 'collapsibleSections', true ); |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
public function getAllowUnsafeRawHtml() { |
| 853 |
return $this->getOption( 'allowUnsafeRawHtml' ); |
| 854 |
} |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
public function setAllowUnsafeRawHtml( $x ) { |
| 865 |
return $this->setOptionLegacy( 'allowUnsafeRawHtml', $x ); |
| 866 |
} |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
public function getWrapOutputClass() { |
| 874 |
return $this->getOption( 'wrapclass' ); |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
public function setWrapOutputClass( $className ) { |
| 885 |
if ( $className === true ) { |
| 886 |
$className = 'mw-parser-output'; |
| 887 |
} |
| 888 |
if ( $className === false ) { |
| 889 |
wfDeprecated( __METHOD__ . '( false )', '1.31' ); |
| 890 |
} |
| 891 |
return $this->setOption( 'wrapclass', $className ); |
| 892 |
} |
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
public function getCurrentRevisionRecordCallback() { |
| 901 |
return $this->getOption( 'currentRevisionRecordCallback' ); |
| 902 |
} |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
public function setCurrentRevisionRecordCallback( $x ) { |
| 912 |
return $this->setOption( 'currentRevisionRecordCallback', $x ); |
| 913 |
} |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
public function getTemplateCallback() { |
| 920 |
return $this->getOption( 'templateCallback' ); |
| 921 |
} |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
public function setTemplateCallback( $x ) { |
| 929 |
return $this->setOptionLegacy( 'templateCallback', $x ); |
| 930 |
} |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
public function getSpeculativeRevId() { |
| 943 |
return $this->getOption( 'speculativeRevId' ); |
| 944 |
} |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
public function getSpeculativePageId() { |
| 957 |
return $this->getOption( 'speculativePageId' ); |
| 958 |
} |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
private static function initSpeculativeRevId( ParserOptions $popt ) { |
| 967 |
$cb = $popt->getOption( 'speculativeRevIdCallback' ); |
| 968 |
$id = $cb ? $cb() : null; |
| 969 |
|
| 970 |
|
| 971 |
return $id ?? false; |
| 972 |
} |
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
private static function initSpeculativePageId( ParserOptions $popt ) { |
| 981 |
$cb = $popt->getOption( 'speculativePageIdCallback' ); |
| 982 |
$id = $cb ? $cb() : null; |
| 983 |
|
| 984 |
|
| 985 |
return $id ?? false; |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
public function setSpeculativeRevIdCallback( $x ) { |
| 995 |
$this->setOption( 'speculativeRevId', null ); |
| 996 |
return $this->setOption( 'speculativeRevIdCallback', $x ); |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
public function setSpeculativePageIdCallback( $x ) { |
| 1006 |
$this->setOption( 'speculativePageId', null ); |
| 1007 |
return $this->setOption( 'speculativePageIdCallback', $x ); |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
public function getTimestamp() { |
| 1015 |
if ( !isset( $this->mTimestamp ) ) { |
| 1016 |
$this->mTimestamp = wfTimestampNow(); |
| 1017 |
} |
| 1018 |
return $this->mTimestamp; |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
public function setTimestamp( $x ) { |
| 1027 |
return wfSetVar( $this->mTimestamp, $x ); |
| 1028 |
} |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
public function setRedirectTarget( $title ) { |
| 1039 |
$this->redirectTarget = $title; |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
public function getRedirectTarget() { |
| 1049 |
return $this->redirectTarget; |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
public function addExtraKey( $key ) { |
| 1059 |
$this->mExtraKey .= '!' . $key; |
| 1060 |
} |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
public function getUserIdentity(): UserIdentity { |
| 1068 |
return $this->mUser; |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
public function __construct( UserIdentity $user, $lang = null ) { |
| 1076 |
if ( $lang === null ) { |
| 1077 |
global $wgLang; |
| 1078 |
StubObject::unstub( $wgLang ); |
| 1079 |
$lang = $wgLang; |
| 1080 |
} |
| 1081 |
$this->initialiseFromUser( $user, $lang ); |
| 1082 |
} |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
public static function newFromAnon() { |
| 1090 |
return new ParserOptions( MediaWikiServices::getInstance()->getUserFactory()->newAnonymous(), |
| 1091 |
MediaWikiServices::getInstance()->getContentLanguage() ); |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
public static function newFromUser( $user ) { |
| 1102 |
return new ParserOptions( $user ); |
| 1103 |
} |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
public static function newFromUserAndLang( UserIdentity $user, Language $lang ) { |
| 1113 |
return new ParserOptions( $user, $lang ); |
| 1114 |
} |
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
public static function newFromContext( IContextSource $context ) { |
| 1123 |
$contextUser = $context->getUser(); |
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
$tempUserCreator = MediaWikiServices::getInstance()->getTempUserCreator(); |
| 1129 |
if ( $tempUserCreator->isEnabled() && IPUtils::isIPAddress( $contextUser->getName() ) ) { |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
$tempName = $tempUserCreator->getStashedName( $context->getRequest()->getSession() ); |
| 1134 |
if ( $tempName !== null ) { |
| 1135 |
$contextUser = UserIdentityValue::newAnonymous( $tempName ); |
| 1136 |
} |
| 1137 |
} |
| 1138 |
|
| 1139 |
return new ParserOptions( $contextUser, $context->getLanguage() ); |
| 1140 |
} |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
public static function newCanonical( $context, $userLang = null ) { |
| 1163 |
if ( $context instanceof IContextSource ) { |
| 1164 |
$ret = self::newFromContext( $context ); |
| 1165 |
} elseif ( $context === 'canonical' ) { |
| 1166 |
$ret = self::newFromAnon(); |
| 1167 |
} elseif ( $context instanceof UserIdentity ) { |
| 1168 |
$ret = new self( $context, $userLang ); |
| 1169 |
} else { |
| 1170 |
throw new InvalidArgumentException( |
| 1171 |
'$context must be an IContextSource, the string "canonical", or a UserIdentity' |
| 1172 |
); |
| 1173 |
} |
| 1174 |
return $ret; |
| 1175 |
} |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
public static function clearStaticCache() { |
| 1182 |
if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) { |
| 1183 |
throw new LogicException( __METHOD__ . ' is just for testing' ); |
| 1184 |
} |
| 1185 |
self::$defaults = null; |
| 1186 |
self::$lazyOptions = null; |
| 1187 |
self::$cacheVaryingOptionsHash = null; |
| 1188 |
} |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
private static function getDefaults() { |
| 1199 |
$services = MediaWikiServices::getInstance(); |
| 1200 |
$mainConfig = $services->getMainConfig(); |
| 1201 |
$interwikiMagic = $mainConfig->get( MainConfigNames::InterwikiMagic ); |
| 1202 |
$allowExternalImages = $mainConfig->get( MainConfigNames::AllowExternalImages ); |
| 1203 |
$allowExternalImagesFrom = $mainConfig->get( MainConfigNames::AllowExternalImagesFrom ); |
| 1204 |
$enableImageWhitelist = $mainConfig->get( MainConfigNames::EnableImageWhitelist ); |
| 1205 |
$allowSpecialInclusion = $mainConfig->get( MainConfigNames::AllowSpecialInclusion ); |
| 1206 |
$maxArticleSize = $mainConfig->get( MainConfigNames::MaxArticleSize ); |
| 1207 |
$maxPPNodeCount = $mainConfig->get( MainConfigNames::MaxPPNodeCount ); |
| 1208 |
$maxTemplateDepth = $mainConfig->get( MainConfigNames::MaxTemplateDepth ); |
| 1209 |
$maxPPExpandDepth = $mainConfig->get( MainConfigNames::MaxPPExpandDepth ); |
| 1210 |
$cleanSignatures = $mainConfig->get( MainConfigNames::CleanSignatures ); |
| 1211 |
$externalLinkTarget = $mainConfig->get( MainConfigNames::ExternalLinkTarget ); |
| 1212 |
$expensiveParserFunctionLimit = $mainConfig->get( MainConfigNames::ExpensiveParserFunctionLimit ); |
| 1213 |
$enableMagicLinks = $mainConfig->get( MainConfigNames::EnableMagicLinks ); |
| 1214 |
$languageConverterFactory = $services->getLanguageConverterFactory(); |
| 1215 |
$userOptionsLookup = $services->getUserOptionsLookup(); |
| 1216 |
$contentLanguage = $services->getContentLanguage(); |
| 1217 |
|
| 1218 |
if ( self::$defaults === null ) { |
| 1219 |
|
| 1220 |
self::$defaults = [ |
| 1221 |
'dateformat' => null, |
| 1222 |
'interfaceMessage' => false, |
| 1223 |
'targetLanguage' => null, |
| 1224 |
'removeComments' => true, |
| 1225 |
'suppressTOC' => false, |
| 1226 |
'suppressSectionEditLinks' => false, |
| 1227 |
'collapsibleSections' => false, |
| 1228 |
'enableLimitReport' => false, |
| 1229 |
'preSaveTransform' => true, |
| 1230 |
'isPreview' => false, |
| 1231 |
'isSectionPreview' => false, |
| 1232 |
'printable' => false, |
| 1233 |
'allowUnsafeRawHtml' => true, |
| 1234 |
'wrapclass' => 'mw-parser-output', |
| 1235 |
'currentRevisionRecordCallback' => [ Parser::class, 'statelessFetchRevisionRecord' ], |
| 1236 |
'templateCallback' => [ Parser::class, 'statelessFetchTemplate' ], |
| 1237 |
'speculativeRevIdCallback' => null, |
| 1238 |
'speculativeRevId' => null, |
| 1239 |
'speculativePageIdCallback' => null, |
| 1240 |
'speculativePageId' => null, |
| 1241 |
'useParsoid' => false, |
| 1242 |
]; |
| 1243 |
|
| 1244 |
self::$cacheVaryingOptionsHash = self::$initialCacheVaryingOptionsHash; |
| 1245 |
self::$lazyOptions = self::$initialLazyOptions; |
| 1246 |
|
| 1247 |
( new HookRunner( $services->getHookContainer() ) )->onParserOptionsRegister( |
| 1248 |
self::$defaults, |
| 1249 |
self::$cacheVaryingOptionsHash, |
| 1250 |
self::$lazyOptions |
| 1251 |
); |
| 1252 |
|
| 1253 |
ksort( self::$cacheVaryingOptionsHash ); |
| 1254 |
} |
| 1255 |
|
| 1256 |
|
| 1257 |
return self::$defaults + [ |
| 1258 |
'interwikiMagic' => $interwikiMagic, |
| 1259 |
'allowExternalImages' => $allowExternalImages, |
| 1260 |
'allowExternalImagesFrom' => $allowExternalImagesFrom, |
| 1261 |
'enableImageWhitelist' => $enableImageWhitelist, |
| 1262 |
'allowSpecialInclusion' => $allowSpecialInclusion, |
| 1263 |
'maxIncludeSize' => $maxArticleSize * 1024, |
| 1264 |
'maxPPNodeCount' => $maxPPNodeCount, |
| 1265 |
'maxPPExpandDepth' => $maxPPExpandDepth, |
| 1266 |
'maxTemplateDepth' => $maxTemplateDepth, |
| 1267 |
'expensiveParserFunctionLimit' => $expensiveParserFunctionLimit, |
| 1268 |
'externalLinkTarget' => $externalLinkTarget, |
| 1269 |
'cleanSignatures' => $cleanSignatures, |
| 1270 |
'disableContentConversion' => $languageConverterFactory->isConversionDisabled(), |
| 1271 |
'disableTitleConversion' => $languageConverterFactory->isLinkConversionDisabled(), |
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
'magicISBNLinks' => $enableMagicLinks['ISBN'] ?? false, |
| 1280 |
'magicPMIDLinks' => $enableMagicLinks['PMID'] ?? false, |
| 1281 |
'magicRFCLinks' => $enableMagicLinks['RFC'] ?? false, |
| 1282 |
'thumbsize' => $userOptionsLookup->getDefaultOption( 'thumbsize' ), |
| 1283 |
'userlang' => $contentLanguage, |
| 1284 |
]; |
| 1285 |
} |
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
private function initialiseFromUser( UserIdentity $user, Language $lang ) { |
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
$this->options = $this->nullifyLazyOption( self::getDefaults() ); |
| 1298 |
|
| 1299 |
$this->mUser = $user; |
| 1300 |
$services = MediaWikiServices::getInstance(); |
| 1301 |
$optionsLookup = $services->getUserOptionsLookup(); |
| 1302 |
$this->options['thumbsize'] = $optionsLookup->getOption( $user, 'thumbsize' ); |
| 1303 |
$this->options['userlang'] = $lang; |
| 1304 |
} |
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
public function matches( ParserOptions $other ) { |
| 1316 |
|
| 1317 |
$options = array_keys( $this->options ); |
| 1318 |
$options = array_diff( $options, [ |
| 1319 |
'enableLimitReport', |
| 1320 |
'tidy', |
| 1321 |
] ); |
| 1322 |
foreach ( $options as $option ) { |
| 1323 |
|
| 1324 |
$this->lazyLoadOption( $option ); |
| 1325 |
$other->lazyLoadOption( $option ); |
| 1326 |
|
| 1327 |
$o1 = $this->optionToString( $this->options[$option] ); |
| 1328 |
$o2 = $this->optionToString( $other->options[$option] ); |
| 1329 |
if ( $o1 !== $o2 ) { |
| 1330 |
return false; |
| 1331 |
} |
| 1332 |
} |
| 1333 |
|
| 1334 |
|
| 1335 |
foreach ( ( new ReflectionClass( $this ) )->getProperties() as $property ) { |
| 1336 |
$field = $property->getName(); |
| 1337 |
if ( $property->isStatic() ) { |
| 1338 |
continue; |
| 1339 |
} |
| 1340 |
if ( in_array( $field, [ |
| 1341 |
'options', |
| 1342 |
'onAccessCallback', |
| 1343 |
] ) ) { |
| 1344 |
continue; |
| 1345 |
} |
| 1346 |
|
| 1347 |
if ( !is_object( $this->$field ) && $this->$field !== $other->$field ) { |
| 1348 |
return false; |
| 1349 |
} |
| 1350 |
} |
| 1351 |
|
| 1352 |
return true; |
| 1353 |
} |
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
public function matchesForCacheKey( ParserOptions $other ) { |
| 1361 |
foreach ( self::allCacheVaryingOptions() as $option ) { |
| 1362 |
|
| 1363 |
$this->lazyLoadOption( $option ); |
| 1364 |
$other->lazyLoadOption( $option ); |
| 1365 |
|
| 1366 |
$o1 = $this->optionToString( $this->options[$option] ); |
| 1367 |
$o2 = $this->optionToString( $other->options[$option] ); |
| 1368 |
if ( $o1 !== $o2 ) { |
| 1369 |
return false; |
| 1370 |
} |
| 1371 |
} |
| 1372 |
|
| 1373 |
return true; |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
public function registerWatcher( $callback ) { |
| 1383 |
$this->onAccessCallback = $callback; |
| 1384 |
} |
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
private function optionUsed( $optionName ) { |
| 1396 |
if ( $this->onAccessCallback ) { |
| 1397 |
call_user_func( $this->onAccessCallback, $optionName ); |
| 1398 |
} |
| 1399 |
} |
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
public static function allCacheVaryingOptions() { |
| 1407 |
return array_keys( array_filter( self::getCacheVaryingOptionsHash() ) ); |
| 1408 |
} |
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
private function optionToString( $value ) { |
| 1416 |
if ( $value === true ) { |
| 1417 |
return '1'; |
| 1418 |
} elseif ( $value === false ) { |
| 1419 |
return '0'; |
| 1420 |
} elseif ( $value === null ) { |
| 1421 |
return ''; |
| 1422 |
} elseif ( $value instanceof Language ) { |
| 1423 |
return $value->getCode(); |
| 1424 |
} elseif ( is_array( $value ) ) { |
| 1425 |
return '[' . implode( ',', array_map( [ $this, 'optionToString' ], $value ) ) . ']'; |
| 1426 |
} else { |
| 1427 |
return (string)$value; |
| 1428 |
} |
| 1429 |
} |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
public function optionsHash( $forOptions, $title = null ) { |
| 1444 |
$renderHashAppend = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::RenderHashAppend ); |
| 1445 |
|
| 1446 |
$inCacheKey = self::allCacheVaryingOptions(); |
| 1447 |
|
| 1448 |
|
| 1449 |
$lazyOpts = array_intersect( $forOptions, |
| 1450 |
$inCacheKey, array_keys( self::getLazyOptions() ) ); |
| 1451 |
foreach ( $lazyOpts as $k ) { |
| 1452 |
$this->lazyLoadOption( $k ); |
| 1453 |
} |
| 1454 |
|
| 1455 |
$options = $this->options; |
| 1456 |
$defaults = self::getDefaults(); |
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
$values = []; |
| 1464 |
foreach ( array_intersect( $inCacheKey, $forOptions ) as $option ) { |
| 1465 |
$v = $this->optionToString( $options[$option] ); |
| 1466 |
$d = $this->optionToString( $defaults[$option] ); |
| 1467 |
if ( $v !== $d ) { |
| 1468 |
$values[] = "$option=$v"; |
| 1469 |
} |
| 1470 |
} |
| 1471 |
|
| 1472 |
$confstr = $values ? implode( '!', $values ) : 'canonical'; |
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
$services = MediaWikiServices::getInstance(); |
| 1477 |
$lang = $title ? $title->getPageLanguage() : $services->getContentLanguage(); |
| 1478 |
$converter = $services->getLanguageConverterFactory()->getLanguageConverter( $lang ); |
| 1479 |
$confstr .= $converter->getExtraHashOptions(); |
| 1480 |
|
| 1481 |
$confstr .= $renderHashAppend; |
| 1482 |
|
| 1483 |
if ( $this->mExtraKey != '' ) { |
| 1484 |
$confstr .= $this->mExtraKey; |
| 1485 |
} |
| 1486 |
|
| 1487 |
$user = $services->getUserFactory()->newFromUserIdentity( $this->getUserIdentity() ); |
| 1488 |
|
| 1489 |
|
| 1490 |
( new HookRunner( $services->getHookContainer() ) )->onPageRenderingHash( |
| 1491 |
$confstr, |
| 1492 |
$user, |
| 1493 |
$forOptions |
| 1494 |
); |
| 1495 |
|
| 1496 |
|
| 1497 |
$confstr = str_replace( ' ', '_', $confstr ); |
| 1498 |
|
| 1499 |
return $confstr; |
| 1500 |
} |
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
public function isSafeToCache( ?array $usedOptions = null ) { |
| 1509 |
$defaults = self::getDefaults(); |
| 1510 |
$inCacheKey = self::getCacheVaryingOptionsHash(); |
| 1511 |
$usedOptions ??= array_keys( $this->options ); |
| 1512 |
foreach ( $usedOptions as $option ) { |
| 1513 |
if ( empty( $inCacheKey[$option] ) && empty( self::$callbacks[$option] ) ) { |
| 1514 |
$v = $this->optionToString( $this->options[$option] ?? null ); |
| 1515 |
$d = $this->optionToString( $defaults[$option] ?? null ); |
| 1516 |
if ( $v !== $d ) { |
| 1517 |
return false; |
| 1518 |
} |
| 1519 |
} |
| 1520 |
} |
| 1521 |
return true; |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
public function setupFakeRevision( $title, $content, $user ) { |
| 1535 |
$oldCallback = $this->setCurrentRevisionRecordCallback( |
| 1536 |
static function ( |
| 1537 |
$titleToCheck, $parser = null ) use ( $title, $content, $user, &$oldCallback |
| 1538 |
) { |
| 1539 |
if ( $titleToCheck->equals( $title ) ) { |
| 1540 |
$revRecord = new MutableRevisionRecord( $title ); |
| 1541 |
$revRecord->setContent( SlotRecord::MAIN, $content ) |
| 1542 |
->setUser( $user ) |
| 1543 |
->setTimestamp( MWTimestamp::now( TS_MW ) ) |
| 1544 |
->setPageId( $title->getArticleID() ) |
| 1545 |
->setParentId( $title->getLatestRevID() ); |
| 1546 |
return $revRecord; |
| 1547 |
} else { |
| 1548 |
return call_user_func( $oldCallback, $titleToCheck, $parser ); |
| 1549 |
} |
| 1550 |
} |
| 1551 |
); |
| 1552 |
|
| 1553 |
$hookContainer = MediaWikiServices::getInstance()->getHookContainer(); |
| 1554 |
$hookScope = $hookContainer->scopedRegister( |
| 1555 |
'TitleExists', |
| 1556 |
static function ( $titleToCheck, &$exists ) use ( $title ) { |
| 1557 |
if ( $titleToCheck->equals( $title ) ) { |
| 1558 |
$exists = true; |
| 1559 |
} |
| 1560 |
} |
| 1561 |
); |
| 1562 |
|
| 1563 |
$linkCache = MediaWikiServices::getInstance()->getLinkCache(); |
| 1564 |
$linkCache->clearBadLink( $title->getPrefixedDBkey() ); |
| 1565 |
|
| 1566 |
return new ScopedCallback( function () use ( $title, $hookScope, $linkCache, $oldCallback ) { |
| 1567 |
ScopedCallback::consume( $hookScope ); |
| 1568 |
$linkCache->clearLink( $title ); |
| 1569 |
$this->setCurrentRevisionRecordCallback( $oldCallback ); |
| 1570 |
} ); |
| 1571 |
} |
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
public function getRenderReason(): string { |
| 1579 |
return $this->renderReason; |
| 1580 |
} |
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
public function setRenderReason( string $renderReason ): void { |
| 1588 |
$this->renderReason = $renderReason; |
| 1589 |
} |
| 1590 |
} |
| 1591 |
|
| 1592 |
|
| 1593 |
class_alias( ParserOptions::class, 'ParserOptions' ); |
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|