3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 namespace MediaWiki\Skin
;
21 use MediaWiki\SpecialPage\SpecialPage
;
25 * @internal for use inside Skin and SkinTemplate classes only
28 class SkinComponentRegistry
{
29 /** @var SkinComponent[]|null null if not initialized. */
30 private $components = null;
32 /** @var SkinComponentRegistryContext */
35 public function __construct( SkinComponentRegistryContext
$skinContext ) {
36 $this->skinContext
= $skinContext;
40 * Get a component. This method has side effects in that
41 * if registered components have been not initialized they
42 * will be registered as part of this method.
45 * @throws RuntimeException with unknown name
46 * @return SkinComponent
48 public function getComponent( string $name ): SkinComponent
{
49 if ( $this->components
=== null ) {
50 $this->registerComponents();
52 $component = $this->components
[$name] ??
null;
54 throw new RuntimeException( 'Unknown component: ' . $name );
60 * Return all registered components.
63 * @return SkinComponent[]
65 public function getComponents() {
66 if ( $this->components
=== null ) {
67 $this->registerComponents();
69 return $this->components
;
73 * Registers a component for use with the skin.
74 * Private for now, but in future we may consider making this a
75 * public method to allow skins to extend component definitions.
78 * @throws RuntimeException if given an unknown name
80 private function registerComponent( string $name ) {
81 $skin = $this->skinContext
;
84 $component = new SkinComponentCopyright(
89 $component = new SkinComponentLogo(
95 $component = new SkinComponentSearch(
97 $skin->getMessageLocalizer(),
98 SpecialPage
::newSearchPage( $skin->getUser() )
102 $component = new SkinComponentTableOfContents( $skin->getOutput() );
104 case 'last-modified':
105 $component = new SkinComponentLastModified(
106 $skin, $skin->getOutput()->getRevisionTimestamp()
110 $component = new SkinComponentFooter( $skin );
113 throw new RuntimeException( 'Unknown component: ' . $name );
115 $this->components
[$name] = $component;
119 * Registers components used by skin.
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' );