22use InvalidArgumentException;
26use Wikimedia\Minify\CSSMin;
134 private const FEATURE_FILES = [
136 'all' => [
'resources/src/mediawiki.skinning/accessibility.less' ],
139 'all' => [
'resources/src/mediawiki.skinning/normalize.less' ],
143 'all' => [
'resources/src/mediawiki.skinning/logo.less' ],
145 'print' => [
'resources/src/mediawiki.skinning/logo-print.less' ],
148 'content-media' => [],
149 'content-media-dark' => [
150 'screen' => [
'resources/src/mediawiki.skinning/content.media-dark.less' ],
153 'screen' => [
'resources/src/mediawiki.skinning/content.links.less' ]
155 'content-links-external' => [
156 'screen' => [
'resources/src/mediawiki.skinning/content.externallinks.less' ]
159 'screen' => [
'resources/src/mediawiki.skinning/content.body.less' ],
160 'print' => [
'resources/src/mediawiki.skinning/content.body-print.less' ],
162 'content-tables' => [
163 'screen' => [
'resources/src/mediawiki.skinning/content.tables.less' ],
164 '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' ],
196 'i18n-ordered-lists' => [
197 'screen' => [
'resources/src/mediawiki.skinning/i18n-ordered-lists.less' ],
199 'i18n-all-lists-margins' => [
200 'screen' => [
'resources/src/mediawiki.skinning/i18n-all-lists-margins.less' ],
203 'screen' => [
'resources/src/mediawiki.skinning/i18n-headings.less' ],
206 'all' => [
'resources/src/mediawiki.skinning/toc/common.less' ],
207 'screen' => [
'resources/src/mediawiki.skinning/toc/screen.less' ],
208 'print' => [
'resources/src/mediawiki.skinning/toc/print.less' ],
212 private const COMPAT_ALIASES = [
214 'content-parser-output' =>
'content-body',
216 'content' =>
'content-media',
217 'content-thumbnails' =>
'content-media',
233 private const DEFAULT_FEATURES_SPECIFIED = [
234 'accessibility' =>
true,
235 'content-body' =>
true,
236 'interface-core' =>
true,
246 private const DEFAULT_FEATURES_ABSENT = [
250 private const LESS_MESSAGES = [
281 $features = $options[
'features'] ?? self::DEFAULT_FEATURES_ABSENT;
282 $listMode = array_keys( $features ) === range( 0, count( $features ) - 1 );
287 $features = $listMode ?
289 array_fill_keys( $features,
true ),
295 foreach ( $features as $key => $enabled ) {
296 if ( !isset( self::FEATURE_FILES[$key] ) ) {
297 throw new InvalidArgumentException(
"Feature '$key' is not recognised" );
301 $this->features = $listMode
302 ? array_keys( array_filter( $features ) )
303 : array_keys( array_filter( $features + self::DEFAULT_FEATURES_SPECIFIED ) );
308 if ( in_array(
'toc', $this->features ) ) {
309 $options[
'lessMessages'] = array_merge(
310 $options[
'lessMessages'] ?? [],
316 $messages .=
'More information can be found at [[mw:Manual:ResourceLoaderSkinModule]]. ';
330 array $features,
bool $addUnspecifiedFeatures =
true, &
$messages =
''
332 if ( isset( $features[
'i18n-all-lists-margins' ] ) ) {
335 $messages .=
'[1.43] The use of the `i18n-all-lists-margins` feature with SkinModule'
336 .
' is deprecated as it is now provided by `elements`. Please remove and '
337 .
' add `elements`, drop support for RTL languages, or incorporate the '
338 .
' styles provided by this module into your skin.';
340 if ( isset( $features[
'interface-message-box' ] ) && $features[
'interface-message-box' ] ) {
345 $messages .=
'[1.43] The use of the `interface-message-box` feature with SkinModule'
346 .
' is deprecated in favor of CodexModule. Please remove this feature.';
349 foreach ( self::COMPAT_ALIASES as $from => $to ) {
350 if ( isset( $features[ $from ] ) && $to !==
null ) {
351 if ( isset( $features[ $to ] ) ) {
352 $messages .=
"SkinModule feature `$from` conflicts with `$to` and was ignored. ";
354 $features[ $to ] = $features[ $from ];
357 unset( $features[ $from ] );
361 if ( $addUnspecifiedFeatures
362 && isset( $features[
'content-links' ] )
363 && !isset( $features[
'content-links-external' ] )
366 $features[
'content-links-external' ] = $features[
'content-links' ];
371 if ( $addUnspecifiedFeatures && isset( $features[
'elements' ] ) && !isset( $features[
'content-links' ] ) ) {
372 $features[
'content-links' ] = $features[
'elements' ];
376 if ( isset( $features[
'interface' ] ) && $features[
'interface' ] ) {
377 $features[
'interface-core' ] =
true;
378 $features[
'interface-indicators' ] =
true;
379 $features[
'interface-subtitle' ] =
true;
380 $features[
'interface-user-message' ] =
true;
381 $features[
'interface-site-notice' ] =
true;
382 $features[
'interface-edit-section-links' ] =
true;
384 unset( $features[
'interface' ] );
397 [ $defaultLocalBasePath, $defaultRemoteBasePath ] =
404 $featureFilePaths = [];
406 foreach ( self::FEATURE_FILES as $feature => $featureFiles ) {
407 if ( in_array( $feature, $this->features ) ) {
408 foreach ( $featureFiles as $mediaType => $files ) {
409 foreach ( $files as $filepath ) {
410 $featureFilePaths[$mediaType][] =
new FilePath(
412 $defaultLocalBasePath,
413 $defaultRemoteBasePath
418 if ( $feature ===
'content-media' ) {
420 $featureFilePaths[
'all'][] =
new FilePath(
421 'resources/src/mediawiki.skinning/content.thumbnails-common.less',
422 $defaultLocalBasePath,
423 $defaultRemoteBasePath
425 $featureFilePaths[
'screen'][] =
new FilePath(
426 'resources/src/mediawiki.skinning/content.thumbnails-screen.less',
427 $defaultLocalBasePath,
428 $defaultRemoteBasePath
430 $featureFilePaths[
'print'][] =
new FilePath(
431 'resources/src/mediawiki.skinning/content.thumbnails-print.less',
432 $defaultLocalBasePath,
433 $defaultRemoteBasePath
440 $featureFilePaths[
'all'][] =
new FilePath(
441 'resources/src/mediawiki.skinning/content.media-common.less',
442 $defaultLocalBasePath,
443 $defaultRemoteBasePath
445 $featureFilePaths[
'screen'][] =
new FilePath(
446 'resources/src/mediawiki.skinning/content.media-screen.less',
447 $defaultLocalBasePath,
448 $defaultRemoteBasePath
450 $featureFilePaths[
'print'][] =
new FilePath(
451 'resources/src/mediawiki.skinning/content.media-print.less',
452 $defaultLocalBasePath,
453 $defaultRemoteBasePath
459 return $featureFilePaths;
471 private function combineFeatureAndParentStyles( $featureStyles, $parentStyles ) {
474 $combinedStyles = array_merge( $combinedFeatureStyles, $combinedParentStyles );
475 return [
'' => $combinedStyles ];
486 $logo = $this->getLogoData( $this->getConfig(), $context->getLanguage() );
487 $default = !is_array( $logo ) ? $logo : ( $logo[
'svg'] ?? $logo[
'1x'] ?? null );
491 return $featureStyles;
494 $featureStyles[
'all'][] =
'.mw-wiki-logo { background-image: ' .
495 CSSMin::buildUrlValue( $default ) .
498 if ( is_array( $logo ) ) {
499 if ( isset( $logo[
'svg'] ) ) {
500 $featureStyles[
'all'][] =
'.mw-wiki-logo { ' .
501 'background-size: 135px auto; }';
503 if ( isset( $logo[
'1.5x'] ) ) {
505 '(-webkit-min-device-pixel-ratio: 1.5), ' .
506 '(min-resolution: 1.5dppx), ' .
507 '(min-resolution: 144dpi)'
508 ][] =
'.mw-wiki-logo { background-image: ' .
509 CSSMin::buildUrlValue( $logo[
'1.5x'] ) .
';' .
510 'background-size: 135px auto; }';
512 if ( isset( $logo[
'2x'] ) ) {
514 '(-webkit-min-device-pixel-ratio: 2), ' .
515 '(min-resolution: 2dppx), ' .
516 '(min-resolution: 192dpi)'
517 ][] =
'.mw-wiki-logo { background-image: ' .
518 CSSMin::buildUrlValue( $logo[
'2x'] ) .
';' .
519 'background-size: 135px auto; }';
523 return $featureStyles;
531 $parentStyles = parent::getStyles( $context );
532 $featureFilePaths = $this->getFeatureFilePaths();
533 $featureStyles = $this->readStyleFiles( $featureFilePaths, $context );
535 $this->normalizeStyles( $featureStyles );
536 $this->normalizeStyles( $parentStyles );
538 $isLogoFeatureEnabled = in_array(
'logo', $this->features );
539 if ( $isLogoFeatureEnabled ) {
540 $featureStyles = $this->generateAndAppendLogoStyles( $featureStyles, $context );
543 return $this->combineFeatureAndParentStyles( $featureStyles, $parentStyles );
547 if ( !in_array(
'logo', $this->features ) ) {
551 $logo = $this->getLogoData( $this->getConfig(), $context->getLanguage() );
553 if ( !is_array( $logo ) ) {
555 return [ $logo => [
'as' =>
'image' ] ];
558 if ( isset( $logo[
'svg'] ) ) {
561 return [ $logo[
'svg'] => [
'as' =>
'image' ] ];
565 foreach ( $logo as $dppx => $src ) {
567 $dppx = substr( $dppx, 0, -1 );
568 $logosPerDppx[$dppx] = $src;
572 uksort( $logosPerDppx,
static function ( $a, $b ) {
580 foreach ( $logosPerDppx as $dppx => $src ) {
587 $logosCount = count( $logos );
594 for ( $i = 0; $i < $logosCount; $i++ ) {
599 $media_query =
'not all and (min-resolution: ' . $logos[1][
'dppx'] .
'dppx)';
600 } elseif ( $i !== $logosCount - 1 ) {
605 $upper_bound = floatval( $logos[$i + 1][
'dppx'] ) - 0.000001;
606 $media_query =
'(min-resolution: ' . $logos[$i][
'dppx'] .
607 'dppx) and (max-resolution: ' . $upper_bound .
'dppx)';
610 $media_query =
'(min-resolution: ' . $logos[$i][
'dppx'] .
'dppx)';
613 $preloadLinks[$logos[$i][
'src']] = [
615 'media' => $media_query
619 return $preloadLinks;
630 private function normalizeStyles( array &$styles ): void {
631 foreach ( $styles as $key => $val ) {
632 if ( !is_array( $val ) ) {
633 $styles[$key] = [ $val ];
644 private static function getRelativeSizedLogo( array $logoElement ) {
645 $width = $logoElement[
'width'];
646 $height = $logoElement[
'height'];
647 $widthRelative = $width / 16;
648 $heightRelative = $height / 16;
650 $logoElement[
'style'] =
'width: ' . $widthRelative .
'em; height: ' . $heightRelative .
'em;';
671 if ( $logos ===
false ) {
677 if ( $lang && isset( $logos[
'variants'][$lang] ) ) {
678 foreach ( $logos[
'variants'][$lang] as $type => $value ) {
679 $logos[$type] = $value;
684 if ( !isset( $logos[
'1x' ] ) ) {
685 $logo = $conf->
get( MainConfigNames::Logo );
687 $logos[
'1x'] = $logo;
691 if ( isset( $logos[
'wordmark'] ) ) {
693 $logos[
'wordmark'] = self::getRelativeSizedLogo( $logos[
'wordmark'] );
695 if ( isset( $logos[
'tagline'] ) ) {
696 $logos[
'tagline'] = self::getRelativeSizedLogo( $logos[
'tagline'] );
712 $logoHD = self::getAvailableLogos( $conf, $lang );
713 $logo = $logoHD[
'1x'];
715 $logo1Url = OutputPage::transformResourcePath( $conf, $logo );
721 if ( isset( $logoHD[
'svg'] ) ) {
722 $logoUrls[
'svg'] = OutputPage::transformResourcePath(
726 } elseif ( isset( $logoHD[
'1.5x'] ) || isset( $logoHD[
'2x'] ) ) {
728 if ( isset( $logoHD[
'1.5x'] ) ) {
729 $logoUrls[
'1.5x'] = OutputPage::transformResourcePath(
734 if ( isset( $logoHD[
'2x'] ) ) {
735 $logoUrls[
'2x'] = OutputPage::transformResourcePath(
765 $lessVars = parent::getLessVars( $context );
766 $logos = self::getAvailableLogos( $this->getConfig(), $context->
getLanguage() );
768 if ( isset( $logos[
'wordmark'] ) ) {
769 $logo = $logos[
'wordmark'];
770 $lessVars[
'logo-enabled' ] =
true;
771 $lessVars[
'logo-wordmark-url' ] = CSSMin::buildUrlValue( $logo[
'src'] );
772 $lessVars[
'logo-wordmark-width' ] = intval( $logo[
'width'] );
773 $lessVars[
'logo-wordmark-height' ] = intval( $logo[
'height'] );
775 $lessVars[
'logo-enabled' ] =
false;
781 $summary = parent::getDefinitionSummary( $context );
783 'logos' => self::getAvailableLogos( $this->getConfig(), $context->
getLanguage() ),
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.