MediaWiki master
SkinComponentRegistry.php
Go to the documentation of this file.
1<?php
19namespace MediaWiki\Skin;
20
22use RuntimeException;
23
30 private $components = null;
31
33 private $skinContext;
34
38 public function __construct( SkinComponentRegistryContext $skinContext ) {
39 $this->skinContext = $skinContext;
40 }
41
51 public function getComponent( string $name ): SkinComponent {
52 if ( $this->components === null ) {
53 $this->registerComponents();
54 }
55 $component = $this->components[$name] ?? null;
56 if ( !$component ) {
57 throw new RuntimeException( 'Unknown component: ' . $name );
58 }
59 return $component;
60 }
61
68 public function getComponents() {
69 if ( $this->components === null ) {
70 $this->registerComponents();
71 }
72 return $this->components;
73 }
74
83 private function registerComponent( string $name ) {
84 $skin = $this->skinContext;
85 switch ( $name ) {
86 case 'copyright':
87 $component = new SkinComponentCopyright(
88 $skin
89 );
90 break;
91 case 'logos':
92 $component = new SkinComponentLogo(
93 $skin->getConfig(),
94 $skin->getLanguage()
95 );
96 break;
97 case 'search-box':
98 $component = new SkinComponentSearch(
99 $skin->getConfig(),
100 $skin->getMessageLocalizer(),
101 SpecialPage::newSearchPage( $skin->getUser() )
102 );
103 break;
104 case 'toc':
105 $component = new SkinComponentTableOfContents( $skin->getOutput() );
106 break;
107 case 'last-modified':
108 $component = new SkinComponentLastModified(
109 $skin, $skin->getOutput()->getRevisionTimestamp()
110 );
111 break;
112 case 'footer':
113 $component = new SkinComponentFooter( $skin );
114 break;
115 default:
116 throw new RuntimeException( 'Unknown component: ' . $name );
117 }
118 $this->components[$name] = $component;
119 }
120
124 private function registerComponents() {
125 $this->registerComponent( 'copyright' );
126 $this->registerComponent( 'last-modified' );
127 $this->registerComponent( 'logos' );
128 $this->registerComponent( 'toc' );
129 $this->registerComponent( 'search-box' );
130 $this->registerComponent( 'footer' );
131 }
132}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
getComponents()
Return all registered components.
getComponent(string $name)
Get a component.
__construct(SkinComponentRegistryContext $skinContext)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Parent class for all special pages.
static newSearchPage(User $user)
Get the users preferred search page.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...