25 use Wikimedia\Assert\Assert;
56 protected $origin = self::ORIGIN_USER_SITEWIDE;
87 if ( $options ===
null ) {
91 foreach ( $options as $member => $option ) {
97 $this->{$member} = $option;
125 foreach ( $this->scripts as $script ) {
126 $pages[$script] = [
'type' =>
'script' ];
131 foreach ( $this->styles as $style ) {
132 $pages[$style] = [
'type' =>
'style' ];
183 $handler =
$content->getContentHandler();
192 return $content->serialize( $format );
206 $overrideCallback =
$context->getContentOverrideCallback();
207 $content = $overrideCallback ? call_user_func( $overrideCallback,
$title ) :
null;
211 'Bad content override for "{title}" in ' . __METHOD__,
212 [
'title' =>
$title->getPrefixedText() ]
221 $content = $revision->getContent( RevisionRecord::RAW );
225 'Failed to load content of JS/CSS page "{title}" in ' . __METHOD__,
226 [
'title' =>
$title->getPrefixedText() ]
233 if ( $maxRedirects ===
null ) {
234 $maxRedirects = $this->
getConfig()->get(
'MaxRedirects' ) ?: 0;
236 if ( $maxRedirects > 0 ) {
237 $newTitle =
$content->getRedirectTarget();
250 $overrideCallback =
$context->getContentOverrideCallback();
251 if ( $overrideCallback && $this->
getSource() ===
'local' ) {
252 foreach ( $this->
getPages( $context ) as $page => $info ) {
254 if (
$title && call_user_func( $overrideCallback,
$title ) !==
null ) {
260 return parent::shouldEmbedModule(
$context );
269 foreach ( $this->
getPages( $context ) as $titleText => $options ) {
270 if ( $options[
'type'] !==
'script' ) {
274 if ( strval( $script ) !==
'' ) {
276 $scripts .= ResourceLoader::makeComment( $titleText ) . $script .
"\n";
288 foreach ( $this->
getPages( $context ) as $titleText => $options ) {
289 if ( $options[
'type'] !==
'style' ) {
292 $media = $options[
'media'] ??
'all';
294 if ( strval( $style ) ===
'' ) {
297 if ( $this->
getFlip( $context ) ) {
298 $style = CSSJanus::transform( $style,
true,
false );
301 [ $style,
false, $this->
getConfig()->
get(
'ScriptPath' ),
true ] );
302 if ( !isset(
$styles[$media] ) ) {
305 $style = ResourceLoader::makeComment( $titleText ) . $style;
330 $summary = parent::getDefinitionSummary(
$context );
332 'pages' => $this->
getPages( $context ),
351 if ( $this->
getGroup() ===
'user' ) {
352 foreach ( $revisions as $revision ) {
353 if ( $revision[
'page_len'] > 0 ) {
364 return count( $revisions ) === 0;
373 return "{$title->getNamespace()}:{$title->getDBkey()}";
384 $pageNames = array_keys( $this->
getPages( $context ) );
386 $batchKey = implode(
'|', $pageNames );
387 if ( !isset( $this->titleInfo[$batchKey] ) ) {
388 $this->titleInfo[$batchKey] = static::fetchTitleInfo(
$dbr, $pageNames, __METHOD__ );
394 $overrideCallback =
$context->getContentOverrideCallback();
395 if ( $overrideCallback ) {
396 foreach ( $pageNames as $page ) {
402 'page_latest' =>
'TBD',
416 foreach ( $pages as $titleText ) {
423 if ( !$batch->isEmpty() ) {
426 [
'page_namespace',
'page_title',
'page_touched',
'page_len',
'page_latest' ],
427 $batch->constructSet(
'page', $db ),
430 foreach (
$res as $row ) {
435 'page_len' => $row->page_len,
436 'page_latest' => $row->page_latest,
437 'page_touched' => $row->page_touched,
453 $rl =
$context->getResourceLoader();
459 foreach ( $moduleNames as
$name ) {
460 $module = $rl->getModule(
$name );
461 if ( $module instanceof
self ) {
462 $mDB = $module->getDB();
464 if ( $mDB->getDomainID() === $db->
getDomainID() ) {
465 $wikiModules[] = $module;
466 $allPages += $module->getPages(
$context );
471 if ( !$wikiModules ) {
476 $pageNames = array_keys( $allPages );
478 $hash = sha1( implode(
'|', $pageNames ) );
481 $func = [ static::class,
'fetchTitleInfo' ];
484 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
485 $allInfo =
$cache->getWithSetCallback(
488 function ( $curVal, &$ttl, array &$setOpts ) use ( $func, $pageNames, $db, $fname ) {
489 $setOpts += Database::getCacheSetOptions( $db );
491 return call_user_func( $func, $db, $pageNames, $fname );
499 foreach ( $wikiModules as $wikiModule ) {
500 $pages = $wikiModule->getPages(
$context );
503 foreach ( $pages as $pageName => $unused ) {
509 $rl->getLogger()->info(
510 'Invalid wiki page title "{title}" in ' . __METHOD__,
511 [
'title' => $pageName ]
515 $info = array_intersect_key( $allInfo, $intersect );
516 $pageNames = array_keys( $pages );
518 $batchKey = implode(
'|', $pageNames );
519 $wikiModule->setTitleInfo( $batchKey, $info );
538 Assert::parameterType(
'string', $domain,
'$domain' );
542 if ( $old && in_array( $old->getContentFormat(), $formats ) ) {
544 } elseif ( $new && in_array( $new->getContentFormat(), $formats ) ) {
547 $purge = (
$title->isSiteConfigPage() ||
$title->isUserConfigPage() );
551 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
552 $key =
$cache->makeGlobalKey(
'resourceloader-titleinfo', $domain );
553 $cache->touchCheckKey( $key );
565 return ( $this->styles && !$this->scripts ) ? self::LOAD_STYLES : self::LOAD_GENERAL;