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