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
35 public function __construct( SkinComponentRegistryContext $skinContext ) {
36 $this->skinContext = $skinContext;
37 }
38
48 public function getComponent( string $name ): SkinComponent {
49 if ( $this->components === null ) {
50 $this->registerComponents();
51 }
52 $component = $this->components[$name] ?? null;
53 if ( !$component ) {
54 throw new RuntimeException( 'Unknown component: ' . $name );
55 }
56 return $component;
57 }
58
65 public function getComponents() {
66 if ( $this->components === null ) {
67 $this->registerComponents();
68 }
69 return $this->components;
70 }
71
80 private function registerComponent( string $name ) {
81 $skin = $this->skinContext;
82 switch ( $name ) {
83 case 'copyright':
84 $component = new SkinComponentCopyright(
85 $skin
86 );
87 break;
88 case 'logos':
89 $component = new SkinComponentLogo(
90 $skin->getConfig(),
91 $skin->getLanguage()
92 );
93 break;
94 case 'search-box':
95 $component = new SkinComponentSearch(
96 $skin->getConfig(),
97 $skin->getMessageLocalizer(),
98 SpecialPage::newSearchPage( $skin->getUser() )
99 );
100 break;
101 case 'toc':
102 $component = new SkinComponentTableOfContents( $skin->getOutput() );
103 break;
104 case 'last-modified':
105 $component = new SkinComponentLastModified(
106 $skin, $skin->getOutput()->getRevisionTimestamp()
107 );
108 break;
109 case 'footer':
110 $component = new SkinComponentFooter( $skin );
111 break;
112 default:
113 throw new RuntimeException( 'Unknown component: ' . $name );
114 }
115 $this->components[$name] = $component;
116 }
117
121 private function registerComponents() {
122 $this->registerComponent( 'copyright' );
123 $this->registerComponent( 'last-modified' );
124 $this->registerComponent( 'logos' );
125 $this->registerComponent( 'toc' );
126 $this->registerComponent( 'search-box' );
127 $this->registerComponent( 'footer' );
128 }
129}
if(!defined('MW_SETUP_CALLBACK'))
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...