24use 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' ],
149 'all' => [
'resources/src/mediawiki.skinning/content.thumbnails-common.less' ],
150 'screen' => [
'resources/src/mediawiki.skinning/content.thumbnails-screen.less' ],
151 'print' => [
'resources/src/mediawiki.skinning/content.thumbnails-print.less' ],
154 'screen' => [
'resources/src/mediawiki.skinning/content.links.less' ]
156 'content-links-external' => [
157 'screen' => [
'resources/src/mediawiki.skinning/content.externallinks.less' ]
160 'screen' => [
'resources/src/mediawiki.skinning/content.body.less' ],
161 'print' => [
'resources/src/mediawiki.skinning/content.body-print.less' ],
163 'content-tables' => [
164 'screen' => [
'resources/src/mediawiki.skinning/content.tables.less' ],
165 'print' => [
'resources/src/mediawiki.skinning/content.tables-print.less' ]
170 'interface-category' => [
171 'screen' => [
'resources/src/mediawiki.skinning/interface.category.less' ],
172 'print' => [
'resources/src/mediawiki.skinning/interface.category-print.less' ],
174 'interface-core' => [
175 'screen' => [
'resources/src/mediawiki.skinning/interface.less' ],
176 'print' => [
'resources/src/mediawiki.skinning/interface-print.less' ],
178 'interface-edit-section-links' => [
179 'screen' => [
'resources/src/mediawiki.skinning/interface-edit-section-links.less' ],
181 'interface-indicators' => [
182 'screen' => [
'resources/src/mediawiki.skinning/interface-indicators.less' ],
184 'interface-site-notice' => [
185 'screen' => [
'resources/src/mediawiki.skinning/interface-site-notice.less' ],
187 'interface-subtitle' => [
188 'screen' => [
'resources/src/mediawiki.skinning/interface-subtitle.less' ],
190 'interface-message-box' => [
191 'all' => [
'resources/src/mediawiki.skinning/messageBoxes.less' ],
193 'interface-user-message' => [
194 'screen' => [
'resources/src/mediawiki.skinning/interface-user-message.less' ],
197 'screen' => [
'resources/src/mediawiki.skinning/elements.less' ],
198 'print' => [
'resources/src/mediawiki.skinning/elements-print.less' ],
203 'i18n-ordered-lists' => [
204 'screen' => [
'resources/src/mediawiki.skinning/i18n-ordered-lists.less' ],
206 'i18n-all-lists-margins' => [
207 'screen' => [
'resources/src/mediawiki.skinning/i18n-all-lists-margins.less' ],
210 'screen' => [
'resources/src/mediawiki.skinning/i18n-headings.less' ],
213 'all' => [
'resources/src/mediawiki.skinning/toc/common.css' ],
214 'screen' => [
'resources/src/mediawiki.skinning/toc/screen.less' ],
215 'print' => [
'resources/src/mediawiki.skinning/toc/print.css' ],
229 private const DEFAULT_FEATURES_SPECIFIED = [
230 'accessibility' =>
true,
231 'content-body' =>
true,
232 'interface-core' =>
true,
244 private const DEFAULT_FEATURES_ABSENT = [
248 private const LESS_MESSAGES = [
279 $features = $options[
'features'] ?? self::DEFAULT_FEATURES_ABSENT;
280 $listMode = array_keys( $features ) === range( 0, count( $features ) - 1 );
286 array_fill_keys( $features,
true ),
false,
$messages
289 foreach ( $features as $key => $enabled ) {
290 if ( !isset( self::FEATURE_FILES[$key] ) ) {
291 throw new InvalidArgumentException(
"Feature '$key' is not recognised" );
295 $this->features = $listMode
296 ? array_keys( array_filter( $features ) )
297 : array_keys( array_filter( $features + self::DEFAULT_FEATURES_SPECIFIED ) );
302 if ( in_array(
'toc', $this->features ) ) {
303 $options[
'lessMessages'] = array_merge(
304 $options[
'lessMessages'] ?? [],
310 $messages .=
'More information can be found at [[mw:Manual:ResourceLoaderSkinModule]]. ';
324 array $features,
bool $addUnspecifiedFeatures =
true, &
$messages =
''
327 if ( isset( $features[
'content' ] ) ) {
328 $features[
'content-media' ] = $features[
'content' ];
329 unset( $features[
'content' ] );
330 $messages .=
'[1.37] The use of the `content` feature with ResourceLoaderSkinModule'
331 .
' is deprecated. Use `content-media` instead. ';
335 if ( isset( $features[
'content-thumbnails' ] ) ) {
336 $features[
'content-media' ] = $features[
'content-thumbnails' ];
337 $messages .=
'[1.37] The use of the `content-thumbnails` feature with ResourceLoaderSkinModule'
338 .
' is deprecated. Use `content-media` instead. ';
339 unset( $features[
'content-thumbnails' ] );
343 if ( $addUnspecifiedFeatures && isset( $features[
'content-links' ] )
344 && !isset( $features[
'content-links-external' ] )
347 $features[
'content-links-external' ] = $features[
'content-links' ];
351 if ( isset( $features[
'legacy'] ) && $features[
'legacy'] ) {
352 $messages .=
'[1.37] The use of the `legacy` feature with ResourceLoaderSkinModule is deprecated'
353 .
'(T89981) and is a NOOP since 1.39 (T304325). This should be urgently omited to retain compatibility '
354 .
'with future MediaWiki versions';
359 if ( $addUnspecifiedFeatures && isset( $features[
'element' ] ) && !isset( $features[
'content-links' ] ) ) {
360 $features[
'content-links' ] = $features[
'element' ];
367 if ( isset( $features[
'content-parser-output' ] ) ) {
368 $features[
'content-body' ] = $features[
'content-parser-output' ];
369 unset( $features[
'content-parser-output' ] );
373 if ( isset( $features[
'interface' ] ) && $features[
'interface' ] ) {
374 unset( $features[
'interface' ] );
375 $features[
'interface-core' ] =
true;
376 $features[
'interface-indicators' ] =
true;
377 $features[
'interface-subtitle' ] =
true;
378 $features[
'interface-user-message' ] =
true;
379 $features[
'interface-site-notice' ] =
true;
380 $features[
'interface-edit-section-links' ] =
true;
392 $styles = parent::getStyleFiles( $context );
396 [ $defaultLocalBasePath, $defaultRemoteBasePath ] =
403 $featureFilePaths = [];
405 foreach ( self::FEATURE_FILES as $feature => $featureFiles ) {
406 if ( in_array( $feature, $this->features ) ) {
407 foreach ( $featureFiles as $mediaType => $files ) {
408 foreach ( $files as $filepath ) {
409 $featureFilePaths[$mediaType][] =
new FilePath(
411 $defaultLocalBasePath,
412 $defaultRemoteBasePath
416 if ( $feature ===
'content-media' && (
420 $featureFilePaths[
'all'][] =
new FilePath(
421 'resources/src/mediawiki.skinning/content.media-common.less',
422 $defaultLocalBasePath,
423 $defaultRemoteBasePath
425 $featureFilePaths[
'screen'][] =
new FilePath(
426 'resources/src/mediawiki.skinning/content.media-screen.less',
427 $defaultLocalBasePath,
428 $defaultRemoteBasePath
430 $featureFilePaths[
'print'][] =
new FilePath(
431 'resources/src/mediawiki.skinning/content.media-print.less',
432 $defaultLocalBasePath,
433 $defaultRemoteBasePath
443 foreach ( $styles as $mediaType => $paths ) {
444 $featureFilePaths[$mediaType] = array_merge( $featureFilePaths[$mediaType] ?? [], $paths );
447 return $featureFilePaths;
455 $logo = $this->getLogoData( $this->getConfig(), $context->
getLanguage() );
456 $styles = parent::getStyles( $context );
457 $this->normalizeStyles( $styles );
459 $isLogoFeatureEnabled = in_array(
'logo', $this->features );
460 if ( $isLogoFeatureEnabled ) {
461 $default = !is_array( $logo ) ? $logo : ( $logo[
'svg'] ?? $logo[
'1x'] ?? null );
466 $styles[
'all'][] =
'.mw-wiki-logo { background-image: ' .
467 CSSMin::buildUrlValue( $default ) .
470 if ( is_array( $logo ) ) {
471 if ( isset( $logo[
'svg'] ) ) {
472 $styles[
'all'][] =
'.mw-wiki-logo { ' .
473 'background-size: 135px auto; }';
475 if ( isset( $logo[
'1.5x'] ) ) {
477 '(-webkit-min-device-pixel-ratio: 1.5), ' .
478 '(min-resolution: 1.5dppx), ' .
479 '(min-resolution: 144dpi)'
480 ][] =
'.mw-wiki-logo { background-image: ' .
481 CSSMin::buildUrlValue( $logo[
'1.5x'] ) .
';' .
482 'background-size: 135px auto; }';
484 if ( isset( $logo[
'2x'] ) ) {
486 '(-webkit-min-device-pixel-ratio: 2), ' .
487 '(min-resolution: 2dppx), ' .
488 '(min-resolution: 192dpi)'
489 ][] =
'.mw-wiki-logo { background-image: ' .
490 CSSMin::buildUrlValue( $logo[
'2x'] ) .
';' .
491 'background-size: 135px auto; }';
505 if ( !in_array(
'logo', $this->features ) ) {
509 $logo = $this->getLogoData( $this->getConfig(), $context->getLanguage() );
511 if ( !is_array( $logo ) ) {
513 return [ $logo => [
'as' =>
'image' ] ];
516 if ( isset( $logo[
'svg'] ) ) {
519 return [ $logo[
'svg'] => [
'as' =>
'image' ] ];
523 foreach ( $logo as $dppx => $src ) {
525 $dppx = substr( $dppx, 0, -1 );
526 $logosPerDppx[$dppx] = $src;
530 uksort( $logosPerDppx,
static function ( $a, $b ) {
538 foreach ( $logosPerDppx as $dppx => $src ) {
545 $logosCount = count( $logos );
552 for ( $i = 0; $i < $logosCount; $i++ ) {
557 $media_query =
'not all and (min-resolution: ' . $logos[1][
'dppx'] .
'dppx)';
558 } elseif ( $i !== $logosCount - 1 ) {
563 $upper_bound = floatval( $logos[$i + 1][
'dppx'] ) - 0.000001;
564 $media_query =
'(min-resolution: ' . $logos[$i][
'dppx'] .
565 'dppx) and (max-resolution: ' . $upper_bound .
'dppx)';
568 $media_query =
'(min-resolution: ' . $logos[$i][
'dppx'] .
'dppx)';
571 $preloadLinks[$logos[$i][
'src']] = [
573 'media' => $media_query
577 return $preloadLinks;
588 private function normalizeStyles( array &$styles ): void {
589 foreach ( $styles as $key => $val ) {
590 if ( !is_array( $val ) ) {
591 $styles[$key] = [ $val ];
602 private static function getRelativeSizedLogo( array $logoElement ) {
603 $width = $logoElement[
'width'];
604 $height = $logoElement[
'height'];
605 $widthRelative = $width / 16;
606 $heightRelative = $height / 16;
608 $logoElement[
'style'] =
'width: ' . $widthRelative .
'em; height: ' . $heightRelative .
'em;';
629 if ( $logos ===
false ) {
635 if (
$lang && isset( $logos[
'variants'][
$lang] ) ) {
636 foreach ( $logos[
'variants'][
$lang] as
$type => $value ) {
637 $logos[
$type] = $value;
642 if ( !isset( $logos[
'1x' ] ) ) {
643 $logo = $conf->
get( MainConfigNames::Logo );
645 $logos[
'1x'] = $logo;
650 $logoHD = $conf->
get( MainConfigNames::LogoHD );
660 if ( isset( $logos[
'wordmark'] ) ) {
662 $logos[
'wordmark'] = self::getRelativeSizedLogo( $logos[
'wordmark'] );
664 if ( isset( $logos[
'tagline'] ) ) {
665 $logos[
'tagline'] = self::getRelativeSizedLogo( $logos[
'tagline'] );
681 $logoHD = self::getAvailableLogos( $conf,
$lang );
682 $logo = $logoHD[
'1x'];
684 $logo1Url = OutputPage::transformResourcePath( $conf, $logo );
690 if ( isset( $logoHD[
'svg'] ) ) {
691 $logoUrls[
'svg'] = OutputPage::transformResourcePath(
695 } elseif ( isset( $logoHD[
'1.5x'] ) || isset( $logoHD[
'2x'] ) ) {
697 if ( isset( $logoHD[
'1.5x'] ) ) {
698 $logoUrls[
'1.5x'] = OutputPage::transformResourcePath(
703 if ( isset( $logoHD[
'2x'] ) ) {
704 $logoUrls[
'2x'] = OutputPage::transformResourcePath(
734 $lessVars = parent::getLessVars( $context );
735 $logos = self::getAvailableLogos( $this->getConfig() );
737 if ( isset( $logos[
'wordmark'] ) ) {
738 $logo = $logos[
'wordmark'];
739 $lessVars[
'logo-enabled' ] =
true;
740 $lessVars[
'logo-wordmark-url' ] = CSSMin::buildUrlValue( $logo[
'src'] );
741 $lessVars[
'logo-wordmark-width' ] = intval( $logo[
'width'] );
742 $lessVars[
'logo-wordmark-height' ] = intval( $logo[
'height'] );
744 $lessVars[
'logo-enabled' ] =
false;
750 $summary = parent::getDefinitionSummary( $context );
752 'logos' => self::getAvailableLogos( $this->getConfig() ),
759class_alias( SkinModule::class,
'ResourceLoaderSkinModule' );
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Exceptions for config failures.
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()
Context object that contains information about the state of a specific ResourceLoader web request.
This is one of the Core classes and should be read at least once by any new developers.
Interface for configuration instances.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
if(!isset( $args[0])) $lang