| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Parser; |
| 22 |
|
| 23 |
use InvalidArgumentException; |
| 24 |
use LogicException; |
| 25 |
use MediaWiki\Edit\ParsoidRenderID; |
| 26 |
use MediaWiki\Json\JsonDeserializable; |
| 27 |
use MediaWiki\MainConfigNames; |
| 28 |
use MediaWiki\MediaWikiServices; |
| 29 |
use MediaWiki\Message\Converter; |
| 30 |
use MediaWiki\Output\OutputPage; |
| 31 |
use MediaWiki\Parser\Parsoid\PageBundleParserOutputConverter; |
| 32 |
use MediaWiki\Title\TitleValue; |
| 33 |
use UnexpectedValueException; |
| 34 |
use Wikimedia\Bcp47Code\Bcp47Code; |
| 35 |
use Wikimedia\Bcp47Code\Bcp47CodeValue; |
| 36 |
use Wikimedia\JsonCodec\Hint; |
| 37 |
use Wikimedia\Message\MessageValue; |
| 38 |
use Wikimedia\Parsoid\Core\ContentMetadataCollector; |
| 39 |
use Wikimedia\Parsoid\Core\ContentMetadataCollectorCompat; |
| 40 |
use Wikimedia\Parsoid\Core\LinkTarget as ParsoidLinkTarget; |
| 41 |
use Wikimedia\Parsoid\Core\TOCData; |
| 42 |
use Wikimedia\Reflection\GhostFieldAccessTrait; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
class ParserOutput extends CacheTime implements ContentMetadataCollector { |
| 94 |
use GhostFieldAccessTrait; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
use ContentMetadataCollectorCompat; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
public const SUPPORTS_STATELESS_TRANSFORMS = 1; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public const SUPPORTS_UNWRAP_TRANSFORM = 1; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public const MW_MERGE_STRATEGY_KEY = '_mw-strategy'; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public const MW_MERGE_STRATEGY_UNION = 'union'; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
private $mRawText = null; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
private $mLanguageLinkMap = []; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
private $mCategories; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
private $mIndicators = []; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
private $mTitleText; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
private $mLinks = []; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
private $mLinksSpecial = []; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
private $mTemplates = []; |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
private $mTemplateIds = []; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
private $mImages = []; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
private $mFileSearchOptions = []; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
private array $mExternalLinks = []; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
private $mInterwikiLinks = []; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
private $mNewSection = false; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
private $mHideNewSection = false; |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
private $mNoGallery = false; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
private $mHeadItems = []; |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
private $mModuleSet = []; |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
private $mModuleStyleSet = []; |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
private $mJsConfigVars = []; |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
private $mWarnings = []; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
private $mWarningMsgs = []; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
private $mTOCData; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
private $mProperties = []; |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
private $mTimestamp; |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
private $mEnableOOUI = false; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
private $mIndexSet = false; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
private $mNoIndexSet = false; |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
private $mExtensionData = []; |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
private $mLimitReportData = []; |
| 288 |
|
| 289 |
|
| 290 |
private $mLimitReportJSData = []; |
| 291 |
|
| 292 |
|
| 293 |
private $mCacheMessage = ''; |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
private $mParseStartTime = []; |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
private $mTimeProfile = []; |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
private $mPreventClickjacking = false; |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
private $mExtraScriptSrcs = []; |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
private $mExtraDefaultSrcs = []; |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
private $mExtraStyleSrcs = []; |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
private $mFlags = []; |
| 331 |
|
| 332 |
private const SPECULATIVE_FIELDS = [ |
| 333 |
'speculativePageIdUsed', |
| 334 |
'mSpeculativeRevId', |
| 335 |
'revisionTimestampUsed', |
| 336 |
]; |
| 337 |
|
| 338 |
|
| 339 |
private $mSpeculativeRevId; |
| 340 |
|
| 341 |
private $speculativePageIdUsed; |
| 342 |
|
| 343 |
private $revisionTimestampUsed; |
| 344 |
|
| 345 |
|
| 346 |
private $revisionUsedSha1Base36; |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
private $mWrapperDivClasses = []; |
| 353 |
|
| 354 |
|
| 355 |
private $mMaxAdaptiveExpiry = INF; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
private const PARSE_FAST_SEC = 0.100; |
| 361 |
private const PARSE_SLOW_SEC = 1.0; |
| 362 |
private const FAST_AR_TTL = 60; |
| 363 |
private const SLOW_AR_TTL = 3600; |
| 364 |
private const MIN_AR_TTL = 15; |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
public function __construct( $text = null, $languageLinks = [], $categoryLinks = [], |
| 377 |
$unused = false, $titletext = '' |
| 378 |
) { |
| 379 |
$this->mRawText = $text; |
| 380 |
$this->mCategories = $categoryLinks; |
| 381 |
$this->mTitleText = $titletext; |
| 382 |
if ( $languageLinks === null ) { |
| 383 |
wfDeprecated( __METHOD__ . ' with null $languageLinks', '1.43' ); |
| 384 |
} |
| 385 |
foreach ( ( $languageLinks ?? [] ) as $ll ) { |
| 386 |
$this->addLanguageLink( $ll ); |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
$this->resetParseStartTime(); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
public function hasText(): bool { |
| 405 |
return ( $this->mRawText !== null ); |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
public function getRawText() { |
| 417 |
if ( $this->mRawText === null ) { |
| 418 |
throw new LogicException( 'This ParserOutput contains no text!' ); |
| 419 |
} |
| 420 |
|
| 421 |
return $this->mRawText; |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
public function getText( $options = [] ) { |
| 469 |
$oldText = $this->mRawText; |
| 470 |
$options += [ 'allowClone' => false ]; |
| 471 |
$po = $this->runPipelineInternal( null, $options ); |
| 472 |
$newText = $po->getContentHolderText(); |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
$this->setRawText( $oldText ); |
| 477 |
return $newText; |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
public function runOutputPipeline( ParserOptions $popts, array $options = [] ): ParserOutput { |
| 526 |
return $this->runPipelineInternal( $popts, $options ); |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
private function runPipelineInternal( ?ParserOptions $popts, array $options = [] ): ParserOutput { |
| 534 |
$pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline(); |
| 535 |
$options += [ |
| 536 |
'allowClone' => true, |
| 537 |
'allowTOC' => true, |
| 538 |
'injectTOC' => true, |
| 539 |
'enableSectionEditLinks' => !$this->getOutputFlag( ParserOutputFlags::NO_SECTION_EDIT_LINKS ), |
| 540 |
'userLang' => null, |
| 541 |
'skin' => null, |
| 542 |
'unwrap' => false, |
| 543 |
'wrapperDivClass' => $this->getWrapperDivClass(), |
| 544 |
'deduplicateStyles' => true, |
| 545 |
'absoluteURLs' => false, |
| 546 |
'includeDebugInfo' => false, |
| 547 |
'isParsoidContent' => PageBundleParserOutputConverter::hasPageBundle( $this ), |
| 548 |
]; |
| 549 |
return $pipeline->run( $this, $popts, $options ); |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
public function addCacheMessage( string $msg ): void { |
| 558 |
$this->mCacheMessage .= $msg; |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
public function addWrapperDivClass( $class ): void { |
| 567 |
$this->mWrapperDivClasses[$class] = true; |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
public function clearWrapperDivClass(): void { |
| 575 |
$this->mWrapperDivClasses = []; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
public function getWrapperDivClass(): string { |
| 586 |
return implode( ' ', array_keys( $this->mWrapperDivClasses ) ); |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
public function setSpeculativeRevIdUsed( $id ): void { |
| 594 |
$this->mSpeculativeRevId = $id; |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
public function getSpeculativeRevIdUsed(): ?int { |
| 602 |
return $this->mSpeculativeRevId; |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
public function setSpeculativePageIdUsed( $id ): void { |
| 610 |
$this->speculativePageIdUsed = $id; |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
public function getSpeculativePageIdUsed() { |
| 618 |
return $this->speculativePageIdUsed; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
public function setRevisionTimestampUsed( $timestamp ): void { |
| 626 |
$this->revisionTimestampUsed = $timestamp; |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
public function getRevisionTimestampUsed() { |
| 634 |
return $this->revisionTimestampUsed; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
public function setRevisionUsedSha1Base36( $hash ): void { |
| 642 |
if ( $hash === null ) { |
| 643 |
return; |
| 644 |
} |
| 645 |
|
| 646 |
if ( |
| 647 |
$this->revisionUsedSha1Base36 !== null && |
| 648 |
$this->revisionUsedSha1Base36 !== $hash |
| 649 |
) { |
| 650 |
$this->revisionUsedSha1Base36 = ''; |
| 651 |
} else { |
| 652 |
$this->revisionUsedSha1Base36 = $hash; |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
public function getRevisionUsedSha1Base36() { |
| 661 |
return $this->revisionUsedSha1Base36; |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
public function getLanguageLinks() { |
| 670 |
$result = []; |
| 671 |
foreach ( $this->mLanguageLinkMap as $lang => $title ) { |
| 672 |
|
| 673 |
$result[] = $title === '|' ? "$lang" : "$lang:$title"; |
| 674 |
} |
| 675 |
return $result; |
| 676 |
} |
| 677 |
|
| 678 |
|
| 679 |
public function getInterwikiLinks() { |
| 680 |
return $this->mInterwikiLinks; |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
public function getCategoryNames(): array { |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
return array_map( 'strval', array_keys( $this->mCategories ) ); |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
public function getCategoryMap(): array { |
| 709 |
return $this->mCategories; |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
public function getCategorySortKey( string $name ): ?string { |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
return $this->mCategories[$name] ?? null; |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
public function getIndicators(): array { |
| 737 |
return $this->mIndicators; |
| 738 |
} |
| 739 |
|
| 740 |
public function getTitleText() { |
| 741 |
return $this->mTitleText; |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
public function getTOCData(): ?TOCData { |
| 749 |
return $this->mTOCData; |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
public function getCacheMessage(): string { |
| 757 |
return $this->mCacheMessage; |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
public function getSections(): array { |
| 765 |
if ( $this->mTOCData !== null ) { |
| 766 |
return $this->mTOCData->toLegacy(); |
| 767 |
} |
| 768 |
|
| 769 |
return []; |
| 770 |
} |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
public function getLinkList( string $linkType ): array { |
| 788 |
|
| 789 |
$result = []; |
| 790 |
switch ( $linkType ) { |
| 791 |
case ParserOutputLinkTypes::CATEGORY: |
| 792 |
foreach ( $this->mCategories as $dbkey => $sort ) { |
| 793 |
$result[] = [ |
| 794 |
'link' => new TitleValue( NS_CATEGORY, (string)$dbkey ), |
| 795 |
'sort' => $sort, |
| 796 |
]; |
| 797 |
} |
| 798 |
break; |
| 799 |
|
| 800 |
case ParserOutputLinkTypes::INTERWIKI: |
| 801 |
foreach ( $this->mInterwikiLinks as $prefix => $arr ) { |
| 802 |
foreach ( $arr as $dbkey => $ignore ) { |
| 803 |
$result[] = [ |
| 804 |
'link' => new TitleValue( NS_MAIN, (string)$dbkey, '', (string)$prefix ), |
| 805 |
]; |
| 806 |
} |
| 807 |
} |
| 808 |
break; |
| 809 |
|
| 810 |
case ParserOutputLinkTypes::LANGUAGE: |
| 811 |
foreach ( $this->mLanguageLinkMap as $lang => $title ) { |
| 812 |
if ( $title === '|' ) { |
| 813 |
continue; |
| 814 |
} |
| 815 |
|
| 816 |
[ $title, $frag ] = array_pad( explode( '#', $title, 2 ), 2, '' ); |
| 817 |
$result[] = [ |
| 818 |
'link' => new TitleValue( NS_MAIN, $title, $frag, (string)$lang ), |
| 819 |
]; |
| 820 |
} |
| 821 |
break; |
| 822 |
|
| 823 |
case ParserOutputLinkTypes::LOCAL: |
| 824 |
foreach ( $this->mLinks as $ns => $arr ) { |
| 825 |
foreach ( $arr as $dbkey => $id ) { |
| 826 |
$result[] = [ |
| 827 |
'link' => new TitleValue( $ns, (string)$dbkey ), |
| 828 |
'pageid' => $id, |
| 829 |
]; |
| 830 |
} |
| 831 |
} |
| 832 |
break; |
| 833 |
|
| 834 |
case ParserOutputLinkTypes::MEDIA: |
| 835 |
foreach ( $this->mImages as $dbkey => $ignore ) { |
| 836 |
$extra = $this->mFileSearchOptions[$dbkey] ?? []; |
| 837 |
$extra['link'] = new TitleValue( NS_FILE, (string)$dbkey ); |
| 838 |
$result[] = $extra; |
| 839 |
} |
| 840 |
break; |
| 841 |
|
| 842 |
case ParserOutputLinkTypes::SPECIAL: |
| 843 |
foreach ( $this->mLinksSpecial as $dbkey => $ignore ) { |
| 844 |
$result[] = [ |
| 845 |
'link' => new TitleValue( NS_SPECIAL, (string)$dbkey ), |
| 846 |
]; |
| 847 |
} |
| 848 |
break; |
| 849 |
|
| 850 |
case ParserOutputLinkTypes::TEMPLATE: |
| 851 |
foreach ( $this->mTemplates as $ns => $arr ) { |
| 852 |
foreach ( $arr as $dbkey => $pageid ) { |
| 853 |
$result[] = [ |
| 854 |
'link' => new TitleValue( $ns, (string)$dbkey ), |
| 855 |
'pageid' => $pageid, |
| 856 |
'revid' => $this->mTemplateIds[$ns][$dbkey], |
| 857 |
]; |
| 858 |
} |
| 859 |
} |
| 860 |
break; |
| 861 |
|
| 862 |
default: |
| 863 |
throw new UnexpectedValueException( "Unknown link type $linkType" ); |
| 864 |
} |
| 865 |
return $result; |
| 866 |
} |
| 867 |
|
| 868 |
|
| 869 |
public function &getLinks() { |
| 870 |
return $this->mLinks; |
| 871 |
} |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
public function &getLinksSpecial() { |
| 879 |
return $this->mLinksSpecial; |
| 880 |
} |
| 881 |
|
| 882 |
|
| 883 |
public function &getTemplates() { |
| 884 |
return $this->mTemplates; |
| 885 |
} |
| 886 |
|
| 887 |
|
| 888 |
public function &getTemplateIds() { |
| 889 |
return $this->mTemplateIds; |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
public function &getImages() { |
| 894 |
return $this->mImages; |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
public function &getFileSearchOptions() { |
| 899 |
return $this->mFileSearchOptions; |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
public function &getExternalLinks(): array { |
| 909 |
return $this->mExternalLinks; |
| 910 |
} |
| 911 |
|
| 912 |
public function setNoGallery( $value ): void { |
| 913 |
$this->mNoGallery = (bool)$value; |
| 914 |
} |
| 915 |
|
| 916 |
public function getNoGallery() { |
| 917 |
return $this->mNoGallery; |
| 918 |
} |
| 919 |
|
| 920 |
public function getHeadItems() { |
| 921 |
return $this->mHeadItems; |
| 922 |
} |
| 923 |
|
| 924 |
public function getModules() { |
| 925 |
return array_keys( $this->mModuleSet ); |
| 926 |
} |
| 927 |
|
| 928 |
public function getModuleStyles() { |
| 929 |
return array_keys( $this->mModuleStyleSet ); |
| 930 |
} |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
public function getJsConfigVars( bool $showStrategyKeys = false ) { |
| 940 |
$result = $this->mJsConfigVars; |
| 941 |
|
| 942 |
foreach ( $result as &$value ) { |
| 943 |
if ( is_array( $value ) && !$showStrategyKeys ) { |
| 944 |
unset( $value[self::MW_MERGE_STRATEGY_KEY] ); |
| 945 |
} |
| 946 |
} |
| 947 |
return $result; |
| 948 |
} |
| 949 |
|
| 950 |
public function getWarnings(): array { |
| 951 |
return array_keys( $this->mWarnings ); |
| 952 |
} |
| 953 |
|
| 954 |
public function getIndexPolicy(): string { |
| 955 |
|
| 956 |
if ( $this->mNoIndexSet ) { |
| 957 |
return 'noindex'; |
| 958 |
} elseif ( $this->mIndexSet ) { |
| 959 |
return 'index'; |
| 960 |
} |
| 961 |
return ''; |
| 962 |
} |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
public function getRevisionTimestamp(): ?string { |
| 968 |
return $this->mTimestamp; |
| 969 |
} |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
public function getTimestamp() { |
| 976 |
return $this->getRevisionTimestamp(); |
| 977 |
} |
| 978 |
|
| 979 |
public function getLimitReportData() { |
| 980 |
return $this->mLimitReportData; |
| 981 |
} |
| 982 |
|
| 983 |
public function getLimitReportJSData() { |
| 984 |
return $this->mLimitReportJSData; |
| 985 |
} |
| 986 |
|
| 987 |
public function getEnableOOUI() { |
| 988 |
return $this->mEnableOOUI; |
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
public function getExtraCSPDefaultSrcs() { |
| 997 |
return $this->mExtraDefaultSrcs; |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
public function getExtraCSPScriptSrcs() { |
| 1006 |
return $this->mExtraScriptSrcs; |
| 1007 |
} |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
public function getExtraCSPStyleSrcs() { |
| 1015 |
return $this->mExtraStyleSrcs; |
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
public function setRawText( ?string $text ): void { |
| 1028 |
$this->mRawText = $text; |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
public function setText( $text ) { |
| 1043 |
return wfSetVar( $this->mRawText, $text, true ); |
| 1044 |
} |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
public function setLanguageLinks( $ll ) { |
| 1050 |
$old = $this->getLanguageLinks(); |
| 1051 |
$this->mLanguageLinkMap = []; |
| 1052 |
if ( $ll === null ) { |
| 1053 |
wfDeprecated( __METHOD__ . ' with null argument', '1.43' ); |
| 1054 |
} |
| 1055 |
foreach ( ( $ll ?? [] ) as $l ) { |
| 1056 |
$this->addLanguageLink( $l ); |
| 1057 |
} |
| 1058 |
return $old; |
| 1059 |
} |
| 1060 |
|
| 1061 |
public function setTitleText( $t ) { |
| 1062 |
return wfSetVar( $this->mTitleText, $t ); |
| 1063 |
} |
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
public function setTOCData( TOCData $tocData ): void { |
| 1069 |
$this->mTOCData = $tocData; |
| 1070 |
} |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
public function setSections( array $sectionArray ) { |
| 1077 |
$oldValue = $this->getSections(); |
| 1078 |
$this->setTOCData( TOCData::fromLegacy( $sectionArray ) ); |
| 1079 |
return $oldValue; |
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
– |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
public function setIndexPolicy( $policy ): string { |
| 1096 |
$old = $this->getIndexPolicy(); |
| 1097 |
if ( $policy === 'noindex' ) { |
| 1098 |
$this->mNoIndexSet = true; |
| 1099 |
} elseif ( $policy === 'index' ) { |
| 1100 |
$this->mIndexSet = true; |
| 1101 |
} |
| 1102 |
return $old; |
| 1103 |
} |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
public function setRevisionTimestamp( ?string $timestamp ): void { |
| 1109 |
$this->mTimestamp = $timestamp; |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
public function setTimestamp( $timestamp ) { |
| 1119 |
return wfSetVar( $this->mTimestamp, $timestamp ); |
| 1120 |
} |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
public function addCategory( $c, $sort = '' ): void { |
| 1138 |
if ( $c instanceof ParsoidLinkTarget ) { |
| 1139 |
$c = $c->getDBkey(); |
| 1140 |
} |
| 1141 |
$this->mCategories[$c] = $sort; |
| 1142 |
} |
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
public function setCategories( array $c ): void { |
| 1150 |
$this->mCategories = $c; |
| 1151 |
} |
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
public function setIndicator( $id, $content ): void { |
| 1160 |
$this->mIndicators[$id] = $content; |
| 1161 |
} |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
public function setEnableOOUI( bool $enable = false ): void { |
| 1171 |
$this->mEnableOOUI = $enable; |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
public function addLanguageLink( $t ): void { |
| 1179 |
|
| 1180 |
if ( $t instanceof ParsoidLinkTarget ) { |
| 1181 |
|
| 1182 |
|
| 1183 |
$lang = $t->getInterwiki(); |
| 1184 |
$title = $t->getText(); |
| 1185 |
if ( $t->hasFragment() ) { |
| 1186 |
$title .= '#' . $t->getFragment(); |
| 1187 |
} |
| 1188 |
} else { |
| 1189 |
[ $lang, $title ] = array_pad( explode( ':', $t, 2 ), -2, '' ); |
| 1190 |
} |
| 1191 |
if ( $lang === '' ) { |
| 1192 |
|
| 1193 |
wfDeprecated( __METHOD__ . ' without prefix', '1.43' ); |
| 1194 |
[ $lang, $title ] = [ $title, '|' ]; |
| 1195 |
} |
| 1196 |
$this->mLanguageLinkMap[$lang] ??= $title; |
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
public function addWarningMsgVal( MessageValue $mv ) { |
| 1207 |
$m = ( new Converter() )->convertMessageValue( $mv ); |
| 1208 |
|
| 1209 |
$this->addWarningMsg( $m->getKey(), ...$m->getParams() ); |
| 1210 |
} |
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
public function addWarningMsg( string $msg, ...$args ): void { |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
$jsonCodec = MediaWikiServices::getInstance()->getJsonCodec(); |
| 1231 |
$path = $jsonCodec->detectNonSerializableData( $args, true ); |
| 1232 |
if ( $path !== null ) { |
| 1233 |
wfDeprecatedMsg( |
| 1234 |
"ParserOutput::addWarningMsg() called with nonserializable arguments: $path", |
| 1235 |
'1.41' |
| 1236 |
); |
| 1237 |
} |
| 1238 |
$this->mWarningMsgs[$msg] = $args; |
| 1239 |
$s = wfMessage( $msg, ...$args ) |
| 1240 |
|
| 1241 |
->inContentLanguage() |
| 1242 |
->text(); |
| 1243 |
$this->mWarnings[$s] = 1; |
| 1244 |
} |
| 1245 |
|
| 1246 |
public function setNewSection( $value ): void { |
| 1247 |
$this->mNewSection = (bool)$value; |
| 1248 |
} |
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
public function setHideNewSection( bool $value ): void { |
| 1254 |
$this->mHideNewSection = $value; |
| 1255 |
} |
| 1256 |
|
| 1257 |
public function getHideNewSection(): bool { |
| 1258 |
return (bool)$this->mHideNewSection; |
| 1259 |
} |
| 1260 |
|
| 1261 |
public function getNewSection(): bool { |
| 1262 |
return (bool)$this->mNewSection; |
| 1263 |
} |
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
public static function isLinkInternal( $internal, $url ): bool { |
| 1274 |
return (bool)preg_match( '/^' . |
| 1275 |
|
| 1276 |
( substr( $internal, 0, 2 ) === '//' ? '(?:https?:)?' : '' ) . |
| 1277 |
preg_quote( $internal, '/' ) . |
| 1278 |
|
| 1279 |
'(?:[\?\/\#]|$)/i', |
| 1280 |
$url |
| 1281 |
); |
| 1282 |
} |
| 1283 |
|
| 1284 |
public function addExternalLink( $url ): void { |
| 1285 |
|
| 1286 |
$config = MediaWikiServices::getInstance()->getMainConfig(); |
| 1287 |
$server = $config->get( MainConfigNames::Server ); |
| 1288 |
$registerInternalExternals = $config->get( MainConfigNames::RegisterInternalExternals ); |
| 1289 |
|
| 1290 |
|
| 1291 |
$url = Parser::normalizeLinkUrl( $url ); |
| 1292 |
|
| 1293 |
$registerExternalLink = true; |
| 1294 |
if ( !$registerInternalExternals ) { |
| 1295 |
$registerExternalLink = !self::isLinkInternal( $server, $url ); |
| 1296 |
} |
| 1297 |
if ( $registerExternalLink ) { |
| 1298 |
$this->mExternalLinks[$url] = 1; |
| 1299 |
} |
| 1300 |
} |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
public function addLink( ParsoidLinkTarget $link, $id = null ): void { |
| 1309 |
if ( $link->isExternal() ) { |
| 1310 |
|
| 1311 |
$this->addInterwikiLink( $link ); |
| 1312 |
return; |
| 1313 |
} |
| 1314 |
$ns = $link->getNamespace(); |
| 1315 |
$dbk = $link->getDBkey(); |
| 1316 |
if ( $ns === NS_MEDIA ) { |
| 1317 |
|
| 1318 |
$ns = NS_FILE; |
| 1319 |
} elseif ( $ns === NS_SPECIAL ) { |
| 1320 |
|
| 1321 |
|
| 1322 |
$this->mLinksSpecial[$dbk] = 1; |
| 1323 |
return; |
| 1324 |
} elseif ( $dbk === '' ) { |
| 1325 |
|
| 1326 |
return; |
| 1327 |
} |
| 1328 |
if ( $id === null ) { |
| 1329 |
|
| 1330 |
$page = MediaWikiServices::getInstance()->getPageStore()->getPageForLink( $link ); |
| 1331 |
$id = $page->getId(); |
| 1332 |
} |
| 1333 |
$this->mLinks[$ns][$dbk] = $id; |
| 1334 |
} |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
public function addImage( $name, $timestamp = null, $sha1 = null ): void { |
| 1343 |
if ( $name instanceof ParsoidLinkTarget ) { |
| 1344 |
$name = $name->getDBkey(); |
| 1345 |
} |
| 1346 |
$this->mImages[$name] = 1; |
| 1347 |
if ( $timestamp !== null && $sha1 !== null ) { |
| 1348 |
$this->mFileSearchOptions[$name] = [ 'time' => $timestamp, 'sha1' => $sha1 ]; |
| 1349 |
} |
| 1350 |
} |
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
public function addTemplate( $link, $page_id, $rev_id ): void { |
| 1360 |
if ( $link->isExternal() ) { |
| 1361 |
|
| 1362 |
wfDeprecated( __METHOD__ . " with interwiki link", '1.42' ); |
| 1363 |
return; |
| 1364 |
} |
| 1365 |
$ns = $link->getNamespace(); |
| 1366 |
$dbk = $link->getDBkey(); |
| 1367 |
|
| 1368 |
$this->mTemplates[$ns][$dbk] = $page_id; |
| 1369 |
$this->mTemplateIds[$ns][$dbk] = $rev_id; |
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
public function addInterwikiLink( $link ): void { |
| 1377 |
if ( !$link->isExternal() ) { |
| 1378 |
throw new InvalidArgumentException( 'Non-interwiki link passed, internal parser error.' ); |
| 1379 |
} |
| 1380 |
$prefix = $link->getInterwiki(); |
| 1381 |
$this->mInterwikiLinks[$prefix][$link->getDBkey()] = 1; |
| 1382 |
} |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
public function addHeadItem( $section, $tag = false ): void { |
| 1392 |
if ( $tag !== false ) { |
| 1393 |
$this->mHeadItems[$tag] = $section; |
| 1394 |
} else { |
| 1395 |
$this->mHeadItems[] = $section; |
| 1396 |
} |
| 1397 |
} |
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
public function addModules( array $modules ): void { |
| 1404 |
$modules = array_fill_keys( $modules, true ); |
| 1405 |
$this->mModuleSet = array_merge( $this->mModuleSet, $modules ); |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
public function addModuleStyles( array $modules ): void { |
| 1413 |
$modules = array_fill_keys( $modules, true ); |
| 1414 |
$this->mModuleStyleSet = array_merge( $this->mModuleStyleSet, $modules ); |
| 1415 |
} |
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
public function addJsConfigVars( $keys, $value = null ): void { |
| 1428 |
wfDeprecated( __METHOD__, '1.38' ); |
| 1429 |
if ( is_array( $keys ) ) { |
| 1430 |
foreach ( $keys as $key => $value ) { |
| 1431 |
$this->mJsConfigVars[$key] = $value; |
| 1432 |
} |
| 1433 |
return; |
| 1434 |
} |
| 1435 |
|
| 1436 |
$this->mJsConfigVars[$keys] = $value; |
| 1437 |
} |
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
public function setJsConfigVar( string $key, $value ): void { |
| 1453 |
if ( |
| 1454 |
array_key_exists( $key, $this->mJsConfigVars ) && |
| 1455 |
$this->mJsConfigVars[$key] !== $value |
| 1456 |
) { |
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
throw new InvalidArgumentException( "Multiple conflicting values given for $key" ); |
| 1461 |
} |
| 1462 |
$this->mJsConfigVars[$key] = $value; |
| 1463 |
} |
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
public function appendJsConfigVar( |
| 1483 |
string $key, |
| 1484 |
string $value, |
| 1485 |
string $strategy = self::MW_MERGE_STRATEGY_UNION |
| 1486 |
): void { |
| 1487 |
if ( $strategy !== self::MW_MERGE_STRATEGY_UNION ) { |
| 1488 |
throw new InvalidArgumentException( "Unknown merge strategy $strategy." ); |
| 1489 |
} |
| 1490 |
if ( !array_key_exists( $key, $this->mJsConfigVars ) ) { |
| 1491 |
$this->mJsConfigVars[$key] = [ |
| 1492 |
|
| 1493 |
self::MW_MERGE_STRATEGY_KEY => $strategy, |
| 1494 |
]; |
| 1495 |
} elseif ( !is_array( $this->mJsConfigVars[$key] ) ) { |
| 1496 |
throw new InvalidArgumentException( "Mixing set and append for $key" ); |
| 1497 |
} elseif ( ( $this->mJsConfigVars[$key][self::MW_MERGE_STRATEGY_KEY] ?? null ) !== $strategy ) { |
| 1498 |
throw new InvalidArgumentException( "Conflicting merge strategies for $key" ); |
| 1499 |
} |
| 1500 |
$this->mJsConfigVars[$key][$value] = true; |
| 1501 |
} |
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
public function addOutputPageMetadata( OutputPage $out ): void { |
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
$this->mPreventClickjacking = $this->mPreventClickjacking || $out->getPreventClickjacking(); |
| 1531 |
|
| 1532 |
$this->addModuleStyles( $out->getModuleStyles() ); |
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
$this->addModules( $out->getModules() ); |
| 1538 |
$this->mJsConfigVars = self::mergeMapStrategy( |
| 1539 |
$this->mJsConfigVars, $out->getJsConfigVars() |
| 1540 |
); |
| 1541 |
$this->mHeadItems = array_merge( $this->mHeadItems, $out->getHeadItemsArray() ); |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
public function setDisplayTitle( $text ): void { |
| 1556 |
$this->setTitleText( $text ); |
| 1557 |
$this->setPageProperty( 'displaytitle', $text ); |
| 1558 |
} |
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
public function getDisplayTitle() { |
| 1569 |
$t = $this->getTitleText(); |
| 1570 |
if ( $t === '' ) { |
| 1571 |
return false; |
| 1572 |
} |
| 1573 |
return $t; |
| 1574 |
} |
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
public function getTitle(): ?ParsoidLinkTarget { |
| 1585 |
$ns = $this->getExtensionData( 'core:title-ns' ); |
| 1586 |
$dbkey = $this->getExtensionData( 'core:title-dbkey' ); |
| 1587 |
if ( $dbkey !== null ) { |
| 1588 |
return new TitleValue( $ns ?? NS_MAIN, $dbkey ); |
| 1589 |
} |
| 1590 |
|
| 1591 |
$dbkey = $this->getExtensionData( 'parsoid:title-dbkey' ); |
| 1592 |
if ( $dbkey !== null ) { |
| 1593 |
|
| 1594 |
$titleFactory = MediaWikiServices::getInstance()->getTitleFactory(); |
| 1595 |
return $titleFactory->newFromDBkey( $dbkey ); |
| 1596 |
} |
| 1597 |
return null; |
| 1598 |
} |
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
public function getLanguage(): ?Bcp47Code { |
| 1639 |
|
| 1640 |
$code = $this->getExtensionData( 'core:target-lang-variant' ); |
| 1641 |
|
| 1642 |
|
| 1643 |
return $code === null ? null : new Bcp47CodeValue( $code ); |
| 1644 |
} |
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
public function setLanguage( Bcp47Code $lang ): void { |
| 1656 |
$this->setExtensionData( 'core:target-lang-variant', $lang->toBcp47Code() ); |
| 1657 |
} |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
public function getRedirectHeader(): ?string { |
| 1666 |
return $this->getExtensionData( 'core:redirect-header' ); |
| 1667 |
} |
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
public function setRedirectHeader( string $html ): void { |
| 1674 |
$this->setExtensionData( 'core:redirect-header', $html ); |
| 1675 |
} |
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
public function setRenderId( string $renderId ): void { |
| 1686 |
$this->setExtensionData( 'core:render-id', $renderId ); |
| 1687 |
} |
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
public function getRenderId(): ?string { |
| 1697 |
|
| 1698 |
|
| 1699 |
$old = $this->getExtensionData( 'parsoid-render-id' ); |
| 1700 |
if ( $old !== null ) { |
| 1701 |
return ParsoidRenderId::newFromKey( $old )->getUniqueID(); |
| 1702 |
} |
| 1703 |
return $this->getExtensionData( 'core:render-id' ); |
| 1704 |
} |
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
public function getAllFlags(): array { |
| 1711 |
return array_keys( $this->mFlags ); |
| 1712 |
} |
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
public function setPageProperty( string $name, $value ): void { |
| 1807 |
if ( $value === null ) { |
| 1808 |
|
| 1809 |
wfDeprecated( __METHOD__ . " with null value for $name", '1.42' ); |
| 1810 |
} elseif ( !is_scalar( $value ) ) { |
| 1811 |
|
| 1812 |
wfDeprecated( __METHOD__ . " with non-scalar value for $name", '1.42' ); |
| 1813 |
} elseif ( !is_string( $value ) ) { |
| 1814 |
|
| 1815 |
wfDeprecated( __METHOD__ . " with non-string value for $name", '1.42' ); |
| 1816 |
} |
| 1817 |
$this->mProperties[$name] = $value; |
| 1818 |
} |
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
public function setNumericPageProperty( string $propName, $numericValue ): void { |
| 1835 |
if ( !is_numeric( $numericValue ) ) { |
| 1836 |
throw new \TypeError( __METHOD__ . " with non-numeric value" ); |
| 1837 |
} |
| 1838 |
|
| 1839 |
$this->mProperties[$propName] = 0 + $numericValue; |
| 1840 |
} |
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
public function setUnsortedPageProperty( string $propName, string $value = '' ): void { |
| 1860 |
$this->mProperties[$propName] = $value; |
| 1861 |
} |
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
public function getPageProperty( string $name ) { |
| 1877 |
return $this->mProperties[$name] ?? null; |
| 1878 |
} |
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
public function unsetPageProperty( string $name ): void { |
| 1886 |
unset( $this->mProperties[$name] ); |
| 1887 |
} |
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
public function getPageProperties(): array { |
| 1895 |
if ( !isset( $this->mProperties ) ) { |
| 1896 |
$this->mProperties = []; |
| 1897 |
} |
| 1898 |
return $this->mProperties; |
| 1899 |
} |
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
public function setOutputFlag( string $name, bool $val = true ): void { |
| 1922 |
switch ( $name ) { |
| 1923 |
case ParserOutputFlags::NO_GALLERY: |
| 1924 |
$this->setNoGallery( $val ); |
| 1925 |
break; |
| 1926 |
|
| 1927 |
case ParserOutputFlags::ENABLE_OOUI: |
| 1928 |
$this->setEnableOOUI( $val ); |
| 1929 |
break; |
| 1930 |
|
| 1931 |
case ParserOutputFlags::NO_INDEX_POLICY: |
| 1932 |
$this->mNoIndexSet = $val; |
| 1933 |
break; |
| 1934 |
|
| 1935 |
case ParserOutputFlags::INDEX_POLICY: |
| 1936 |
$this->mIndexSet = $val; |
| 1937 |
break; |
| 1938 |
|
| 1939 |
case ParserOutputFlags::NEW_SECTION: |
| 1940 |
$this->setNewSection( $val ); |
| 1941 |
break; |
| 1942 |
|
| 1943 |
case ParserOutputFlags::HIDE_NEW_SECTION: |
| 1944 |
$this->setHideNewSection( $val ); |
| 1945 |
break; |
| 1946 |
|
| 1947 |
case ParserOutputFlags::PREVENT_CLICKJACKING: |
| 1948 |
$this->setPreventClickjacking( $val ); |
| 1949 |
break; |
| 1950 |
|
| 1951 |
default: |
| 1952 |
if ( $val ) { |
| 1953 |
$this->mFlags[$name] = true; |
| 1954 |
} else { |
| 1955 |
unset( $this->mFlags[$name] ); |
| 1956 |
} |
| 1957 |
break; |
| 1958 |
} |
| 1959 |
} |
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
public function getOutputFlag( string $name ): bool { |
| 1974 |
switch ( $name ) { |
| 1975 |
case ParserOutputFlags::NO_GALLERY: |
| 1976 |
return $this->getNoGallery(); |
| 1977 |
|
| 1978 |
case ParserOutputFlags::ENABLE_OOUI: |
| 1979 |
return $this->getEnableOOUI(); |
| 1980 |
|
| 1981 |
case ParserOutputFlags::INDEX_POLICY: |
| 1982 |
return $this->mIndexSet; |
| 1983 |
|
| 1984 |
case ParserOutputFlags::NO_INDEX_POLICY: |
| 1985 |
return $this->mNoIndexSet; |
| 1986 |
|
| 1987 |
case ParserOutputFlags::NEW_SECTION: |
| 1988 |
return $this->getNewSection(); |
| 1989 |
|
| 1990 |
case ParserOutputFlags::HIDE_NEW_SECTION: |
| 1991 |
return $this->getHideNewSection(); |
| 1992 |
|
| 1993 |
case ParserOutputFlags::PREVENT_CLICKJACKING: |
| 1994 |
return $this->getPreventClickjacking(); |
| 1995 |
|
| 1996 |
default: |
| 1997 |
return isset( $this->mFlags[$name] ); |
| 1998 |
|
| 1999 |
} |
| 2000 |
} |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
public function appendOutputStrings( string $name, array $value ): void { |
| 2014 |
switch ( $name ) { |
| 2015 |
case ParserOutputStringSets::MODULE: |
| 2016 |
$this->addModules( $value ); |
| 2017 |
break; |
| 2018 |
case ParserOutputStringSets::MODULE_STYLE: |
| 2019 |
$this->addModuleStyles( $value ); |
| 2020 |
break; |
| 2021 |
case ParserOutputStringSets::EXTRA_CSP_DEFAULT_SRC: |
| 2022 |
foreach ( $value as $v ) { |
| 2023 |
$this->addExtraCSPDefaultSrc( $v ); |
| 2024 |
} |
| 2025 |
break; |
| 2026 |
case ParserOutputStringSets::EXTRA_CSP_SCRIPT_SRC: |
| 2027 |
foreach ( $value as $v ) { |
| 2028 |
$this->addExtraCSPScriptSrc( $v ); |
| 2029 |
} |
| 2030 |
break; |
| 2031 |
case ParserOutputStringSets::EXTRA_CSP_STYLE_SRC: |
| 2032 |
foreach ( $value as $v ) { |
| 2033 |
$this->addExtraCSPStyleSrc( $v ); |
| 2034 |
} |
| 2035 |
break; |
| 2036 |
default: |
| 2037 |
throw new UnexpectedValueException( "Unknown output string set name $name" ); |
| 2038 |
} |
| 2039 |
} |
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
public function getOutputStrings( string $name ): array { |
| 2054 |
switch ( $name ) { |
| 2055 |
case ParserOutputStringSets::MODULE: |
| 2056 |
return $this->getModules(); |
| 2057 |
case ParserOutputStringSets::MODULE_STYLE: |
| 2058 |
return $this->getModuleStyles(); |
| 2059 |
case ParserOutputStringSets::EXTRA_CSP_DEFAULT_SRC: |
| 2060 |
return $this->getExtraCSPDefaultSrcs(); |
| 2061 |
case ParserOutputStringSets::EXTRA_CSP_SCRIPT_SRC: |
| 2062 |
return $this->getExtraCSPScriptSrcs(); |
| 2063 |
case ParserOutputStringSets::EXTRA_CSP_STYLE_SRC: |
| 2064 |
return $this->getExtraCSPStyleSrcs(); |
| 2065 |
default: |
| 2066 |
throw new UnexpectedValueException( "Unknown output string set name $name" ); |
| 2067 |
} |
| 2068 |
} |
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
|
| 2112 |
|
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
public function setExtensionData( $key, $value ): void { |
| 2120 |
if ( |
| 2121 |
array_key_exists( $key, $this->mExtensionData ) && |
| 2122 |
$this->mExtensionData[$key] !== $value |
| 2123 |
) { |
| 2124 |
|
| 2125 |
|
| 2126 |
} |
| 2127 |
if ( $value === null ) { |
| 2128 |
unset( $this->mExtensionData[$key] ); |
| 2129 |
} else { |
| 2130 |
$this->mExtensionData[$key] = $value; |
| 2131 |
} |
| 2132 |
} |
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
public function appendExtensionData( |
| 2160 |
string $key, |
| 2161 |
$value, |
| 2162 |
string $strategy = self::MW_MERGE_STRATEGY_UNION |
| 2163 |
): void { |
| 2164 |
if ( $strategy !== self::MW_MERGE_STRATEGY_UNION ) { |
| 2165 |
throw new InvalidArgumentException( "Unknown merge strategy $strategy." ); |
| 2166 |
} |
| 2167 |
if ( !array_key_exists( $key, $this->mExtensionData ) ) { |
| 2168 |
$this->mExtensionData[$key] = [ |
| 2169 |
|
| 2170 |
self::MW_MERGE_STRATEGY_KEY => $strategy, |
| 2171 |
]; |
| 2172 |
} elseif ( !is_array( $this->mExtensionData[$key] ) ) { |
| 2173 |
throw new InvalidArgumentException( "Mixing set and append for $key" ); |
| 2174 |
} elseif ( ( $this->mExtensionData[$key][self::MW_MERGE_STRATEGY_KEY] ?? null ) !== $strategy ) { |
| 2175 |
throw new InvalidArgumentException( "Conflicting merge strategies for $key" ); |
| 2176 |
} |
| 2177 |
$this->mExtensionData[$key][$value] = true; |
| 2178 |
} |
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
public function getExtensionData( $key ) { |
| 2192 |
$value = $this->mExtensionData[$key] ?? null; |
| 2193 |
if ( is_array( $value ) ) { |
| 2194 |
|
| 2195 |
unset( $value[self::MW_MERGE_STRATEGY_KEY] ); |
| 2196 |
} |
| 2197 |
return $value; |
| 2198 |
} |
| 2199 |
|
| 2200 |
private static function getTimes( $clock = null ): array { |
| 2201 |
$ret = []; |
| 2202 |
if ( !$clock || $clock === 'wall' ) { |
| 2203 |
$ret['wall'] = microtime( true ); |
| 2204 |
} |
| 2205 |
if ( !$clock || $clock === 'cpu' ) { |
| 2206 |
$ru = getrusage( 0 ); |
| 2207 |
$ret['cpu'] = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6; |
| 2208 |
$ret['cpu'] += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6; |
| 2209 |
} |
| 2210 |
return $ret; |
| 2211 |
} |
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
public function resetParseStartTime(): void { |
| 2220 |
$this->mParseStartTime = self::getTimes(); |
| 2221 |
$this->mTimeProfile = []; |
| 2222 |
} |
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
public function clearParseStartTime(): void { |
| 2234 |
$this->mParseStartTime = []; |
| 2235 |
} |
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
public function recordTimeProfile() { |
| 2248 |
if ( !$this->mParseStartTime ) { |
| 2249 |
|
| 2250 |
return; |
| 2251 |
} |
| 2252 |
|
| 2253 |
if ( $this->mTimeProfile !== [] ) { |
| 2254 |
|
| 2255 |
return; |
| 2256 |
} |
| 2257 |
|
| 2258 |
$now = self::getTimes(); |
| 2259 |
$this->mTimeProfile = [ |
| 2260 |
'wall' => $now['wall'] - $this->mParseStartTime['wall'], |
| 2261 |
'cpu' => $now['cpu'] - $this->mParseStartTime['cpu'], |
| 2262 |
]; |
| 2263 |
} |
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
public function getTimeProfile( string $clock ) { |
| 2283 |
return $this->mTimeProfile[ $clock ] ?? null; |
| 2284 |
} |
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
public function getTimeSinceStart( $clock ) { |
| 2299 |
wfDeprecated( __METHOD__, '1.42' ); |
| 2300 |
|
| 2301 |
if ( !isset( $this->mParseStartTime[$clock] ) ) { |
| 2302 |
return null; |
| 2303 |
} |
| 2304 |
|
| 2305 |
$end = self::getTimes( $clock ); |
| 2306 |
return $end[$clock] - $this->mParseStartTime[$clock]; |
| 2307 |
} |
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
public function setLimitReportData( $key, $value ): void { |
| 2329 |
$this->mLimitReportData[$key] = $value; |
| 2330 |
|
| 2331 |
if ( is_array( $value ) ) { |
| 2332 |
if ( array_keys( $value ) === [ 0, 1 ] |
| 2333 |
&& is_numeric( $value[0] ) |
| 2334 |
&& is_numeric( $value[1] ) |
| 2335 |
) { |
| 2336 |
$data = [ 'value' => $value[0], 'limit' => $value[1] ]; |
| 2337 |
} else { |
| 2338 |
$data = $value; |
| 2339 |
} |
| 2340 |
} else { |
| 2341 |
$data = $value; |
| 2342 |
} |
| 2343 |
|
| 2344 |
if ( strpos( $key, '-' ) ) { |
| 2345 |
[ $ns, $name ] = explode( '-', $key, 2 ); |
| 2346 |
$this->mLimitReportJSData[$ns][$name] = $data; |
| 2347 |
} else { |
| 2348 |
$this->mLimitReportJSData[$key] = $data; |
| 2349 |
} |
| 2350 |
} |
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
public function hasReducedExpiry(): bool { |
| 2369 |
$parserCacheExpireTime = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 2370 |
MainConfigNames::ParserCacheExpireTime ); |
| 2371 |
|
| 2372 |
return $this->getCacheExpiry() < $parserCacheExpireTime; |
| 2373 |
} |
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
public function setPreventClickjacking( bool $flag ): void { |
| 2388 |
$this->mPreventClickjacking = $flag; |
| 2389 |
} |
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
public function getPreventClickjacking(): bool { |
| 2399 |
return $this->mPreventClickjacking; |
| 2400 |
} |
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
public function updateRuntimeAdaptiveExpiry( $ttl ): void { |
| 2409 |
$this->mMaxAdaptiveExpiry = min( $ttl, $this->mMaxAdaptiveExpiry ); |
| 2410 |
$this->updateCacheExpiry( $ttl ); |
| 2411 |
} |
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
public function addExtraCSPDefaultSrc( $src ): void { |
| 2423 |
$this->mExtraDefaultSrcs[] = $src; |
| 2424 |
} |
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
public function addExtraCSPStyleSrc( $src ): void { |
| 2433 |
$this->mExtraStyleSrcs[] = $src; |
| 2434 |
} |
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
public function addExtraCSPScriptSrc( $src ): void { |
| 2445 |
$this->mExtraScriptSrcs[] = $src; |
| 2446 |
} |
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
public function finalizeAdaptiveCacheExpiry(): void { |
| 2454 |
if ( is_infinite( $this->mMaxAdaptiveExpiry ) ) { |
| 2455 |
return; |
| 2456 |
} |
| 2457 |
|
| 2458 |
$runtime = $this->getTimeProfile( 'wall' ); |
| 2459 |
if ( is_float( $runtime ) ) { |
| 2460 |
$slope = ( self::SLOW_AR_TTL - self::FAST_AR_TTL ) |
| 2461 |
/ ( self::PARSE_SLOW_SEC - self::PARSE_FAST_SEC ); |
| 2462 |
|
| 2463 |
$point = self::SLOW_AR_TTL - self::PARSE_SLOW_SEC * $slope; |
| 2464 |
|
| 2465 |
$adaptiveTTL = min( |
| 2466 |
max( $slope * $runtime + $point, self::MIN_AR_TTL ), |
| 2467 |
$this->mMaxAdaptiveExpiry |
| 2468 |
); |
| 2469 |
$this->updateCacheExpiry( $adaptiveTTL ); |
| 2470 |
} |
| 2471 |
} |
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
public function setFromParserOptions( ParserOptions $parserOptions ) { |
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
$class = $parserOptions->getWrapOutputClass(); |
| 2484 |
if ( $class !== false && !$parserOptions->getInterfaceMessage() ) { |
| 2485 |
$this->addWrapperDivClass( $class ); |
| 2486 |
} |
| 2487 |
|
| 2488 |
|
| 2489 |
if ( $parserOptions->getSuppressSectionEditLinks() ) { |
| 2490 |
$this->setOutputFlag( ParserOutputFlags::NO_SECTION_EDIT_LINKS ); |
| 2491 |
} |
| 2492 |
|
| 2493 |
|
| 2494 |
if ( $parserOptions->getCollapsibleSections() ) { |
| 2495 |
$this->setOutputFlag( ParserOutputFlags::COLLAPSIBLE_SECTIONS ); |
| 2496 |
} |
| 2497 |
|
| 2498 |
|
| 2499 |
if ( $parserOptions->getIsPreview() ) { |
| 2500 |
$this->setOutputFlag( ParserOutputFlags::IS_PREVIEW, true ); |
| 2501 |
|
| 2502 |
$this->updateCacheExpiry( 0 ); |
| 2503 |
} |
| 2504 |
} |
| 2505 |
|
| 2506 |
public function __sleep() { |
| 2507 |
return array_filter( array_keys( get_object_vars( $this ) ), |
| 2508 |
static function ( $field ) { |
| 2509 |
if ( $field === 'mParseStartTime' || $field === 'mWarningMsgs' ) { |
| 2510 |
return false; |
| 2511 |
} |
| 2512 |
|
| 2513 |
|
| 2514 |
return strpos( $field, "\0" ) === false; |
| 2515 |
} |
| 2516 |
); |
| 2517 |
} |
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
public function mergeInternalMetaDataFrom( ParserOutput $source ): void { |
| 2527 |
$this->mWarnings = self::mergeMap( $this->mWarnings, $source->mWarnings ); |
| 2528 |
$this->mTimestamp = $this->useMaxValue( $this->mTimestamp, $source->getRevisionTimestamp() ); |
| 2529 |
if ( $source->hasCacheTime() ) { |
| 2530 |
$sourceCacheTime = $source->getCacheTime(); |
| 2531 |
if ( |
| 2532 |
!$this->hasCacheTime() || |
| 2533 |
|
| 2534 |
|
| 2535 |
strval( $sourceCacheTime ) === '-1' || |
| 2536 |
( |
| 2537 |
strval( $this->getCacheTime() ) !== '-1' && |
| 2538 |
|
| 2539 |
$this->getCacheTime() < $sourceCacheTime |
| 2540 |
) |
| 2541 |
) { |
| 2542 |
$this->setCacheTime( $sourceCacheTime ); |
| 2543 |
} |
| 2544 |
} |
| 2545 |
if ( $source->getRenderId() !== null ) { |
| 2546 |
|
| 2547 |
$rid = ( $this->getRenderId() ?? '' ) . $source->getRenderId(); |
| 2548 |
$this->setRenderId( $rid ); |
| 2549 |
} |
| 2550 |
if ( $source->getCacheRevisionId() !== null ) { |
| 2551 |
$sourceCacheRevisionId = $source->getCacheRevisionId(); |
| 2552 |
$thisCacheRevisionId = $this->getCacheRevisionId(); |
| 2553 |
if ( $thisCacheRevisionId === null ) { |
| 2554 |
$this->setCacheRevisionId( $sourceCacheRevisionId ); |
| 2555 |
} elseif ( $sourceCacheRevisionId !== $thisCacheRevisionId ) { |
| 2556 |
|
| 2557 |
wfDeprecated( |
| 2558 |
__METHOD__ . ": conflicting revision IDs " . |
| 2559 |
"$thisCacheRevisionId and $sourceCacheRevisionId" |
| 2560 |
); |
| 2561 |
} |
| 2562 |
} |
| 2563 |
|
| 2564 |
foreach ( self::SPECULATIVE_FIELDS as $field ) { |
| 2565 |
if ( $this->$field && $source->$field && $this->$field !== $source->$field ) { |
| 2566 |
wfLogWarning( __METHOD__ . ": inconsistent '$field' properties!" ); |
| 2567 |
} |
| 2568 |
$this->$field = $this->useMaxValue( $this->$field, $source->$field ); |
| 2569 |
} |
| 2570 |
|
| 2571 |
$this->mParseStartTime = $this->useEachMinValue( |
| 2572 |
$this->mParseStartTime, |
| 2573 |
$source->mParseStartTime |
| 2574 |
); |
| 2575 |
|
| 2576 |
$this->mTimeProfile = $this->useEachTotalValue( |
| 2577 |
$this->mTimeProfile, |
| 2578 |
$source->mTimeProfile |
| 2579 |
); |
| 2580 |
|
| 2581 |
$this->mFlags = self::mergeMap( $this->mFlags, $source->mFlags ); |
| 2582 |
$this->mParseUsedOptions = self::mergeMap( $this->mParseUsedOptions, $source->mParseUsedOptions ); |
| 2583 |
|
| 2584 |
|
| 2585 |
if ( !$this->mLimitReportData ) { |
| 2586 |
$this->mLimitReportData = $source->mLimitReportData; |
| 2587 |
} |
| 2588 |
if ( !$this->mLimitReportJSData ) { |
| 2589 |
$this->mLimitReportJSData = $source->mLimitReportJSData; |
| 2590 |
} |
| 2591 |
} |
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
public function mergeHtmlMetaDataFrom( ParserOutput $source ): void { |
| 2601 |
|
| 2602 |
$this->mHeadItems = self::mergeMixedList( $this->mHeadItems, $source->getHeadItems() ); |
| 2603 |
$this->addModules( $source->getModules() ); |
| 2604 |
$this->addModuleStyles( $source->getModuleStyles() ); |
| 2605 |
$this->mJsConfigVars = self::mergeMapStrategy( $this->mJsConfigVars, $source->mJsConfigVars ); |
| 2606 |
$this->mMaxAdaptiveExpiry = min( $this->mMaxAdaptiveExpiry, $source->mMaxAdaptiveExpiry ); |
| 2607 |
$this->mExtraStyleSrcs = self::mergeList( |
| 2608 |
$this->mExtraStyleSrcs, |
| 2609 |
$source->getExtraCSPStyleSrcs() |
| 2610 |
); |
| 2611 |
$this->mExtraScriptSrcs = self::mergeList( |
| 2612 |
$this->mExtraScriptSrcs, |
| 2613 |
$source->getExtraCSPScriptSrcs() |
| 2614 |
); |
| 2615 |
$this->mExtraDefaultSrcs = self::mergeList( |
| 2616 |
$this->mExtraDefaultSrcs, |
| 2617 |
$source->getExtraCSPDefaultSrcs() |
| 2618 |
); |
| 2619 |
|
| 2620 |
|
| 2621 |
$this->mIndexSet = $this->mIndexSet || $source->mIndexSet; |
| 2622 |
$this->mNoIndexSet = $this->mNoIndexSet || $source->mNoIndexSet; |
| 2623 |
|
| 2624 |
|
| 2625 |
$this->mNewSection = $this->mNewSection || $source->getNewSection(); |
| 2626 |
$this->mHideNewSection = $this->mHideNewSection || $source->getHideNewSection(); |
| 2627 |
$this->mNoGallery = $this->mNoGallery || $source->getNoGallery(); |
| 2628 |
$this->mEnableOOUI = $this->mEnableOOUI || $source->getEnableOOUI(); |
| 2629 |
$this->mPreventClickjacking = $this->mPreventClickjacking || $source->getPreventClickjacking(); |
| 2630 |
|
| 2631 |
$tocData = $this->getTOCData(); |
| 2632 |
$sourceTocData = $source->getTOCData(); |
| 2633 |
if ( $tocData !== null ) { |
| 2634 |
if ( $sourceTocData !== null ) { |
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
foreach ( $sourceTocData->getSections() as $s ) { |
| 2640 |
$tocData->addSection( $s ); |
| 2641 |
} |
| 2642 |
} |
| 2643 |
} elseif ( $sourceTocData !== null ) { |
| 2644 |
$this->setTOCData( $sourceTocData ); |
| 2645 |
} |
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
if ( $this->mTitleText === null || $this->mTitleText === '' ) { |
| 2650 |
$this->mTitleText = $source->mTitleText; |
| 2651 |
} |
| 2652 |
|
| 2653 |
|
| 2654 |
$this->mWrapperDivClasses = self::mergeMap( |
| 2655 |
$this->mWrapperDivClasses, |
| 2656 |
$source->mWrapperDivClasses |
| 2657 |
); |
| 2658 |
|
| 2659 |
|
| 2660 |
$this->mIndicators = self::mergeMap( $this->mIndicators, $source->getIndicators() ); |
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
|
| 2665 |
$this->mExtensionData = self::mergeMapStrategy( |
| 2666 |
$this->mExtensionData, |
| 2667 |
$source->mExtensionData |
| 2668 |
); |
| 2669 |
} |
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
public function mergeTrackingMetaDataFrom( ParserOutput $source ): void { |
| 2679 |
foreach ( $source->getLanguageLinks() as $ll ) { |
| 2680 |
$this->addLanguageLink( $ll ); |
| 2681 |
} |
| 2682 |
$this->mCategories = self::mergeMap( $this->mCategories, $source->getCategoryMap() ); |
| 2683 |
$this->mLinks = self::merge2D( $this->mLinks, $source->getLinks() ); |
| 2684 |
$this->mTemplates = self::merge2D( $this->mTemplates, $source->getTemplates() ); |
| 2685 |
$this->mTemplateIds = self::merge2D( $this->mTemplateIds, $source->getTemplateIds() ); |
| 2686 |
$this->mImages = self::mergeMap( $this->mImages, $source->getImages() ); |
| 2687 |
$this->mFileSearchOptions = self::mergeMap( |
| 2688 |
$this->mFileSearchOptions, |
| 2689 |
$source->getFileSearchOptions() |
| 2690 |
); |
| 2691 |
$this->mExternalLinks = self::mergeMap( $this->mExternalLinks, $source->getExternalLinks() ); |
| 2692 |
$this->mInterwikiLinks = self::merge2D( |
| 2693 |
$this->mInterwikiLinks, |
| 2694 |
$source->getInterwikiLinks() |
| 2695 |
); |
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
$this->mProperties = self::mergeMap( $this->mProperties, $source->getPageProperties() ); |
| 2701 |
|
| 2702 |
|
| 2703 |
$this->mExtensionData = self::mergeMapStrategy( |
| 2704 |
$this->mExtensionData, |
| 2705 |
$source->mExtensionData |
| 2706 |
); |
| 2707 |
} |
| 2708 |
|
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
|
| 2718 |
public function collectMetadata( ContentMetadataCollector $metadata ): void { |
| 2719 |
|
| 2720 |
$flags = array_keys( |
| 2721 |
$this->mFlags + array_flip( ParserOutputFlags::cases() ) |
| 2722 |
); |
| 2723 |
foreach ( $flags as $name ) { |
| 2724 |
if ( $this->getOutputFlag( $name ) ) { |
| 2725 |
$metadata->setOutputFlag( $name ); |
| 2726 |
} |
| 2727 |
} |
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
foreach ( ParserOutputStringSets::cases() as $name ) { |
| 2732 |
$metadata->appendOutputStrings( |
| 2733 |
$name, $this->getOutputStrings( $name ) |
| 2734 |
); |
| 2735 |
} |
| 2736 |
|
| 2737 |
foreach ( $this->mCategories as $cat => $key ) { |
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
$lt = TitleValue::tryNew( NS_CATEGORY, (string)$cat ); |
| 2742 |
$metadata->addCategory( $lt, $key ); |
| 2743 |
} |
| 2744 |
|
| 2745 |
foreach ( $this->mLinks as $ns => $arr ) { |
| 2746 |
foreach ( $arr as $dbk => $id ) { |
| 2747 |
|
| 2748 |
|
| 2749 |
$lt = TitleValue::tryNew( $ns, (string)$dbk ); |
| 2750 |
$metadata->addLink( $lt, $id ); |
| 2751 |
} |
| 2752 |
} |
| 2753 |
|
| 2754 |
foreach ( $this->mInterwikiLinks as $prefix => $arr ) { |
| 2755 |
foreach ( $arr as $dbk => $ignore ) { |
| 2756 |
$lt = TitleValue::tryNew( NS_MAIN, (string)$dbk, '', $prefix ); |
| 2757 |
$metadata->addLink( $lt ); |
| 2758 |
} |
| 2759 |
} |
| 2760 |
|
| 2761 |
foreach ( $this->mLinksSpecial as $dbk => $ignore ) { |
| 2762 |
|
| 2763 |
|
| 2764 |
$lt = TitleValue::tryNew( NS_SPECIAL, (string)$dbk ); |
| 2765 |
$metadata->addLink( $lt ); |
| 2766 |
} |
| 2767 |
|
| 2768 |
foreach ( $this->mImages as $name => $ignore ) { |
| 2769 |
|
| 2770 |
$lt = TitleValue::tryNew( NS_FILE, (string)$name ); |
| 2771 |
$props = $this->mFileSearchOptions[$name] ?? []; |
| 2772 |
$metadata->addImage( $lt, $props['time'] ?? null, $props['sha1'] ?? null ); |
| 2773 |
} |
| 2774 |
|
| 2775 |
foreach ( $this->mLanguageLinkMap as $lang => $title ) { |
| 2776 |
if ( $title === '|' ) { |
| 2777 |
continue; |
| 2778 |
} |
| 2779 |
|
| 2780 |
[ $title, $frag ] = array_pad( explode( '#', $title, 2 ), 2, '' ); |
| 2781 |
$lt = TitleValue::tryNew( NS_MAIN, $title, $frag, (string)$lang ); |
| 2782 |
$metadata->addLanguageLink( $lt ); |
| 2783 |
} |
| 2784 |
|
| 2785 |
foreach ( $this->mJsConfigVars as $key => $value ) { |
| 2786 |
if ( is_array( $value ) && isset( $value[self::MW_MERGE_STRATEGY_KEY] ) ) { |
| 2787 |
$strategy = $value[self::MW_MERGE_STRATEGY_KEY]; |
| 2788 |
foreach ( $value as $item => $ignore ) { |
| 2789 |
if ( $item !== self::MW_MERGE_STRATEGY_KEY ) { |
| 2790 |
$metadata->appendJsConfigVar( $key, $item, $strategy ); |
| 2791 |
} |
| 2792 |
} |
| 2793 |
} elseif ( $metadata instanceof ParserOutput && |
| 2794 |
array_key_exists( $key, $metadata->mJsConfigVars ) |
| 2795 |
) { |
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
$metadata->mJsConfigVars[$key] = $value; |
| 2802 |
} else { |
| 2803 |
$metadata->setJsConfigVar( $key, $value ); |
| 2804 |
} |
| 2805 |
} |
| 2806 |
foreach ( $this->mExtensionData as $key => $value ) { |
| 2807 |
if ( is_array( $value ) && isset( $value[self::MW_MERGE_STRATEGY_KEY] ) ) { |
| 2808 |
$strategy = $value[self::MW_MERGE_STRATEGY_KEY]; |
| 2809 |
foreach ( $value as $item => $ignore ) { |
| 2810 |
if ( $item !== self::MW_MERGE_STRATEGY_KEY ) { |
| 2811 |
$metadata->appendExtensionData( $key, $item, $strategy ); |
| 2812 |
} |
| 2813 |
} |
| 2814 |
} elseif ( $metadata instanceof ParserOutput && |
| 2815 |
array_key_exists( $key, $metadata->mExtensionData ) |
| 2816 |
) { |
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
$metadata->mExtensionData[$key] = $value; |
| 2823 |
} else { |
| 2824 |
$metadata->setExtensionData( $key, $value ); |
| 2825 |
} |
| 2826 |
} |
| 2827 |
foreach ( $this->mExternalLinks as $url => $ignore ) { |
| 2828 |
$metadata->addExternalLink( $url ); |
| 2829 |
} |
| 2830 |
foreach ( $this->mProperties as $prop => $value ) { |
| 2831 |
if ( is_numeric( $value ) ) { |
| 2832 |
$metadata->setNumericPageProperty( $prop, $value ); |
| 2833 |
} elseif ( is_string( $value ) ) { |
| 2834 |
$metadata->setUnsortedPageProperty( $prop, $value ); |
| 2835 |
} else { |
| 2836 |
|
| 2837 |
|
| 2838 |
$metadata->setPageProperty( $prop, $value ); |
| 2839 |
} |
| 2840 |
} |
| 2841 |
foreach ( $this->mWarningMsgs as $msg => $args ) { |
| 2842 |
$metadata->addWarningMsg( $msg, ...$args ); |
| 2843 |
} |
| 2844 |
foreach ( $this->mLimitReportData as $key => $value ) { |
| 2845 |
$metadata->setLimitReportData( $key, $value ); |
| 2846 |
} |
| 2847 |
foreach ( $this->mIndicators as $id => $content ) { |
| 2848 |
$metadata->setIndicator( $id, $content ); |
| 2849 |
} |
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
if ( $metadata instanceof ParserOutput ) { |
| 2865 |
foreach ( $this->getUsedOptions() as $opt ) { |
| 2866 |
$metadata->recordOption( $opt ); |
| 2867 |
} |
| 2868 |
if ( $this->mCacheExpiry !== null ) { |
| 2869 |
$metadata->updateCacheExpiry( $this->mCacheExpiry ); |
| 2870 |
} |
| 2871 |
if ( $this->mCacheTime !== '' ) { |
| 2872 |
$metadata->setCacheTime( $this->mCacheTime ); |
| 2873 |
} |
| 2874 |
if ( $this->mCacheRevisionId !== null ) { |
| 2875 |
$metadata->setCacheRevisionId( $this->mCacheRevisionId ); |
| 2876 |
} |
| 2877 |
|
| 2878 |
|
| 2879 |
$otherTitle = $metadata->getTitleText(); |
| 2880 |
if ( $otherTitle === null || $otherTitle === '' ) { |
| 2881 |
$metadata->setTitleText( $this->getTitleText() ); |
| 2882 |
} |
| 2883 |
foreach ( $this->mTemplates as $ns => $arr ) { |
| 2884 |
foreach ( $arr as $dbk => $page_id ) { |
| 2885 |
$rev_id = $this->mTemplateIds[$ns][$dbk]; |
| 2886 |
$metadata->addTemplate( TitleValue::tryNew( $ns, (string)$dbk ), $page_id, $rev_id ); |
| 2887 |
} |
| 2888 |
} |
| 2889 |
} |
| 2890 |
} |
| 2891 |
|
| 2892 |
private static function mergeMixedList( array $a, array $b ): array { |
| 2893 |
return array_unique( array_merge( $a, $b ), SORT_REGULAR ); |
| 2894 |
} |
| 2895 |
|
| 2896 |
private static function mergeList( array $a, array $b ): array { |
| 2897 |
return array_values( array_unique( array_merge( $a, $b ), SORT_REGULAR ) ); |
| 2898 |
} |
| 2899 |
|
| 2900 |
private static function mergeMap( array $a, array $b ): array { |
| 2901 |
return array_replace( $a, $b ); |
| 2902 |
} |
| 2903 |
|
| 2904 |
private static function mergeMapStrategy( array $a, array $b ): array { |
| 2905 |
foreach ( $b as $key => $bValue ) { |
| 2906 |
if ( !array_key_exists( $key, $a ) ) { |
| 2907 |
$a[$key] = $bValue; |
| 2908 |
} elseif ( |
| 2909 |
is_array( $a[$key] ) && |
| 2910 |
isset( $a[$key][self::MW_MERGE_STRATEGY_KEY] ) && |
| 2911 |
isset( $bValue[self::MW_MERGE_STRATEGY_KEY] ) |
| 2912 |
) { |
| 2913 |
$strategy = $bValue[self::MW_MERGE_STRATEGY_KEY]; |
| 2914 |
if ( $strategy !== $a[$key][self::MW_MERGE_STRATEGY_KEY] ) { |
| 2915 |
throw new InvalidArgumentException( "Conflicting merge strategy for $key" ); |
| 2916 |
} |
| 2917 |
if ( $strategy === self::MW_MERGE_STRATEGY_UNION ) { |
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
$a[$key] = array_replace( $a[$key], $bValue ); |
| 2923 |
} else { |
| 2924 |
throw new InvalidArgumentException( "Unknown merge strategy $strategy" ); |
| 2925 |
} |
| 2926 |
} else { |
| 2927 |
$valuesSame = ( $a[$key] === $bValue ); |
| 2928 |
if ( ( !$valuesSame ) && |
| 2929 |
is_object( $a[$key] ) && |
| 2930 |
is_object( $bValue ) |
| 2931 |
) { |
| 2932 |
$jsonCodec = MediaWikiServices::getInstance()->getJsonCodec(); |
| 2933 |
$valuesSame = ( $jsonCodec->serialize( $a[$key] ) === $jsonCodec->serialize( $bValue ) ); |
| 2934 |
} |
| 2935 |
if ( !$valuesSame ) { |
| 2936 |
|
| 2937 |
|
| 2938 |
$a[$key] = $bValue; |
| 2939 |
} |
| 2940 |
} |
| 2941 |
} |
| 2942 |
return $a; |
| 2943 |
} |
| 2944 |
|
| 2945 |
private static function merge2D( array $a, array $b ): array { |
| 2946 |
$values = []; |
| 2947 |
$keys = array_merge( array_keys( $a ), array_keys( $b ) ); |
| 2948 |
|
| 2949 |
foreach ( $keys as $k ) { |
| 2950 |
if ( empty( $a[$k] ) ) { |
| 2951 |
$values[$k] = $b[$k]; |
| 2952 |
} elseif ( empty( $b[$k] ) ) { |
| 2953 |
$values[$k] = $a[$k]; |
| 2954 |
} elseif ( is_array( $a[$k] ) && is_array( $b[$k] ) ) { |
| 2955 |
$values[$k] = array_replace( $a[$k], $b[$k] ); |
| 2956 |
} else { |
| 2957 |
$values[$k] = $b[$k]; |
| 2958 |
} |
| 2959 |
} |
| 2960 |
|
| 2961 |
return $values; |
| 2962 |
} |
| 2963 |
|
| 2964 |
private static function useEachMinValue( array $a, array $b ): array { |
| 2965 |
$values = []; |
| 2966 |
$keys = array_merge( array_keys( $a ), array_keys( $b ) ); |
| 2967 |
|
| 2968 |
foreach ( $keys as $k ) { |
| 2969 |
$values[$k] = min( $a[$k] ?? INF, $b[$k] ?? INF ); |
| 2970 |
} |
| 2971 |
|
| 2972 |
return $values; |
| 2973 |
} |
| 2974 |
|
| 2975 |
private static function useEachTotalValue( array $a, array $b ): array { |
| 2976 |
$values = []; |
| 2977 |
$keys = array_merge( array_keys( $a ), array_keys( $b ) ); |
| 2978 |
|
| 2979 |
foreach ( $keys as $k ) { |
| 2980 |
$values[$k] = ( $a[$k] ?? 0 ) + ( $b[$k] ?? 0 ); |
| 2981 |
} |
| 2982 |
|
| 2983 |
return $values; |
| 2984 |
} |
| 2985 |
|
| 2986 |
private static function useMaxValue( $a, $b ) { |
| 2987 |
if ( $a === null ) { |
| 2988 |
return $b; |
| 2989 |
} |
| 2990 |
|
| 2991 |
if ( $b === null ) { |
| 2992 |
return $a; |
| 2993 |
} |
| 2994 |
|
| 2995 |
return max( $a, $b ); |
| 2996 |
} |
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
|
| 3001 |
|
| 3002 |
|
| 3003 |
|
| 3004 |
public function toJsonArray(): array { |
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
$data = [ |
| 3009 |
'Text' => $this->mRawText, |
| 3010 |
'LanguageLinks' => $this->getLanguageLinks(), |
| 3011 |
'Categories' => $this->mCategories, |
| 3012 |
'Indicators' => $this->mIndicators, |
| 3013 |
'TitleText' => $this->mTitleText, |
| 3014 |
'Links' => $this->mLinks, |
| 3015 |
'LinksSpecial' => $this->mLinksSpecial, |
| 3016 |
'Templates' => $this->mTemplates, |
| 3017 |
'TemplateIds' => $this->mTemplateIds, |
| 3018 |
'Images' => $this->mImages, |
| 3019 |
'FileSearchOptions' => $this->mFileSearchOptions, |
| 3020 |
'ExternalLinks' => $this->mExternalLinks, |
| 3021 |
'InterwikiLinks' => $this->mInterwikiLinks, |
| 3022 |
'NewSection' => $this->mNewSection, |
| 3023 |
'HideNewSection' => $this->mHideNewSection, |
| 3024 |
'NoGallery' => $this->mNoGallery, |
| 3025 |
'HeadItems' => $this->mHeadItems, |
| 3026 |
'Modules' => array_keys( $this->mModuleSet ), |
| 3027 |
'ModuleStyles' => array_keys( $this->mModuleStyleSet ), |
| 3028 |
'JsConfigVars' => $this->mJsConfigVars, |
| 3029 |
'Warnings' => $this->mWarnings, |
| 3030 |
'Sections' => $this->getSections(), |
| 3031 |
'Properties' => self::detectAndEncodeBinary( $this->mProperties ), |
| 3032 |
'Timestamp' => $this->mTimestamp, |
| 3033 |
'EnableOOUI' => $this->mEnableOOUI, |
| 3034 |
'IndexPolicy' => $this->getIndexPolicy(), |
| 3035 |
|
| 3036 |
'ExtensionData' => $this->mExtensionData, |
| 3037 |
'LimitReportData' => $this->mLimitReportData, |
| 3038 |
'LimitReportJSData' => $this->mLimitReportJSData, |
| 3039 |
'CacheMessage' => $this->mCacheMessage, |
| 3040 |
'TimeProfile' => $this->mTimeProfile, |
| 3041 |
'ParseStartTime' => [], |
| 3042 |
'PreventClickjacking' => $this->mPreventClickjacking, |
| 3043 |
'ExtraScriptSrcs' => $this->mExtraScriptSrcs, |
| 3044 |
'ExtraDefaultSrcs' => $this->mExtraDefaultSrcs, |
| 3045 |
'ExtraStyleSrcs' => $this->mExtraStyleSrcs, |
| 3046 |
'Flags' => $this->mFlags + ( |
| 3047 |
|
| 3048 |
|
| 3049 |
$this->mTOCData === null ? [] : [ 'mw:toc-set' => true ] |
| 3050 |
), |
| 3051 |
'SpeculativeRevId' => $this->mSpeculativeRevId, |
| 3052 |
'SpeculativePageIdUsed' => $this->speculativePageIdUsed, |
| 3053 |
'RevisionTimestampUsed' => $this->revisionTimestampUsed, |
| 3054 |
'RevisionUsedSha1Base36' => $this->revisionUsedSha1Base36, |
| 3055 |
'WrapperDivClasses' => $this->mWrapperDivClasses, |
| 3056 |
]; |
| 3057 |
|
| 3058 |
|
| 3059 |
$data += parent::toJsonArray(); |
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
if ( $this->mMaxAdaptiveExpiry !== INF ) { |
| 3064 |
|
| 3065 |
$data['MaxAdaptiveExpiry'] = $this->mMaxAdaptiveExpiry; |
| 3066 |
} |
| 3067 |
|
| 3068 |
if ( $this->mTOCData ) { |
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
$toc = $this->mTOCData->jsonSerialize(); |
| 3073 |
if ( isset( $toc['extensionData'] ) ) { |
| 3074 |
$data['TOCExtensionData'] = $toc['extensionData']; |
| 3075 |
} |
| 3076 |
} |
| 3077 |
|
| 3078 |
return $data; |
| 3079 |
} |
| 3080 |
|
| 3081 |
public static function newFromJsonArray( array $json ): ParserOutput { |
| 3082 |
$parserOutput = new ParserOutput(); |
| 3083 |
$parserOutput->initFromJson( $json ); |
| 3084 |
return $parserOutput; |
| 3085 |
} |
| 3086 |
|
| 3087 |
|
| 3088 |
public static function jsonClassHintFor( string $keyName ) { |
| 3089 |
return match ( $keyName ) { |
| 3090 |
'TOCData' => Hint::build( TOCData::class, Hint::ONLY_FOR_DECODE ), |
| 3091 |
'WarningMsgs' => Hint::build( MessageValue::class, Hint::LIST, Hint::ONLY_FOR_DECODE ), |
| 3092 |
default => null, |
| 3093 |
}; |
| 3094 |
} |
| 3095 |
|
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
|
| 3100 |
protected function initFromJson( array $jsonData ): void { |
| 3101 |
parent::initFromJson( $jsonData ); |
| 3102 |
|
| 3103 |
|
| 3104 |
|
| 3105 |
|
| 3106 |
|
| 3107 |
$this->mRawText = $jsonData['Text']; |
| 3108 |
$this->mLanguageLinkMap = []; |
| 3109 |
foreach ( ( $jsonData['LanguageLinks'] ?? [] ) as $l ) { |
| 3110 |
$this->addLanguageLink( $l ); |
| 3111 |
} |
| 3112 |
|
| 3113 |
$this->mCategories = $jsonData['Categories'] ?? []; |
| 3114 |
$this->mIndicators = $jsonData['Indicators'] ?? []; |
| 3115 |
$this->mTitleText = $jsonData['TitleText'] ?? ''; |
| 3116 |
$this->mLinks = $jsonData['Links'] ?? []; |
| 3117 |
$this->mLinksSpecial = $jsonData['LinksSpecial'] ?? []; |
| 3118 |
$this->mTemplates = $jsonData['Templates'] ?? []; |
| 3119 |
$this->mTemplateIds = $jsonData['TemplateIds'] ?? []; |
| 3120 |
$this->mImages = $jsonData['Images'] ?? []; |
| 3121 |
$this->mFileSearchOptions = $jsonData['FileSearchOptions'] ?? []; |
| 3122 |
$this->mExternalLinks = $jsonData['ExternalLinks'] ?? []; |
| 3123 |
$this->mInterwikiLinks = $jsonData['InterwikiLinks'] ?? []; |
| 3124 |
$this->mHeadItems = $jsonData['HeadItems'] ?? []; |
| 3125 |
$this->mModuleSet = array_fill_keys( $jsonData['Modules'] ?? [], true ); |
| 3126 |
$this->mModuleStyleSet = array_fill_keys( $jsonData['ModuleStyles'] ?? [], true ); |
| 3127 |
$this->mJsConfigVars = $jsonData['JsConfigVars'] ?? []; |
| 3128 |
$this->mWarnings = $jsonData['Warnings'] ?? []; |
| 3129 |
|
| 3130 |
|
| 3131 |
$this->mFlags = $jsonData['Flags'] ?? []; |
| 3132 |
$this->mNoGallery = $jsonData['NoGallery'] ?? false; |
| 3133 |
$this->mEnableOOUI = $jsonData['EnableOOUI'] ?? false; |
| 3134 |
$this->setIndexPolicy( $jsonData['IndexPolicy'] ?? '' ); |
| 3135 |
$this->mNewSection = $jsonData['NewSection'] ?? false; |
| 3136 |
$this->mHideNewSection = $jsonData['HideNewSection'] ?? false; |
| 3137 |
$this->mPreventClickjacking = $jsonData['PreventClickjacking'] ?? false; |
| 3138 |
|
| 3139 |
|
| 3140 |
|
| 3141 |
foreach ( $jsonData['OutputFlags'] ?? [] as $flag ) { |
| 3142 |
$this->setOutputFlag( $flag ); |
| 3143 |
} |
| 3144 |
|
| 3145 |
if ( isset( $jsonData['TOCData'] ) ) { |
| 3146 |
$this->mTOCData = $jsonData['TOCData']; |
| 3147 |
|
| 3148 |
|
| 3149 |
} elseif ( |
| 3150 |
( $jsonData['Sections'] ?? [] ) !== [] || |
| 3151 |
|
| 3152 |
$this->getOutputFlag( 'mw:toc-set' ) |
| 3153 |
) { |
| 3154 |
$this->setSections( $jsonData['Sections'] ?? [] ); |
| 3155 |
unset( $this->mFlags['mw:toc-set'] ); |
| 3156 |
if ( isset( $jsonData['TOCExtensionData'] ) ) { |
| 3157 |
$tocData = $this->getTOCData(); |
| 3158 |
foreach ( $jsonData['TOCExtensionData'] as $key => $value ) { |
| 3159 |
$tocData->setExtensionData( $key, $value ); |
| 3160 |
} |
| 3161 |
} |
| 3162 |
} |
| 3163 |
$this->mProperties = self::detectAndDecodeBinary( $jsonData['Properties'] ?? [] ); |
| 3164 |
$this->mTimestamp = $jsonData['Timestamp'] ?? null; |
| 3165 |
$this->mExtensionData = $jsonData['ExtensionData'] ?? []; |
| 3166 |
$this->mLimitReportData = $jsonData['LimitReportData'] ?? []; |
| 3167 |
$this->mLimitReportJSData = $jsonData['LimitReportJSData'] ?? []; |
| 3168 |
$this->mCacheMessage = $jsonData['CacheMessage'] ?? ''; |
| 3169 |
$this->mParseStartTime = []; |
| 3170 |
$this->mTimeProfile = $jsonData['TimeProfile'] ?? []; |
| 3171 |
$this->mExtraScriptSrcs = $jsonData['ExtraScriptSrcs'] ?? []; |
| 3172 |
$this->mExtraDefaultSrcs = $jsonData['ExtraDefaultSrcs'] ?? []; |
| 3173 |
$this->mExtraStyleSrcs = $jsonData['ExtraStyleSrcs'] ?? []; |
| 3174 |
$this->mSpeculativeRevId = $jsonData['SpeculativeRevId'] ?? null; |
| 3175 |
$this->speculativePageIdUsed = $jsonData['SpeculativePageIdUsed'] ?? null; |
| 3176 |
$this->revisionTimestampUsed = $jsonData['RevisionTimestampUsed'] ?? null; |
| 3177 |
$this->revisionUsedSha1Base36 = $jsonData['RevisionUsedSha1Base36'] ?? null; |
| 3178 |
$this->mWrapperDivClasses = $jsonData['WrapperDivClasses'] ?? []; |
| 3179 |
$this->mMaxAdaptiveExpiry = $jsonData['MaxAdaptiveExpiry'] ?? INF; |
| 3180 |
} |
| 3181 |
|
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
private static function detectAndEncodeBinary( array $properties ) { |
| 3192 |
foreach ( $properties as $key => $value ) { |
| 3193 |
if ( is_string( $value ) ) { |
| 3194 |
if ( !mb_detect_encoding( $value, 'UTF-8', true ) ) { |
| 3195 |
$properties[$key] = [ |
| 3196 |
|
| 3197 |
'_type_' => 'string', |
| 3198 |
'_encoding_' => 'base64', |
| 3199 |
'_data_' => base64_encode( $value ), |
| 3200 |
]; |
| 3201 |
} |
| 3202 |
} |
| 3203 |
} |
| 3204 |
|
| 3205 |
return $properties; |
| 3206 |
} |
| 3207 |
|
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
private static function detectAndDecodeBinary( array $properties ) { |
| 3217 |
foreach ( $properties as $key => $value ) { |
| 3218 |
if ( is_array( $value ) && isset( $value['_encoding_'] ) ) { |
| 3219 |
if ( $value['_encoding_'] === 'base64' ) { |
| 3220 |
$properties[$key] = base64_decode( $value['_data_'] ); |
| 3221 |
} |
| 3222 |
} |
| 3223 |
} |
| 3224 |
|
| 3225 |
return $properties; |
| 3226 |
} |
| 3227 |
|
| 3228 |
public function __wakeup() { |
| 3229 |
$oldAliases = [ |
| 3230 |
|
| 3231 |
|
| 3232 |
'ParserOutput', |
| 3233 |
]; |
| 3234 |
|
| 3235 |
$priorAccessedOptions = $this->getGhostFieldValue( 'mAccessedOptions', ...$oldAliases ); |
| 3236 |
if ( $priorAccessedOptions ) { |
| 3237 |
$this->mParseUsedOptions = $priorAccessedOptions; |
| 3238 |
} |
| 3239 |
|
| 3240 |
$priorIndexPolicy = $this->getGhostFieldValue( 'mIndexPolicy', ...$oldAliases ); |
| 3241 |
if ( $priorIndexPolicy ) { |
| 3242 |
$this->setIndexPolicy( $priorIndexPolicy ); |
| 3243 |
} |
| 3244 |
|
| 3245 |
$mSections = $this->getGhostFieldValue( 'mSections', ...$oldAliases ); |
| 3246 |
if ( $mSections !== null && $mSections !== [] ) { |
| 3247 |
$this->setSections( $mSections ); |
| 3248 |
} |
| 3249 |
|
| 3250 |
$mModules = $this->getGhostFieldValue( 'mModules', ...$oldAliases ); |
| 3251 |
if ( $mModules !== null && $mModules !== [] ) { |
| 3252 |
$this->addModules( $mModules ); |
| 3253 |
} |
| 3254 |
|
| 3255 |
$mModuleStyles = $this->getGhostFieldValue( 'mModuleStyles', ...$oldAliases ); |
| 3256 |
if ( $mModuleStyles !== null && $mModuleStyles !== [] ) { |
| 3257 |
$this->addModuleStyles( $mModuleStyles ); |
| 3258 |
} |
| 3259 |
|
| 3260 |
$mText = $this->getGhostFieldValue( 'mText', ...$oldAliases ); |
| 3261 |
if ( $mText !== null ) { |
| 3262 |
$this->setRawText( $mText ); |
| 3263 |
} |
| 3264 |
|
| 3265 |
$ll = $this->getGhostFieldValue( 'mLanguageLinks', ...$oldAliases ); |
| 3266 |
if ( $ll !== null && $ll !== [] ) { |
| 3267 |
foreach ( $ll as $l ) { |
| 3268 |
$this->addLanguageLink( $l ); |
| 3269 |
} |
| 3270 |
} |
| 3271 |
|
| 3272 |
$oldPrivateFields = [ |
| 3273 |
'mRawText', |
| 3274 |
'mCategories', |
| 3275 |
'mIndicators', |
| 3276 |
'mTitleText', |
| 3277 |
'mLinks', |
| 3278 |
'mLinksSpecial', |
| 3279 |
'mTemplates', |
| 3280 |
'mTemplateIds', |
| 3281 |
'mImages', |
| 3282 |
'mFileSearchOptions', |
| 3283 |
'mExternalLinks', |
| 3284 |
'mInterwikiLinks', |
| 3285 |
'mNewSection', |
| 3286 |
'mHideNewSection', |
| 3287 |
'mNoGallery', |
| 3288 |
'mHeadItems', |
| 3289 |
'mModuleSet', |
| 3290 |
'mModuleStyleSet', |
| 3291 |
'mJsConfigVars', |
| 3292 |
'mWarnings', |
| 3293 |
'mWarningMsgs', |
| 3294 |
'mTOCData', |
| 3295 |
'mProperties', |
| 3296 |
'mTimestamp', |
| 3297 |
'mEnableOOUI', |
| 3298 |
'mIndexSet', |
| 3299 |
'mNoIndexSet', |
| 3300 |
'mExtensionData', |
| 3301 |
'mLimitReportData', |
| 3302 |
'mLimitReportJSData', |
| 3303 |
'mCacheMessage', |
| 3304 |
'mParseStartTime', |
| 3305 |
'mTimeProfile', |
| 3306 |
'mPreventClickjacking', |
| 3307 |
'mExtraScriptSrcs', |
| 3308 |
'mExtraDefaultSrcs', |
| 3309 |
'mExtraStyleSrcs', |
| 3310 |
'mFlags', |
| 3311 |
'mSpeculativeRevId', |
| 3312 |
'speculativePageIdUsed', |
| 3313 |
'revisionTimestampUsed', |
| 3314 |
'revisionUsedSha1Base36', |
| 3315 |
'mWrapperDivClasses', |
| 3316 |
'mMaxAdaptiveExpiry', |
| 3317 |
]; |
| 3318 |
foreach ( $oldPrivateFields as $f ) { |
| 3319 |
$this->restoreAliasedGhostField( $f, ...$oldAliases ); |
| 3320 |
} |
| 3321 |
$this->clearParseStartTime(); |
| 3322 |
} |
| 3323 |
|
| 3324 |
public function __clone() { |
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
if ( $this->mTOCData ) { |
| 3337 |
$this->mTOCData = clone $this->mTOCData; |
| 3338 |
} |
| 3339 |
} |
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
public function getContentHolderText(): string { |
| 3350 |
return $this->getRawText(); |
| 3351 |
} |
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
public function setContentHolderText( string $s ): void { |
| 3361 |
$this->setRawText( $s ); |
| 3362 |
} |
| 3363 |
|
| 3364 |
public function __get( $name ) { |
| 3365 |
if ( property_exists( get_called_class(), $name ) ) { |
| 3366 |
|
| 3367 |
wfDeprecatedMsg( "ParserOutput::{$name} public read access deprecated", '1.38' ); |
| 3368 |
return $this->$name; |
| 3369 |
} elseif ( property_exists( $this, $name ) ) { |
| 3370 |
|
| 3371 |
wfDeprecatedMsg( "ParserOutput::{$name} dynamic property read access deprecated", '1.38' ); |
| 3372 |
return $this->$name; |
| 3373 |
} else { |
| 3374 |
trigger_error( "Inaccessible property via __get(): $name" ); |
| 3375 |
return null; |
| 3376 |
} |
| 3377 |
} |
| 3378 |
|
| 3379 |
public function __set( $name, $value ) { |
| 3380 |
if ( property_exists( get_called_class(), $name ) ) { |
| 3381 |
|
| 3382 |
wfDeprecatedMsg( "ParserOutput::$name public write access deprecated", '1.38' ); |
| 3383 |
$this->$name = $value; |
| 3384 |
} else { |
| 3385 |
|
| 3386 |
wfDeprecatedMsg( "ParserOutput::$name dynamic property write access deprecated", '1.38' ); |
| 3387 |
$this->$name = $value; |
| 3388 |
} |
| 3389 |
} |
| 3390 |
} |
| 3391 |
|
| 3392 |
|
| 3393 |
class_alias( ParserOutput::class, 'ParserOutput' ); |