From 77bcb3a1b1d6896114e1a25e874a44672ac24c5e Mon Sep 17 00:00:00 2001 From: DannyS712 Date: Sat, 11 Apr 2020 00:49:04 +0000 Subject: [PATCH] immobile-source-namespace: use `blanknamespace` for main namespace Also for target-namespace Bug: T224350 Change-Id: I878b5f7ea1d2cebfc295bf08de372726a580cc28 --- includes/MovePage.php | 12 ++++++++++-- includes/Permissions/PermissionManager.php | 12 ++++++++++-- tests/phpunit/includes/MovePageTest.php | 9 +++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/includes/MovePage.php b/includes/MovePage.php index 5a0f04c6554..9ec463b23dd 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -203,7 +203,11 @@ class MovePage { } elseif ( $this->oldTitle->isExternal() ) { $status->fatal( 'immobile-source-namespace-iw' ); } elseif ( !$this->oldTitle->isMovable() ) { - $status->fatal( 'immobile-source-namespace', $this->oldTitle->getNsText() ); + $nsText = $this->oldTitle->getNsText(); + if ( $nsText === '' ) { + $nsText = wfMessage( 'blanknamespace' )->text(); + } + $status->fatal( 'immobile-source-namespace', $nsText ); } elseif ( !$this->oldTitle->exists() ) { $status->fatal( 'movepage-source-doesnt-exist' ); } @@ -211,7 +215,11 @@ class MovePage { if ( $this->newTitle->isExternal() ) { $status->fatal( 'immobile-target-namespace-iw' ); } elseif ( !$this->newTitle->isMovable() ) { - $status->fatal( 'immobile-target-namespace', $this->newTitle->getNsText() ); + $nsText = $this->newTitle->getNsText(); + if ( $nsText === '' ) { + $nsText = wfMessage( 'blanknamespace' )->text(); + } + $status->fatal( 'immobile-target-namespace', $nsText ); } if ( !$this->newTitle->isValid() ) { $status->fatal( 'movepage-invalid-target-title' ); diff --git a/includes/Permissions/PermissionManager.php b/includes/Permissions/PermissionManager.php index ef8f640b4d5..6caecf72e17 100644 --- a/includes/Permissions/PermissionManager.php +++ b/includes/Permissions/PermissionManager.php @@ -965,14 +965,22 @@ class PermissionManager { // Check for immobile pages if ( !$this->nsInfo->isMovable( $title->getNamespace() ) ) { // Specific message for this case - $errors[] = [ 'immobile-source-namespace', $title->getNsText() ]; + $nsText = $title->getNsText(); + if ( $nsText === '' ) { + $nsText = wfMessage( 'blanknamespace' )->text(); + } + $errors[] = [ 'immobile-source-namespace', $nsText ]; } elseif ( !$title->isMovable() ) { // Less specific message for rarer cases $errors[] = [ 'immobile-source-page' ]; } } elseif ( $action == 'move-target' ) { if ( !$this->nsInfo->isMovable( $title->getNamespace() ) ) { - $errors[] = [ 'immobile-target-namespace', $title->getNsText() ]; + $nsText = $title->getNsText(); + if ( $nsText === '' ) { + $nsText = wfMessage( 'blanknamespace' )->text(); + } + $errors[] = [ 'immobile-target-namespace', $nsText ]; } elseif ( !$title->isMovable() ) { $errors[] = [ 'immobile-target-page' ]; } diff --git a/tests/phpunit/includes/MovePageTest.php b/tests/phpunit/includes/MovePageTest.php index 19c39f7505f..919572b08bd 100644 --- a/tests/phpunit/includes/MovePageTest.php +++ b/tests/phpunit/includes/MovePageTest.php @@ -265,14 +265,15 @@ class MovePageTest extends MediaWikiTestCase { 'Aborted by hook' => [ 'Hooked in place', 'Nonexistent', - // @todo Error is wrong - [ [ 'immobile-source-namespace', '' ] ], + [ [ 'immobile-source-namespace', '(Main)' ] ], ], 'Doubly aborted by hook' => [ 'Hooked in place', 'Hooked In Place', - // @todo Both errors are wrong - [ [ 'immobile-source-namespace', '' ], [ 'immobile-target-namespace', '' ] ], + [ + [ 'immobile-source-namespace', '(Main)' ], + [ 'immobile-target-namespace', '(Main)' ] + ], ], 'Non-file to file' => [ 'Existent', 'File:Nonexistent.jpg', [ [ 'nonfile-cannot-move-to-file' ] ] ],