| 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\ResourceLoader; |
| 24 |
|
| 25 |
use CSSJanus; |
| 26 |
use MediaWiki\Content\Content; |
| 27 |
use MediaWiki\Json\FormatJson; |
| 28 |
use MediaWiki\Linker\LinkTarget; |
| 29 |
use MediaWiki\MainConfigNames; |
| 30 |
use MediaWiki\MediaWikiServices; |
| 31 |
use MediaWiki\Page\PageIdentity; |
| 32 |
use MediaWiki\Revision\RevisionRecord; |
| 33 |
use MediaWiki\Revision\SlotRecord; |
| 34 |
use MediaWiki\Title\Title; |
| 35 |
use MediaWiki\Title\TitleValue; |
| 36 |
use MemoizedCallable; |
| 37 |
use Wikimedia\Minify\CSSMin; |
| 38 |
use Wikimedia\Rdbms\Database; |
| 39 |
use Wikimedia\Rdbms\IReadableDatabase; |
| 40 |
use Wikimedia\Timestamp\ConvertibleTimestamp; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
class WikiModule extends Module { |
| 66 |
|
| 67 |
protected $origin = self::ORIGIN_USER_SITEWIDE; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
protected $titleInfo = []; |
| 86 |
|
| 87 |
|
| 88 |
protected $styles = []; |
| 89 |
|
| 90 |
|
| 91 |
protected $scripts = []; |
| 92 |
|
| 93 |
|
| 94 |
protected $datas = []; |
| 95 |
|
| 96 |
|
| 97 |
protected $group; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public function __construct( ?array $options = null ) { |
| 104 |
if ( $options === null ) { |
| 105 |
return; |
| 106 |
} |
| 107 |
|
| 108 |
foreach ( $options as $member => $option ) { |
| 109 |
switch ( $member ) { |
| 110 |
case 'styles': |
| 111 |
case 'scripts': |
| 112 |
case 'datas': |
| 113 |
case 'group': |
| 114 |
$this->{$member} = $option; |
| 115 |
break; |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
protected function getPages( Context $context ) { |
| 139 |
$config = $this->getConfig(); |
| 140 |
$pages = []; |
| 141 |
|
| 142 |
|
| 143 |
if ( $config->get( MainConfigNames::UseSiteJs ) ) { |
| 144 |
foreach ( $this->scripts as $script ) { |
| 145 |
$pages[$script] = [ 'type' => 'script' ]; |
| 146 |
} |
| 147 |
foreach ( $this->datas as $data ) { |
| 148 |
$pages[$data] = [ 'type' => 'data' ]; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
if ( $config->get( MainConfigNames::UseSiteCss ) ) { |
| 153 |
foreach ( $this->styles as $style ) { |
| 154 |
$pages[$style] = [ 'type' => 'style' ]; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
return $pages; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
public function getGroup() { |
| 167 |
return $this->group; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
protected function getDB() { |
| 185 |
return MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
protected function getContent( $titleText, Context $context ) { |
| 195 |
$pageStore = MediaWikiServices::getInstance()->getPageStore(); |
| 196 |
$title = $pageStore->getPageByText( $titleText ); |
| 197 |
if ( !$title ) { |
| 198 |
return null; |
| 199 |
} |
| 200 |
|
| 201 |
$content = $this->getContentObj( $title, $context ); |
| 202 |
if ( !$content ) { |
| 203 |
return null; |
| 204 |
} |
| 205 |
|
| 206 |
$handler = $content->getContentHandler(); |
| 207 |
if ( $handler->isSupportedFormat( CONTENT_FORMAT_CSS ) ) { |
| 208 |
$format = CONTENT_FORMAT_CSS; |
| 209 |
} elseif ( $handler->isSupportedFormat( CONTENT_FORMAT_JAVASCRIPT ) ) { |
| 210 |
$format = CONTENT_FORMAT_JAVASCRIPT; |
| 211 |
} elseif ( $handler->isSupportedFormat( CONTENT_FORMAT_JSON ) ) { |
| 212 |
$format = CONTENT_FORMAT_JSON; |
| 213 |
} else { |
| 214 |
return null; |
| 215 |
} |
| 216 |
|
| 217 |
return $content->serialize( $format ); |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
protected function getContentObj( |
| 230 |
PageIdentity $page, Context $context, $maxRedirects = 1 |
| 231 |
) { |
| 232 |
$overrideCallback = $context->getContentOverrideCallback(); |
| 233 |
$content = $overrideCallback ? call_user_func( $overrideCallback, $page ) : null; |
| 234 |
if ( $content ) { |
| 235 |
if ( !$content instanceof Content ) { |
| 236 |
$this->getLogger()->error( |
| 237 |
'Bad content override for "{title}" in ' . __METHOD__, |
| 238 |
[ 'title' => (string)$page ] |
| 239 |
); |
| 240 |
return null; |
| 241 |
} |
| 242 |
} else { |
| 243 |
$revision = MediaWikiServices::getInstance() |
| 244 |
->getRevisionLookup() |
| 245 |
->getKnownCurrentRevision( $page ); |
| 246 |
if ( !$revision ) { |
| 247 |
return null; |
| 248 |
} |
| 249 |
$content = $revision->getContent( SlotRecord::MAIN, RevisionRecord::RAW ); |
| 250 |
|
| 251 |
if ( !$content ) { |
| 252 |
$this->getLogger()->error( |
| 253 |
'Failed to load content of CSS/JS/JSON page "{title}" in ' . __METHOD__, |
| 254 |
[ 'title' => (string)$page ] |
| 255 |
); |
| 256 |
return null; |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
if ( $maxRedirects > 0 ) { |
| 261 |
$newTitle = $content->getRedirectTarget(); |
| 262 |
if ( $newTitle ) { |
| 263 |
return $this->getContentObj( $newTitle, $context, 0 ); |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
return $content; |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
public function shouldEmbedModule( Context $context ) { |
| 275 |
$overrideCallback = $context->getContentOverrideCallback(); |
| 276 |
if ( $overrideCallback && $this->getSource() === 'local' ) { |
| 277 |
foreach ( $this->getPages( $context ) as $page => $info ) { |
| 278 |
$title = Title::newFromText( $page ); |
| 279 |
if ( $title && call_user_func( $overrideCallback, $title ) !== null ) { |
| 280 |
return true; |
| 281 |
} |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
return parent::shouldEmbedModule( $context ); |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public function getScript( Context $context ) { |
| 293 |
if ( $this->isPackaged() ) { |
| 294 |
return $this->getPackageFiles( $context ); |
| 295 |
} else { |
| 296 |
$scripts = ''; |
| 297 |
foreach ( $this->getPages( $context ) as $titleText => $options ) { |
| 298 |
if ( $options['type'] !== 'script' ) { |
| 299 |
continue; |
| 300 |
} |
| 301 |
$script = $this->getContent( $titleText, $context ); |
| 302 |
if ( strval( $script ) !== '' ) { |
| 303 |
$script = $this->validateScriptFile( $titleText, $script ); |
| 304 |
$scripts .= ResourceLoader::makeComment( $titleText ) . $script . "\n"; |
| 305 |
} |
| 306 |
} |
| 307 |
return $scripts; |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
protected function isPackaged(): bool { |
| 326 |
|
| 327 |
|
| 328 |
return false; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
public function supportsURLLoading() { |
| 335 |
|
| 336 |
return !$this->isPackaged(); |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
protected function getRequireKey( string $titleText ): string { |
| 350 |
return $titleText; |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
private function getPackageFiles( Context $context ): array { |
| 358 |
$main = null; |
| 359 |
|
| 360 |
$files = []; |
| 361 |
foreach ( $this->getPages( $context ) as $titleText => $options ) { |
| 362 |
if ( $options['type'] !== 'script' && $options['type'] !== 'data' ) { |
| 363 |
continue; |
| 364 |
} |
| 365 |
$content = $this->getContent( $titleText, $context ); |
| 366 |
if ( strval( $content ) !== '' ) { |
| 367 |
$fileKey = $this->getRequireKey( $titleText ); |
| 368 |
if ( $options['type'] === 'script' ) { |
| 369 |
$script = $this->validateScriptFile( $titleText, $content ); |
| 370 |
$files[$fileKey] = [ |
| 371 |
'type' => 'script', |
| 372 |
'content' => $script, |
| 373 |
]; |
| 374 |
|
| 375 |
$main ??= $fileKey; |
| 376 |
} elseif ( $options['type'] === 'data' ) { |
| 377 |
$data = FormatJson::decode( $content ); |
| 378 |
if ( $data == null ) { |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
$data = [ 'error' => 'Invalid JSON' ]; |
| 383 |
} |
| 384 |
$files[$fileKey] = [ |
| 385 |
'type' => 'data', |
| 386 |
'content' => $data, |
| 387 |
]; |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
return [ |
| 393 |
'main' => $main, |
| 394 |
'files' => $files, |
| 395 |
]; |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
public function getStyles( Context $context ) { |
| 403 |
$remoteDir = $this->getConfig()->get( MainConfigNames::ScriptPath ); |
| 404 |
if ( $remoteDir === '' ) { |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
$remoteDir = '/'; |
| 411 |
} |
| 412 |
|
| 413 |
$styles = []; |
| 414 |
foreach ( $this->getPages( $context ) as $titleText => $options ) { |
| 415 |
if ( $options['type'] !== 'style' ) { |
| 416 |
continue; |
| 417 |
} |
| 418 |
$style = $this->getContent( $titleText, $context ); |
| 419 |
if ( strval( $style ) === '' ) { |
| 420 |
continue; |
| 421 |
} |
| 422 |
if ( $this->getFlip( $context ) ) { |
| 423 |
$style = CSSJanus::transform( $style, true, false ); |
| 424 |
} |
| 425 |
|
| 426 |
$style = MemoizedCallable::call( |
| 427 |
[ CSSMin::class, 'remap' ], |
| 428 |
[ $style, false, $remoteDir, true ] |
| 429 |
); |
| 430 |
$media = $options['media'] ?? 'all'; |
| 431 |
$style = ResourceLoader::makeComment( $titleText ) . $style; |
| 432 |
$styles[$media][] = $style; |
| 433 |
} |
| 434 |
return $styles; |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
public function enableModuleContentVersion() { |
| 448 |
return false; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
public function getDefinitionSummary( Context $context ) { |
| 456 |
$summary = parent::getDefinitionSummary( $context ); |
| 457 |
$summary[] = [ |
| 458 |
'pages' => $this->getPages( $context ), |
| 459 |
|
| 460 |
'titleInfo' => $this->getTitleInfo( $context ), |
| 461 |
]; |
| 462 |
return $summary; |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
public function isKnownEmpty( Context $context ) { |
| 470 |
|
| 471 |
if ( $this->getDependencies() ) { |
| 472 |
return false; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
$revisions = $this->getTitleInfo( $context ); |
| 479 |
if ( $this->getGroup() === self::GROUP_USER ) { |
| 480 |
foreach ( $revisions as $revision ) { |
| 481 |
if ( $revision['page_len'] > 0 ) { |
| 482 |
|
| 483 |
return false; |
| 484 |
} |
| 485 |
} |
| 486 |
return true; |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
return count( $revisions ) === 0; |
| 493 |
} |
| 494 |
|
| 495 |
private function setTitleInfo( $batchKey, array $titleInfo ) { |
| 496 |
$this->titleInfo[$batchKey] = $titleInfo; |
| 497 |
} |
| 498 |
|
| 499 |
private static function makeTitleKey( LinkTarget $title ) { |
| 500 |
|
| 501 |
return "{$title->getNamespace()}:{$title->getDBkey()}"; |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
protected function getTitleInfo( Context $context ) { |
| 510 |
$pageNames = array_keys( $this->getPages( $context ) ); |
| 511 |
sort( $pageNames ); |
| 512 |
$batchKey = implode( '|', $pageNames ); |
| 513 |
if ( !isset( $this->titleInfo[$batchKey] ) ) { |
| 514 |
$this->titleInfo[$batchKey] = static::fetchTitleInfo( $this->getDB(), $pageNames, __METHOD__ ); |
| 515 |
} |
| 516 |
|
| 517 |
$titleInfo = $this->titleInfo[$batchKey]; |
| 518 |
|
| 519 |
|
| 520 |
$overrideCallback = $context->getContentOverrideCallback(); |
| 521 |
if ( $overrideCallback ) { |
| 522 |
foreach ( $pageNames as $page ) { |
| 523 |
$title = Title::newFromText( $page ); |
| 524 |
$content = $title ? call_user_func( $overrideCallback, $title ) : null; |
| 525 |
if ( $content !== null ) { |
| 526 |
$titleInfo[$title->getPrefixedText()] = [ |
| 527 |
'page_len' => $content->getSize(), |
| 528 |
'page_latest' => 'TBD', |
| 529 |
'page_touched' => ConvertibleTimestamp::now( TS_MW ), |
| 530 |
]; |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
return $titleInfo; |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
protected static function fetchTitleInfo( IReadableDatabase $db, array $pages, $fname = __METHOD__ ) { |
| 545 |
$titleInfo = []; |
| 546 |
$linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory(); |
| 547 |
$batch = $linkBatchFactory->newLinkBatch(); |
| 548 |
foreach ( $pages as $titleText ) { |
| 549 |
$title = Title::newFromText( $titleText ); |
| 550 |
if ( $title ) { |
| 551 |
|
| 552 |
$batch->addObj( $title ); |
| 553 |
} |
| 554 |
} |
| 555 |
if ( !$batch->isEmpty() ) { |
| 556 |
$res = $db->newSelectQueryBuilder() |
| 557 |
|
| 558 |
->select( [ 'page_namespace', 'page_title', 'page_touched', 'page_len', 'page_latest' ] ) |
| 559 |
->from( 'page' ) |
| 560 |
->where( $batch->constructSet( 'page', $db ) ) |
| 561 |
->caller( $fname )->fetchResultSet(); |
| 562 |
foreach ( $res as $row ) { |
| 563 |
|
| 564 |
|
| 565 |
$title = new TitleValue( (int)$row->page_namespace, $row->page_title ); |
| 566 |
$titleInfo[self::makeTitleKey( $title )] = [ |
| 567 |
'page_len' => $row->page_len, |
| 568 |
'page_latest' => $row->page_latest, |
| 569 |
'page_touched' => ConvertibleTimestamp::convert( TS_MW, $row->page_touched ), |
| 570 |
]; |
| 571 |
} |
| 572 |
} |
| 573 |
return $titleInfo; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
public static function preloadTitleInfo( |
| 589 |
Context $context, array $moduleNames |
| 590 |
) { |
| 591 |
$rl = $context->getResourceLoader(); |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
$byDomain = []; |
| 599 |
foreach ( $moduleNames as $name ) { |
| 600 |
$module = $rl->getModule( $name ); |
| 601 |
if ( $module instanceof self ) { |
| 602 |
|
| 603 |
$db = $module->getDB(); |
| 604 |
$domain = $db->getDomainID(); |
| 605 |
|
| 606 |
$byDomain[ $domain ] ??= [ 'db' => $db, 'pages' => [], 'modules' => [] ]; |
| 607 |
$byDomain[ $domain ]['pages'] = array_merge( |
| 608 |
$byDomain[ $domain ]['pages'], |
| 609 |
array_keys( $module->getPages( $context ) ) |
| 610 |
); |
| 611 |
$byDomain[ $domain ]['modules'][] = $module; |
| 612 |
} |
| 613 |
} |
| 614 |
|
| 615 |
if ( !$byDomain ) { |
| 616 |
|
| 617 |
return; |
| 618 |
} |
| 619 |
|
| 620 |
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
| 621 |
$fname = __METHOD__; |
| 622 |
|
| 623 |
foreach ( $byDomain as $domainId => $batch ) { |
| 624 |
|
| 625 |
sort( $batch['pages'] ); |
| 626 |
$pagesHash = sha1( implode( '|', $batch['pages'] ) ); |
| 627 |
$allInfo = $cache->getWithSetCallback( |
| 628 |
$cache->makeGlobalKey( 'resourceloader-titleinfo', $domainId, $pagesHash ), |
| 629 |
$cache::TTL_HOUR, |
| 630 |
static function ( $curVal, &$ttl, array &$setOpts ) use ( $batch, $fname ) { |
| 631 |
$setOpts += Database::getCacheSetOptions( $batch['db'] ); |
| 632 |
return static::fetchTitleInfo( $batch['db'], $batch['pages'], $fname ); |
| 633 |
}, |
| 634 |
[ |
| 635 |
'checkKeys' => [ |
| 636 |
$cache->makeGlobalKey( 'resourceloader-titleinfo', $domainId ) ] |
| 637 |
] |
| 638 |
); |
| 639 |
|
| 640 |
|
| 641 |
foreach ( $batch['modules'] as $wikiModule ) { |
| 642 |
$pages = $wikiModule->getPages( $context ); |
| 643 |
$info = []; |
| 644 |
foreach ( $pages as $pageName => $unused ) { |
| 645 |
|
| 646 |
$title = Title::newFromText( $pageName ); |
| 647 |
if ( !$title ) { |
| 648 |
|
| 649 |
$rl->getLogger()->info( |
| 650 |
'Invalid wiki page title "{title}" in ' . __METHOD__, |
| 651 |
[ 'title' => $pageName ] |
| 652 |
); |
| 653 |
continue; |
| 654 |
} |
| 655 |
$infoKey = self::makeTitleKey( $title ); |
| 656 |
if ( isset( $allInfo[$infoKey] ) ) { |
| 657 |
$info[$infoKey] = $allInfo[$infoKey]; |
| 658 |
} |
| 659 |
} |
| 660 |
$pageNames = array_keys( $pages ); |
| 661 |
sort( $pageNames ); |
| 662 |
$batchKey = implode( '|', $pageNames ); |
| 663 |
$wikiModule->setTitleInfo( $batchKey, $info ); |
| 664 |
} |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
public static function invalidateModuleCache( |
| 679 |
PageIdentity $page, |
| 680 |
?RevisionRecord $old, |
| 681 |
?RevisionRecord $new, |
| 682 |
string $domain |
| 683 |
) { |
| 684 |
static $models = [ CONTENT_MODEL_CSS, CONTENT_MODEL_JAVASCRIPT ]; |
| 685 |
|
| 686 |
$purge = false; |
| 687 |
|
| 688 |
|
| 689 |
if ( $old ) { |
| 690 |
$oldModel = $old->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel(); |
| 691 |
if ( in_array( $oldModel, $models ) ) { |
| 692 |
$purge = true; |
| 693 |
} |
| 694 |
} |
| 695 |
|
| 696 |
if ( !$purge && $new ) { |
| 697 |
$newModel = $new->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel(); |
| 698 |
if ( in_array( $newModel, $models ) ) { |
| 699 |
$purge = true; |
| 700 |
} |
| 701 |
} |
| 702 |
|
| 703 |
if ( !$purge ) { |
| 704 |
$title = Title::newFromPageIdentity( $page ); |
| 705 |
$purge = ( $title->isSiteConfigPage() || $title->isUserConfigPage() ); |
| 706 |
} |
| 707 |
|
| 708 |
if ( $purge ) { |
| 709 |
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
| 710 |
$key = $cache->makeGlobalKey( 'resourceloader-titleinfo', $domain ); |
| 711 |
$cache->touchCheckKey( $key ); |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
public function getType() { |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
return ( $this->styles && !$this->scripts ) ? self::LOAD_STYLES : self::LOAD_GENERAL; |
| 724 |
} |
| 725 |
} |