22use InvalidArgumentException;
27use Wikimedia\Minify\CSSMin;
135 private const FEATURE_FILES = [
137 'all' => [
'resources/src/mediawiki.skinning/accessibility.less' ],
140 'all' => [
'resources/src/mediawiki.skinning/normalize.less' ],
144 'all' => [
'resources/src/mediawiki.skinning/logo.less' ],
146 'print' => [
'resources/src/mediawiki.skinning/logo-print.less' ],
148 'content-media' => [],
150 'screen' => [
'resources/src/mediawiki.skinning/content.links.less' ]
152 'content-links-external' => [
153 'screen' => [
'resources/src/mediawiki.skinning/content.externallinks.less' ]
156 'screen' => [
'resources/src/mediawiki.skinning/content.body.less' ],
157 'print' => [
'resources/src/mediawiki.skinning/content.body-print.less' ],
159 'content-tables' => [
160 'screen' => [
'resources/src/mediawiki.skinning/content.tables.less' ],
161 'print' => [
'resources/src/mediawiki.skinning/content.tables-print.less' ]
166 'interface-category' => [
167 'screen' => [
'resources/src/mediawiki.skinning/interface.category.less' ],
168 'print' => [
'resources/src/mediawiki.skinning/interface.category-print.less' ],
170 'interface-core' => [
171 'screen' => [
'resources/src/mediawiki.skinning/interface.less' ],
172 'print' => [
'resources/src/mediawiki.skinning/interface-print.less' ],
174 'interface-edit-section-links' => [
175 'screen' => [
'resources/src/mediawiki.skinning/interface-edit-section-links.less' ],
177 'interface-indicators' => [
178 'screen' => [
'resources/src/mediawiki.skinning/interface-indicators.less' ],
180 'interface-site-notice' => [
181 'screen' => [
'resources/src/mediawiki.skinning/interface-site-notice.less' ],
183 'interface-subtitle' => [
184 'screen' => [
'resources/src/mediawiki.skinning/interface-subtitle.less' ],
186 'interface-message-box' => [
187 'all' => [
'resources/src/mediawiki.skinning/messageBoxes.less' ],
189 'interface-user-message' => [
190 'screen' => [
'resources/src/mediawiki.skinning/interface-user-message.less' ],
193 'screen' => [
'resources/src/mediawiki.skinning/elements.less' ],
194 'print' => [
'resources/src/mediawiki.skinning/elements-print.less' ],
199 'i18n-ordered-lists' => [
200 'screen' => [
'resources/src/mediawiki.skinning/i18n-ordered-lists.less' ],
202 'i18n-all-lists-margins' => [
203 'screen' => [
'resources/src/mediawiki.skinning/i18n-all-lists-margins.less' ],
206 'screen' => [
'resources/src/mediawiki.skinning/i18n-headings.less' ],
209 'all' => [
'resources/src/mediawiki.skinning/toc/common.css' ],
210 'screen' => [
'resources/src/mediawiki.skinning/toc/screen.less' ],
211 'print' => [
'resources/src/mediawiki.skinning/toc/print.css' ],
225 private const DEFAULT_FEATURES_SPECIFIED = [
226 'accessibility' =>
true,
227 'content-body' =>
true,
228 'interface-core' =>
true,
240 private const DEFAULT_FEATURES_ABSENT = [
244 private const LESS_MESSAGES = [
275 $features = $options[
'features'] ?? self::DEFAULT_FEATURES_ABSENT;
276 $listMode = array_keys( $features ) === range( 0, count( $features ) - 1 );
282 array_fill_keys( $features,
true ),
false,
$messages
285 foreach ( $features as $key => $enabled ) {
286 if ( !isset( self::FEATURE_FILES[$key] ) ) {
287 throw new InvalidArgumentException(
"Feature '$key' is not recognised" );
291 $this->features = $listMode
292 ? array_keys( array_filter( $features ) )
293 : array_keys( array_filter( $features + self::DEFAULT_FEATURES_SPECIFIED ) );
298 if ( in_array(
'toc', $this->features ) ) {
299 $options[
'lessMessages'] = array_merge(
300 $options[
'lessMessages'] ?? [],
306 $messages .=
'More information can be found at [[mw:Manual:ResourceLoaderSkinModule]]. ';
320 array $features,
bool $addUnspecifiedFeatures =
true, &
$messages =
''
323 if ( isset( $features[
'content' ] ) ) {
324 $features[
'content-media' ] = $features[
'content' ];
325 unset( $features[
'content' ] );
326 $messages .=
'[1.37] The use of the `content` feature with SkinModule'
327 .
' is deprecated. Use `content-media` instead. ';
331 if ( isset( $features[
'content-thumbnails' ] ) ) {
332 $features[
'content-media' ] = $features[
'content-thumbnails' ];
333 $messages .=
'[1.37] The use of the `content-thumbnails` feature with SkinModule'
334 .
' is deprecated. Use `content-media` instead. ';
335 unset( $features[
'content-thumbnails' ] );
339 if ( $addUnspecifiedFeatures && isset( $features[
'content-links' ] )
340 && !isset( $features[
'content-links-external' ] )
343 $features[
'content-links-external' ] = $features[
'content-links' ];
347 if ( isset( $features[
'legacy'] ) && $features[
'legacy'] ) {
348 $messages .=
'[1.37] The use of the `legacy` feature with SkinModule is deprecated'
349 .
'(T89981) and is a NOOP since 1.39 (T304325). This should be urgently omited to retain compatibility '
350 .
'with future MediaWiki versions';
355 if ( $addUnspecifiedFeatures && isset( $features[
'element' ] ) && !isset( $features[
'content-links' ] ) ) {
356 $features[
'content-links' ] = $features[
'element' ];
363 if ( isset( $features[
'content-parser-output' ] ) ) {
364 $features[
'content-body' ] = $features[
'content-parser-output' ];
365 unset( $features[
'content-parser-output' ] );
369 if ( isset( $features[
'interface' ] ) && $features[
'interface' ] ) {
370 unset( $features[
'interface' ] );
371 $features[
'interface-core' ] =
true;
372 $features[
'interface-indicators' ] =
true;
373 $features[
'interface-subtitle' ] =
true;
374 $features[
'interface-user-message' ] =
true;
375 $features[
'interface-site-notice' ] =
true;
376 $features[
'interface-edit-section-links' ] =
true;
388 $styles = parent::getStyleFiles( $context );
392 [ $defaultLocalBasePath, $defaultRemoteBasePath ] =
399 $featureFilePaths = [];
401 foreach ( self::FEATURE_FILES as $feature => $featureFiles ) {
402 if ( in_array( $feature, $this->features ) ) {
403 foreach ( $featureFiles as $mediaType => $files ) {
404 foreach ( $files as $filepath ) {
405 $featureFilePaths[$mediaType][] =
new FilePath(
407 $defaultLocalBasePath,
408 $defaultRemoteBasePath
413 if ( $feature ===
'content-media' ) {
415 $featureFilePaths[
'all'][] =
new FilePath(
416 'resources/src/mediawiki.skinning/content.thumbnails-common.less',
417 $defaultLocalBasePath,
418 $defaultRemoteBasePath
420 $featureFilePaths[
'screen'][] =
new FilePath(
421 'resources/src/mediawiki.skinning/content.thumbnails-screen.less',
422 $defaultLocalBasePath,
423 $defaultRemoteBasePath
425 $featureFilePaths[
'print'][] =
new FilePath(
426 'resources/src/mediawiki.skinning/content.thumbnails-print.less',
427 $defaultLocalBasePath,
428 $defaultRemoteBasePath
435 $featureFilePaths[
'all'][] =
new FilePath(
436 'resources/src/mediawiki.skinning/content.media-common.less',
437 $defaultLocalBasePath,
438 $defaultRemoteBasePath
440 $featureFilePaths[
'screen'][] =
new FilePath(
441 'resources/src/mediawiki.skinning/content.media-screen.less',
442 $defaultLocalBasePath,
443 $defaultRemoteBasePath
445 $featureFilePaths[
'print'][] =
new FilePath(
446 'resources/src/mediawiki.skinning/content.media-print.less',
447 $defaultLocalBasePath,
448 $defaultRemoteBasePath
459 foreach ( $styles as $mediaType => $paths ) {
460 $featureFilePaths[$mediaType] = array_merge( $featureFilePaths[$mediaType] ?? [], $paths );
463 return $featureFilePaths;
471 $logo = $this->getLogoData( $this->getConfig(), $context->
getLanguage() );
472 $styles = parent::getStyles( $context );
473 $this->normalizeStyles( $styles );
475 $isLogoFeatureEnabled = in_array(
'logo', $this->features );
476 if ( $isLogoFeatureEnabled ) {
477 $default = !is_array( $logo ) ? $logo : ( $logo[
'svg'] ?? $logo[
'1x'] ?? null );
482 $styles[
'all'][] =
'.mw-wiki-logo { background-image: ' .
483 CSSMin::buildUrlValue( $default ) .
486 if ( is_array( $logo ) ) {
487 if ( isset( $logo[
'svg'] ) ) {
488 $styles[
'all'][] =
'.mw-wiki-logo { ' .
489 'background-size: 135px auto; }';
491 if ( isset( $logo[
'1.5x'] ) ) {
493 '(-webkit-min-device-pixel-ratio: 1.5), ' .
494 '(min-resolution: 1.5dppx), ' .
495 '(min-resolution: 144dpi)'
496 ][] =
'.mw-wiki-logo { background-image: ' .
497 CSSMin::buildUrlValue( $logo[
'1.5x'] ) .
';' .
498 'background-size: 135px auto; }';
500 if ( isset( $logo[
'2x'] ) ) {
502 '(-webkit-min-device-pixel-ratio: 2), ' .
503 '(min-resolution: 2dppx), ' .
504 '(min-resolution: 192dpi)'
505 ][] =
'.mw-wiki-logo { background-image: ' .
506 CSSMin::buildUrlValue( $logo[
'2x'] ) .
';' .
507 'background-size: 135px auto; }';
521 if ( !in_array(
'logo', $this->features ) ) {
525 $logo = $this->getLogoData( $this->getConfig(), $context->getLanguage() );
527 if ( !is_array( $logo ) ) {
529 return [ $logo => [
'as' =>
'image' ] ];
532 if ( isset( $logo[
'svg'] ) ) {
535 return [ $logo[
'svg'] => [
'as' =>
'image' ] ];
539 foreach ( $logo as $dppx => $src ) {
541 $dppx = substr( $dppx, 0, -1 );
542 $logosPerDppx[$dppx] = $src;
546 uksort( $logosPerDppx,
static function ( $a, $b ) {
554 foreach ( $logosPerDppx as $dppx => $src ) {
561 $logosCount = count( $logos );
568 for ( $i = 0; $i < $logosCount; $i++ ) {
573 $media_query =
'not all and (min-resolution: ' . $logos[1][
'dppx'] .
'dppx)';
574 } elseif ( $i !== $logosCount - 1 ) {
579 $upper_bound = floatval( $logos[$i + 1][
'dppx'] ) - 0.000001;
580 $media_query =
'(min-resolution: ' . $logos[$i][
'dppx'] .
581 'dppx) and (max-resolution: ' . $upper_bound .
'dppx)';
584 $media_query =
'(min-resolution: ' . $logos[$i][
'dppx'] .
'dppx)';
587 $preloadLinks[$logos[$i][
'src']] = [
589 'media' => $media_query
593 return $preloadLinks;
604 private function normalizeStyles( array &$styles ): void {
605 foreach ( $styles as $key => $val ) {
606 if ( !is_array( $val ) ) {
607 $styles[$key] = [ $val ];
618 private static function getRelativeSizedLogo( array $logoElement ) {
619 $width = $logoElement[
'width'];
620 $height = $logoElement[
'height'];
621 $widthRelative = $width / 16;
622 $heightRelative = $height / 16;
624 $logoElement[
'style'] =
'width: ' . $widthRelative .
'em; height: ' . $heightRelative .
'em;';
645 if ( $logos ===
false ) {
651 if ( $lang && isset( $logos[
'variants'][$lang] ) ) {
652 foreach ( $logos[
'variants'][$lang] as $type => $value ) {
653 $logos[$type] = $value;
658 if ( !isset( $logos[
'1x' ] ) ) {
659 $logo = $conf->
get( MainConfigNames::Logo );
661 $logos[
'1x'] = $logo;
666 $logoHD = $conf->
get( MainConfigNames::LogoHD );
672 }
catch ( ConfigException $e ) {
676 if ( isset( $logos[
'wordmark'] ) ) {
678 $logos[
'wordmark'] = self::getRelativeSizedLogo( $logos[
'wordmark'] );
680 if ( isset( $logos[
'tagline'] ) ) {
681 $logos[
'tagline'] = self::getRelativeSizedLogo( $logos[
'tagline'] );
697 $logoHD = self::getAvailableLogos( $conf, $lang );
698 $logo = $logoHD[
'1x'];
700 $logo1Url = OutputPage::transformResourcePath( $conf, $logo );
706 if ( isset( $logoHD[
'svg'] ) ) {
707 $logoUrls[
'svg'] = OutputPage::transformResourcePath(
711 } elseif ( isset( $logoHD[
'1.5x'] ) || isset( $logoHD[
'2x'] ) ) {
713 if ( isset( $logoHD[
'1.5x'] ) ) {
714 $logoUrls[
'1.5x'] = OutputPage::transformResourcePath(
719 if ( isset( $logoHD[
'2x'] ) ) {
720 $logoUrls[
'2x'] = OutputPage::transformResourcePath(
750 $lessVars = parent::getLessVars( $context );
751 $logos = self::getAvailableLogos( $this->getConfig() );
753 if ( isset( $logos[
'wordmark'] ) ) {
754 $logo = $logos[
'wordmark'];
755 $lessVars[
'logo-enabled' ] =
true;
756 $lessVars[
'logo-wordmark-url' ] = CSSMin::buildUrlValue( $logo[
'src'] );
757 $lessVars[
'logo-wordmark-width' ] = intval( $logo[
'width'] );
758 $lessVars[
'logo-wordmark-height' ] = intval( $logo[
'height'] );
760 $lessVars[
'logo-enabled' ] =
false;
766 $summary = parent::getDefinitionSummary( $context );
768 'logos' => self::getAvailableLogos( $this->getConfig() ),
775class_alias( SkinModule::class,
'ResourceLoaderSkinModule' );
if(!defined('MW_SETUP_CALLBACK'))
A class containing constants representing the names of configuration variables.
const UseContentMediaStyles
Name constant for the UseContentMediaStyles setting, for use with Config::get()
const ResourceBasePath
Name constant for the ResourceBasePath setting, for use with Config::get()
const ParserEnableLegacyMediaDOM
Name constant for the ParserEnableLegacyMediaDOM setting, for use with Config::get()
const UseLegacyMediaStyles
Name constant for the UseLegacyMediaStyles setting, for use with Config::get()
This is one of the Core classes and should be read at least once by any new developers.
Context object that contains information about the state of a specific ResourceLoader web request.