From a01f28c8a38e70ddea9abbc64e816918c4500802 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Mon, 6 Jan 2020 17:41:17 +0900 Subject: [PATCH] ApiVisualEditor.php: Add notices also when not blocked Bug: T241693 Change-Id: I2c4355f7a2398b742d635f1de0cf87d4ec527cb3 --- includes/ApiVisualEditor.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/includes/ApiVisualEditor.php b/includes/ApiVisualEditor.php index 96ab94889c..46a7750ae7 100644 --- a/includes/ApiVisualEditor.php +++ b/includes/ApiVisualEditor.php @@ -539,6 +539,14 @@ class ApiVisualEditor extends ApiBase { } } + // Simplified EditPage::getEditPermissionErrors() + // Will be false e.g. if user is blocked or page is protected + $editPermErrors = $title->getUserPermissionsErrors( 'edit', $user, 'full' ); + $canEdit = !( + $editPermErrors || + ( !$title->exists() && $title->getUserPermissionsErrors( 'create', $user, 'full' ) ) + ); + $block = null; $blockinfo = null; $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); @@ -558,15 +566,14 @@ class ApiVisualEditor extends ApiBase { ]; $blockinfo = $this->getBlockDetails( $block ); + } elseif ( $editPermErrors ) { + // For cases where the user is not blocked but has not permission to edit. (e.g. T241693) + $notices[] = $this->msg( + 'permissionserrorstext-withaction', 1, + $this->msg( $title->exists() ? 'action-edit' : 'action-createpage' ) + ) . "
" . call_user_func_array( [ $this, 'msg' ], $editPermErrors[0] )->parse(); } - // Simplified EditPage::getEditPermissionErrors() - // Will be false e.g. if user is blocked or page is protected - $canEdit = !( - $title->getUserPermissionsErrors( 'edit', $user, 'full' ) || - ( !$title->exists() && $title->getUserPermissionsErrors( 'create', $user, 'full' ) ) - ); - // HACK: Build a fake EditPage so we can get checkboxes from it // Deliberately omitting ,0 so oldid comes from request $article = new Article( $title );