| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 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 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 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 |
|
| 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 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 202 |
|
| 203 |
protected function getGroupName() { |
| 204 |
return 'wiki'; |
| 205 |
} |
| 206 |
|
| 207 |
} |