MediaWiki master
SpecialNamespaceInfo.php
Go to the documentation of this file.
1<?php
2
9namespace MediaWiki\Specials;
10
14
23
24 public function __construct(
25 private readonly NamespaceInfo $namespaceInfo
26 ) {
27 parent::__construct( 'NamespaceInfo' );
28 }
29
33 public function execute( $par ) {
34 $this->setHeaders();
35 $this->outputHeader();
36
37 $out = $this->getOutput();
38
39 $idHeading = Html::element(
40 'th',
41 [],
42 $this->msg( 'namespaceinfo-heading-id' )->text()
43 );
44 $canonicalHeading = Html::element(
45 'th',
46 [],
47 $this->msg( 'namespaceinfo-heading-canonical' )->text()
48 );
49 $localHeading = Html::element(
50 'th',
51 [],
52 $this->msg( 'namespaceinfo-heading-local' )->text()
53 );
54 $infoHeading = Html::element(
55 'th',
56 [],
57 $this->msg( 'namespaceinfo-heading-info' )->text()
58 );
59 $tableHeadingRow = Html::rawElement(
60 'tr',
61 [],
62 $idHeading . $canonicalHeading . $localHeading . $infoHeading
63 );
64
65 $tableBodyRows = '';
66 foreach ( $this->getContentLanguage()->getFormattedNamespaces() as $ns => $localName ) {
67 $tableBodyRows .= $this->makeNamespaceRow( $ns, $localName );
68 }
69
70 $table = Html::rawElement(
71 'table',
72 [ 'class' => 'wikitable' ],
73 $tableHeadingRow . $tableBodyRows
74 );
75
76 $out->addHtml( $table );
77 }
78
86 private function makeNamespaceRow( int $ns, string $localName ): string {
87 $canonicalName = $this->namespaceInfo->getCanonicalName( $ns );
88 if ( $canonicalName ) {
89 $canonicalName = strtr( $canonicalName, '_', ' ' );
90 } else {
91 $canonicalName = '';
92 }
93
94 // Special handling for main namespace
95 if ( $ns === NS_MAIN ) {
96 $localName = $this->msg( 'blanknamespace' )->escaped();
97 $canonicalName = $this->msg( 'blanknamespace' )->inLanguage( 'en' )->escaped();
98 }
99
100 $description = $this->msg( 'namespaceinfo-description-ns' . $ns );
101 if ( $description->isDisabled() ) {
102 // Custom namespace with no message
103
104 if ( $this->namespaceInfo->isTalk( $ns ) ) {
105 $subjectNs = $this->namespaceInfo->getSubject( $ns );
106 $subjectName = strtr(
107 $this->namespaceInfo->getCanonicalName( $subjectNs ),
108 '_',
109 ' '
110 );
111 $description = $this->msg( 'namespaceinfo-description-custom-talk',
112 $subjectName,
113 $subjectNs
114 );
115 } else {
116 $description = $this->msg( 'namespaceinfo-description-custom', $localName );
117 }
118 }
119 $descriptionText = $description->parse();
120
121 $properties = [];
122 if ( $ns >= NS_MAIN ) {
123 // Don't talk about immovable namespaces for virtual NS_SPECIAL or NS_MEDIA
124 $namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
125 if ( isset( $namespaceProtection[$ns] ) ) {
126 $rightsNeeded = $namespaceProtection[$ns];
127 if ( !is_array( $rightsNeeded ) ) {
128 $rightsNeeded = [ $rightsNeeded ];
129 }
130 foreach ( $rightsNeeded as $right ) {
131 $properties[] = $this->msg( 'namespaceinfo-namespace-protection-right', $right )
132 ->parse();
133 }
134 }
135
136 if ( !$this->namespaceInfo->isMovable( $ns ) ) {
137 $properties[] = $this->msg( 'namespaceinfo-namespace-immovable' )->parse();
138 }
139 if ( $this->namespaceInfo->isContent( $ns ) ) {
140 $properties[] = $this->msg( 'namespaceinfo-namespace-iscontent' )->parse();
141 }
142 if ( $this->namespaceInfo->hasSubpages( $ns ) ) {
143 $properties[] = $this->msg( 'namespaceinfo-namespace-subpages' )->parse();
144 }
145 if ( $this->namespaceInfo->isNonincludable( $ns ) ) {
146 $properties[] = $this->msg( 'namespaceinfo-namespace-nonincludable' )->parse();
147 }
148 $contentModel = $this->namespaceInfo->getNamespaceContentModel( $ns );
149 if ( $contentModel !== null ) {
150 $properties[] = $this->msg( 'namespaceinfo-namespace-default-contentmodel' )
151 ->params( $contentModel )
152 ->parse();
153 }
154 }
155
156 // Convert to a string
157 $namespaceProperties = '';
158 if ( $properties !== [] ) {
159 $namespaceProperties = Html::openElement( 'ul' );
160 foreach ( $properties as $propertyText ) {
161 $namespaceProperties .= Html::rawElement(
162 'li',
163 [],
164 $propertyText
165 );
166 }
167 $namespaceProperties .= Html::closeElement( 'ul' );
168 }
169
170 $idField = Html::rawElement( 'td', [], (string)$ns );
171 $canonicalField = Html::rawElement( 'td', [], $canonicalName );
172 $localField = Html::rawElement( 'td', [], $localName );
173 $infoField = Html::rawElement( 'td', [], $descriptionText . $namespaceProperties );
174
175 return Html::rawElement(
176 'tr',
177 [],
178 $idField . $canonicalField . $localField . $infoField
179 );
180 }
181
185 protected function getGroupName() {
186 return 'wiki';
187 }
188
189}
const NS_MAIN
Definition Defines.php:51
This class is a collection of static functions that serve two purposes:
Definition Html.php:43
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getConfig()
Shortcut to get main config object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getContentLanguage()
Shortcut to get content language.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
Show information about the different namespaces.
__construct(private readonly NamespaceInfo $namespaceInfo)
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
element(SerializerNode $parent, SerializerNode $node, $contents)