MediaWiki REL1_40
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 'copyright':
88 $component = new SkinComponentCopyright(
89 $skin
90 );
91 break;
92 case 'logos':
93 $component = new SkinComponentLogo(
94 $skin->getConfig(),
95 $skin->getLanguage()
96 );
97 break;
98 case 'search-box':
99 $component = new SkinComponentSearch(
100 $skin->getConfig(),
101 $user,
102 $skin->getMessageLocalizer(),
104 $skin->getRelevantTitle()
105 );
106 break;
107 case 'toc':
108 $component = new SkinComponentTableOfContents( $skin->getOutput() );
109 break;
110 case 'last-modified':
111 $component = new SkinComponentLastModified(
112 $skin, $skin->getOutput()->getRevisionTimestamp()
113 );
114 break;
115 case 'footer':
116 $component = new SkinComponentFooter( $skin );
117 break;
118 default:
119 throw new RuntimeException( 'Unknown component: ' . $name );
120 }
121 $this->components[$name] = $component;
122 }
123
127 private function registerComponents() {
128 $this->registerComponent( 'copyright' );
129 $this->registerComponent( 'last-modified' );
130 $this->registerComponent( 'logos' );
131 $this->registerComponent( 'toc' );
132 $this->registerComponent( 'search-box' );
133 $this->registerComponent( 'footer' );
134 }
135}
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:88
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...