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' ],
147 'content-media' => [],
149 'screen' => [
'resources/src/mediawiki.skinning/content.links.less' ]
151 'content-links-external' => [
152 'screen' => [
'resources/src/mediawiki.skinning/content.externallinks.less' ]
155 'screen' => [
'resources/src/mediawiki.skinning/content.body.less' ],
156 'print' => [
'resources/src/mediawiki.skinning/content.body-print.less' ],
158 'content-tables' => [
159 'screen' => [
'resources/src/mediawiki.skinning/content.tables.less' ],
160 'print' => [
'resources/src/mediawiki.skinning/content.tables-print.less' ]
165 'interface-category' => [
166 'screen' => [
'resources/src/mediawiki.skinning/interface.category.less' ],
167 'print' => [
'resources/src/mediawiki.skinning/interface.category-print.less' ],
169 'interface-core' => [
170 'screen' => [
'resources/src/mediawiki.skinning/interface.less' ],
171 'print' => [
'resources/src/mediawiki.skinning/interface-print.less' ],
173 'interface-edit-section-links' => [
174 'screen' => [
'resources/src/mediawiki.skinning/interface-edit-section-links.less' ],
176 'interface-indicators' => [
177 'screen' => [
'resources/src/mediawiki.skinning/interface-indicators.less' ],
179 'interface-site-notice' => [
180 'screen' => [
'resources/src/mediawiki.skinning/interface-site-notice.less' ],
182 'interface-subtitle' => [
183 'screen' => [
'resources/src/mediawiki.skinning/interface-subtitle.less' ],
185 'interface-message-box' => [
186 'all' => [
'resources/src/mediawiki.skinning/messageBoxes.less' ],
188 'interface-user-message' => [
189 'screen' => [
'resources/src/mediawiki.skinning/interface-user-message.less' ],
192 'screen' => [
'resources/src/mediawiki.skinning/elements.less' ],
193 'print' => [
'resources/src/mediawiki.skinning/elements-print.less' ],
198 'i18n-ordered-lists' => [
199 'screen' => [
'resources/src/mediawiki.skinning/i18n-ordered-lists.less' ],
202 'i18n-all-lists-margins' => [],
204 'screen' => [
'resources/src/mediawiki.skinning/i18n-headings.less' ],
207 'all' => [
'resources/src/mediawiki.skinning/toc/common.css' ],
208 'screen' => [
'resources/src/mediawiki.skinning/toc/screen.less' ],
209 'print' => [
'resources/src/mediawiki.skinning/toc/print.css' ],
223 private const DEFAULT_FEATURES_SPECIFIED = [
224 'accessibility' =>
true,
225 'content-body' =>
true,
226 'interface-core' =>
true,
238 private const DEFAULT_FEATURES_ABSENT = [
242 private const LESS_MESSAGES = [
273 $features = $options[
'features'] ?? self::DEFAULT_FEATURES_ABSENT;
274 $listMode = array_keys( $features ) === range( 0, count( $features ) - 1 );
280 array_fill_keys( $features,
true ),
false,
$messages
283 foreach ( $features as $key => $enabled ) {
284 if ( !isset( self::FEATURE_FILES[$key] ) ) {
285 throw new InvalidArgumentException(
"Feature '$key' is not recognised" );
289 $this->features = $listMode
290 ? array_keys( array_filter( $features ) )
291 : array_keys( array_filter( $features + self::DEFAULT_FEATURES_SPECIFIED ) );
296 if ( in_array(
'toc', $this->features ) ) {
297 $options[
'lessMessages'] = array_merge(
298 $options[
'lessMessages'] ?? [],
304 $messages .=
'More information can be found at [[mw:Manual:ResourceLoaderSkinModule]]. ';
318 array $features,
bool $addUnspecifiedFeatures =
true, &
$messages =
''
320 if ( isset( $features[
'i18n-all-lists-margins' ] ) ) {
321 unset( $features[
'i18n-all-lists-margins' ] );
322 $messages .=
'[1.43] The use of the `i18n-all-lists-margins` feature with SkinModule'
323 .
' is deprecated. Please remove. ';
326 if ( isset( $features[
'content' ] ) ) {
327 $features[
'content-media' ] = $features[
'content' ];
328 unset( $features[
'content' ] );
329 $messages .=
'[1.37] The use of the `content` feature with SkinModule'
330 .
' is deprecated. Use `content-media` instead. ';
334 if ( isset( $features[
'content-thumbnails' ] ) ) {
335 $features[
'content-media' ] = $features[
'content-thumbnails' ];
336 $messages .=
'[1.37] The use of the `content-thumbnails` feature with SkinModule'
337 .
' is deprecated. Use `content-media` instead. ';
338 unset( $features[
'content-thumbnails' ] );
342 if ( $addUnspecifiedFeatures && isset( $features[
'content-links' ] )
343 && !isset( $features[
'content-links-external' ] )
346 $features[
'content-links-external' ] = $features[
'content-links' ];
350 if ( isset( $features[
'legacy'] ) && $features[
'legacy'] ) {
351 $messages .=
'[1.37] The use of the `legacy` feature with SkinModule is deprecated'
352 .
'(T89981) and is a NOOP since 1.39 (T304325). This should be urgently omited to retain compatibility '
353 .
'with future MediaWiki versions';
358 if ( $addUnspecifiedFeatures && isset( $features[
'element' ] ) && !isset( $features[
'content-links' ] ) ) {
359 $features[
'content-links' ] = $features[
'element' ];
366 if ( isset( $features[
'content-parser-output' ] ) ) {
367 $features[
'content-body' ] = $features[
'content-parser-output' ];
368 unset( $features[
'content-parser-output' ] );
372 if ( isset( $features[
'interface' ] ) && $features[
'interface' ] ) {
373 unset( $features[
'interface' ] );
374 $features[
'interface-core' ] =
true;
375 $features[
'interface-indicators' ] =
true;
376 $features[
'interface-subtitle' ] =
true;
377 $features[
'interface-user-message' ] =
true;
378 $features[
'interface-site-notice' ] =
true;
379 $features[
'interface-edit-section-links' ] =
true;
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
454 return $featureFilePaths;
466 private function combineFeatureAndParentStyles( $featureStyles, $parentStyles ) {
469 $combinedStyles = array_merge( $combinedFeatureStyles, $combinedParentStyles );
470 return [
'' => $combinedStyles ];
481 $logo = $this->getLogoData( $this->getConfig(), $context->getLanguage() );
482 $default = !is_array( $logo ) ? $logo : ( $logo[
'svg'] ?? $logo[
'1x'] ?? null );
486 return $featureStyles;
489 $featureStyles[
'all'][] =
'.mw-wiki-logo { background-image: ' .
490 CSSMin::buildUrlValue( $default ) .
493 if ( is_array( $logo ) ) {
494 if ( isset( $logo[
'svg'] ) ) {
495 $featureStyles[
'all'][] =
'.mw-wiki-logo { ' .
496 'background-size: 135px auto; }';
498 if ( isset( $logo[
'1.5x'] ) ) {
500 '(-webkit-min-device-pixel-ratio: 1.5), ' .
501 '(min-resolution: 1.5dppx), ' .
502 '(min-resolution: 144dpi)'
503 ][] =
'.mw-wiki-logo { background-image: ' .
504 CSSMin::buildUrlValue( $logo[
'1.5x'] ) .
';' .
505 'background-size: 135px auto; }';
507 if ( isset( $logo[
'2x'] ) ) {
509 '(-webkit-min-device-pixel-ratio: 2), ' .
510 '(min-resolution: 2dppx), ' .
511 '(min-resolution: 192dpi)'
512 ][] =
'.mw-wiki-logo { background-image: ' .
513 CSSMin::buildUrlValue( $logo[
'2x'] ) .
';' .
514 'background-size: 135px auto; }';
518 return $featureStyles;
526 $parentStyles = parent::getStyles( $context );
527 $featureFilePaths = $this->getFeatureFilePaths();
528 $featureStyles = $this->readStyleFiles( $featureFilePaths, $context );
530 $this->normalizeStyles( $featureStyles );
531 $this->normalizeStyles( $parentStyles );
533 $isLogoFeatureEnabled = in_array(
'logo', $this->features );
534 if ( $isLogoFeatureEnabled ) {
535 $featureStyles = $this->generateAndAppendLogoStyles( $featureStyles, $context );
538 return $this->combineFeatureAndParentStyles( $featureStyles, $parentStyles );
546 if ( !in_array(
'logo', $this->features ) ) {
550 $logo = $this->getLogoData( $this->getConfig(), $context->getLanguage() );
552 if ( !is_array( $logo ) ) {
554 return [ $logo => [
'as' =>
'image' ] ];
557 if ( isset( $logo[
'svg'] ) ) {
560 return [ $logo[
'svg'] => [
'as' =>
'image' ] ];
564 foreach ( $logo as $dppx => $src ) {
566 $dppx = substr( $dppx, 0, -1 );
567 $logosPerDppx[$dppx] = $src;
571 uksort( $logosPerDppx,
static function ( $a, $b ) {
579 foreach ( $logosPerDppx as $dppx => $src ) {
586 $logosCount = count( $logos );
593 for ( $i = 0; $i < $logosCount; $i++ ) {
598 $media_query =
'not all and (min-resolution: ' . $logos[1][
'dppx'] .
'dppx)';
599 } elseif ( $i !== $logosCount - 1 ) {
604 $upper_bound = floatval( $logos[$i + 1][
'dppx'] ) - 0.000001;
605 $media_query =
'(min-resolution: ' . $logos[$i][
'dppx'] .
606 'dppx) and (max-resolution: ' . $upper_bound .
'dppx)';
609 $media_query =
'(min-resolution: ' . $logos[$i][
'dppx'] .
'dppx)';
612 $preloadLinks[$logos[$i][
'src']] = [
614 'media' => $media_query
618 return $preloadLinks;
629 private function normalizeStyles( array &$styles ): void {
630 foreach ( $styles as $key => $val ) {
631 if ( !is_array( $val ) ) {
632 $styles[$key] = [ $val ];
643 private static function getRelativeSizedLogo( array $logoElement ) {
644 $width = $logoElement[
'width'];
645 $height = $logoElement[
'height'];
646 $widthRelative = $width / 16;
647 $heightRelative = $height / 16;
649 $logoElement[
'style'] =
'width: ' . $widthRelative .
'em; height: ' . $heightRelative .
'em;';
670 if ( $logos ===
false ) {
676 if ( $lang && isset( $logos[
'variants'][$lang] ) ) {
677 foreach ( $logos[
'variants'][$lang] as $type => $value ) {
678 $logos[$type] = $value;
683 if ( !isset( $logos[
'1x' ] ) ) {
684 $logo = $conf->
get( MainConfigNames::Logo );
686 $logos[
'1x'] = $logo;
690 if ( isset( $logos[
'wordmark'] ) ) {
692 $logos[
'wordmark'] = self::getRelativeSizedLogo( $logos[
'wordmark'] );
694 if ( isset( $logos[
'tagline'] ) ) {
695 $logos[
'tagline'] = self::getRelativeSizedLogo( $logos[
'tagline'] );
711 $logoHD = self::getAvailableLogos( $conf, $lang );
712 $logo = $logoHD[
'1x'];
714 $logo1Url = OutputPage::transformResourcePath( $conf, $logo );
720 if ( isset( $logoHD[
'svg'] ) ) {
721 $logoUrls[
'svg'] = OutputPage::transformResourcePath(
725 } elseif ( isset( $logoHD[
'1.5x'] ) || isset( $logoHD[
'2x'] ) ) {
727 if ( isset( $logoHD[
'1.5x'] ) ) {
728 $logoUrls[
'1.5x'] = OutputPage::transformResourcePath(
733 if ( isset( $logoHD[
'2x'] ) ) {
734 $logoUrls[
'2x'] = OutputPage::transformResourcePath(
764 $lessVars = parent::getLessVars( $context );
765 $logos = self::getAvailableLogos( $this->getConfig(), $context->
getLanguage() );
767 if ( isset( $logos[
'wordmark'] ) ) {
768 $logo = $logos[
'wordmark'];
769 $lessVars[
'logo-enabled' ] =
true;
770 $lessVars[
'logo-wordmark-url' ] = CSSMin::buildUrlValue( $logo[
'src'] );
771 $lessVars[
'logo-wordmark-width' ] = intval( $logo[
'width'] );
772 $lessVars[
'logo-wordmark-height' ] = intval( $logo[
'height'] );
774 $lessVars[
'logo-enabled' ] =
false;
780 $summary = parent::getDefinitionSummary( $context );
782 '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.