Debian Codegraph @

includes/specials/SpecialNamespaceInfo.php

raw symbols SCIP
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 * @ingroup SpecialPage
21 */
22
23 namespace MediaWiki\Specials;
24
25 use MediaWiki\Html\Html;
26 use MediaWiki\SpecialPage\SpecialPage;
27 use MediaWiki\Title\NamespaceInfo;
28
29 /**
30 * Show information about the different namespaces
31 *
32 * @since 1.43
33 * @author DannyS712
34 * @ingroup SpecialPage
35 */
36 class SpecialNamespaceInfo extends SpecialPage {
37
38 private NamespaceInfo $namespaceInfo;
39
40 public function __construct( NamespaceInfo $namespaceInfo ) {
41 parent::__construct( 'NamespaceInfo' );
42
43 $this->namespaceInfo = $namespaceInfo;
44 }
45
46 /**
47 * @param string|null $par
48 */
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
95 /**
96 * Get the HTML for a row for a specific namespace
97 *
98 * @param int $ns
99 * @param string $localName
100 * @return string
101 */
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
200 /**
201 * @return string
202 */
203 protected function getGroupName() {
204 return 'wiki';
205 }
206
207 }