MediaWiki REL1_39
SkinComponentRegistry.php
Go to the documentation of this file.
1<?php
19namespace MediaWiki\Skin;
20
21use RuntimeException;
22use SpecialPage;
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 $user = $skin->getUser();
86 switch ( $name ) {
87 case 'logos':
88 $component = new SkinComponentLogo(
89 $skin->getConfig(),
90 $skin->getLanguage()
91 );
92 break;
93 case 'search-box':
94 $component = new SkinComponentSearch(
95 $skin->getConfig(),
96 $user,
97 $skin->getMessageLocalizer(),
99 $skin->getRelevantTitle()
100 );
101 break;
102 case 'toc':
103 $component = new SkinComponentTableOfContents(
104 $skin->getOutput()
105 );
106 break;
107 default:
108 throw new RuntimeException( 'Unknown component: ' . $name );
109 }
110 $this->components[$name] = $component;
111 }
112
116 private function registerComponents() {
117 $this->registerComponent( 'logos' );
118 $this->registerComponent( 'toc' );
119 $this->registerComponent( 'search-box' );
120 }
121}
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:82
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...