}
protected function appendNamespaces( $property ) {
+ $nsProtection = $this->getConfig()->get( 'NamespaceProtection' );
+
$data = [
ApiResult::META_TYPE => 'assoc',
];
$data[$ns]['content'] = $nsInfo->isContent( $ns );
$data[$ns]['nonincludable'] = $nsInfo->isNonincludable( $ns );
+ if ( isset( $nsProtection[$ns] ) ) {
+ if ( is_array( $nsProtection[$ns] ) ) {
+ $specificNs = implode( "|", array_filter( $nsProtection[$ns] ) );
+ } elseif ( $nsProtection[$ns] !== '' ) {
+ $specificNs = $nsProtection[$ns];
+ }
+ if ( isset( $specificNs ) && $specificNs !== '' ) {
+ $data[$ns]['namespaceprotection'] = $specificNs;
+ }
+ }
+
$contentmodel = $nsInfo->getNamespaceContentModel( $ns );
if ( $contentmodel ) {
$data[$ns]['defaultcontentmodel'] = $contentmodel;
$this->assertSame( 'Need more donations', $data['readonlyreason'] );
}
- public function testNamespaces() {
- $this->setMwGlobals( 'wgExtraNamespaces', [ '138' => 'Testing' ] );
+ public function testNamespacesBasic() {
+ $this->assertSame(
+ array_keys( MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces() ),
+ array_keys( $this->doQuery( 'namespaces' ) )
+ );
+ }
+ public function testNamespacesExtraNS() {
+ $this->setMwGlobals( 'wgExtraNamespaces', [ '138' => 'Testing' ] );
$this->assertSame(
array_keys( MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces() ),
array_keys( $this->doQuery( 'namespaces' ) )
);
}
+ public function testNamespacesProtection() {
+ $this->setMwGlobals(
+ 'wgNamespaceProtection',
+ [
+ '0' => '',
+ '2' => [ '' ],
+ '4' => 'editsemiprotected',
+ '8' => [
+ 'editinterface',
+ 'noratelimit'
+ ],
+ '14' => [
+ 'move-categorypages',
+ ''
+ ]
+ ]
+ );
+ $data = $this->doQuery( 'namespaces' );
+ $this->assertArrayNotHasKey( 'namespaceprotection', $data['0'] );
+ $this->assertArrayNotHasKey( 'namespaceprotection', $data['2'] );
+ $this->assertSame( 'editsemiprotected', $data['4']['namespaceprotection'] );
+ $this->assertSame( 'editinterface|noratelimit', $data['8']['namespaceprotection'] );
+ $this->assertSame( 'move-categorypages', $data['14']['namespaceprotection'] );
+ }
+
public function testNamespaceAliases() {
global $wgNamespaceAliases;