| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Output; |
| 24 |
|
| 25 |
use Article; |
| 26 |
use CSSJanus; |
| 27 |
use Exception; |
| 28 |
use File; |
| 29 |
use HtmlArmor; |
| 30 |
use InvalidArgumentException; |
| 31 |
use MediaWiki\Cache\LinkCache; |
| 32 |
use MediaWiki\Config\Config; |
| 33 |
use MediaWiki\Content\Content; |
| 34 |
use MediaWiki\Content\JavaScriptContent; |
| 35 |
use MediaWiki\Content\TextContent; |
| 36 |
use MediaWiki\Context\ContextSource; |
| 37 |
use MediaWiki\Context\IContextSource; |
| 38 |
use MediaWiki\Context\RequestContext; |
| 39 |
use MediaWiki\Debug\DeprecationHelper; |
| 40 |
use MediaWiki\Debug\MWDebug; |
| 41 |
use MediaWiki\HookContainer\ProtectedHookAccessorTrait; |
| 42 |
use MediaWiki\Html\Html; |
| 43 |
use MediaWiki\Language\Language; |
| 44 |
use MediaWiki\Language\LanguageCode; |
| 45 |
use MediaWiki\Linker\LinkTarget; |
| 46 |
use MediaWiki\MainConfigNames; |
| 47 |
use MediaWiki\MediaWikiServices; |
| 48 |
use MediaWiki\Message\Message; |
| 49 |
use MediaWiki\Page\PageRecord; |
| 50 |
use MediaWiki\Page\PageReference; |
| 51 |
use MediaWiki\Parser\Parser; |
| 52 |
use MediaWiki\Parser\ParserOptions; |
| 53 |
use MediaWiki\Parser\ParserOutput; |
| 54 |
use MediaWiki\Parser\ParserOutputFlags; |
| 55 |
use MediaWiki\Parser\Sanitizer; |
| 56 |
use MediaWiki\Permissions\PermissionStatus; |
| 57 |
use MediaWiki\Registration\ExtensionRegistry; |
| 58 |
use MediaWiki\Request\ContentSecurityPolicy; |
| 59 |
use MediaWiki\Request\FauxRequest; |
| 60 |
use MediaWiki\Request\WebRequest; |
| 61 |
use MediaWiki\ResourceLoader as RL; |
| 62 |
use MediaWiki\ResourceLoader\ResourceLoader; |
| 63 |
use MediaWiki\Session\SessionManager; |
| 64 |
use MediaWiki\SpecialPage\SpecialPage; |
| 65 |
use MediaWiki\Title\Title; |
| 66 |
use MediaWiki\Title\TitleValue; |
| 67 |
use MediaWiki\Utils\MWTimestamp; |
| 68 |
use OOUI\Element; |
| 69 |
use OOUI\Theme; |
| 70 |
use RuntimeException; |
| 71 |
use Skin; |
| 72 |
use Wikimedia\Assert\Assert; |
| 73 |
use Wikimedia\Bcp47Code\Bcp47Code; |
| 74 |
use Wikimedia\LightweightObjectStore\ExpirationAwareness; |
| 75 |
use Wikimedia\Message\MessageSpecifier; |
| 76 |
use Wikimedia\Parsoid\Core\LinkTarget as ParsoidLinkTarget; |
| 77 |
use Wikimedia\Parsoid\Core\TOCData; |
| 78 |
use Wikimedia\Rdbms\IResultWrapper; |
| 79 |
use Wikimedia\RelPath; |
| 80 |
use Wikimedia\WrappedString; |
| 81 |
use Wikimedia\WrappedStringList; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
class OutputPage extends ContextSource { |
| 99 |
use ProtectedHookAccessorTrait; |
| 100 |
use DeprecationHelper; |
| 101 |
|
| 102 |
|
| 103 |
public const CSP_HEADERS = 'headers'; |
| 104 |
|
| 105 |
public const CSP_META = 'meta'; |
| 106 |
|
| 107 |
|
| 108 |
private const JS_VAR_EARLY = 1; |
| 109 |
private const JS_VAR_LATE = 2; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
private const CORE_LATE_JS_CONFIG_VAR_NAMES = []; |
| 114 |
|
| 115 |
|
| 116 |
private static $oouiSetupDone = false; |
| 117 |
|
| 118 |
|
| 119 |
protected $mMetatags = []; |
| 120 |
|
| 121 |
|
| 122 |
protected $mLinktags = []; |
| 123 |
|
| 124 |
|
| 125 |
protected $mCanonicalUrl = false; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
private $mPageTitle = ''; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
private $displayTitle; |
| 140 |
|
| 141 |
|
| 142 |
private $cacheIsFinal = false; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
public $mBodytext = ''; |
| 149 |
|
| 150 |
|
| 151 |
private $mHTMLtitle = ''; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
private $mIsArticle = false; |
| 158 |
|
| 159 |
|
| 160 |
private $mIsArticleRelated = true; |
| 161 |
|
| 162 |
|
| 163 |
private $mHasCopyright = false; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
private $mPrintable = false; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
private $tocData; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
private $mSubtitle = []; |
| 182 |
|
| 183 |
|
| 184 |
public $mRedirect = ''; |
| 185 |
|
| 186 |
|
| 187 |
protected $mStatusCode; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
protected $mLastModified = ''; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
private $mCategoryLinks = []; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
private $mCategories = [ |
| 206 |
'hidden' => [], |
| 207 |
'normal' => [], |
| 208 |
]; |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
private array $mCategoryData = []; |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
private bool $mCategoriesSorted = true; |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
private $mIndicators = []; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
private $mScripts = ''; |
| 242 |
|
| 243 |
|
| 244 |
protected $mInlineStyles = ''; |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
protected $mAdditionalHtmlClasses = []; |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
private $mHeadItems = []; |
| 257 |
|
| 258 |
|
| 259 |
protected $mAdditionalBodyClasses = []; |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
private $mModules = []; |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
private $mModuleStyles = []; |
| 272 |
|
| 273 |
|
| 274 |
protected $mResourceLoader; |
| 275 |
|
| 276 |
|
| 277 |
private $rlClient; |
| 278 |
|
| 279 |
|
| 280 |
private $rlClientContext; |
| 281 |
|
| 282 |
|
| 283 |
private $rlExemptStyleModules; |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
private $mJsConfigVars = []; |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
private $mTemplateIds = []; |
| 296 |
|
| 297 |
|
| 298 |
protected $mImageTimeKeys = []; |
| 299 |
|
| 300 |
|
| 301 |
public $mRedirectCode = ''; |
| 302 |
|
| 303 |
|
| 304 |
protected $mFeedLinksAppendQuery = null; |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
protected $mAllowedModules = [ |
| 312 |
RL\Module::TYPE_COMBINED => RL\Module::ORIGIN_ALL, |
| 313 |
]; |
| 314 |
|
| 315 |
|
| 316 |
protected $mDoNothing = false; |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
protected $mParserOptions = null; |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
private $mFeedLinks = []; |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
private $mEnableClientCache = true; |
| 341 |
|
| 342 |
|
| 343 |
private $mArticleBodyOnly = false; |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
private $mNewSectionLink = false; |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
private $mHideNewSectionLink = false; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
private $mNoGallery = false; |
| 364 |
|
| 365 |
|
| 366 |
protected $mCdnMaxage = 0; |
| 367 |
|
| 368 |
protected $mCdnMaxageLimit = INF; |
| 369 |
|
| 370 |
|
| 371 |
private $mRevisionId = null; |
| 372 |
|
| 373 |
|
| 374 |
private $mRevisionIsCurrent = null; |
| 375 |
|
| 376 |
|
| 377 |
private $mRevisionTimestamp = null; |
| 378 |
|
| 379 |
|
| 380 |
protected $mFileVersion = null; |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
protected $styles = []; |
| 391 |
|
| 392 |
|
| 393 |
private $mFollowPolicy = 'follow'; |
| 394 |
|
| 395 |
|
| 396 |
private $mRobotsOptions = [ 'max-image-preview' => 'standard' ]; |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
private $mVaryHeader = [ |
| 404 |
'Accept-Encoding' => null, |
| 405 |
]; |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
private $mRedirectedFrom = null; |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
private $mProperties = []; |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
private $mTarget = null; |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
private $mEnableTOC = false; |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
private $mOutputFlags = []; |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
private $copyrightUrl; |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
private $contentLang; |
| 445 |
|
| 446 |
|
| 447 |
private $limitReportJSData = []; |
| 448 |
|
| 449 |
|
| 450 |
private $contentOverrides = []; |
| 451 |
|
| 452 |
|
| 453 |
private $contentOverrideCallbacks = []; |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
private $mLinkHeader = []; |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
private $CSP; |
| 465 |
|
| 466 |
private string $cspOutputMode = self::CSP_HEADERS; |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
private ParserOutput $metadata; |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
private static $cacheVaryCookies = null; |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
public function __construct( IContextSource $context ) { |
| 490 |
$this->deprecatePublicProperty( 'mCategoryLinks', '1.38', __CLASS__ ); |
| 491 |
$this->deprecatePublicProperty( 'mCategories', '1.38', __CLASS__ ); |
| 492 |
$this->deprecatePublicProperty( 'mIndicators', '1.38', __CLASS__ ); |
| 493 |
$this->deprecatePublicProperty( 'mHeadItems', '1.38', __CLASS__ ); |
| 494 |
$this->deprecatePublicProperty( 'mModules', '1.38', __CLASS__ ); |
| 495 |
$this->deprecatePublicProperty( 'mModuleStyles', '1.38', __CLASS__ ); |
| 496 |
$this->deprecatePublicProperty( 'mJsConfigVars', '1.38', __CLASS__ ); |
| 497 |
$this->deprecatePublicProperty( 'mTemplateIds', '1.38', __CLASS__ ); |
| 498 |
$this->deprecatePublicProperty( 'mEnableClientCache', '1.38', __CLASS__ ); |
| 499 |
$this->deprecatePublicProperty( 'mNewSectionLink', '1.38', __CLASS__ ); |
| 500 |
$this->deprecatePublicProperty( 'mHideNewSectionLink', '1.38', __CLASS__ ); |
| 501 |
$this->deprecatePublicProperty( 'mNoGallery', '1.38', __CLASS__ ); |
| 502 |
$this->setContext( $context ); |
| 503 |
$this->metadata = new ParserOutput( null ); |
| 504 |
$this->metadata->setPreventClickjacking( true ); |
| 505 |
$this->CSP = new ContentSecurityPolicy( |
| 506 |
$context->getRequest()->response(), |
| 507 |
$context->getConfig(), |
| 508 |
$this->getHookContainer() |
| 509 |
); |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
public function redirect( $url, $responsecode = '302' ) { |
| 519 |
|
| 520 |
$this->mRedirect = str_replace( "\n", '', $url ); |
| 521 |
$this->mRedirectCode = (string)$responsecode; |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
public function getRedirect() { |
| 530 |
return $this->mRedirect; |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
public function setCopyrightUrl( $url ) { |
| 542 |
$this->copyrightUrl = $url; |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
public function setStatusCode( $statusCode ) { |
| 551 |
$this->mStatusCode = $statusCode; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
public function getMetadata(): ParserOutput { |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
return $this->metadata; |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
public function addMeta( $name, $val ) { |
| 575 |
$this->mMetatags[] = [ $name, $val ]; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
public function getMetaTags() { |
| 585 |
return $this->mMetatags; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
public function addLink( array $linkarr ) { |
| 596 |
$this->mLinktags[] = $linkarr; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
public function getLinkTags() { |
| 606 |
return $this->mLinktags; |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
public function setCanonicalUrl( $url ) { |
| 615 |
$this->mCanonicalUrl = $url; |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
public function getCanonicalUrl() { |
| 626 |
return $this->mCanonicalUrl; |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
public function addScript( $script ) { |
| 638 |
$this->mScripts .= $script; |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
public function addScriptFile( $file, $unused = null ) { |
| 650 |
$this->addScript( Html::linkedScript( $file ) ); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
public function addInlineScript( $script ) { |
| 661 |
$this->mScripts .= Html::inlineScript( "\n$script\n" ) . "\n"; |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
protected function filterModules( array $modules, $position = null, |
| 673 |
$type = RL\Module::TYPE_COMBINED |
| 674 |
) { |
| 675 |
$resourceLoader = $this->getResourceLoader(); |
| 676 |
$filteredModules = []; |
| 677 |
foreach ( $modules as $val ) { |
| 678 |
$module = $resourceLoader->getModule( $val ); |
| 679 |
if ( $module instanceof RL\Module |
| 680 |
&& $module->getOrigin() <= $this->getAllowedModules( $type ) |
| 681 |
) { |
| 682 |
$filteredModules[] = $val; |
| 683 |
} |
| 684 |
} |
| 685 |
return $filteredModules; |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
public function getModules( $filter = false, $position = null, $param = 'mModules', |
| 698 |
$type = RL\Module::TYPE_COMBINED |
| 699 |
) { |
| 700 |
$modules = array_values( array_unique( $this->$param ) ); |
| 701 |
return $filter |
| 702 |
? $this->filterModules( $modules, null, $type ) |
| 703 |
: $modules; |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
public function addModules( $modules ) { |
| 712 |
$this->mModules = array_merge( $this->mModules, (array)$modules ); |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
public function getModuleStyles( $filter = false, $position = null ) { |
| 723 |
return $this->getModules( $filter, null, 'mModuleStyles', |
| 724 |
RL\Module::TYPE_STYLES |
| 725 |
); |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
public function addModuleStyles( $modules ) { |
| 738 |
$this->mModuleStyles = array_merge( $this->mModuleStyles, (array)$modules ); |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
public function getTarget() { |
| 745 |
return $this->mTarget; |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
public function addContentOverride( $target, Content $content ) { |
| 756 |
if ( !$this->contentOverrides ) { |
| 757 |
|
| 758 |
$this->addContentOverrideCallback( function ( $target ) { |
| 759 |
$key = $target->getNamespace() . ':' . $target->getDBkey(); |
| 760 |
return $this->contentOverrides[$key] ?? null; |
| 761 |
} ); |
| 762 |
} |
| 763 |
|
| 764 |
$key = $target->getNamespace() . ':' . $target->getDBkey(); |
| 765 |
$this->contentOverrides[$key] = $content; |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
public function addContentOverrideCallback( callable $callback ) { |
| 776 |
$this->contentOverrideCallbacks[] = $callback; |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
public function addHtmlClasses( $classes ) { |
| 787 |
$this->mAdditionalHtmlClasses = array_merge( $this->mAdditionalHtmlClasses, (array)$classes ); |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
public function getHeadItemsArray() { |
| 796 |
return $this->mHeadItems; |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
public function addHeadItem( $name, $value ) { |
| 813 |
$this->mHeadItems[$name] = $value; |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
public function addHeadItems( $values ) { |
| 824 |
$this->mHeadItems = array_merge( $this->mHeadItems, (array)$values ); |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
public function hasHeadItem( $name ) { |
| 834 |
return isset( $this->mHeadItems[$name] ); |
| 835 |
} |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
public function addBodyClasses( $classes ) { |
| 844 |
$this->mAdditionalBodyClasses = array_merge( $this->mAdditionalBodyClasses, (array)$classes ); |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
public function setArticleBodyOnly( $only ) { |
| 855 |
$this->mArticleBodyOnly = $only; |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
public function getArticleBodyOnly() { |
| 864 |
return $this->mArticleBodyOnly; |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
public function setProperty( $name, $value ) { |
| 875 |
$this->mProperties[$name] = $value; |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
public function getProperty( $name ) { |
| 886 |
return $this->mProperties[$name] ?? null; |
| 887 |
} |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
public function checkLastModified( $timestamp ) { |
| 901 |
if ( !$timestamp || $timestamp == '19700101000000' ) { |
| 902 |
wfDebug( __METHOD__ . ': CACHE DISABLED, NO TIMESTAMP' ); |
| 903 |
return false; |
| 904 |
} |
| 905 |
$config = $this->getConfig(); |
| 906 |
if ( !$config->get( MainConfigNames::CachePages ) ) { |
| 907 |
wfDebug( __METHOD__ . ': CACHE DISABLED' ); |
| 908 |
return false; |
| 909 |
} |
| 910 |
|
| 911 |
$timestamp = wfTimestamp( TS_MW, $timestamp ); |
| 912 |
$modifiedTimes = [ |
| 913 |
'page' => $timestamp, |
| 914 |
'user' => $this->getUser()->getTouched(), |
| 915 |
'epoch' => $config->get( MainConfigNames::CacheEpoch ) |
| 916 |
]; |
| 917 |
if ( $config->get( MainConfigNames::UseCdn ) ) { |
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
$modifiedTimes['sepoch'] = wfTimestamp( |
| 923 |
TS_MW, |
| 924 |
time() - $config->get( MainConfigNames::CdnMaxAge ) |
| 925 |
); |
| 926 |
} |
| 927 |
$this->getHookRunner()->onOutputPageCheckLastModified( $modifiedTimes, $this ); |
| 928 |
|
| 929 |
$maxModified = max( $modifiedTimes ); |
| 930 |
$this->mLastModified = wfTimestamp( TS_RFC2822, $maxModified ); |
| 931 |
|
| 932 |
$clientHeader = $this->getRequest()->getHeader( 'If-Modified-Since' ); |
| 933 |
if ( $clientHeader === false ) { |
| 934 |
wfDebug( __METHOD__ . ': client did not send If-Modified-Since header', 'private' ); |
| 935 |
return false; |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
$clientHeader = preg_replace( '/;.*$/', '', $clientHeader ); |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
$clientHeaderTime = @strtotime( $clientHeader ); |
| 946 |
if ( !$clientHeaderTime ) { |
| 947 |
wfDebug( __METHOD__ |
| 948 |
. ": unable to parse the client's If-Modified-Since header: $clientHeader" ); |
| 949 |
return false; |
| 950 |
} |
| 951 |
$clientHeaderTime = wfTimestamp( TS_MW, $clientHeaderTime ); |
| 952 |
|
| 953 |
|
| 954 |
$info = ''; |
| 955 |
foreach ( $modifiedTimes as $name => $value ) { |
| 956 |
if ( $info !== '' ) { |
| 957 |
$info .= ', '; |
| 958 |
} |
| 959 |
$info .= "$name=" . wfTimestamp( TS_ISO_8601, $value ); |
| 960 |
} |
| 961 |
|
| 962 |
wfDebug( __METHOD__ . ': client sent If-Modified-Since: ' . |
| 963 |
wfTimestamp( TS_ISO_8601, $clientHeaderTime ), 'private' ); |
| 964 |
wfDebug( __METHOD__ . ': effective Last-Modified: ' . |
| 965 |
wfTimestamp( TS_ISO_8601, $maxModified ), 'private' ); |
| 966 |
if ( $clientHeaderTime < $maxModified ) { |
| 967 |
wfDebug( __METHOD__ . ": STALE, $info", 'private' ); |
| 968 |
return false; |
| 969 |
} |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
wfDebug( __METHOD__ . ": NOT MODIFIED, $info", 'private' ); |
| 974 |
ini_set( 'zlib.output_compression', 0 ); |
| 975 |
$this->getRequest()->response()->statusHeader( 304 ); |
| 976 |
$this->sendCacheControl(); |
| 977 |
$this->disable(); |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
wfResetOutputBuffers( false ); |
| 983 |
|
| 984 |
return true; |
| 985 |
} |
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
public function setLastModified( $timestamp ) { |
| 994 |
$this->mLastModified = wfTimestamp( TS_RFC2822, $timestamp ); |
| 995 |
} |
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
public function setRobotPolicy( $policy ) { |
| 1005 |
$policy = Article::formatRobotPolicy( $policy ); |
| 1006 |
|
| 1007 |
if ( isset( $policy['index'] ) ) { |
| 1008 |
$this->setIndexPolicy( $policy['index'] ); |
| 1009 |
} |
| 1010 |
if ( isset( $policy['follow'] ) ) { |
| 1011 |
$this->setFollowPolicy( $policy['follow'] ); |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
public function getRobotPolicy() { |
| 1022 |
$indexPolicy = $this->getIndexPolicy(); |
| 1023 |
return "{$indexPolicy},{$this->mFollowPolicy}"; |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
private function formatRobotsOptions(): string { |
| 1032 |
$options = $this->mRobotsOptions; |
| 1033 |
|
| 1034 |
if ( count( array_filter( array_keys( $options ), 'is_string' ) ) > 0 ) { |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
array_walk( $options, static function ( &$value, $key ) { |
| 1040 |
$value = is_string( $key ) ? "{$key}:{$value}" : "{$value}"; |
| 1041 |
} ); |
| 1042 |
} |
| 1043 |
return implode( ',', $options ); |
| 1044 |
} |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
public function setRobotsOptions( array $options = [] ): void { |
| 1054 |
$this->mRobotsOptions = array_merge( $this->mRobotsOptions, $options ); |
| 1055 |
} |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
private function getRobotsContent(): string { |
| 1064 |
$robotOptionString = $this->formatRobotsOptions(); |
| 1065 |
$robotArgs = ( $this->getIndexPolicy() === 'index' && |
| 1066 |
$this->mFollowPolicy === 'follow' ) ? |
| 1067 |
[] : |
| 1068 |
[ |
| 1069 |
$this->getIndexPolicy(), |
| 1070 |
$this->mFollowPolicy, |
| 1071 |
]; |
| 1072 |
if ( $robotOptionString ) { |
| 1073 |
$robotArgs[] = $robotOptionString; |
| 1074 |
} |
| 1075 |
return implode( ',', $robotArgs ); |
| 1076 |
} |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
public function setIndexPolicy( $policy ) { |
| 1092 |
$policy = trim( $policy ); |
| 1093 |
if ( $policy === 'index' && $this->metadata->getIndexPolicy() === 'noindex' ) { |
| 1094 |
wfDeprecated( __METHOD__ . ' with index after noindex', '1.43' ); |
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
$this->metadata->setOutputFlag( ParserOutputFlags::NO_INDEX_POLICY, false ); |
| 1099 |
} |
| 1100 |
$this->metadata->setIndexPolicy( $policy ); |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
public function getIndexPolicy() { |
| 1110 |
|
| 1111 |
|
| 1112 |
$policy = $this->metadata->getIndexPolicy(); |
| 1113 |
if ( $policy === '' ) { |
| 1114 |
$policy = 'index'; |
| 1115 |
} |
| 1116 |
return $policy; |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
public function setFollowPolicy( $policy ) { |
| 1126 |
$policy = trim( $policy ); |
| 1127 |
if ( in_array( $policy, [ 'follow', 'nofollow' ] ) ) { |
| 1128 |
$this->mFollowPolicy = $policy; |
| 1129 |
} |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
public function getFollowPolicy() { |
| 1138 |
return $this->mFollowPolicy; |
| 1139 |
} |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
public function setHTMLTitle( $name ) { |
| 1148 |
if ( $name instanceof Message ) { |
| 1149 |
$this->mHTMLtitle = $name->setContext( $this->getContext() )->text(); |
| 1150 |
} else { |
| 1151 |
$this->mHTMLtitle = $name; |
| 1152 |
} |
| 1153 |
} |
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
public function getHTMLTitle() { |
| 1161 |
return $this->mHTMLtitle; |
| 1162 |
} |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
public function setRedirectedFrom( PageReference $t ) { |
| 1170 |
$this->mRedirectedFrom = $t; |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
public function setPageTitle( $name ) { |
| 1189 |
if ( $name instanceof Message ) { |
| 1190 |
|
| 1191 |
wfDeprecated( __METHOD__ . ' with Message argument', '1.41' ); |
| 1192 |
$name = $name->setContext( $this->getContext() )->text(); |
| 1193 |
} |
| 1194 |
$this->setPageTitleInternal( $name ); |
| 1195 |
} |
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
public function setPageTitleMsg( Message $msg ): void { |
| 1213 |
$this->setPageTitleInternal( |
| 1214 |
$msg->setContext( $this->getContext() )->escaped() |
| 1215 |
); |
| 1216 |
} |
| 1217 |
|
| 1218 |
private function setPageTitleInternal( string $name ): void { |
| 1219 |
|
| 1220 |
|
| 1221 |
$nameWithTags = Sanitizer::removeSomeTags( $name ); |
| 1222 |
$this->mPageTitle = $nameWithTags; |
| 1223 |
|
| 1224 |
|
| 1225 |
$this->setHTMLTitle( |
| 1226 |
$this->msg( 'pagetitle' )->plaintextParams( Sanitizer::stripAllTags( $nameWithTags ) ) |
| 1227 |
->inContentLanguage() |
| 1228 |
); |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
public function getPageTitle() { |
| 1237 |
return $this->mPageTitle; |
| 1238 |
} |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
public function setDisplayTitle( $html ) { |
| 1248 |
$this->displayTitle = $html; |
| 1249 |
} |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
public function getDisplayTitle() { |
| 1260 |
$html = $this->displayTitle; |
| 1261 |
if ( $html === null ) { |
| 1262 |
return htmlspecialchars( $this->getTitle()->getPrefixedText(), ENT_NOQUOTES ); |
| 1263 |
} |
| 1264 |
|
| 1265 |
return Sanitizer::removeSomeTags( $html ); |
| 1266 |
} |
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
public function getUnprefixedDisplayTitle() { |
| 1277 |
$service = MediaWikiServices::getInstance(); |
| 1278 |
$languageConverter = $service->getLanguageConverterFactory() |
| 1279 |
->getLanguageConverter( $service->getContentLanguage() ); |
| 1280 |
$text = $this->getDisplayTitle(); |
| 1281 |
|
| 1282 |
|
| 1283 |
$pageTitleRegexp = '/^' . str_replace( |
| 1284 |
preg_quote( '(.+?)', '/' ), |
| 1285 |
'(.+?)', |
| 1286 |
preg_quote( Parser::formatPageTitle( '(.+?)', '(.+?)', '(.+?)' ), '/' ) |
| 1287 |
) . '$/'; |
| 1288 |
$matches = []; |
| 1289 |
if ( preg_match( $pageTitleRegexp, $text, $matches ) ) { |
| 1290 |
|
| 1291 |
|
| 1292 |
return Sanitizer::removeSomeTags( $matches[3] ); |
| 1293 |
} |
| 1294 |
|
| 1295 |
$nsPrefix = $languageConverter->convertNamespace( |
| 1296 |
$this->getTitle()->getNamespace() |
| 1297 |
) . ':'; |
| 1298 |
$prefix = preg_quote( $nsPrefix, '/' ); |
| 1299 |
|
| 1300 |
return preg_replace( "/^$prefix/i", '', $text ); |
| 1301 |
} |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
public function setTitle( PageReference $t ) { |
| 1309 |
$t = Title::newFromPageReference( $t ); |
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
$this->getContext()->setTitle( $t ); |
| 1314 |
} |
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
public function setSubtitle( $str ) { |
| 1322 |
$this->clearSubtitle(); |
| 1323 |
$this->addSubtitle( $str ); |
| 1324 |
} |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
public function addSubtitle( $str ) { |
| 1333 |
if ( $str instanceof Message ) { |
| 1334 |
$this->mSubtitle[] = $str->setContext( $this->getContext() )->parse(); |
| 1335 |
} else { |
| 1336 |
$this->mSubtitle[] = $str; |
| 1337 |
} |
| 1338 |
} |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
public static function buildBacklinkSubtitle( PageReference $page, $query = [] ) { |
| 1349 |
if ( $page instanceof PageRecord || $page instanceof Title ) { |
| 1350 |
|
| 1351 |
if ( $page->isRedirect() ) { |
| 1352 |
$query['redirect'] = 'no'; |
| 1353 |
} |
| 1354 |
} elseif ( $page->getNamespace() !== NS_SPECIAL ) { |
| 1355 |
|
| 1356 |
$query['redirect'] = 'no'; |
| 1357 |
} |
| 1358 |
|
| 1359 |
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); |
| 1360 |
return wfMessage( 'backlinksubtitle' ) |
| 1361 |
->rawParams( $linkRenderer->makeLink( $page, null, [], $query ) ); |
| 1362 |
} |
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
public function addBacklinkSubtitle( PageReference $title, $query = [] ) { |
| 1371 |
$this->addSubtitle( self::buildBacklinkSubtitle( $title, $query ) ); |
| 1372 |
} |
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
public function clearSubtitle() { |
| 1378 |
$this->mSubtitle = []; |
| 1379 |
} |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
public function getSubtitle() { |
| 1385 |
return implode( "<br />\n\t\t\t\t", $this->mSubtitle ); |
| 1386 |
} |
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
public function setPrintable() { |
| 1393 |
$this->mPrintable = true; |
| 1394 |
} |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
public function isPrintable() { |
| 1402 |
return $this->mPrintable; |
| 1403 |
} |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
public function disable() { |
| 1409 |
$this->mDoNothing = true; |
| 1410 |
} |
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
public function isDisabled() { |
| 1418 |
return $this->mDoNothing; |
| 1419 |
} |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
public function showNewSectionLink() { |
| 1427 |
return $this->mNewSectionLink; |
| 1428 |
} |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
public function forceHideNewSectionLink() { |
| 1436 |
return $this->mHideNewSectionLink; |
| 1437 |
} |
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
public function setSyndicated( $show = true ) { |
| 1448 |
if ( $show ) { |
| 1449 |
$this->setFeedAppendQuery( false ); |
| 1450 |
} else { |
| 1451 |
$this->mFeedLinks = []; |
| 1452 |
} |
| 1453 |
} |
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
protected function getAdvertisedFeedTypes() { |
| 1462 |
if ( $this->getConfig()->get( MainConfigNames::Feed ) ) { |
| 1463 |
return $this->getConfig()->get( MainConfigNames::AdvertisedFeedTypes ); |
| 1464 |
} else { |
| 1465 |
return []; |
| 1466 |
} |
| 1467 |
} |
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
public function setFeedAppendQuery( $val ) { |
| 1479 |
$this->mFeedLinks = []; |
| 1480 |
|
| 1481 |
foreach ( $this->getAdvertisedFeedTypes() as $type ) { |
| 1482 |
$query = "feed=$type"; |
| 1483 |
if ( is_string( $val ) ) { |
| 1484 |
$query .= '&' . $val; |
| 1485 |
} |
| 1486 |
$this->mFeedLinks[$type] = $this->getTitle()->getLocalURL( $query ); |
| 1487 |
} |
| 1488 |
} |
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
public function addFeedLink( $format, $href ) { |
| 1497 |
if ( in_array( $format, $this->getAdvertisedFeedTypes() ) ) { |
| 1498 |
$this->mFeedLinks[$format] = $href; |
| 1499 |
} |
| 1500 |
} |
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
public function isSyndicated() { |
| 1507 |
return count( $this->mFeedLinks ) > 0; |
| 1508 |
} |
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
public function getSyndicationLinks() { |
| 1515 |
return $this->mFeedLinks; |
| 1516 |
} |
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
public function getFeedAppendQuery() { |
| 1524 |
return $this->mFeedLinksAppendQuery; |
| 1525 |
} |
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
public function setArticleFlag( $newVal ) { |
| 1535 |
$this->mIsArticle = $newVal; |
| 1536 |
if ( $newVal ) { |
| 1537 |
$this->mIsArticleRelated = $newVal; |
| 1538 |
} |
| 1539 |
} |
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
public function isArticle() { |
| 1548 |
return $this->mIsArticle; |
| 1549 |
} |
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
public function setArticleRelated( $newVal ) { |
| 1558 |
$this->mIsArticleRelated = $newVal; |
| 1559 |
if ( !$newVal ) { |
| 1560 |
$this->mIsArticle = false; |
| 1561 |
} |
| 1562 |
} |
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
public function isArticleRelated() { |
| 1570 |
return $this->mIsArticleRelated; |
| 1571 |
} |
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
public function setCopyright( $hasCopyright ) { |
| 1579 |
$this->mHasCopyright = $hasCopyright; |
| 1580 |
} |
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
public function showsCopyright() { |
| 1592 |
return $this->isArticle() || $this->mHasCopyright; |
| 1593 |
} |
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
public function addLanguageLinks( array $newLinkArray ) { |
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
foreach ( $newLinkArray as $t ) { |
| 1606 |
$this->metadata->addLanguageLink( $t ); |
| 1607 |
} |
| 1608 |
} |
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
public function setLanguageLinks( array $newLinkArray ) { |
| 1620 |
$this->metadata->setLanguageLinks( $newLinkArray ); |
| 1621 |
} |
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
public function getLanguageLinks() { |
| 1629 |
return $this->metadata->getLanguageLinks(); |
| 1630 |
} |
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
public function getNoGallery(): bool { |
| 1639 |
return $this->mNoGallery; |
| 1640 |
} |
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
public function addCategoryLinks( array $categories ) { |
| 1648 |
if ( !$categories ) { |
| 1649 |
return; |
| 1650 |
} |
| 1651 |
|
| 1652 |
$res = $this->addCategoryLinksToLBAndGetResult( $categories ); |
| 1653 |
|
| 1654 |
|
| 1655 |
$categories = array_fill_keys( array_keys( $categories ), 'normal' ); |
| 1656 |
$pageData = []; |
| 1657 |
|
| 1658 |
|
| 1659 |
foreach ( $res as $row ) { |
| 1660 |
if ( isset( $row->pp_value ) ) { |
| 1661 |
$categories[$row->page_title] = 'hidden'; |
| 1662 |
} |
| 1663 |
|
| 1664 |
if ( isset( $row->page_id ) ) { |
| 1665 |
$pageData[$row->page_title] = $row; |
| 1666 |
} |
| 1667 |
} |
| 1668 |
|
| 1669 |
|
| 1670 |
if ( $this->getHookRunner()->onOutputPageMakeCategoryLinks( |
| 1671 |
$this, $categories, $this->mCategoryLinks ) |
| 1672 |
) { |
| 1673 |
$services = MediaWikiServices::getInstance(); |
| 1674 |
$linkRenderer = $services->getLinkRenderer(); |
| 1675 |
$languageConverter = $services->getLanguageConverterFactory() |
| 1676 |
->getLanguageConverter( $services->getContentLanguage() ); |
| 1677 |
$collation = $services->getCollationFactory()->getCategoryCollation(); |
| 1678 |
foreach ( $categories as $category => $type ) { |
| 1679 |
|
| 1680 |
$category = (string)$category; |
| 1681 |
$origcategory = $category; |
| 1682 |
if ( array_key_exists( $category, $pageData ) ) { |
| 1683 |
$title = Title::newFromRow( $pageData[$category] ); |
| 1684 |
} else { |
| 1685 |
$title = Title::makeTitleSafe( NS_CATEGORY, $category ); |
| 1686 |
} |
| 1687 |
if ( !$title ) { |
| 1688 |
continue; |
| 1689 |
} |
| 1690 |
$languageConverter->findVariantLink( $category, $title, true ); |
| 1691 |
|
| 1692 |
if ( $category != $origcategory && array_key_exists( $category, $categories ) ) { |
| 1693 |
continue; |
| 1694 |
} |
| 1695 |
$text = $languageConverter->convertHtml( $title->getText() ); |
| 1696 |
$link = null; |
| 1697 |
$this->getHookRunner()->onOutputPageRenderCategoryLink( $this, $title->toPageIdentity(), $text, $link ); |
| 1698 |
if ( $link === null ) { |
| 1699 |
$link = $linkRenderer->makeLink( $title, new HtmlArmor( $text ) ); |
| 1700 |
} |
| 1701 |
$this->mCategoryData[] = [ |
| 1702 |
'sortKey' => $collation->getSortKey( $text ), |
| 1703 |
'type' => $type, |
| 1704 |
'title' => $title->getText(), |
| 1705 |
'link' => $link, |
| 1706 |
]; |
| 1707 |
$this->mCategoriesSorted = false; |
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
$this->mCategories[$type][] = $title->getText(); |
| 1712 |
$this->mCategoryLinks[$type][] = $link; |
| 1713 |
} |
| 1714 |
} else { |
| 1715 |
|
| 1716 |
$this->mCategoriesSorted = false; |
| 1717 |
} |
| 1718 |
} |
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
protected function addCategoryLinksToLBAndGetResult( array $categories ) { |
| 1725 |
|
| 1726 |
$arr = [ NS_CATEGORY => $categories ]; |
| 1727 |
$linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory(); |
| 1728 |
$lb = $linkBatchFactory->newLinkBatch(); |
| 1729 |
$lb->setArray( $arr ); |
| 1730 |
|
| 1731 |
|
| 1732 |
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
| 1733 |
$fields = array_merge( |
| 1734 |
LinkCache::getSelectFields(), |
| 1735 |
[ 'pp_value' ] |
| 1736 |
); |
| 1737 |
|
| 1738 |
$res = $dbr->newSelectQueryBuilder() |
| 1739 |
->select( $fields ) |
| 1740 |
->from( 'page' ) |
| 1741 |
->leftJoin( 'page_props', null, [ |
| 1742 |
'pp_propname' => 'hiddencat', |
| 1743 |
'pp_page = page_id', |
| 1744 |
] ) |
| 1745 |
->where( $lb->constructSet( 'page', $dbr ) ) |
| 1746 |
->caller( __METHOD__ ) |
| 1747 |
->fetchResultSet(); |
| 1748 |
|
| 1749 |
|
| 1750 |
$linkCache = MediaWikiServices::getInstance()->getLinkCache(); |
| 1751 |
$lb->addResultToCache( $linkCache, $res ); |
| 1752 |
|
| 1753 |
return $res; |
| 1754 |
} |
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
public function setCategoryLinks( array $categories ) { |
| 1763 |
wfDeprecated( __METHOD__, '1.43' ); |
| 1764 |
$this->mCategoryLinks = []; |
| 1765 |
foreach ( $this->mCategoryData as &$arr ) { |
| 1766 |
|
| 1767 |
$arr['link'] = null; |
| 1768 |
} |
| 1769 |
$this->addCategoryLinks( $categories ); |
| 1770 |
} |
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
public function getCategoryLinks() { |
| 1782 |
$this->maybeSortCategories(); |
| 1783 |
return $this->mCategoryLinks; |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
public function getCategories( $type = 'all' ) { |
| 1796 |
$this->maybeSortCategories(); |
| 1797 |
if ( $type === 'all' ) { |
| 1798 |
$allCategories = []; |
| 1799 |
foreach ( $this->mCategories as $categories ) { |
| 1800 |
$allCategories = array_merge( $allCategories, $categories ); |
| 1801 |
} |
| 1802 |
return $allCategories; |
| 1803 |
} |
| 1804 |
if ( !isset( $this->mCategories[$type] ) ) { |
| 1805 |
throw new InvalidArgumentException( 'Invalid category type given: ' . $type ); |
| 1806 |
} |
| 1807 |
return $this->mCategories[$type]; |
| 1808 |
} |
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
private function maybeSortCategories(): void { |
| 1816 |
if ( $this->mCategoriesSorted ) { |
| 1817 |
return; |
| 1818 |
} |
| 1819 |
|
| 1820 |
$sortCategories = $this->getConfig()->get( MainConfigNames::SortedCategories ); |
| 1821 |
|
| 1822 |
$sortCategories = $this->getRequest()->getFuzzyBool( 'sortcat', $sortCategories ); |
| 1823 |
if ( $sortCategories ) { |
| 1824 |
|
| 1825 |
|
| 1826 |
usort( $this->mCategoryData, static function ( $a, $b ): int { |
| 1827 |
return $a['type'] <=> $b['type'] ?: |
| 1828 |
$a['sortKey'] <=> $b['sortKey'] ?: |
| 1829 |
$a['title'] <=> $b['sortKey'] ?: |
| 1830 |
$a['link'] <=> $b['link']; |
| 1831 |
} ); |
| 1832 |
} |
| 1833 |
|
| 1834 |
$this->mCategories = [ |
| 1835 |
'hidden' => [], |
| 1836 |
'normal' => [], |
| 1837 |
]; |
| 1838 |
$this->mCategoryLinks = []; |
| 1839 |
foreach ( $this->mCategoryData as $c ) { |
| 1840 |
$this->mCategories[$c['type']][] = $c['title']; |
| 1841 |
if ( $c['link'] !== null ) { |
| 1842 |
|
| 1843 |
$this->mCategoryLinks[$c['type']][] = $c['link']; |
| 1844 |
} |
| 1845 |
} |
| 1846 |
$this->mCategoriesSorted = true; |
| 1847 |
} |
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
public function setIndicators( array $indicators ) { |
| 1864 |
$this->mIndicators = $indicators + $this->mIndicators; |
| 1865 |
|
| 1866 |
ksort( $this->mIndicators ); |
| 1867 |
} |
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
public function getIndicators(): array { |
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
return $this->mIndicators; |
| 1888 |
} |
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
public function addHelpLink( $to, $overrideBaseUrl = false ) { |
| 1899 |
$this->addModuleStyles( 'mediawiki.helplink' ); |
| 1900 |
$text = $this->msg( 'helppage-top-gethelp' )->escaped(); |
| 1901 |
|
| 1902 |
if ( $overrideBaseUrl ) { |
| 1903 |
$helpUrl = $to; |
| 1904 |
} else { |
| 1905 |
$toUrlencoded = wfUrlencode( str_replace( ' ', '_', $to ) ); |
| 1906 |
$helpUrl = "https://www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded"; |
| 1907 |
} |
| 1908 |
|
| 1909 |
$link = Html::rawElement( |
| 1910 |
'a', |
| 1911 |
[ |
| 1912 |
'href' => $helpUrl, |
| 1913 |
'target' => '_blank', |
| 1914 |
'class' => 'mw-helplink', |
| 1915 |
], |
| 1916 |
Html::element( 'span', [ 'class' => 'mw-helplink-icon' ] ) . $text |
| 1917 |
); |
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
$this->setIndicators( [ 'mw-helplink' => $link ] ); |
| 1923 |
} |
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
public function disallowUserJs() { |
| 1934 |
$this->reduceAllowedModules( |
| 1935 |
RL\Module::TYPE_SCRIPTS, |
| 1936 |
RL\Module::ORIGIN_CORE_INDIVIDUAL |
| 1937 |
); |
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
if ( $this->getConfig()->get( MainConfigNames::AllowSiteCSSOnRestrictedPages ) ) { |
| 1942 |
$styleOrigin = RL\Module::ORIGIN_USER_SITEWIDE; |
| 1943 |
} else { |
| 1944 |
$styleOrigin = RL\Module::ORIGIN_CORE_INDIVIDUAL; |
| 1945 |
} |
| 1946 |
$this->reduceAllowedModules( |
| 1947 |
RL\Module::TYPE_STYLES, |
| 1948 |
$styleOrigin |
| 1949 |
); |
| 1950 |
} |
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
public function getAllowedModules( $type ) { |
| 1959 |
if ( $type == RL\Module::TYPE_COMBINED ) { |
| 1960 |
return min( array_values( $this->mAllowedModules ) ); |
| 1961 |
} else { |
| 1962 |
return $this->mAllowedModules[$type] ?? RL\Module::ORIGIN_ALL; |
| 1963 |
} |
| 1964 |
} |
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
public function reduceAllowedModules( $type, $level ) { |
| 1976 |
$this->mAllowedModules[$type] = min( $this->getAllowedModules( $type ), $level ); |
| 1977 |
} |
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
public function prependHTML( $text ) { |
| 1986 |
$this->mBodytext = $text . $this->mBodytext; |
| 1987 |
} |
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
public function addHTML( $text ) { |
| 1996 |
$this->mBodytext .= $text; |
| 1997 |
} |
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
public function addElement( $element, array $attribs = [], $contents = '' ) { |
| 2009 |
$this->addHTML( Html::element( $element, $attribs, $contents ) ); |
| 2010 |
} |
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
public function clearHTML() { |
| 2016 |
$this->mBodytext = ''; |
| 2017 |
} |
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
public function getHTML() { |
| 2025 |
return $this->mBodytext; |
| 2026 |
} |
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
public function parserOptions() { |
| 2034 |
if ( !$this->mParserOptions ) { |
| 2035 |
if ( !$this->getUser()->isSafeToLoad() ) { |
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
$po = ParserOptions::newFromAnon(); |
| 2040 |
$po->setAllowUnsafeRawHtml( false ); |
| 2041 |
return $po; |
| 2042 |
} |
| 2043 |
|
| 2044 |
$this->mParserOptions = ParserOptions::newFromContext( $this->getContext() ); |
| 2045 |
$this->mParserOptions->setAllowUnsafeRawHtml( false ); |
| 2046 |
} |
| 2047 |
|
| 2048 |
return $this->mParserOptions; |
| 2049 |
} |
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
public function setRevisionId( $revid ) { |
| 2059 |
$val = $revid === null ? null : intval( $revid ); |
| 2060 |
return wfSetVar( $this->mRevisionId, $val, true ); |
| 2061 |
} |
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
public function getRevisionId() { |
| 2069 |
return $this->mRevisionId; |
| 2070 |
} |
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
public function setRevisionIsCurrent( bool $isCurrent ): void { |
| 2079 |
$this->mRevisionIsCurrent = $isCurrent; |
| 2080 |
} |
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
public function isRevisionCurrent(): bool { |
| 2089 |
return $this->mRevisionId == 0 || ( |
| 2090 |
$this->mRevisionIsCurrent ?? ( |
| 2091 |
$this->mRevisionId == $this->getTitle()->getLatestRevID() |
| 2092 |
) |
| 2093 |
); |
| 2094 |
} |
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
public function setRevisionTimestamp( $timestamp ) { |
| 2104 |
return wfSetVar( $this->mRevisionTimestamp, $timestamp, true ); |
| 2105 |
} |
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
|
| 2112 |
|
| 2113 |
public function getRevisionTimestamp() { |
| 2114 |
return $this->mRevisionTimestamp; |
| 2115 |
} |
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
public function setFileVersion( $file ) { |
| 2124 |
$val = null; |
| 2125 |
if ( $file instanceof File && $file->exists() ) { |
| 2126 |
$val = [ 'time' => $file->getTimestamp(), 'sha1' => $file->getSha1() ]; |
| 2127 |
} |
| 2128 |
return wfSetVar( $this->mFileVersion, $val, true ); |
| 2129 |
} |
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
public function getFileVersion() { |
| 2137 |
return $this->mFileVersion; |
| 2138 |
} |
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
public function getTemplateIds() { |
| 2147 |
return $this->mTemplateIds; |
| 2148 |
} |
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
public function getFileSearchOptions() { |
| 2157 |
return $this->mImageTimeKeys; |
| 2158 |
} |
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
public function addWikiTextAsInterface( |
| 2175 |
$text, $linestart = true, ?PageReference $title = null |
| 2176 |
) { |
| 2177 |
$title ??= $this->getTitle(); |
| 2178 |
if ( $title === null ) { |
| 2179 |
throw new RuntimeException( 'No title in ' . __METHOD__ ); |
| 2180 |
} |
| 2181 |
$this->addWikiTextTitleInternal( $text, $title, $linestart, true ); |
| 2182 |
} |
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
public function wrapWikiTextAsInterface( |
| 2198 |
$wrapperClass, $text |
| 2199 |
) { |
| 2200 |
$title = $this->getTitle(); |
| 2201 |
if ( $title === null ) { |
| 2202 |
throw new RuntimeException( 'No title in ' . __METHOD__ ); |
| 2203 |
} |
| 2204 |
$this->addWikiTextTitleInternal( |
| 2205 |
$text, $title, |
| 2206 |
true, true, |
| 2207 |
$wrapperClass |
| 2208 |
); |
| 2209 |
} |
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
public function addWikiTextAsContent( |
| 2225 |
$text, $linestart = true, ?PageReference $title = null |
| 2226 |
) { |
| 2227 |
$title ??= $this->getTitle(); |
| 2228 |
if ( !$title ) { |
| 2229 |
throw new RuntimeException( 'No title in ' . __METHOD__ ); |
| 2230 |
} |
| 2231 |
$this->addWikiTextTitleInternal( $text, $title, $linestart, false ); |
| 2232 |
} |
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
private function addWikiTextTitleInternal( |
| 2247 |
string $text, PageReference $title, bool $linestart, bool $interface, |
| 2248 |
?string $wrapperClass = null |
| 2249 |
) { |
| 2250 |
$parserOutput = $this->parseInternal( |
| 2251 |
$text, $title, $linestart, $interface |
| 2252 |
); |
| 2253 |
|
| 2254 |
$this->addParserOutput( $parserOutput, [ |
| 2255 |
'enableSectionEditLinks' => false, |
| 2256 |
'wrapperDivClass' => $wrapperClass ?? '', |
| 2257 |
] ); |
| 2258 |
} |
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
public function setTOCData( TOCData $tocData ) { |
| 2266 |
$this->tocData = $tocData; |
| 2267 |
} |
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
public function getTOCData(): ?TOCData { |
| 2275 |
return $this->tocData; |
| 2276 |
} |
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
public function getOutputFlag( string $name ): bool { |
| 2285 |
return isset( $this->mOutputFlags[$name] ); |
| 2286 |
} |
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
public function setContentLangForJS( Bcp47Code $lang ): void { |
| 2294 |
$this->contentLang = MediaWikiServices::getInstance()->getLanguageFactory() |
| 2295 |
->getLanguage( $lang ); |
| 2296 |
} |
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
private function getContentLangForJS(): Language { |
| 2313 |
if ( !$this->contentLang ) { |
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
$title = $this->getTitle(); |
| 2330 |
if ( $title->isSpecialPage() ) { |
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
$pageLang = $this->getLanguage(); |
| 2335 |
} else { |
| 2336 |
wfDebug( __METHOD__ . ' has to guess ParserOutput language' ); |
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
$pageLang = $title->getPageLanguage(); |
| 2349 |
} |
| 2350 |
if ( $title->getNamespace() !== NS_MEDIAWIKI ) { |
| 2351 |
$services = MediaWikiServices::getInstance(); |
| 2352 |
$langConv = $services->getLanguageConverterFactory()->getLanguageConverter( $pageLang ); |
| 2353 |
|
| 2354 |
|
| 2355 |
$variant = $langConv->getPreferredVariant(); |
| 2356 |
if ( $pageLang->getCode() !== $variant ) { |
| 2357 |
$pageLang = $services->getLanguageFactory()->getLanguage( $variant ); |
| 2358 |
} |
| 2359 |
} |
| 2360 |
$this->contentLang = $pageLang; |
| 2361 |
} |
| 2362 |
return $this->contentLang; |
| 2363 |
} |
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
public function addParserOutputMetadata( ParserOutput $parserOutput ) { |
| 2374 |
|
| 2375 |
|
| 2376 |
$this->addLanguageLinks( $parserOutput->getLanguageLinks() ); |
| 2377 |
$this->addCategoryLinks( $parserOutput->getCategoryMap() ); |
| 2378 |
|
| 2379 |
|
| 2380 |
$wrapClass = $parserOutput->getWrapperDivClass(); |
| 2381 |
$result = []; |
| 2382 |
foreach ( $parserOutput->getIndicators() as $name => $html ) { |
| 2383 |
if ( $html !== '' && $wrapClass !== '' ) { |
| 2384 |
$html = Html::rawElement( 'div', [ 'class' => $wrapClass ], $html ); |
| 2385 |
} |
| 2386 |
$result[$name] = $html; |
| 2387 |
} |
| 2388 |
$this->setIndicators( $result ); |
| 2389 |
|
| 2390 |
$tocData = $parserOutput->getTOCData(); |
| 2391 |
|
| 2392 |
|
| 2393 |
if ( $tocData !== null && ( $this->tocData === null || count( $tocData->getSections() ) > 0 ) ) { |
| 2394 |
$this->setTOCData( $tocData ); |
| 2395 |
} |
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
$this->mNewSectionLink = $parserOutput->getNewSection(); |
| 2404 |
$this->mHideNewSectionLink = $parserOutput->getHideNewSection(); |
| 2405 |
$this->mNoGallery = $parserOutput->getNoGallery(); |
| 2406 |
|
| 2407 |
if ( !$parserOutput->isCacheable() ) { |
| 2408 |
$this->disableClientCache(); |
| 2409 |
} |
| 2410 |
$this->addHeadItems( $parserOutput->getHeadItems() ); |
| 2411 |
$this->addModules( $parserOutput->getModules() ); |
| 2412 |
$this->addModuleStyles( $parserOutput->getModuleStyles() ); |
| 2413 |
$this->addJsConfigVars( $parserOutput->getJsConfigVars() ); |
| 2414 |
if ( $parserOutput->getPreventClickjacking() ) { |
| 2415 |
$this->metadata->setPreventClickjacking( true ); |
| 2416 |
} |
| 2417 |
$scriptSrcs = $parserOutput->getExtraCSPScriptSrcs(); |
| 2418 |
foreach ( $scriptSrcs as $src ) { |
| 2419 |
$this->getCSP()->addScriptSrc( $src ); |
| 2420 |
} |
| 2421 |
$defaultSrcs = $parserOutput->getExtraCSPDefaultSrcs(); |
| 2422 |
foreach ( $defaultSrcs as $src ) { |
| 2423 |
$this->getCSP()->addDefaultSrc( $src ); |
| 2424 |
} |
| 2425 |
$styleSrcs = $parserOutput->getExtraCSPStyleSrcs(); |
| 2426 |
foreach ( $styleSrcs as $src ) { |
| 2427 |
$this->getCSP()->addStyleSrc( $src ); |
| 2428 |
} |
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
if ( $this->getConfig()->get( MainConfigNames::ImagePreconnect ) && count( $parserOutput->getImages() ) ) { |
| 2433 |
$preconnect = []; |
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
$repoGroup = MediaWikiServices::getInstance()->getRepoGroup(); |
| 2438 |
$repoGroup->forEachForeignRepo( static function ( $repo ) use ( &$preconnect ) { |
| 2439 |
$preconnect[] = $repo->getZoneUrl( 'thumb' ); |
| 2440 |
} ); |
| 2441 |
|
| 2442 |
|
| 2443 |
$preconnect[] = $repoGroup->getLocalRepo()->getZoneUrl( 'thumb' ); |
| 2444 |
foreach ( $preconnect as $url ) { |
| 2445 |
$host = parse_url( $url, PHP_URL_HOST ); |
| 2446 |
|
| 2447 |
if ( $host ) { |
| 2448 |
$this->addLink( [ 'rel' => 'preconnect', 'href' => '//' . $host ] ); |
| 2449 |
break; |
| 2450 |
} |
| 2451 |
} |
| 2452 |
} |
| 2453 |
|
| 2454 |
|
| 2455 |
foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) { |
| 2456 |
if ( isset( $this->mTemplateIds[$ns] ) ) { |
| 2457 |
$this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns]; |
| 2458 |
} else { |
| 2459 |
$this->mTemplateIds[$ns] = $dbks; |
| 2460 |
} |
| 2461 |
} |
| 2462 |
|
| 2463 |
foreach ( (array)$parserOutput->getFileSearchOptions() as $dbk => $data ) { |
| 2464 |
$this->mImageTimeKeys[$dbk] = $data; |
| 2465 |
} |
| 2466 |
|
| 2467 |
|
| 2468 |
if ( $parserOutput->getEnableOOUI() ) { |
| 2469 |
$this->enableOOUI(); |
| 2470 |
} |
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
if ( !$this->limitReportJSData ) { |
| 2477 |
$this->limitReportJSData = $parserOutput->getLimitReportJSData(); |
| 2478 |
} |
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
$linkFlags = []; |
| 2483 |
$languageLinks = $this->metadata->getLanguageLinks(); |
| 2484 |
|
| 2485 |
$this->getHookRunner()->onLanguageLinks( $this->getTitle(), $languageLinks, $linkFlags ); |
| 2486 |
$this->metadata->setLanguageLinks( $languageLinks ); |
| 2487 |
|
| 2488 |
$this->getHookRunner()->onOutputPageParserOutput( $this, $parserOutput ); |
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
$this->mEnableTOC = $this->mEnableTOC || |
| 2498 |
$parserOutput->getOutputFlag( ParserOutputFlags::SHOW_TOC ); |
| 2499 |
|
| 2500 |
|
| 2501 |
$flags = |
| 2502 |
array_flip( $parserOutput->getAllFlags() ) + |
| 2503 |
array_flip( ParserOutputFlags::cases() ); |
| 2504 |
foreach ( $flags as $name => $ignore ) { |
| 2505 |
if ( $parserOutput->getOutputFlag( $name ) ) { |
| 2506 |
$this->mOutputFlags[$name] = true; |
| 2507 |
} |
| 2508 |
} |
| 2509 |
} |
| 2510 |
|
| 2511 |
private function getParserOutputText( ParserOutput $parserOutput, array $poOptions = [] ): string { |
| 2512 |
|
| 2513 |
$skin = $this->getSkin(); |
| 2514 |
$skinOptions = $skin->getOptions(); |
| 2515 |
$oldText = $parserOutput->getRawText(); |
| 2516 |
$poOptions += [ |
| 2517 |
'allowClone' => false, |
| 2518 |
'skin' => $skin, |
| 2519 |
'injectTOC' => $skinOptions['toc'], |
| 2520 |
]; |
| 2521 |
$pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline(); |
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
$text = $pipeline->run( $parserOutput, $this->parserOptions(), $poOptions )->getContentHolderText(); |
| 2526 |
$parserOutput->setRawText( $oldText ); |
| 2527 |
return $text; |
| 2528 |
} |
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
public function addParserOutputContent( ParserOutput $parserOutput, $poOptions = [] ) { |
| 2539 |
$text = $this->getParserOutputText( $parserOutput, $poOptions ); |
| 2540 |
$this->addParserOutputText( $text, $poOptions ); |
| 2541 |
|
| 2542 |
$this->addModules( $parserOutput->getModules() ); |
| 2543 |
$this->addModuleStyles( $parserOutput->getModuleStyles() ); |
| 2544 |
|
| 2545 |
$this->addJsConfigVars( $parserOutput->getJsConfigVars() ); |
| 2546 |
} |
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
public function addParserOutputText( $text, $poOptions = [] ) { |
| 2556 |
if ( $text instanceof ParserOutput ) { |
| 2557 |
wfDeprecated( __METHOD__ . ' with ParserOutput as first arg', '1.42' ); |
| 2558 |
$text = $this->getParserOutputText( $text, $poOptions ); |
| 2559 |
} |
| 2560 |
$this->getHookRunner()->onOutputPageBeforeHTML( $this, $text ); |
| 2561 |
$this->addHTML( $text ); |
| 2562 |
} |
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
public function addParserOutput( ParserOutput $parserOutput, $poOptions = [] ) { |
| 2571 |
$text = $this->getParserOutputText( $parserOutput, $poOptions ); |
| 2572 |
$this->addParserOutputMetadata( $parserOutput ); |
| 2573 |
$this->addParserOutputText( $text, $poOptions ); |
| 2574 |
} |
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
public function addTemplate( &$template ) { |
| 2582 |
$this->addHTML( $template->getHTML() ); |
| 2583 |
} |
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
public function parseAsContent( $text, $linestart = true ) { |
| 2596 |
$title = $this->getTitle(); |
| 2597 |
if ( $title === null ) { |
| 2598 |
throw new RuntimeException( 'No title in ' . __METHOD__ ); |
| 2599 |
} |
| 2600 |
$po = $this->parseInternal( |
| 2601 |
$text, $title, $linestart, false |
| 2602 |
); |
| 2603 |
$pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline(); |
| 2604 |
|
| 2605 |
return $pipeline->run( $po, $this->parserOptions(), [ |
| 2606 |
'allowTOC' => false, |
| 2607 |
'enableSectionEditLinks' => false, |
| 2608 |
'wrapperDivClass' => '', |
| 2609 |
'userLang' => $this->getContext()->getLanguage(), |
| 2610 |
] )->getContentHolderText(); |
| 2611 |
} |
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
public function parseAsInterface( $text, $linestart = true ) { |
| 2625 |
$title = $this->getTitle(); |
| 2626 |
if ( $title === null ) { |
| 2627 |
throw new RuntimeException( 'No title in ' . __METHOD__ ); |
| 2628 |
} |
| 2629 |
$po = $this->parseInternal( |
| 2630 |
$text, $title, $linestart, true |
| 2631 |
); |
| 2632 |
$pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline(); |
| 2633 |
|
| 2634 |
return $pipeline->run( $po, $this->parserOptions(), [ |
| 2635 |
'allowTOC' => false, |
| 2636 |
'enableSectionEditLinks' => false, |
| 2637 |
'wrapperDivClass' => '', |
| 2638 |
'userLang' => $this->getContext()->getLanguage(), |
| 2639 |
] )->getContentHolderText(); |
| 2640 |
} |
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
public function parseInlineAsInterface( $text, $linestart = true ) { |
| 2656 |
return Parser::stripOuterParagraph( |
| 2657 |
$this->parseAsInterface( $text, $linestart ) |
| 2658 |
); |
| 2659 |
} |
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
private function parseInternal( |
| 2673 |
string $text, PageReference $title, bool $linestart, bool $interface |
| 2674 |
) { |
| 2675 |
$popts = $this->parserOptions(); |
| 2676 |
|
| 2677 |
$oldInterface = $popts->setInterfaceMessage( $interface ); |
| 2678 |
|
| 2679 |
$parserOutput = MediaWikiServices::getInstance()->getParserFactory()->getInstance() |
| 2680 |
->parse( |
| 2681 |
$text, $title, $popts, |
| 2682 |
$linestart, true, $this->mRevisionId |
| 2683 |
); |
| 2684 |
|
| 2685 |
$popts->setInterfaceMessage( $oldInterface ); |
| 2686 |
|
| 2687 |
return $parserOutput; |
| 2688 |
} |
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
public function setCdnMaxage( $maxage ) { |
| 2696 |
$this->mCdnMaxage = min( $maxage, $this->mCdnMaxageLimit ); |
| 2697 |
} |
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
public function lowerCdnMaxage( $maxage ) { |
| 2709 |
$this->mCdnMaxageLimit = min( $maxage, $this->mCdnMaxageLimit ); |
| 2710 |
$this->setCdnMaxage( $this->mCdnMaxage ); |
| 2711 |
} |
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
|
| 2725 |
public function adaptCdnTTL( $mtime, $minTTL = 0, $maxTTL = 0 ) { |
| 2726 |
$minTTL = $minTTL ?: ExpirationAwareness::TTL_MINUTE; |
| 2727 |
$maxTTL = $maxTTL ?: $this->getConfig()->get( MainConfigNames::CdnMaxAge ); |
| 2728 |
|
| 2729 |
if ( $mtime === null || $mtime === false ) { |
| 2730 |
return; |
| 2731 |
} |
| 2732 |
|
| 2733 |
$age = MWTimestamp::time() - (int)wfTimestamp( TS_UNIX, $mtime ); |
| 2734 |
$adaptiveTTL = max( 0.9 * $age, $minTTL ); |
| 2735 |
$adaptiveTTL = min( $adaptiveTTL, $maxTTL ); |
| 2736 |
|
| 2737 |
$this->lowerCdnMaxage( (int)$adaptiveTTL ); |
| 2738 |
} |
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
public function enableClientCache(): void { |
| 2744 |
$this->mEnableClientCache = true; |
| 2745 |
} |
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
public function disableClientCache(): void { |
| 2752 |
$this->mEnableClientCache = false; |
| 2753 |
} |
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
public function couldBePublicCached() { |
| 2762 |
if ( !$this->cacheIsFinal ) { |
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
return true; |
| 2770 |
} |
| 2771 |
|
| 2772 |
return $this->mEnableClientCache; |
| 2773 |
} |
| 2774 |
|
| 2775 |
|
| 2776 |
|
| 2777 |
|
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
public function considerCacheSettingsFinal() { |
| 2785 |
$this->cacheIsFinal = true; |
| 2786 |
} |
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
public function getCacheVaryCookies() { |
| 2794 |
if ( self::$cacheVaryCookies === null ) { |
| 2795 |
$config = $this->getConfig(); |
| 2796 |
self::$cacheVaryCookies = array_values( array_unique( array_merge( |
| 2797 |
SessionManager::singleton()->getVaryCookies(), |
| 2798 |
[ |
| 2799 |
'forceHTTPS', |
| 2800 |
], |
| 2801 |
$config->get( MainConfigNames::CacheVaryCookies ) |
| 2802 |
) ) ); |
| 2803 |
$this->getHookRunner()->onGetCacheVaryCookies( $this, self::$cacheVaryCookies ); |
| 2804 |
} |
| 2805 |
return self::$cacheVaryCookies; |
| 2806 |
} |
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
public function haveCacheVaryCookies() { |
| 2815 |
$request = $this->getRequest(); |
| 2816 |
foreach ( $this->getCacheVaryCookies() as $cookieName ) { |
| 2817 |
if ( $request->getCookie( $cookieName, '', '' ) !== '' ) { |
| 2818 |
wfDebug( __METHOD__ . ": found $cookieName" ); |
| 2819 |
return true; |
| 2820 |
} |
| 2821 |
} |
| 2822 |
wfDebug( __METHOD__ . ': no cache-varying cookies found' ); |
| 2823 |
return false; |
| 2824 |
} |
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
public function addVaryHeader( $header ) { |
| 2832 |
if ( !array_key_exists( $header, $this->mVaryHeader ) ) { |
| 2833 |
$this->mVaryHeader[$header] = null; |
| 2834 |
} |
| 2835 |
} |
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
public function getVaryHeader() { |
| 2844 |
|
| 2845 |
if ( $this->getCacheVaryCookies() ) { |
| 2846 |
$this->addVaryHeader( 'Cookie' ); |
| 2847 |
} |
| 2848 |
|
| 2849 |
foreach ( SessionManager::singleton()->getVaryHeaders() as $header => $_ ) { |
| 2850 |
$this->addVaryHeader( $header ); |
| 2851 |
} |
| 2852 |
return 'Vary: ' . implode( ', ', array_keys( $this->mVaryHeader ) ); |
| 2853 |
} |
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
public function addLinkHeader( $header ) { |
| 2861 |
$this->mLinkHeader[] = $header; |
| 2862 |
} |
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
|
| 2868 |
|
| 2869 |
public function getLinkHeader() { |
| 2870 |
if ( !$this->mLinkHeader ) { |
| 2871 |
return false; |
| 2872 |
} |
| 2873 |
|
| 2874 |
return 'Link: ' . implode( ',', $this->mLinkHeader ); |
| 2875 |
} |
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
private function addAcceptLanguage() { |
| 2885 |
$title = $this->getTitle(); |
| 2886 |
if ( !$title instanceof Title ) { |
| 2887 |
return; |
| 2888 |
} |
| 2889 |
|
| 2890 |
$languageConverter = MediaWikiServices::getInstance()->getLanguageConverterFactory() |
| 2891 |
->getLanguageConverter( $title->getPageLanguage() ); |
| 2892 |
if ( !$this->getRequest()->getCheck( 'variant' ) && $languageConverter->hasVariants() ) { |
| 2893 |
$this->addVaryHeader( 'Accept-Language' ); |
| 2894 |
} |
| 2895 |
} |
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
|
| 2910 |
|
| 2911 |
|
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
public function setPreventClickjacking( bool $enable ) { |
| 2917 |
$this->metadata->setPreventClickjacking( $enable ); |
| 2918 |
} |
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
|
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
public function getPreventClickjacking() { |
| 2928 |
return $this->metadata->getPreventClickjacking(); |
| 2929 |
} |
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
public function getFrameOptions() { |
| 2939 |
$config = $this->getConfig(); |
| 2940 |
if ( $config->get( MainConfigNames::BreakFrames ) ) { |
| 2941 |
return 'DENY'; |
| 2942 |
} elseif ( |
| 2943 |
$this->metadata->getPreventClickjacking() && |
| 2944 |
$config->get( MainConfigNames::EditPageFrameOptions ) |
| 2945 |
) { |
| 2946 |
return $config->get( MainConfigNames::EditPageFrameOptions ); |
| 2947 |
} |
| 2948 |
return false; |
| 2949 |
} |
| 2950 |
|
| 2951 |
private function getReportTo() { |
| 2952 |
$config = $this->getConfig(); |
| 2953 |
|
| 2954 |
$expiry = $config->get( MainConfigNames::ReportToExpiry ); |
| 2955 |
|
| 2956 |
if ( !$expiry ) { |
| 2957 |
return false; |
| 2958 |
} |
| 2959 |
|
| 2960 |
$endpoints = $config->get( MainConfigNames::ReportToEndpoints ); |
| 2961 |
|
| 2962 |
if ( !$endpoints ) { |
| 2963 |
return false; |
| 2964 |
} |
| 2965 |
|
| 2966 |
$output = [ 'max_age' => $expiry, 'endpoints' => [] ]; |
| 2967 |
|
| 2968 |
foreach ( $endpoints as $endpoint ) { |
| 2969 |
$output['endpoints'][] = [ 'url' => $endpoint ]; |
| 2970 |
} |
| 2971 |
|
| 2972 |
return json_encode( $output, JSON_UNESCAPED_SLASHES ); |
| 2973 |
} |
| 2974 |
|
| 2975 |
private function getFeaturePolicyReportOnly() { |
| 2976 |
$config = $this->getConfig(); |
| 2977 |
|
| 2978 |
$features = $config->get( MainConfigNames::FeaturePolicyReportOnly ); |
| 2979 |
return implode( ';', $features ); |
| 2980 |
} |
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
|
| 2985 |
public function sendCacheControl() { |
| 2986 |
$response = $this->getRequest()->response(); |
| 2987 |
$config = $this->getConfig(); |
| 2988 |
|
| 2989 |
$this->addVaryHeader( 'Cookie' ); |
| 2990 |
$this->addAcceptLanguage(); |
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
$response->header( $this->getVaryHeader() ); |
| 2995 |
|
| 2996 |
if ( $this->mEnableClientCache ) { |
| 2997 |
if ( !$config->get( MainConfigNames::UseCdn ) ) { |
| 2998 |
$privateReason = 'config'; |
| 2999 |
} elseif ( $response->hasCookies() ) { |
| 3000 |
$privateReason = 'set-cookies'; |
| 3001 |
|
| 3002 |
|
| 3003 |
} elseif ( SessionManager::getGlobalSession()->isPersistent() ) { |
| 3004 |
$privateReason = 'session'; |
| 3005 |
} elseif ( $this->isPrintable() ) { |
| 3006 |
$privateReason = 'printable'; |
| 3007 |
} elseif ( $this->mCdnMaxage == 0 ) { |
| 3008 |
$privateReason = 'no-maxage'; |
| 3009 |
} elseif ( $this->haveCacheVaryCookies() ) { |
| 3010 |
$privateReason = 'cache-vary-cookies'; |
| 3011 |
} else { |
| 3012 |
$privateReason = false; |
| 3013 |
} |
| 3014 |
|
| 3015 |
if ( $privateReason === false ) { |
| 3016 |
|
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
wfDebug( __METHOD__ . |
| 3021 |
": local proxy caching; {$this->mLastModified} **", 'private' ); |
| 3022 |
|
| 3023 |
|
| 3024 |
$response->header( 'Cache-Control: ' . |
| 3025 |
"s-maxage={$this->mCdnMaxage}, must-revalidate, max-age=0" ); |
| 3026 |
} else { |
| 3027 |
|
| 3028 |
|
| 3029 |
wfDebug( __METHOD__ . ": private caching ($privateReason); {$this->mLastModified} **", 'private' ); |
| 3030 |
|
| 3031 |
$response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' ); |
| 3032 |
$response->header( 'Cache-Control: private, must-revalidate, max-age=0' ); |
| 3033 |
} |
| 3034 |
if ( $this->mLastModified ) { |
| 3035 |
$response->header( "Last-Modified: {$this->mLastModified}" ); |
| 3036 |
} |
| 3037 |
} else { |
| 3038 |
wfDebug( __METHOD__ . ': no caching **', 'private' ); |
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
$response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' ); |
| 3043 |
$response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' ); |
| 3044 |
} |
| 3045 |
} |
| 3046 |
|
| 3047 |
|
| 3048 |
|
| 3049 |
|
| 3050 |
|
| 3051 |
|
| 3052 |
public function loadSkinModules( $sk ) { |
| 3053 |
foreach ( $sk->getDefaultModules() as $group => $modules ) { |
| 3054 |
if ( $group === 'styles' ) { |
| 3055 |
foreach ( $modules as $moduleMembers ) { |
| 3056 |
$this->addModuleStyles( $moduleMembers ); |
| 3057 |
} |
| 3058 |
} else { |
| 3059 |
$this->addModules( $modules ); |
| 3060 |
} |
| 3061 |
} |
| 3062 |
} |
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
|
| 3071 |
public function output( $return = false ) { |
| 3072 |
if ( $this->mDoNothing ) { |
| 3073 |
return $return ? '' : null; |
| 3074 |
} |
| 3075 |
|
| 3076 |
$request = $this->getRequest(); |
| 3077 |
$response = $request->response(); |
| 3078 |
$config = $this->getConfig(); |
| 3079 |
|
| 3080 |
if ( $this->mRedirect != '' ) { |
| 3081 |
$services = MediaWikiServices::getInstance(); |
| 3082 |
|
| 3083 |
|
| 3084 |
$this->mRedirect = (string)$services->getUrlUtils()->expand( $this->mRedirect, PROTO_CURRENT ); |
| 3085 |
|
| 3086 |
$redirect = $this->mRedirect; |
| 3087 |
$code = $this->mRedirectCode; |
| 3088 |
$content = ''; |
| 3089 |
|
| 3090 |
if ( $this->getHookRunner()->onBeforePageRedirect( $this, $redirect, $code ) ) { |
| 3091 |
if ( $code == '301' || $code == '303' ) { |
| 3092 |
if ( !$config->get( MainConfigNames::DebugRedirects ) ) { |
| 3093 |
$response->statusHeader( (int)$code ); |
| 3094 |
} |
| 3095 |
$this->mLastModified = wfTimestamp( TS_RFC2822 ); |
| 3096 |
} |
| 3097 |
if ( $config->get( MainConfigNames::VaryOnXFP ) ) { |
| 3098 |
$this->addVaryHeader( 'X-Forwarded-Proto' ); |
| 3099 |
} |
| 3100 |
$this->sendCacheControl(); |
| 3101 |
|
| 3102 |
$response->header( 'Content-Type: text/html; charset=UTF-8' ); |
| 3103 |
if ( $config->get( MainConfigNames::DebugRedirects ) ) { |
| 3104 |
$url = htmlspecialchars( $redirect ); |
| 3105 |
$content = "<!DOCTYPE html>\n<html>\n<head>\n" |
| 3106 |
. "<title>Redirect</title>\n</head>\n<body>\n" |
| 3107 |
. "<p>Location: <a href=\"$url\">$url</a></p>\n" |
| 3108 |
. "</body>\n</html>\n"; |
| 3109 |
|
| 3110 |
if ( !$return ) { |
| 3111 |
print $content; |
| 3112 |
} |
| 3113 |
|
| 3114 |
} else { |
| 3115 |
$response->header( 'Location: ' . $redirect ); |
| 3116 |
} |
| 3117 |
} |
| 3118 |
|
| 3119 |
return $return ? $content : null; |
| 3120 |
} elseif ( $this->mStatusCode ) { |
| 3121 |
$response->statusHeader( $this->mStatusCode ); |
| 3122 |
} |
| 3123 |
|
| 3124 |
|
| 3125 |
ob_start(); |
| 3126 |
|
| 3127 |
$response->header( 'Content-language: ' . |
| 3128 |
MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() ); |
| 3129 |
|
| 3130 |
$linkHeader = $this->getLinkHeader(); |
| 3131 |
if ( $linkHeader ) { |
| 3132 |
$response->header( $linkHeader ); |
| 3133 |
} |
| 3134 |
|
| 3135 |
|
| 3136 |
$frameOptions = $this->getFrameOptions(); |
| 3137 |
if ( $frameOptions ) { |
| 3138 |
$response->header( "X-Frame-Options: $frameOptions" ); |
| 3139 |
} |
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
$originTrials = $config->get( MainConfigNames::OriginTrials ); |
| 3144 |
foreach ( $originTrials as $originTrial ) { |
| 3145 |
$response->header( "Origin-Trial: $originTrial", false ); |
| 3146 |
} |
| 3147 |
|
| 3148 |
$reportTo = $this->getReportTo(); |
| 3149 |
if ( $reportTo ) { |
| 3150 |
$response->header( "Report-To: $reportTo" ); |
| 3151 |
} |
| 3152 |
|
| 3153 |
$featurePolicyReportOnly = $this->getFeaturePolicyReportOnly(); |
| 3154 |
if ( $featurePolicyReportOnly ) { |
| 3155 |
$response->header( "Feature-Policy-Report-Only: $featurePolicyReportOnly" ); |
| 3156 |
} |
| 3157 |
|
| 3158 |
if ( $this->mArticleBodyOnly ) { |
| 3159 |
$response->header( 'Content-type: ' . $config->get( MainConfigNames::MimeType ) . '; charset=UTF-8' ); |
| 3160 |
if ( $this->cspOutputMode === self::CSP_HEADERS ) { |
| 3161 |
$this->CSP->sendHeaders(); |
| 3162 |
} |
| 3163 |
echo $this->mBodytext; |
| 3164 |
} else { |
| 3165 |
|
| 3166 |
if ( $this->getRequest()->getBool( 'safemode' ) ) { |
| 3167 |
$this->disallowUserJs(); |
| 3168 |
} |
| 3169 |
|
| 3170 |
$sk = $this->getSkin(); |
| 3171 |
$skinOptions = $sk->getOptions(); |
| 3172 |
|
| 3173 |
if ( $skinOptions['format'] === 'json' ) { |
| 3174 |
$response->header( 'Content-type: application/json; charset=UTF-8' ); |
| 3175 |
return json_encode( [ |
| 3176 |
$this->msg( 'skin-json-warning' )->escaped() => $this->msg( 'skin-json-warning-message' )->escaped() |
| 3177 |
] + $sk->getTemplateData() ); |
| 3178 |
} |
| 3179 |
$response->header( 'Content-type: ' . $config->get( MainConfigNames::MimeType ) . '; charset=UTF-8' ); |
| 3180 |
$this->loadSkinModules( $sk ); |
| 3181 |
|
| 3182 |
MWDebug::addModules( $this ); |
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
$this->getHookRunner()->onBeforePageDisplay( $this, $sk ); |
| 3187 |
|
| 3188 |
if ( $this->cspOutputMode === self::CSP_HEADERS ) { |
| 3189 |
$this->CSP->sendHeaders(); |
| 3190 |
} |
| 3191 |
|
| 3192 |
try { |
| 3193 |
$sk->outputPageFinal( $this ); |
| 3194 |
} catch ( Exception $e ) { |
| 3195 |
ob_end_clean(); |
| 3196 |
throw $e; |
| 3197 |
} |
| 3198 |
} |
| 3199 |
|
| 3200 |
try { |
| 3201 |
|
| 3202 |
$this->getHookRunner()->onAfterFinalPageOutput( $this ); |
| 3203 |
} catch ( Exception $e ) { |
| 3204 |
ob_end_clean(); |
| 3205 |
throw $e; |
| 3206 |
} |
| 3207 |
|
| 3208 |
$this->sendCacheControl(); |
| 3209 |
|
| 3210 |
if ( $return ) { |
| 3211 |
return ob_get_clean(); |
| 3212 |
} else { |
| 3213 |
ob_end_flush(); |
| 3214 |
return null; |
| 3215 |
} |
| 3216 |
} |
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
|
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
public function prepareErrorPage( $pageTitle = null, $htmlTitle = false ) { |
| 3231 |
if ( $pageTitle !== null || $htmlTitle !== false ) { |
| 3232 |
wfDeprecated( __METHOD__ . ' with explicit arguments', '1.41' ); |
| 3233 |
if ( $pageTitle !== null ) { |
| 3234 |
$this->setPageTitle( $pageTitle ); |
| 3235 |
} |
| 3236 |
if ( $htmlTitle !== false ) { |
| 3237 |
$this->setHTMLTitle( $htmlTitle ); |
| 3238 |
} |
| 3239 |
} |
| 3240 |
$this->setRobotPolicy( 'noindex,nofollow' ); |
| 3241 |
$this->setArticleRelated( false ); |
| 3242 |
$this->disableClientCache(); |
| 3243 |
$this->mRedirect = ''; |
| 3244 |
$this->clearSubtitle(); |
| 3245 |
$this->clearHTML(); |
| 3246 |
} |
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
|
| 3255 |
|
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
|
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
public function showErrorPage( |
| 3265 |
$title, $msg, $params = [], $returnto = null, $returntoquery = null |
| 3266 |
) { |
| 3267 |
if ( !$title instanceof Message ) { |
| 3268 |
$title = $this->msg( $title ); |
| 3269 |
} |
| 3270 |
|
| 3271 |
$this->prepareErrorPage(); |
| 3272 |
$this->setPageTitleMsg( $title ); |
| 3273 |
|
| 3274 |
if ( $msg instanceof Message ) { |
| 3275 |
if ( $params !== [] ) { |
| 3276 |
trigger_error( 'Argument ignored: $params. The message parameters argument ' |
| 3277 |
. 'is discarded when the $msg argument is a Message object instead of ' |
| 3278 |
. 'a string.', E_USER_NOTICE ); |
| 3279 |
} |
| 3280 |
$this->addHTML( $msg->parseAsBlock() ); |
| 3281 |
} else { |
| 3282 |
$this->addWikiMsgArray( $msg, $params ); |
| 3283 |
} |
| 3284 |
|
| 3285 |
$this->returnToMain( null, $returnto, $returntoquery ); |
| 3286 |
} |
| 3287 |
|
| 3288 |
|
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
public function showPermissionStatus( PermissionStatus $status, $action = null ) { |
| 3295 |
Assert::precondition( !$status->isGood(), 'Status must have errors' ); |
| 3296 |
|
| 3297 |
$this->showPermissionInternal( |
| 3298 |
array_map( fn ( $msg ) => $this->msg( $msg ), $status->getMessages() ), |
| 3299 |
$action |
| 3300 |
); |
| 3301 |
} |
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
public function showPermissionsErrorPage( array $errors, $action = null ) { |
| 3311 |
wfDeprecated( __METHOD__, '1.43' ); |
| 3312 |
foreach ( $errors as $key => $error ) { |
| 3313 |
$errors[$key] = (array)$error; |
| 3314 |
} |
| 3315 |
|
| 3316 |
$this->showPermissionInternal( |
| 3317 |
|
| 3318 |
array_map( fn ( $err ) => $this->msg( ...$err ), $errors ), |
| 3319 |
$action |
| 3320 |
); |
| 3321 |
} |
| 3322 |
|
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
public function showPermissionInternal( array $messages, $action = null ) { |
| 3331 |
$services = MediaWikiServices::getInstance(); |
| 3332 |
$groupPermissionsLookup = $services->getGroupPermissionsLookup(); |
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
if ( in_array( $action, [ 'read', 'edit', 'createpage', 'createtalk', 'upload' ] ) |
| 3341 |
&& !$this->getUser()->isNamed() && count( $messages ) == 1 |
| 3342 |
&& ( $messages[0]->getKey() == 'badaccess-groups' || $messages[0]->getKey() == 'badaccess-group0' ) |
| 3343 |
&& ( $groupPermissionsLookup->groupHasPermission( 'user', $action ) |
| 3344 |
|| $groupPermissionsLookup->groupHasPermission( 'autoconfirmed', $action ) ) |
| 3345 |
) { |
| 3346 |
$displayReturnto = null; |
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
$request = $this->getRequest(); |
| 3353 |
$returnto = Title::newFromText( $request->getText( 'title' ) ); |
| 3354 |
if ( $action == 'edit' ) { |
| 3355 |
$msg = 'whitelistedittext'; |
| 3356 |
$displayReturnto = $returnto; |
| 3357 |
} elseif ( $action == 'createpage' || $action == 'createtalk' ) { |
| 3358 |
$msg = 'nocreatetext'; |
| 3359 |
} elseif ( $action == 'upload' ) { |
| 3360 |
$msg = 'uploadnologintext'; |
| 3361 |
} else { |
| 3362 |
$msg = 'loginreqpagetext'; |
| 3363 |
$displayReturnto = Title::newMainPage(); |
| 3364 |
} |
| 3365 |
|
| 3366 |
$query = []; |
| 3367 |
|
| 3368 |
if ( $returnto ) { |
| 3369 |
$query['returnto'] = $returnto->getPrefixedText(); |
| 3370 |
|
| 3371 |
if ( !$request->wasPosted() ) { |
| 3372 |
$returntoquery = $request->getValues(); |
| 3373 |
unset( $returntoquery['title'] ); |
| 3374 |
unset( $returntoquery['returnto'] ); |
| 3375 |
unset( $returntoquery['returntoquery'] ); |
| 3376 |
$query['returntoquery'] = wfArrayToCgi( $returntoquery ); |
| 3377 |
} |
| 3378 |
} |
| 3379 |
|
| 3380 |
$title = SpecialPage::getTitleFor( 'Userlogin' ); |
| 3381 |
$linkRenderer = $services->getLinkRenderer(); |
| 3382 |
$loginUrl = $title->getLinkURL( $query, false, PROTO_RELATIVE ); |
| 3383 |
$loginLink = $linkRenderer->makeKnownLink( |
| 3384 |
$title, |
| 3385 |
$this->msg( 'loginreqlink' )->text(), |
| 3386 |
[], |
| 3387 |
$query |
| 3388 |
); |
| 3389 |
|
| 3390 |
$this->prepareErrorPage(); |
| 3391 |
$this->setPageTitleMsg( $this->msg( 'loginreqtitle' ) ); |
| 3392 |
$this->addHTML( $this->msg( $msg )->rawParams( $loginLink )->params( $loginUrl )->parse() ); |
| 3393 |
|
| 3394 |
|
| 3395 |
|
| 3396 |
if ( $displayReturnto && $this->getAuthority()->probablyCan( 'read', $displayReturnto ) ) { |
| 3397 |
$this->returnToMain( null, $displayReturnto ); |
| 3398 |
} |
| 3399 |
} else { |
| 3400 |
$this->prepareErrorPage(); |
| 3401 |
$this->setPageTitleMsg( $this->msg( 'permissionserrors' ) ); |
| 3402 |
$this->addWikiTextAsInterface( $this->formatPermissionInternal( $messages, $action ) ); |
| 3403 |
} |
| 3404 |
} |
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
public function versionRequired( $version ) { |
| 3413 |
$this->prepareErrorPage(); |
| 3414 |
$this->setPageTitleMsg( |
| 3415 |
$this->msg( 'versionrequired' )->plaintextParams( $version ) |
| 3416 |
); |
| 3417 |
|
| 3418 |
$this->addWikiMsg( 'versionrequiredtext', $version ); |
| 3419 |
$this->returnToMain(); |
| 3420 |
} |
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
|
| 3431 |
public function formatPermissionStatus( PermissionStatus $status, ?string $action = null ): string { |
| 3432 |
if ( $status->isGood() ) { |
| 3433 |
return ''; |
| 3434 |
} |
| 3435 |
return $this->formatPermissionInternal( |
| 3436 |
array_map( fn ( $msg ) => $this->msg( $msg ), $status->getMessages() ), |
| 3437 |
$action |
| 3438 |
); |
| 3439 |
} |
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
|
| 3450 |
|
| 3451 |
|
| 3452 |
public function formatPermissionsErrorMessage( array $errors, $action = null ) { |
| 3453 |
wfDeprecated( __METHOD__, '1.36' ); |
| 3454 |
return $this->formatPermissionInternal( |
| 3455 |
|
| 3456 |
array_map( fn ( $err ) => $this->msg( ...$err ), $errors ), |
| 3457 |
$action |
| 3458 |
); |
| 3459 |
} |
| 3460 |
|
| 3461 |
|
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
|
| 3466 |
|
| 3467 |
|
| 3468 |
|
| 3469 |
|
| 3470 |
|
| 3471 |
|
| 3472 |
|
| 3473 |
private function formatPermissionInternal( array $messages, $action = null ) { |
| 3474 |
if ( $action == null ) { |
| 3475 |
$text = $this->msg( 'permissionserrorstext', count( $messages ) )->plain() . "\n\n"; |
| 3476 |
} else { |
| 3477 |
$action_desc = $this->msg( "action-$action" )->plain(); |
| 3478 |
$text = $this->msg( |
| 3479 |
'permissionserrorstext-withaction', |
| 3480 |
count( $messages ), |
| 3481 |
$action_desc |
| 3482 |
)->plain() . "\n\n"; |
| 3483 |
} |
| 3484 |
|
| 3485 |
if ( count( $messages ) > 1 ) { |
| 3486 |
$text .= Html::openElement( 'ul', [ 'class' => 'permissions-errors' ] ); |
| 3487 |
foreach ( $messages as $message ) { |
| 3488 |
$text .= Html::rawElement( |
| 3489 |
'li', |
| 3490 |
[ 'class' => 'mw-permissionerror-' . $message->getKey() ], |
| 3491 |
$message->plain() |
| 3492 |
); |
| 3493 |
} |
| 3494 |
$text .= Html::closeElement( 'ul' ); |
| 3495 |
} else { |
| 3496 |
$text .= Html::openElement( 'div', [ 'class' => 'permissions-errors' ] ); |
| 3497 |
$text .= Html::rawElement( |
| 3498 |
'div', |
| 3499 |
[ 'class' => 'mw-permissionerror-' . $messages[ 0 ]->getKey() ], |
| 3500 |
$messages[ 0 ]->plain() |
| 3501 |
); |
| 3502 |
$text .= Html::closeElement( 'div' ); |
| 3503 |
} |
| 3504 |
|
| 3505 |
return $text; |
| 3506 |
} |
| 3507 |
|
| 3508 |
|
| 3509 |
|
| 3510 |
|
| 3511 |
|
| 3512 |
|
| 3513 |
|
| 3514 |
|
| 3515 |
|
| 3516 |
|
| 3517 |
public function showLagWarning( $lag ) { |
| 3518 |
$config = $this->getConfig(); |
| 3519 |
if ( $lag >= $config->get( MainConfigNames::DatabaseReplicaLagWarning ) ) { |
| 3520 |
$lag = floor( $lag ); |
| 3521 |
$message = $lag < $config->get( MainConfigNames::DatabaseReplicaLagCritical ) |
| 3522 |
? 'lag-warn-normal' |
| 3523 |
: 'lag-warn-high'; |
| 3524 |
|
| 3525 |
$wrap = Html::rawElement( 'div', [ 'class' => "mw-{$message}" ], "\n$1\n" ); |
| 3526 |
$this->wrapWikiMsg( "$wrap\n", [ $message, $this->getLanguage()->formatNum( $lag ) ] ); |
| 3527 |
} |
| 3528 |
} |
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
|
| 3535 |
|
| 3536 |
public function showFatalError( $message ) { |
| 3537 |
wfDeprecated( __METHOD__, '1.43' ); |
| 3538 |
|
| 3539 |
$this->prepareErrorPage(); |
| 3540 |
$this->setPageTitleMsg( $this->msg( 'internalerror' ) ); |
| 3541 |
|
| 3542 |
$this->addHTML( $message ); |
| 3543 |
} |
| 3544 |
|
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
|
| 3550 |
|
| 3551 |
|
| 3552 |
|
| 3553 |
public function addReturnTo( $title, array $query = [], $text = null, $options = [] ) { |
| 3554 |
$linkRenderer = MediaWikiServices::getInstance() |
| 3555 |
->getLinkRendererFactory()->createFromLegacyOptions( $options ); |
| 3556 |
$link = $this->msg( 'returnto' )->rawParams( |
| 3557 |
$linkRenderer->makeLink( $title, $text, [], $query ) )->escaped(); |
| 3558 |
$this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" ); |
| 3559 |
} |
| 3560 |
|
| 3561 |
|
| 3562 |
|
| 3563 |
|
| 3564 |
|
| 3565 |
|
| 3566 |
|
| 3567 |
|
| 3568 |
|
| 3569 |
public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) { |
| 3570 |
$returnto ??= $this->getRequest()->getText( 'returnto' ); |
| 3571 |
|
| 3572 |
$returntoquery ??= $this->getRequest()->getText( 'returntoquery' ); |
| 3573 |
|
| 3574 |
if ( $returnto === '' ) { |
| 3575 |
$returnto = Title::newMainPage(); |
| 3576 |
} |
| 3577 |
|
| 3578 |
if ( is_object( $returnto ) ) { |
| 3579 |
$linkTarget = TitleValue::castPageToLinkTarget( $returnto ); |
| 3580 |
} else { |
| 3581 |
$linkTarget = Title::newFromText( $returnto ); |
| 3582 |
} |
| 3583 |
|
| 3584 |
|
| 3585 |
|
| 3586 |
if ( !is_object( $linkTarget ) || $linkTarget->isExternal() ) { |
| 3587 |
$linkTarget = Title::newMainPage(); |
| 3588 |
} |
| 3589 |
|
| 3590 |
$this->addReturnTo( $linkTarget, wfCgiToArray( $returntoquery ) ); |
| 3591 |
} |
| 3592 |
|
| 3593 |
|
| 3594 |
|
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
|
| 3599 |
|
| 3600 |
|
| 3601 |
|
| 3602 |
|
| 3603 |
|
| 3604 |
|
| 3605 |
|
| 3606 |
|
| 3607 |
|
| 3608 |
|
| 3609 |
public function showPendingTakeover( |
| 3610 |
$fallbackUrl, $msg, ...$params |
| 3611 |
) { |
| 3612 |
if ( $msg instanceof Message ) { |
| 3613 |
if ( $params !== [] ) { |
| 3614 |
trigger_error( 'Argument ignored: $params. The message parameters argument ' |
| 3615 |
. 'is discarded when the $msg argument is a Message object instead of ' |
| 3616 |
. 'a string.', E_USER_NOTICE ); |
| 3617 |
} |
| 3618 |
$this->addHTML( $msg->parseAsBlock() ); |
| 3619 |
} else { |
| 3620 |
$this->addHTML( $this->msg( $msg, ...$params )->parseAsBlock() ); |
| 3621 |
} |
| 3622 |
|
| 3623 |
|
| 3624 |
$escapedUrl = htmlspecialchars( $fallbackUrl ); |
| 3625 |
$this->addHeadItem( |
| 3626 |
'mw-noscript-fallback', |
| 3627 |
|
| 3628 |
|
| 3629 |
|
| 3630 |
"<noscript><meta http-equiv=\"refresh\" content=\"0; url=$escapedUrl\"></noscript>" |
| 3631 |
); |
| 3632 |
|
| 3633 |
$this->addScript( Html::inlineScript( |
| 3634 |
'(window.NORLQ=window.NORLQ||[]).push(' . |
| 3635 |
'function(){' . |
| 3636 |
'location.href=' . json_encode( $fallbackUrl ) . ';' . |
| 3637 |
'}' . |
| 3638 |
');' |
| 3639 |
) ); |
| 3640 |
} |
| 3641 |
|
| 3642 |
private function getRlClientContext() { |
| 3643 |
if ( !$this->rlClientContext ) { |
| 3644 |
$query = ResourceLoader::makeLoaderQuery( |
| 3645 |
[], |
| 3646 |
$this->getLanguage()->getCode(), |
| 3647 |
$this->getSkin()->getSkinName(), |
| 3648 |
$this->getUser()->isRegistered() ? $this->getUser()->getName() : null, |
| 3649 |
null, |
| 3650 |
ResourceLoader::inDebugMode(), |
| 3651 |
null, |
| 3652 |
$this->isPrintable() |
| 3653 |
); |
| 3654 |
$this->rlClientContext = new RL\Context( |
| 3655 |
$this->getResourceLoader(), |
| 3656 |
new FauxRequest( $query ) |
| 3657 |
); |
| 3658 |
if ( $this->contentOverrideCallbacks ) { |
| 3659 |
$this->rlClientContext = new RL\DerivativeContext( $this->rlClientContext ); |
| 3660 |
$this->rlClientContext->setContentOverrideCallback( function ( $page ) { |
| 3661 |
foreach ( $this->contentOverrideCallbacks as $callback ) { |
| 3662 |
$content = $callback( $page ); |
| 3663 |
if ( $content !== null ) { |
| 3664 |
$text = ( $content instanceof TextContent ) ? $content->getText() : ''; |
| 3665 |
if ( preg_match( '/<\/?script/i', $text ) ) { |
| 3666 |
|
| 3667 |
|
| 3668 |
|
| 3669 |
$content = new JavaScriptContent( |
| 3670 |
Html::encodeJsCall( 'mw.log.error', [ |
| 3671 |
"Cannot preview $page due to suspecting script tag inside (T200506)." |
| 3672 |
] ) |
| 3673 |
); |
| 3674 |
} |
| 3675 |
return $content; |
| 3676 |
} |
| 3677 |
} |
| 3678 |
return null; |
| 3679 |
} ); |
| 3680 |
} |
| 3681 |
} |
| 3682 |
return $this->rlClientContext; |
| 3683 |
} |
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
|
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
|
| 3695 |
|
| 3696 |
public function getRlClient() { |
| 3697 |
if ( !$this->rlClient ) { |
| 3698 |
$context = $this->getRlClientContext(); |
| 3699 |
$rl = $this->getResourceLoader(); |
| 3700 |
$this->addModules( [ |
| 3701 |
'user', |
| 3702 |
'user.options', |
| 3703 |
] ); |
| 3704 |
$this->addModuleStyles( [ |
| 3705 |
'site.styles', |
| 3706 |
'noscript', |
| 3707 |
'user.styles', |
| 3708 |
] ); |
| 3709 |
|
| 3710 |
|
| 3711 |
$exemptGroups = [ |
| 3712 |
RL\Module::GROUP_SITE => [], |
| 3713 |
RL\Module::GROUP_NOSCRIPT => [], |
| 3714 |
RL\Module::GROUP_PRIVATE => [], |
| 3715 |
RL\Module::GROUP_USER => [] |
| 3716 |
]; |
| 3717 |
$exemptStates = []; |
| 3718 |
$moduleStyles = $this->getModuleStyles( true ); |
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
$userBatch = [ 'user.styles', 'user' ]; |
| 3723 |
$siteBatch = array_diff( $moduleStyles, $userBatch ); |
| 3724 |
RL\WikiModule::preloadTitleInfo( $context, $siteBatch ); |
| 3725 |
RL\WikiModule::preloadTitleInfo( $context, $userBatch ); |
| 3726 |
|
| 3727 |
|
| 3728 |
$moduleStyles = array_filter( $moduleStyles, |
| 3729 |
static function ( $name ) use ( $rl, $context, &$exemptGroups, &$exemptStates ) { |
| 3730 |
$module = $rl->getModule( $name ); |
| 3731 |
if ( $module ) { |
| 3732 |
$group = $module->getGroup(); |
| 3733 |
if ( $group !== null && isset( $exemptGroups[$group] ) ) { |
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
if ( $group !== RL\Module::GROUP_NOSCRIPT ) { |
| 3738 |
$exemptStates[$name] = 'ready'; |
| 3739 |
} |
| 3740 |
if ( !$module->isKnownEmpty( $context ) ) { |
| 3741 |
|
| 3742 |
$exemptGroups[$group][] = $name; |
| 3743 |
} |
| 3744 |
return false; |
| 3745 |
} |
| 3746 |
} |
| 3747 |
return true; |
| 3748 |
} |
| 3749 |
); |
| 3750 |
$this->rlExemptStyleModules = $exemptGroups; |
| 3751 |
|
| 3752 |
$config = $this->getConfig(); |
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
$clientPrefEnabled = ( |
| 3757 |
$this->getSkin()->getOptions()['clientPrefEnabled'] && |
| 3758 |
!$this->getUser()->isNamed() |
| 3759 |
); |
| 3760 |
$clientPrefCookiePrefix = $config->get( MainConfigNames::CookiePrefix ); |
| 3761 |
|
| 3762 |
$rlClient = new RL\ClientHtml( $context, [ |
| 3763 |
'target' => $this->getTarget(), |
| 3764 |
|
| 3765 |
|
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
'safemode' => ( $this->getAllowedModules( RL\Module::TYPE_COMBINED ) |
| 3772 |
<= RL\Module::ORIGIN_CORE_INDIVIDUAL |
| 3773 |
) ? '1' : null, |
| 3774 |
'clientPrefEnabled' => $clientPrefEnabled, |
| 3775 |
'clientPrefCookiePrefix' => $clientPrefCookiePrefix, |
| 3776 |
] ); |
| 3777 |
$rlClient->setConfig( $this->getJSVars( self::JS_VAR_EARLY ) ); |
| 3778 |
$rlClient->setModules( $this->getModules( true ) ); |
| 3779 |
$rlClient->setModuleStyles( $moduleStyles ); |
| 3780 |
$rlClient->setExemptStates( $exemptStates ); |
| 3781 |
$this->rlClient = $rlClient; |
| 3782 |
} |
| 3783 |
return $this->rlClient; |
| 3784 |
} |
| 3785 |
|
| 3786 |
|
| 3787 |
|
| 3788 |
|
| 3789 |
|
| 3790 |
|
| 3791 |
public function headElement( Skin $sk, $includeStyle = true ) { |
| 3792 |
$config = $this->getConfig(); |
| 3793 |
$userdir = $this->getLanguage()->getDir(); |
| 3794 |
$services = MediaWikiServices::getInstance(); |
| 3795 |
$sitedir = $services->getContentLanguage()->getDir(); |
| 3796 |
|
| 3797 |
$pieces = []; |
| 3798 |
$htmlAttribs = Sanitizer::mergeAttributes( Sanitizer::mergeAttributes( |
| 3799 |
$this->getRlClient()->getDocumentAttributes(), |
| 3800 |
$sk->getHtmlElementAttributes() |
| 3801 |
), [ 'class' => implode( ' ', $this->mAdditionalHtmlClasses ) ] ); |
| 3802 |
$pieces[] = Html::htmlHeader( $htmlAttribs ); |
| 3803 |
$pieces[] = Html::openElement( 'head' ); |
| 3804 |
|
| 3805 |
if ( $this->getHTMLTitle() == '' ) { |
| 3806 |
$this->setHTMLTitle( $this->msg( 'pagetitle', $this->getPageTitle() )->inContentLanguage() ); |
| 3807 |
} |
| 3808 |
|
| 3809 |
if ( !Html::isXmlMimeType( $config->get( MainConfigNames::MimeType ) ) ) { |
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
|
| 3816 |
|
| 3817 |
|
| 3818 |
$pieces[] = Html::element( 'meta', [ 'charset' => 'UTF-8' ] ); |
| 3819 |
} |
| 3820 |
|
| 3821 |
$pieces[] = Html::element( 'title', [], $this->getHTMLTitle() ); |
| 3822 |
$pieces[] = $this->getRlClient()->getHeadHtml( $htmlAttribs['class'] ?? null ); |
| 3823 |
$pieces[] = $this->buildExemptModules(); |
| 3824 |
$pieces = array_merge( $pieces, array_values( $this->getHeadLinksArray() ) ); |
| 3825 |
$pieces = array_merge( $pieces, array_values( $this->mHeadItems ) ); |
| 3826 |
|
| 3827 |
$pieces[] = Html::closeElement( 'head' ); |
| 3828 |
|
| 3829 |
$skinOptions = $sk->getOptions(); |
| 3830 |
$bodyClasses = array_merge( $this->mAdditionalBodyClasses, $skinOptions['bodyClasses'] ); |
| 3831 |
$bodyClasses[] = 'mediawiki'; |
| 3832 |
|
| 3833 |
|
| 3834 |
$bodyClasses[] = $userdir; |
| 3835 |
$bodyClasses[] = "sitedir-$sitedir"; |
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
$underline = $services->getUserOptionsLookup()->getOption( $this->getUser(), 'underline' ); |
| 3840 |
if ( $underline < 2 ) { |
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
$bodyClasses[] = 'mw-underline-' . ( $underline ? 'always' : 'never' ); |
| 3845 |
} |
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
$bodyClasses[] = 'mw-hide-empty-elt'; |
| 3851 |
|
| 3852 |
$bodyClasses[] = $sk->getPageClasses( $this->getTitle() ); |
| 3853 |
$bodyClasses[] = 'skin-' . Sanitizer::escapeClass( $sk->getSkinName() ); |
| 3854 |
$bodyClasses[] = |
| 3855 |
'action-' . Sanitizer::escapeClass( $this->getContext()->getActionName() ); |
| 3856 |
|
| 3857 |
if ( $sk->isResponsive() ) { |
| 3858 |
$bodyClasses[] = 'skin--responsive'; |
| 3859 |
} |
| 3860 |
|
| 3861 |
$bodyAttrs = []; |
| 3862 |
|
| 3863 |
|
| 3864 |
$bodyAttrs['class'] = implode( ' ', $bodyClasses ); |
| 3865 |
|
| 3866 |
$this->getHookRunner()->onOutputPageBodyAttributes( $this, $sk, $bodyAttrs ); |
| 3867 |
|
| 3868 |
$pieces[] = Html::openElement( 'body', $bodyAttrs ); |
| 3869 |
|
| 3870 |
return self::combineWrappedStrings( $pieces ); |
| 3871 |
} |
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
|
| 3876 |
|
| 3877 |
|
| 3878 |
public function getResourceLoader() { |
| 3879 |
if ( $this->mResourceLoader === null ) { |
| 3880 |
|
| 3881 |
$this->mResourceLoader = MediaWikiServices::getInstance()->getResourceLoader(); |
| 3882 |
} |
| 3883 |
return $this->mResourceLoader; |
| 3884 |
} |
| 3885 |
|
| 3886 |
|
| 3887 |
|
| 3888 |
|
| 3889 |
|
| 3890 |
|
| 3891 |
|
| 3892 |
|
| 3893 |
|
| 3894 |
public function makeResourceLoaderLink( $modules, $only, array $extraQuery = [] ) { |
| 3895 |
|
| 3896 |
$modules = $this->filterModules( (array)$modules, null, $only ); |
| 3897 |
|
| 3898 |
return RL\ClientHtml::makeLoad( |
| 3899 |
$this->getRlClientContext(), |
| 3900 |
$modules, |
| 3901 |
$only, |
| 3902 |
$extraQuery |
| 3903 |
); |
| 3904 |
} |
| 3905 |
|
| 3906 |
|
| 3907 |
|
| 3908 |
|
| 3909 |
|
| 3910 |
|
| 3911 |
|
| 3912 |
protected static function combineWrappedStrings( array $chunks ) { |
| 3913 |
|
| 3914 |
$chunks = array_filter( $chunks, 'strlen' ); |
| 3915 |
return WrappedString::join( "\n", $chunks ); |
| 3916 |
} |
| 3917 |
|
| 3918 |
|
| 3919 |
|
| 3920 |
|
| 3921 |
|
| 3922 |
|
| 3923 |
|
| 3924 |
public function getBottomScripts() { |
| 3925 |
|
| 3926 |
|
| 3927 |
$extraHtml = ''; |
| 3928 |
$this->getHookRunner()->onSkinAfterBottomScripts( $this->getSkin(), $extraHtml ); |
| 3929 |
|
| 3930 |
$chunks = []; |
| 3931 |
$chunks[] = $this->getRlClient()->getBodyHtml(); |
| 3932 |
|
| 3933 |
|
| 3934 |
$chunks[] = $this->mScripts; |
| 3935 |
|
| 3936 |
|
| 3937 |
|
| 3938 |
$vars = []; |
| 3939 |
if ( $this->getConfig()->get( MainConfigNames::ShowHostnames ) ) { |
| 3940 |
$vars['wgHostname'] = wfHostname(); |
| 3941 |
} |
| 3942 |
$elapsed = $this->getRequest()->getElapsedTime(); |
| 3943 |
|
| 3944 |
$vars['wgBackendResponseTime'] = round( $elapsed * 1000 ); |
| 3945 |
|
| 3946 |
$vars += $this->getJSVars( self::JS_VAR_LATE ); |
| 3947 |
if ( $this->limitReportJSData ) { |
| 3948 |
$vars['wgPageParseReport'] = $this->limitReportJSData; |
| 3949 |
} |
| 3950 |
|
| 3951 |
$rlContext = $this->getRlClientContext(); |
| 3952 |
$chunks[] = ResourceLoader::makeInlineScript( |
| 3953 |
'mw.config.set(' . $rlContext->encodeJson( $vars ) . ');' |
| 3954 |
); |
| 3955 |
|
| 3956 |
$chunks = [ self::combineWrappedStrings( $chunks ) ]; |
| 3957 |
if ( $extraHtml !== '' ) { |
| 3958 |
$chunks[] = $extraHtml; |
| 3959 |
} |
| 3960 |
|
| 3961 |
return WrappedString::join( "\n", $chunks ); |
| 3962 |
} |
| 3963 |
|
| 3964 |
|
| 3965 |
|
| 3966 |
|
| 3967 |
|
| 3968 |
|
| 3969 |
|
| 3970 |
public function getJsConfigVars() { |
| 3971 |
return $this->mJsConfigVars; |
| 3972 |
} |
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
|
| 3977 |
|
| 3978 |
|
| 3979 |
|
| 3980 |
public function addJsConfigVars( $keys, $value = null ) { |
| 3981 |
if ( is_array( $keys ) ) { |
| 3982 |
foreach ( $keys as $key => $value ) { |
| 3983 |
$this->mJsConfigVars[$key] = $value; |
| 3984 |
} |
| 3985 |
return; |
| 3986 |
} |
| 3987 |
|
| 3988 |
$this->mJsConfigVars[$keys] = $value; |
| 3989 |
} |
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
|
| 3996 |
|
| 3997 |
|
| 3998 |
|
| 3999 |
|
| 4000 |
|
| 4001 |
|
| 4002 |
|
| 4003 |
|
| 4004 |
|
| 4005 |
|
| 4006 |
|
| 4007 |
|
| 4008 |
|
| 4009 |
public function getJSVars( ?int $flag = null ) { |
| 4010 |
$curRevisionId = 0; |
| 4011 |
$articleId = 0; |
| 4012 |
$canonicalSpecialPageName = false; |
| 4013 |
$services = MediaWikiServices::getInstance(); |
| 4014 |
|
| 4015 |
$title = $this->getTitle(); |
| 4016 |
$ns = $title->getNamespace(); |
| 4017 |
$nsInfo = $services->getNamespaceInfo(); |
| 4018 |
$canonicalNamespace = $nsInfo->exists( $ns ) |
| 4019 |
? $nsInfo->getCanonicalName( $ns ) |
| 4020 |
: $title->getNsText(); |
| 4021 |
|
| 4022 |
$sk = $this->getSkin(); |
| 4023 |
|
| 4024 |
|
| 4025 |
$relevantTitle = $sk->getRelevantTitle(); |
| 4026 |
|
| 4027 |
if ( $ns === NS_SPECIAL ) { |
| 4028 |
[ $canonicalSpecialPageName, ] = |
| 4029 |
$services->getSpecialPageFactory()-> |
| 4030 |
resolveAlias( $title->getDBkey() ); |
| 4031 |
} elseif ( $this->canUseWikiPage() ) { |
| 4032 |
$wikiPage = $this->getWikiPage(); |
| 4033 |
|
| 4034 |
|
| 4035 |
if ( $this->isRevisionCurrent() && $this->getRevisionId() ) { |
| 4036 |
$curRevisionId = $this->getRevisionId(); |
| 4037 |
} else { |
| 4038 |
$curRevisionId = $wikiPage->getLatest(); |
| 4039 |
} |
| 4040 |
$articleId = $wikiPage->getId(); |
| 4041 |
} |
| 4042 |
|
| 4043 |
|
| 4044 |
|
| 4045 |
$lang = $this->getContentLangForJS(); |
| 4046 |
|
| 4047 |
|
| 4048 |
$separatorTransTable = $lang->separatorTransformTable(); |
| 4049 |
$separatorTransTable = $separatorTransTable ?: []; |
| 4050 |
$compactSeparatorTransTable = [ |
| 4051 |
implode( "\t", array_keys( $separatorTransTable ) ), |
| 4052 |
implode( "\t", $separatorTransTable ), |
| 4053 |
]; |
| 4054 |
$digitTransTable = $lang->digitTransformTable(); |
| 4055 |
$digitTransTable = $digitTransTable ?: []; |
| 4056 |
$compactDigitTransTable = [ |
| 4057 |
implode( "\t", array_keys( $digitTransTable ) ), |
| 4058 |
implode( "\t", $digitTransTable ), |
| 4059 |
]; |
| 4060 |
|
| 4061 |
$user = $this->getUser(); |
| 4062 |
|
| 4063 |
|
| 4064 |
$vars = [ |
| 4065 |
|
| 4066 |
'wgBreakFrames' => $this->getFrameOptions() == 'DENY', |
| 4067 |
|
| 4068 |
|
| 4069 |
'wgSeparatorTransformTable' => $compactSeparatorTransTable, |
| 4070 |
'wgDigitTransformTable' => $compactDigitTransTable, |
| 4071 |
'wgDefaultDateFormat' => $lang->getDefaultDateFormat(), |
| 4072 |
'wgMonthNames' => $lang->getMonthNamesArray(), |
| 4073 |
|
| 4074 |
|
| 4075 |
'wgRequestId' => WebRequest::getRequestId(), |
| 4076 |
]; |
| 4077 |
|
| 4078 |
|
| 4079 |
$vars += [ |
| 4080 |
'wgCanonicalNamespace' => $canonicalNamespace, |
| 4081 |
'wgCanonicalSpecialPageName' => $canonicalSpecialPageName, |
| 4082 |
'wgNamespaceNumber' => $title->getNamespace(), |
| 4083 |
'wgPageName' => $title->getPrefixedDBkey(), |
| 4084 |
'wgTitle' => $title->getText(), |
| 4085 |
'wgCurRevisionId' => $curRevisionId, |
| 4086 |
'wgRevisionId' => (int)$this->getRevisionId(), |
| 4087 |
'wgArticleId' => $articleId, |
| 4088 |
'wgIsArticle' => $this->isArticle(), |
| 4089 |
'wgIsRedirect' => $title->isRedirect(), |
| 4090 |
'wgAction' => $this->getContext()->getActionName(), |
| 4091 |
'wgUserName' => $user->isAnon() ? null : $user->getName(), |
| 4092 |
'wgUserGroups' => $services->getUserGroupManager()->getUserEffectiveGroups( $user ), |
| 4093 |
'wgCategories' => $this->getCategories(), |
| 4094 |
'wgPageViewLanguage' => $lang->getCode(), |
| 4095 |
'wgPageContentLanguage' => $lang->getCode(), |
| 4096 |
'wgPageContentModel' => $title->getContentModel(), |
| 4097 |
'wgRelevantPageName' => $relevantTitle->getPrefixedDBkey(), |
| 4098 |
'wgRelevantArticleId' => $relevantTitle->getArticleID(), |
| 4099 |
]; |
| 4100 |
if ( $user->isRegistered() ) { |
| 4101 |
$vars['wgUserId'] = $user->getId(); |
| 4102 |
$vars['wgUserIsTemp'] = $user->isTemp(); |
| 4103 |
$vars['wgUserEditCount'] = $user->getEditCount(); |
| 4104 |
$userReg = $user->getRegistration(); |
| 4105 |
$vars['wgUserRegistration'] = $userReg ? (int)wfTimestamp( TS_UNIX, $userReg ) * 1000 : null; |
| 4106 |
$userFirstReg = $services->getUserRegistrationLookup()->getFirstRegistration( $user ); |
| 4107 |
$vars['wgUserFirstRegistration'] = $userFirstReg ? (int)wfTimestamp( TS_UNIX, $userFirstReg ) * 1000 : null; |
| 4108 |
|
| 4109 |
|
| 4110 |
|
| 4111 |
$userNewMsgRevId = $this->getLastSeenUserTalkRevId(); |
| 4112 |
|
| 4113 |
|
| 4114 |
if ( $userNewMsgRevId ) { |
| 4115 |
$vars['wgUserNewMsgRevisionId'] = $userNewMsgRevId; |
| 4116 |
} |
| 4117 |
} else { |
| 4118 |
$tempUserCreator = $services->getTempUserCreator(); |
| 4119 |
if ( $tempUserCreator->isEnabled() ) { |
| 4120 |
|
| 4121 |
|
| 4122 |
|
| 4123 |
$session = $this->getRequest()->getSession(); |
| 4124 |
$vars['wgTempUserName'] = $tempUserCreator->getStashedName( $session ); |
| 4125 |
} |
| 4126 |
} |
| 4127 |
$languageConverter = $services->getLanguageConverterFactory() |
| 4128 |
->getLanguageConverter( $title->getPageLanguage() ); |
| 4129 |
if ( $languageConverter->hasVariants() ) { |
| 4130 |
$vars['wgUserVariant'] = $languageConverter->getPreferredVariant(); |
| 4131 |
} |
| 4132 |
|
| 4133 |
$vars['wgIsProbablyEditable'] = $this->getAuthority()->probablyCan( 'edit', $title ); |
| 4134 |
$vars['wgRelevantPageIsProbablyEditable'] = $relevantTitle && |
| 4135 |
$this->getAuthority()->probablyCan( 'edit', $relevantTitle ); |
| 4136 |
$restrictionStore = $services->getRestrictionStore(); |
| 4137 |
foreach ( $restrictionStore->listApplicableRestrictionTypes( $title ) as $type ) { |
| 4138 |
|
| 4139 |
|
| 4140 |
$vars['wgRestriction' . ucfirst( $type )] = $restrictionStore->getRestrictions( $title, $type ); |
| 4141 |
} |
| 4142 |
if ( $title->isMainPage() ) { |
| 4143 |
$vars['wgIsMainPage'] = true; |
| 4144 |
} |
| 4145 |
|
| 4146 |
$relevantUser = $sk->getRelevantUser(); |
| 4147 |
if ( $relevantUser ) { |
| 4148 |
$vars['wgRelevantUserName'] = $relevantUser->getName(); |
| 4149 |
} |
| 4150 |
|
| 4151 |
|
| 4152 |
$titleFormatter = $services->getTitleFormatter(); |
| 4153 |
|
| 4154 |
if ( $this->mRedirectedFrom ) { |
| 4155 |
|
| 4156 |
$vars['wgRedirectedFrom'] = $titleFormatter->getPrefixedDBkey( $this->mRedirectedFrom ); |
| 4157 |
} |
| 4158 |
|
| 4159 |
|
| 4160 |
|
| 4161 |
|
| 4162 |
|
| 4163 |
$this->getHookRunner()->onMakeGlobalVariablesScript( $vars, $this ); |
| 4164 |
|
| 4165 |
|
| 4166 |
$vars = array_merge( $vars, $this->getJsConfigVars() ); |
| 4167 |
|
| 4168 |
|
| 4169 |
if ( $flag !== null ) { |
| 4170 |
$lateVarNames = |
| 4171 |
array_fill_keys( self::CORE_LATE_JS_CONFIG_VAR_NAMES, true ) + |
| 4172 |
array_fill_keys( ExtensionRegistry::getInstance()->getAttribute( 'LateJSConfigVarNames' ), true ); |
| 4173 |
foreach ( $vars as $name => $_ ) { |
| 4174 |
|
| 4175 |
if ( isset( $lateVarNames[ $name ] ) !== ( $flag === self::JS_VAR_LATE ) ) { |
| 4176 |
unset( $vars[ $name ] ); |
| 4177 |
} |
| 4178 |
} |
| 4179 |
} |
| 4180 |
|
| 4181 |
return $vars; |
| 4182 |
} |
| 4183 |
|
| 4184 |
|
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
private function getLastSeenUserTalkRevId() { |
| 4190 |
$services = MediaWikiServices::getInstance(); |
| 4191 |
$user = $this->getUser(); |
| 4192 |
$userHasNewMessages = $services |
| 4193 |
->getTalkPageNotificationManager() |
| 4194 |
->userHasNewMessages( $user ); |
| 4195 |
if ( !$userHasNewMessages ) { |
| 4196 |
return null; |
| 4197 |
} |
| 4198 |
|
| 4199 |
$timestamp = $services |
| 4200 |
->getTalkPageNotificationManager() |
| 4201 |
->getLatestSeenMessageTimestamp( $user ); |
| 4202 |
if ( !$timestamp ) { |
| 4203 |
return null; |
| 4204 |
} |
| 4205 |
|
| 4206 |
$revRecord = $services->getRevisionLookup()->getRevisionByTimestamp( |
| 4207 |
$user->getTalkPage(), |
| 4208 |
$timestamp |
| 4209 |
); |
| 4210 |
return $revRecord ? $revRecord->getId() : null; |
| 4211 |
} |
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
|
| 4216 |
|
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
public function userCanPreview() { |
| 4223 |
$request = $this->getRequest(); |
| 4224 |
if ( |
| 4225 |
$request->getRawVal( 'action' ) !== 'submit' || |
| 4226 |
!$request->wasPosted() |
| 4227 |
) { |
| 4228 |
return false; |
| 4229 |
} |
| 4230 |
|
| 4231 |
$user = $this->getUser(); |
| 4232 |
|
| 4233 |
if ( !$user->isRegistered() ) { |
| 4234 |
|
| 4235 |
return false; |
| 4236 |
} |
| 4237 |
if ( !$user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) { |
| 4238 |
return false; |
| 4239 |
} |
| 4240 |
|
| 4241 |
$title = $this->getTitle(); |
| 4242 |
if ( !$this->getAuthority()->probablyCan( 'edit', $title ) ) { |
| 4243 |
return false; |
| 4244 |
} |
| 4245 |
|
| 4246 |
return true; |
| 4247 |
} |
| 4248 |
|
| 4249 |
|
| 4250 |
|
| 4251 |
|
| 4252 |
public function getHeadLinksArray() { |
| 4253 |
$tags = []; |
| 4254 |
$config = $this->getConfig(); |
| 4255 |
|
| 4256 |
if ( $this->cspOutputMode === self::CSP_META ) { |
| 4257 |
foreach ( $this->CSP->getDirectives() as $header => $directive ) { |
| 4258 |
$tags["meta-csp-$header"] = Html::element( 'meta', [ |
| 4259 |
'http-equiv' => $header, |
| 4260 |
'content' => $directive, |
| 4261 |
] ); |
| 4262 |
} |
| 4263 |
} |
| 4264 |
|
| 4265 |
$tags['meta-generator'] = Html::element( 'meta', [ |
| 4266 |
'name' => 'generator', |
| 4267 |
'content' => 'MediaWiki ' . MW_VERSION, |
| 4268 |
] ); |
| 4269 |
|
| 4270 |
if ( $config->get( MainConfigNames::ReferrerPolicy ) !== false ) { |
| 4271 |
|
| 4272 |
|
| 4273 |
foreach ( array_reverse( (array)$config->get( MainConfigNames::ReferrerPolicy ) ) as $i => $policy ) { |
| 4274 |
$tags["meta-referrer-$i"] = Html::element( 'meta', [ |
| 4275 |
'name' => 'referrer', |
| 4276 |
'content' => $policy, |
| 4277 |
] ); |
| 4278 |
} |
| 4279 |
} |
| 4280 |
|
| 4281 |
$p = $this->getRobotsContent(); |
| 4282 |
if ( $p ) { |
| 4283 |
|
| 4284 |
|
| 4285 |
$tags['meta-robots'] = Html::element( 'meta', [ |
| 4286 |
'name' => 'robots', |
| 4287 |
'content' => $p, |
| 4288 |
] ); |
| 4289 |
} |
| 4290 |
|
| 4291 |
|
| 4292 |
if ( $config->get( MainConfigNames::BrowserFormatDetection ) !== false ) { |
| 4293 |
$tags['meta-format-detection'] = Html::element( 'meta', [ |
| 4294 |
'name' => 'format-detection', |
| 4295 |
'content' => $config->get( MainConfigNames::BrowserFormatDetection ), |
| 4296 |
] ); |
| 4297 |
} |
| 4298 |
|
| 4299 |
foreach ( $this->mMetatags as [ $name, $val ] ) { |
| 4300 |
$attrs = []; |
| 4301 |
if ( strncasecmp( $name, 'http:', 5 ) === 0 ) { |
| 4302 |
$name = substr( $name, 5 ); |
| 4303 |
$attrs['http-equiv'] = $name; |
| 4304 |
} elseif ( strncasecmp( $name, 'og:', 3 ) === 0 ) { |
| 4305 |
$attrs['property'] = $name; |
| 4306 |
} else { |
| 4307 |
$attrs['name'] = $name; |
| 4308 |
} |
| 4309 |
$attrs['content'] = $val; |
| 4310 |
$tagName = "meta-$name"; |
| 4311 |
if ( isset( $tags[$tagName] ) ) { |
| 4312 |
$tagName .= $val; |
| 4313 |
} |
| 4314 |
$tags[$tagName] = Html::element( 'meta', $attrs ); |
| 4315 |
} |
| 4316 |
|
| 4317 |
foreach ( $this->mLinktags as $tag ) { |
| 4318 |
$tags[] = Html::element( 'link', $tag ); |
| 4319 |
} |
| 4320 |
|
| 4321 |
if ( $config->get( MainConfigNames::UniversalEditButton ) && $this->isArticleRelated() ) { |
| 4322 |
if ( $this->getAuthority()->probablyCan( 'edit', $this->getTitle() ) ) { |
| 4323 |
$msg = $this->msg( 'edit' )->text(); |
| 4324 |
|
| 4325 |
$tags['universal-edit-button'] = Html::element( 'link', [ |
| 4326 |
'rel' => 'alternate', |
| 4327 |
'type' => 'application/x-wiki', |
| 4328 |
'title' => $msg, |
| 4329 |
'href' => $this->getTitle()->getEditURL(), |
| 4330 |
] ); |
| 4331 |
} |
| 4332 |
} |
| 4333 |
|
| 4334 |
|
| 4335 |
|
| 4336 |
|
| 4337 |
|
| 4338 |
$appleTouchIconHref = $config->get( MainConfigNames::AppleTouchIcon ); |
| 4339 |
|
| 4340 |
if ( |
| 4341 |
$appleTouchIconHref !== false && |
| 4342 |
$appleTouchIconHref !== '/apple-touch-icon.png' && |
| 4343 |
$appleTouchIconHref !== '/apple-touch-icon-precomposed.png' |
| 4344 |
) { |
| 4345 |
$tags['apple-touch-icon'] = Html::element( 'link', [ |
| 4346 |
'rel' => 'apple-touch-icon', |
| 4347 |
'href' => $appleTouchIconHref |
| 4348 |
] ); |
| 4349 |
} |
| 4350 |
|
| 4351 |
$faviconHref = $config->get( MainConfigNames::Favicon ); |
| 4352 |
|
| 4353 |
if ( $faviconHref !== false && $faviconHref !== '/favicon.ico' ) { |
| 4354 |
$tags['favicon'] = Html::element( 'link', [ |
| 4355 |
'rel' => 'icon', |
| 4356 |
'href' => $faviconHref |
| 4357 |
] ); |
| 4358 |
} |
| 4359 |
|
| 4360 |
|
| 4361 |
$tags['opensearch'] = Html::element( 'link', [ |
| 4362 |
'rel' => 'search', |
| 4363 |
'type' => 'application/opensearchdescription+xml', |
| 4364 |
'href' => wfScript( 'rest' ) . '/v1/search', |
| 4365 |
'title' => $this->msg( 'opensearch-desc' )->inContentLanguage()->text(), |
| 4366 |
] ); |
| 4367 |
|
| 4368 |
$services = MediaWikiServices::getInstance(); |
| 4369 |
|
| 4370 |
|
| 4371 |
|
| 4372 |
|
| 4373 |
|
| 4374 |
$tags['rsd'] = Html::element( 'link', [ |
| 4375 |
'rel' => 'EditURI', |
| 4376 |
'type' => 'application/rsd+xml', |
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
'href' => (string)$services->getUrlUtils()->expand( wfAppendQuery( |
| 4381 |
wfScript( 'api' ), |
| 4382 |
[ 'action' => 'rsd' ] ), |
| 4383 |
PROTO_RELATIVE |
| 4384 |
), |
| 4385 |
] ); |
| 4386 |
|
| 4387 |
$tags = array_merge( |
| 4388 |
$tags, |
| 4389 |
$this->getHeadLinksCanonicalURLArray( $config ), |
| 4390 |
$this->getHeadLinksAlternateURLsArray(), |
| 4391 |
$this->getHeadLinksCopyrightArray( $config ), |
| 4392 |
$this->getHeadLinksSyndicationArray( $config ), |
| 4393 |
); |
| 4394 |
|
| 4395 |
|
| 4396 |
|
| 4397 |
|
| 4398 |
|
| 4399 |
|
| 4400 |
$this->getHookRunner()->onOutputPageAfterGetHeadLinksArray( $tags, $this ); |
| 4401 |
|
| 4402 |
return $tags; |
| 4403 |
} |
| 4404 |
|
| 4405 |
|
| 4406 |
|
| 4407 |
|
| 4408 |
|
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
|
| 4415 |
|
| 4416 |
|
| 4417 |
|
| 4418 |
|
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
|
| 4424 |
private function getHeadLinksCanonicalURLArray( Config $config ) { |
| 4425 |
$tags = []; |
| 4426 |
$canonicalUrl = $this->mCanonicalUrl; |
| 4427 |
|
| 4428 |
if ( $config->get( MainConfigNames::EnableCanonicalServerLink ) ) { |
| 4429 |
$query = []; |
| 4430 |
$action = $this->getContext()->getActionName(); |
| 4431 |
$isCanonicalUrlAction = in_array( $action, [ 'history', 'info' ] ); |
| 4432 |
$services = MediaWikiServices::getInstance(); |
| 4433 |
$languageConverterFactory = $services->getLanguageConverterFactory(); |
| 4434 |
$isLangConversionDisabled = $languageConverterFactory->isConversionDisabled(); |
| 4435 |
$pageLang = $this->getTitle()->getPageLanguage(); |
| 4436 |
$pageLanguageConverter = $languageConverterFactory->getLanguageConverter( $pageLang ); |
| 4437 |
$urlVariant = $pageLanguageConverter->getURLVariant(); |
| 4438 |
|
| 4439 |
if ( $canonicalUrl !== false ) { |
| 4440 |
$canonicalUrl = (string)$services->getUrlUtils()->expand( $canonicalUrl, PROTO_CANONICAL ); |
| 4441 |
} elseif ( $this->isArticleRelated() ) { |
| 4442 |
if ( $isCanonicalUrlAction ) { |
| 4443 |
$query['action'] = $action; |
| 4444 |
} elseif ( !$isLangConversionDisabled && $urlVariant ) { |
| 4445 |
|
| 4446 |
$query['variant'] = $urlVariant; |
| 4447 |
} |
| 4448 |
$canonicalUrl = $this->getTitle()->getCanonicalURL( $query ); |
| 4449 |
} else { |
| 4450 |
$reqUrl = $this->getRequest()->getRequestURL(); |
| 4451 |
$canonicalUrl = (string)$services->getUrlUtils()->expand( $reqUrl, PROTO_CANONICAL ); |
| 4452 |
} |
| 4453 |
} |
| 4454 |
|
| 4455 |
if ( $canonicalUrl !== false ) { |
| 4456 |
$tags['link-canonical'] = Html::element( 'link', [ |
| 4457 |
'rel' => 'canonical', |
| 4458 |
'href' => $canonicalUrl |
| 4459 |
] ); |
| 4460 |
} |
| 4461 |
|
| 4462 |
return $tags; |
| 4463 |
} |
| 4464 |
|
| 4465 |
|
| 4466 |
|
| 4467 |
|
| 4468 |
|
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 |
|
| 4473 |
private function getHeadLinksAlternateURLsArray() { |
| 4474 |
$tags = []; |
| 4475 |
$languageUrls = []; |
| 4476 |
$action = $this->getContext()->getActionName(); |
| 4477 |
$isCanonicalUrlAction = in_array( $action, [ 'history', 'info' ] ); |
| 4478 |
$services = MediaWikiServices::getInstance(); |
| 4479 |
$languageConverterFactory = $services->getLanguageConverterFactory(); |
| 4480 |
$isLangConversionDisabled = $languageConverterFactory->isConversionDisabled(); |
| 4481 |
$pageLang = $this->getTitle()->getPageLanguage(); |
| 4482 |
$pageLanguageConverter = $languageConverterFactory->getLanguageConverter( $pageLang ); |
| 4483 |
|
| 4484 |
|
| 4485 |
if ( |
| 4486 |
$this->isArticleRelated() && |
| 4487 |
!$isCanonicalUrlAction && |
| 4488 |
$pageLanguageConverter->hasVariants() && |
| 4489 |
!$isLangConversionDisabled |
| 4490 |
) { |
| 4491 |
$variants = $pageLanguageConverter->getVariants(); |
| 4492 |
foreach ( $variants as $variant ) { |
| 4493 |
$bcp47 = LanguageCode::bcp47( $variant ); |
| 4494 |
$languageUrls[$bcp47] = $this->getTitle() |
| 4495 |
->getFullURL( [ 'variant' => $variant ], false, PROTO_CURRENT ); |
| 4496 |
} |
| 4497 |
} |
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
if ( $languageUrls ) { |
| 4503 |
|
| 4504 |
|
| 4505 |
$currentUrl = $this->getTitle()->getFullURL( [], false, PROTO_CURRENT ); |
| 4506 |
$pageLangCodeBcp47 = LanguageCode::bcp47( $pageLang->getCode() ); |
| 4507 |
$languageUrls[$pageLangCodeBcp47] = $currentUrl; |
| 4508 |
|
| 4509 |
ksort( $languageUrls ); |
| 4510 |
|
| 4511 |
|
| 4512 |
$languageUrls['x-default'] = $currentUrl; |
| 4513 |
|
| 4514 |
|
| 4515 |
foreach ( $languageUrls as $bcp47 => $languageUrl ) { |
| 4516 |
$bcp47lowercase = strtolower( $bcp47 ); |
| 4517 |
$tags['link-alternate-language-' . $bcp47lowercase] = Html::element( 'link', [ |
| 4518 |
'rel' => 'alternate', |
| 4519 |
'hreflang' => $bcp47, |
| 4520 |
'href' => $languageUrl, |
| 4521 |
] ); |
| 4522 |
} |
| 4523 |
} |
| 4524 |
|
| 4525 |
return $tags; |
| 4526 |
} |
| 4527 |
|
| 4528 |
|
| 4529 |
|
| 4530 |
|
| 4531 |
|
| 4532 |
|
| 4533 |
|
| 4534 |
private function getHeadLinksCopyrightArray( Config $config ) { |
| 4535 |
$tags = []; |
| 4536 |
|
| 4537 |
if ( $this->copyrightUrl !== null ) { |
| 4538 |
$copyright = $this->copyrightUrl; |
| 4539 |
} else { |
| 4540 |
$copyright = ''; |
| 4541 |
if ( $config->get( MainConfigNames::RightsPage ) ) { |
| 4542 |
$copy = Title::newFromText( $config->get( MainConfigNames::RightsPage ) ); |
| 4543 |
|
| 4544 |
if ( $copy ) { |
| 4545 |
$copyright = $copy->getLocalURL(); |
| 4546 |
} |
| 4547 |
} |
| 4548 |
|
| 4549 |
if ( !$copyright && $config->get( MainConfigNames::RightsUrl ) ) { |
| 4550 |
$copyright = $config->get( MainConfigNames::RightsUrl ); |
| 4551 |
} |
| 4552 |
} |
| 4553 |
|
| 4554 |
if ( $copyright ) { |
| 4555 |
$tags['copyright'] = Html::element( 'link', [ |
| 4556 |
'rel' => 'license', |
| 4557 |
'href' => $copyright |
| 4558 |
] ); |
| 4559 |
} |
| 4560 |
|
| 4561 |
return $tags; |
| 4562 |
} |
| 4563 |
|
| 4564 |
|
| 4565 |
|
| 4566 |
|
| 4567 |
|
| 4568 |
|
| 4569 |
|
| 4570 |
private function getHeadLinksSyndicationArray( Config $config ) { |
| 4571 |
if ( !$config->get( MainConfigNames::Feed ) ) { |
| 4572 |
return []; |
| 4573 |
} |
| 4574 |
|
| 4575 |
$tags = []; |
| 4576 |
$feedLinks = []; |
| 4577 |
|
| 4578 |
foreach ( $this->getSyndicationLinks() as $format => $link ) { |
| 4579 |
|
| 4580 |
|
| 4581 |
|
| 4582 |
|
| 4583 |
|
| 4584 |
$feedLinks[] = $this->feedLink( |
| 4585 |
$format, |
| 4586 |
$link, |
| 4587 |
|
| 4588 |
$this->msg( |
| 4589 |
"page-{$format}-feed", $this->getTitle()->getPrefixedText() |
| 4590 |
)->text() |
| 4591 |
); |
| 4592 |
} |
| 4593 |
|
| 4594 |
|
| 4595 |
|
| 4596 |
|
| 4597 |
|
| 4598 |
|
| 4599 |
|
| 4600 |
|
| 4601 |
$sitename = $config->get( MainConfigNames::Sitename ); |
| 4602 |
$overrideSiteFeed = $config->get( MainConfigNames::OverrideSiteFeed ); |
| 4603 |
if ( $overrideSiteFeed ) { |
| 4604 |
foreach ( $overrideSiteFeed as $type => $feedUrl ) { |
| 4605 |
|
| 4606 |
$feedLinks[] = $this->feedLink( |
| 4607 |
$type, |
| 4608 |
$feedUrl, |
| 4609 |
$this->msg( "site-{$type}-feed", $sitename )->text() |
| 4610 |
); |
| 4611 |
} |
| 4612 |
} elseif ( !$this->getTitle()->isSpecial( 'Recentchanges' ) ) { |
| 4613 |
$rctitle = SpecialPage::getTitleFor( 'Recentchanges' ); |
| 4614 |
foreach ( $this->getAdvertisedFeedTypes() as $format ) { |
| 4615 |
$feedLinks[] = $this->feedLink( |
| 4616 |
$format, |
| 4617 |
$rctitle->getLocalURL( [ 'feed' => $format ] ), |
| 4618 |
|
| 4619 |
$this->msg( "site-{$format}-feed", $sitename )->text() |
| 4620 |
); |
| 4621 |
} |
| 4622 |
} |
| 4623 |
|
| 4624 |
|
| 4625 |
|
| 4626 |
|
| 4627 |
$this->getHookRunner()->onAfterBuildFeedLinks( $feedLinks ); |
| 4628 |
|
| 4629 |
$tags += $feedLinks; |
| 4630 |
|
| 4631 |
return $tags; |
| 4632 |
} |
| 4633 |
|
| 4634 |
|
| 4635 |
|
| 4636 |
|
| 4637 |
|
| 4638 |
|
| 4639 |
|
| 4640 |
|
| 4641 |
|
| 4642 |
private function feedLink( $type, $url, $text ) { |
| 4643 |
return Html::element( 'link', [ |
| 4644 |
'rel' => 'alternate', |
| 4645 |
'type' => "application/$type+xml", |
| 4646 |
'title' => $text, |
| 4647 |
'href' => $url ] |
| 4648 |
); |
| 4649 |
} |
| 4650 |
|
| 4651 |
|
| 4652 |
|
| 4653 |
|
| 4654 |
|
| 4655 |
|
| 4656 |
|
| 4657 |
|
| 4658 |
|
| 4659 |
|
| 4660 |
public function addStyle( $style, $media = '', $condition = '', $dir = '' ) { |
| 4661 |
$options = []; |
| 4662 |
if ( $media ) { |
| 4663 |
$options['media'] = $media; |
| 4664 |
} |
| 4665 |
if ( $condition ) { |
| 4666 |
$options['condition'] = $condition; |
| 4667 |
} |
| 4668 |
if ( $dir ) { |
| 4669 |
$options['dir'] = $dir; |
| 4670 |
} |
| 4671 |
$this->styles[$style] = $options; |
| 4672 |
} |
| 4673 |
|
| 4674 |
|
| 4675 |
|
| 4676 |
|
| 4677 |
|
| 4678 |
|
| 4679 |
|
| 4680 |
|
| 4681 |
|
| 4682 |
public function addInlineStyle( $style_css, $flip = 'noflip' ) { |
| 4683 |
if ( $flip === 'flip' && $this->getLanguage()->isRTL() ) { |
| 4684 |
|
| 4685 |
$style_css = CSSJanus::transform( $style_css, true, false ); |
| 4686 |
} |
| 4687 |
$this->mInlineStyles .= Html::inlineStyle( $style_css ); |
| 4688 |
} |
| 4689 |
|
| 4690 |
|
| 4691 |
|
| 4692 |
|
| 4693 |
|
| 4694 |
|
| 4695 |
protected function buildExemptModules() { |
| 4696 |
$chunks = []; |
| 4697 |
|
| 4698 |
|
| 4699 |
|
| 4700 |
|
| 4701 |
|
| 4702 |
|
| 4703 |
|
| 4704 |
|
| 4705 |
|
| 4706 |
|
| 4707 |
|
| 4708 |
|
| 4709 |
|
| 4710 |
|
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
$chunks[] = implode( '', $this->buildCssLinksArray() ) . $this->mInlineStyles; |
| 4716 |
|
| 4717 |
|
| 4718 |
$append = []; |
| 4719 |
$separateReq = [ 'site.styles', 'user.styles' ]; |
| 4720 |
foreach ( $this->rlExemptStyleModules as $moduleNames ) { |
| 4721 |
if ( $moduleNames ) { |
| 4722 |
$append[] = $this->makeResourceLoaderLink( |
| 4723 |
array_diff( $moduleNames, $separateReq ), |
| 4724 |
RL\Module::TYPE_STYLES |
| 4725 |
); |
| 4726 |
|
| 4727 |
foreach ( array_intersect( $moduleNames, $separateReq ) as $name ) { |
| 4728 |
|
| 4729 |
|
| 4730 |
$append[] = $this->makeResourceLoaderLink( $name, |
| 4731 |
RL\Module::TYPE_STYLES |
| 4732 |
); |
| 4733 |
} |
| 4734 |
} |
| 4735 |
} |
| 4736 |
if ( $append ) { |
| 4737 |
$chunks[] = Html::element( |
| 4738 |
'meta', |
| 4739 |
[ 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ] |
| 4740 |
); |
| 4741 |
$chunks = array_merge( $chunks, $append ); |
| 4742 |
} |
| 4743 |
|
| 4744 |
return self::combineWrappedStrings( $chunks ); |
| 4745 |
} |
| 4746 |
|
| 4747 |
|
| 4748 |
|
| 4749 |
|
| 4750 |
public function buildCssLinksArray() { |
| 4751 |
$links = []; |
| 4752 |
|
| 4753 |
foreach ( $this->styles as $file => $options ) { |
| 4754 |
$link = $this->styleLink( $file, $options ); |
| 4755 |
if ( $link ) { |
| 4756 |
$links[$file] = $link; |
| 4757 |
} |
| 4758 |
} |
| 4759 |
return $links; |
| 4760 |
} |
| 4761 |
|
| 4762 |
|
| 4763 |
|
| 4764 |
|
| 4765 |
|
| 4766 |
|
| 4767 |
|
| 4768 |
|
| 4769 |
protected function styleLink( $style, array $options ) { |
| 4770 |
if ( isset( $options['dir'] ) && $this->getLanguage()->getDir() != $options['dir'] ) { |
| 4771 |
return ''; |
| 4772 |
} |
| 4773 |
|
| 4774 |
if ( isset( $options['media'] ) ) { |
| 4775 |
$media = self::transformCssMedia( $options['media'] ); |
| 4776 |
if ( $media === null ) { |
| 4777 |
return ''; |
| 4778 |
} |
| 4779 |
} else { |
| 4780 |
$media = 'all'; |
| 4781 |
} |
| 4782 |
|
| 4783 |
if ( str_starts_with( $style, '/' ) || |
| 4784 |
str_starts_with( $style, 'http:' ) || |
| 4785 |
str_starts_with( $style, 'https:' ) |
| 4786 |
) { |
| 4787 |
$url = $style; |
| 4788 |
} else { |
| 4789 |
$config = $this->getConfig(); |
| 4790 |
|
| 4791 |
$url = self::transformResourcePath( |
| 4792 |
$config, |
| 4793 |
$config->get( MainConfigNames::StylePath ) . '/' . $style |
| 4794 |
); |
| 4795 |
} |
| 4796 |
|
| 4797 |
$link = Html::linkedStyle( $url, $media ); |
| 4798 |
|
| 4799 |
if ( isset( $options['condition'] ) ) { |
| 4800 |
$condition = htmlspecialchars( $options['condition'] ); |
| 4801 |
$link = "<!--[if $condition]>$link<![endif]-->"; |
| 4802 |
} |
| 4803 |
return $link; |
| 4804 |
} |
| 4805 |
|
| 4806 |
|
| 4807 |
|
| 4808 |
|
| 4809 |
|
| 4810 |
|
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
|
| 4815 |
|
| 4816 |
|
| 4817 |
|
| 4818 |
|
| 4819 |
|
| 4820 |
|
| 4821 |
|
| 4822 |
|
| 4823 |
|
| 4824 |
|
| 4825 |
|
| 4826 |
|
| 4827 |
public static function transformResourcePath( Config $config, $path ) { |
| 4828 |
$localDir = $config->get( MainConfigNames::BaseDirectory ); |
| 4829 |
$remotePathPrefix = $config->get( MainConfigNames::ResourceBasePath ); |
| 4830 |
if ( $remotePathPrefix === '' ) { |
| 4831 |
|
| 4832 |
|
| 4833 |
$remotePath = '/'; |
| 4834 |
} else { |
| 4835 |
$remotePath = $remotePathPrefix; |
| 4836 |
} |
| 4837 |
if ( !str_starts_with( $path, $remotePath ) || str_starts_with( $path, '//' ) ) { |
| 4838 |
|
| 4839 |
|
| 4840 |
return $path; |
| 4841 |
} |
| 4842 |
|
| 4843 |
|
| 4844 |
|
| 4845 |
|
| 4846 |
$uploadPath = $config->get( MainConfigNames::UploadPath ); |
| 4847 |
if ( strpos( $path, $uploadPath ) === 0 ) { |
| 4848 |
$localDir = $config->get( MainConfigNames::UploadDirectory ); |
| 4849 |
$remotePathPrefix = $remotePath = $uploadPath; |
| 4850 |
} |
| 4851 |
|
| 4852 |
$path = RelPath::getRelativePath( $path, $remotePath ); |
| 4853 |
return self::transformFilePath( $remotePathPrefix, $localDir, $path ); |
| 4854 |
} |
| 4855 |
|
| 4856 |
|
| 4857 |
|
| 4858 |
|
| 4859 |
|
| 4860 |
|
| 4861 |
|
| 4862 |
|
| 4863 |
|
| 4864 |
|
| 4865 |
|
| 4866 |
|
| 4867 |
public static function transformFilePath( $remotePathPrefix, $localPath, $file ) { |
| 4868 |
|
| 4869 |
$localFile = "$localPath/$file"; |
| 4870 |
$url = "$remotePathPrefix/$file"; |
| 4871 |
if ( is_file( $localFile ) ) { |
| 4872 |
$hash = md5_file( $localFile ); |
| 4873 |
if ( $hash === false ) { |
| 4874 |
wfLogWarning( __METHOD__ . ": Failed to hash $localFile" ); |
| 4875 |
$hash = ''; |
| 4876 |
} |
| 4877 |
$url .= '?' . substr( $hash, 0, 5 ); |
| 4878 |
} |
| 4879 |
return $url; |
| 4880 |
} |
| 4881 |
|
| 4882 |
|
| 4883 |
|
| 4884 |
|
| 4885 |
|
| 4886 |
|
| 4887 |
|
| 4888 |
|
| 4889 |
public static function transformCssMedia( $media ) { |
| 4890 |
global $wgRequest; |
| 4891 |
|
| 4892 |
if ( $wgRequest->getBool( 'printable' ) ) { |
| 4893 |
|
| 4894 |
|
| 4895 |
if ( $media === 'print' ) { |
| 4896 |
return ''; |
| 4897 |
} |
| 4898 |
|
| 4899 |
|
| 4900 |
|
| 4901 |
|
| 4902 |
|
| 4903 |
|
| 4904 |
|
| 4905 |
|
| 4906 |
|
| 4907 |
|
| 4908 |
|
| 4909 |
|
| 4910 |
|
| 4911 |
$screenMediaQueryRegex = '/^(?:only\s+)?screen\b/i'; |
| 4912 |
if ( preg_match( $screenMediaQueryRegex, $media ) === 1 ) { |
| 4913 |
return null; |
| 4914 |
} |
| 4915 |
} |
| 4916 |
|
| 4917 |
return $media; |
| 4918 |
} |
| 4919 |
|
| 4920 |
|
| 4921 |
|
| 4922 |
|
| 4923 |
|
| 4924 |
|
| 4925 |
|
| 4926 |
|
| 4927 |
public function addWikiMsg( $name, ...$args ) { |
| 4928 |
$this->addWikiMsgArray( $name, $args ); |
| 4929 |
} |
| 4930 |
|
| 4931 |
|
| 4932 |
|
| 4933 |
|
| 4934 |
|
| 4935 |
|
| 4936 |
|
| 4937 |
|
| 4938 |
|
| 4939 |
public function addWikiMsgArray( $name, $args ) { |
| 4940 |
$this->addHTML( $this->msg( $name, $args )->parseAsBlock() ); |
| 4941 |
} |
| 4942 |
|
| 4943 |
|
| 4944 |
|
| 4945 |
|
| 4946 |
|
| 4947 |
|
| 4948 |
|
| 4949 |
|
| 4950 |
|
| 4951 |
|
| 4952 |
|
| 4953 |
|
| 4954 |
|
| 4955 |
|
| 4956 |
|
| 4957 |
|
| 4958 |
|
| 4959 |
|
| 4960 |
|
| 4961 |
|
| 4962 |
|
| 4963 |
|
| 4964 |
|
| 4965 |
|
| 4966 |
|
| 4967 |
|
| 4968 |
|
| 4969 |
public function wrapWikiMsg( $wrap, ...$msgSpecs ) { |
| 4970 |
$s = $wrap; |
| 4971 |
foreach ( $msgSpecs as $n => $spec ) { |
| 4972 |
if ( is_array( $spec ) ) { |
| 4973 |
$args = $spec; |
| 4974 |
$name = array_shift( $args ); |
| 4975 |
} else { |
| 4976 |
$args = []; |
| 4977 |
$name = $spec; |
| 4978 |
} |
| 4979 |
$s = str_replace( '$' . ( $n + 1 ), $this->msg( $name, $args )->plain(), $s ); |
| 4980 |
} |
| 4981 |
$this->addWikiTextAsInterface( $s ); |
| 4982 |
} |
| 4983 |
|
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
|
| 4988 |
|
| 4989 |
|
| 4990 |
public function isTOCEnabled() { |
| 4991 |
return $this->mEnableTOC; |
| 4992 |
} |
| 4993 |
|
| 4994 |
|
| 4995 |
|
| 4996 |
|
| 4997 |
|
| 4998 |
|
| 4999 |
|
| 5000 |
|
| 5001 |
public static function setupOOUI( $skinName = null, $dir = null ) { |
| 5002 |
if ( !self::$oouiSetupDone ) { |
| 5003 |
self::$oouiSetupDone = true; |
| 5004 |
$context = RequestContext::getMain(); |
| 5005 |
$skinName = $context->getSkinName(); |
| 5006 |
$dir = $context->getLanguage()->getDir(); |
| 5007 |
$themes = RL\OOUIFileModule::getSkinThemeMap(); |
| 5008 |
$theme = $themes[$skinName] ?? $themes['default']; |
| 5009 |
|
| 5010 |
$themeClass = "OOUI\\{$theme}Theme"; |
| 5011 |
Theme::setSingleton( new $themeClass() ); |
| 5012 |
Element::setDefaultDir( $dir ); |
| 5013 |
} |
| 5014 |
} |
| 5015 |
|
| 5016 |
|
| 5017 |
|
| 5018 |
|
| 5019 |
|
| 5020 |
|
| 5021 |
public static function resetOOUI() { |
| 5022 |
if ( self::$oouiSetupDone ) { |
| 5023 |
self::$oouiSetupDone = false; |
| 5024 |
self::setupOOUI(); |
| 5025 |
} |
| 5026 |
} |
| 5027 |
|
| 5028 |
|
| 5029 |
|
| 5030 |
|
| 5031 |
|
| 5032 |
|
| 5033 |
|
| 5034 |
public function enableOOUI() { |
| 5035 |
self::setupOOUI(); |
| 5036 |
$this->addModuleStyles( [ |
| 5037 |
'oojs-ui-core.styles', |
| 5038 |
'oojs-ui.styles.indicators', |
| 5039 |
'mediawiki.widgets.styles', |
| 5040 |
'oojs-ui-core.icons', |
| 5041 |
] ); |
| 5042 |
} |
| 5043 |
|
| 5044 |
|
| 5045 |
|
| 5046 |
|
| 5047 |
|
| 5048 |
|
| 5049 |
|
| 5050 |
public function getCSP() { |
| 5051 |
return $this->CSP; |
| 5052 |
} |
| 5053 |
|
| 5054 |
|
| 5055 |
|
| 5056 |
|
| 5057 |
|
| 5058 |
|
| 5059 |
|
| 5060 |
|
| 5061 |
|
| 5062 |
|
| 5063 |
|
| 5064 |
|
| 5065 |
|
| 5066 |
|
| 5067 |
public function setCspOutputMode( string $mode ): void { |
| 5068 |
$this->cspOutputMode = $mode; |
| 5069 |
} |
| 5070 |
|
| 5071 |
|
| 5072 |
|
| 5073 |
|
| 5074 |
|
| 5075 |
|
| 5076 |
|
| 5077 |
|
| 5078 |
|
| 5079 |
|
| 5080 |
public function tailElement( $skin ) { |
| 5081 |
$tail = [ |
| 5082 |
MWDebug::getDebugHTML( $skin ), |
| 5083 |
$this->getBottomScripts(), |
| 5084 |
MWDebug::getHTMLDebugLog(), |
| 5085 |
Html::closeElement( 'body' ), |
| 5086 |
Html::closeElement( 'html' ), |
| 5087 |
]; |
| 5088 |
|
| 5089 |
return WrappedStringList::join( "\n", $tail ); |
| 5090 |
} |
| 5091 |
} |
| 5092 |
|
| 5093 |
|
| 5094 |
class_alias( OutputPage::class, 'OutputPage' ); |