MediaWiki master
SpecialNamespaceInfo.php
Go to the documentation of this file.
1<?php
2
23namespace MediaWiki\Specials;
24
28
37
38 private NamespaceInfo $namespaceInfo;
39
40 public function __construct( NamespaceInfo $namespaceInfo ) {
41 parent::__construct( 'NamespaceInfo' );
42
43 $this->namespaceInfo = $namespaceInfo;
44 }
45
49 public function execute( $par ) {
50 $this->setHeaders();
51 $this->outputHeader();
52
53 $out = $this->getOutput();
54
55 $idHeading = Html::element(
56 'th',
57 [],
58 $this->msg( 'namespaceinfo-heading-id' )->text()
59 );
60 $canonicalHeading = Html::element(
61 'th',
62 [],
63 $this->msg( 'namespaceinfo-heading-canonical' )->text()
64 );
65 $localHeading = Html::element(
66 'th',
67 [],
68 $this->msg( 'namespaceinfo-heading-local' )->text()
69 );
70 $infoHeading = Html::element(
71 'th',
72 [],
73 $this->msg( 'namespaceinfo-heading-info' )->text()
74 );
75 $tableHeadingRow = Html::rawElement(
76 'tr',
77 [],
78 $idHeading . $canonicalHeading . $localHeading . $infoHeading
79 );
80
81 $tableBodyRows = '';
82 foreach ( $this->getContentLanguage()->getFormattedNamespaces() as $ns => $localName ) {
83 $tableBodyRows .= $this->makeNamespaceRow( $ns, $localName );
84 }
85
86 $table = Html::rawElement(
87 'table',
88 [ 'class' => 'wikitable' ],
89 $tableHeadingRow . $tableBodyRows
90 );
91
92 $out->addHtml( $table );
93 }
94
102 private function makeNamespaceRow( int $ns, string $localName ): string {
103 $canonicalName = $this->namespaceInfo->getCanonicalName( $ns );
104 if ( $canonicalName ) {
105 $canonicalName = strtr( $canonicalName, '_', ' ' );
106 } else {
107 $canonicalName = '';
108 }
109
110 // Special handling for main namespace
111 if ( $ns === NS_MAIN ) {
112 $localName = $this->msg( 'blanknamespace' )->escaped();
113 $canonicalName = $this->msg( 'blanknamespace' )->inLanguage( 'en' )->escaped();
114 }
115
116 $description = $this->msg( 'namespaceinfo-description-ns' . $ns );
117 if ( $description->isDisabled() ) {
118 // Custom namespace with no message
119
120 if ( $this->namespaceInfo->isTalk( $ns ) ) {
121 $subjectNs = $this->namespaceInfo->getSubject( $ns );
122 $subjectName = strtr(
123 $this->namespaceInfo->getCanonicalName( $subjectNs ),
124 '_',
125 ' '
126 );
127 $description = $this->msg( 'namespaceinfo-description-custom-talk' )
128 ->params(
129 $subjectName,
130 $subjectNs
131 );
132 } else {
133 $description = $this->msg( 'namespaceinfo-description-custom' )
134 ->params( $localName );
135 }
136 }
137 $descriptionText = $description->parse();
138
139 $properties = [];
140 if ( $ns >= NS_MAIN ) {
141 // Don't talk about immovable namespaces for virtual NS_SPECIAL or NS_MEDIA
142 $namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
143 if ( isset( $namespaceProtection[$ns] ) ) {
144 $rightsNeeded = $namespaceProtection[$ns];
145 if ( !is_array( $rightsNeeded ) ) {
146 $rightsNeeded = [ $rightsNeeded ];
147 }
148 foreach ( $rightsNeeded as $right ) {
149 $properties[] = $this->msg( 'namespaceinfo-namespace-protection-right' )
150 ->params( $right )
151 ->parse();
152 }
153 }
154
155 if ( !$this->namespaceInfo->isMovable( $ns ) ) {
156 $properties[] = $this->msg( 'namespaceinfo-namespace-immovable' )->parse();
157 }
158 if ( $this->namespaceInfo->isContent( $ns ) ) {
159 $properties[] = $this->msg( 'namespaceinfo-namespace-iscontent' )->parse();
160 }
161 if ( $this->namespaceInfo->hasSubpages( $ns ) ) {
162 $properties[] = $this->msg( 'namespaceinfo-namespace-subpages' )->parse();
163 }
164 if ( $this->namespaceInfo->isNonincludable( $ns ) ) {
165 $properties[] = $this->msg( 'namespaceinfo-namespace-nonincludable' )->parse();
166 }
167 if ( $this->namespaceInfo->getNamespaceContentModel( $ns ) !== null ) {
168 $properties[] = $this->msg( 'namespaceinfo-namespace-default-contentmodel' )
169 ->params( $this->namespaceInfo->getNamespaceContentModel( $ns ) )
170 ->parse();
171 }
172 }
173
174 // Convert to a string
175 $namespaceProperties = '';
176 if ( $properties !== [] ) {
177 $namespaceProperties = Html::openElement( 'ul' );
178 foreach ( $properties as $propertyText ) {
179 $namespaceProperties .= Html::rawElement(
180 'li',
181 [],
182 $propertyText
183 );
184 }
185 $namespaceProperties .= Html::closeElement( 'ul' );
186 }
187
188 $idField = Html::rawElement( 'td', [], (string)$ns );
189 $canonicalField = Html::rawElement( 'td', [], $canonicalName );
190 $localField = Html::rawElement( 'td', [], $localName );
191 $infoField = Html::rawElement( 'td', [], $descriptionText . $namespaceProperties );
192
193 return Html::rawElement(
194 'tr',
195 [],
196 $idField . $canonicalField . $localField . $infoField
197 );
198 }
199
203 protected function getGroupName() {
204 return 'wiki';
205 }
206
207}
const NS_MAIN
Definition Defines.php:65
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
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(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)