From 6ebaa5caf6f2491501a5bb3e8bd1a886e45f4113 Mon Sep 17 00:00:00 2001 From: Roman Stolar Date: Thu, 24 Jun 2021 17:10:43 +0300 Subject: [PATCH] Remove the fallback for create rights (covered in PM edit rights check). Remove key to i18n message, no longer being used. Bug: T272079 Change-Id: Id6566e5241b06ba377c2eca083221ee02556365f --- includes/EditPage.php | 15 --------------- includes/OutputPage.php | 21 +++------------------ includes/api/ApiEditPage.php | 2 +- includes/content/ContentModelChange.php | 3 --- includes/import/WikiImporter.php | 7 ------- includes/page/Article.php | 3 +-- includes/skins/SkinTemplate.php | 5 +---- includes/specials/SpecialSearch.php | 1 - includes/upload/UploadBase.php | 3 --- languages/i18n/en.json | 1 - languages/i18n/qqq.json | 1 - tests/phpunit/includes/OutputPageTest.php | 2 +- 12 files changed, 7 insertions(+), 57 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index f6b595ecb27..b47ff5acfad 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -734,21 +734,6 @@ class EditPage implements IEditObject { $this->mTitle, $rigor ); - # Can this title be created? - if ( !$this->mTitle->exists() ) { - $permErrors = array_merge( - $permErrors, - wfArrayDiff2( - $this->permManager->getPermissionErrors( - 'create', - $user, - $this->mTitle, - $rigor - ), - $permErrors - ) - ); - } # Ignore some permissions errors when a user is just previewing/viewing diffs $remove = []; foreach ( $permErrors as $error ) { diff --git a/includes/OutputPage.php b/includes/OutputPage.php index b437cfb33bf..bfa6aea66f5 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -23,10 +23,8 @@ use MediaWiki\HookContainer\ProtectedHookAccessorTrait; use MediaWiki\Linker\LinkTarget; use MediaWiki\MediaWikiServices; -use MediaWiki\Page\PageIdentity; use MediaWiki\Page\PageRecord; use MediaWiki\Page\PageReference; -use MediaWiki\Permissions\Authority; use MediaWiki\Permissions\PermissionStatus; use MediaWiki\Session\SessionManager; use Wikimedia\Rdbms\IResultWrapper; @@ -3395,9 +3393,9 @@ class OutputPage extends ContextSource { $vars['wgUserVariant'] = $languageConverter->getPreferredVariant(); } // Same test as SkinTemplate - $vars['wgIsProbablyEditable'] = $this->performerCanEditOrCreate( $this->getAuthority(), $title ); + $vars['wgIsProbablyEditable'] = $this->getAuthority()->probablyCan( 'edit', $title ); $vars['wgRelevantPageIsProbablyEditable'] = $relevantTitle && - $this->performerCanEditOrCreate( $this->getAuthority(), $relevantTitle ); + $this->getAuthority()->probablyCan( 'edit', $relevantTitle ); foreach ( $title->getRestrictionTypes() as $type ) { // Following keys are set in $vars: // wgRestrictionCreate, wgRestrictionEdit, wgRestrictionMove, wgRestrictionUpload @@ -3501,19 +3499,6 @@ class OutputPage extends ContextSource { return true; } - /** - * @param Authority $performer - * @param PageIdentity $page - * @return bool - */ - private function performerCanEditOrCreate( - Authority $performer, - PageIdentity $page - ) { - return $performer->probablyCan( 'edit', $page ) - && ( $page->exists() || $performer->probablyCan( 'create', $page ) ); - } - /** * @return array Array in format "link name or number => 'link html'". */ @@ -3576,7 +3561,7 @@ class OutputPage extends ContextSource { # Universal edit button if ( $config->get( 'UniversalEditButton' ) && $this->isArticleRelated() ) { - if ( $this->performerCanEditOrCreate( $this->getAuthority(), $this->getTitle() ) ) { + if ( $this->getAuthority()->probablyCan( 'edit', $this->getTitle() ) ) { // Original UniversalEditButton $msg = $this->msg( 'edit' )->text(); $tags['universal-edit-button'] = Html::element( 'link', [ diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index d5e76ba5d74..6104a139627 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -156,7 +156,7 @@ class ApiEditPage extends ApiBase { // Now let's check whether we're even allowed to do this $this->checkTitleUserPermissions( $titleObj, - $titleObj->exists() ? 'edit' : [ 'edit', 'create' ], + 'edit', [ 'autoblock' => true ] ); diff --git a/includes/content/ContentModelChange.php b/includes/content/ContentModelChange.php index 258bdf49531..16a2ee520af 100644 --- a/includes/content/ContentModelChange.php +++ b/includes/content/ContentModelChange.php @@ -113,9 +113,6 @@ class ContentModelChange { $titleWithNewContentModel->setContentModel( $this->newModel ); $status = PermissionStatus::newEmpty(); - if ( !$current->exists() ) { - $authorizer( 'create', $current, $status ); - } $authorizer( 'editcontentmodel', $current, $status ); $authorizer( 'edit', $current, $status ); $authorizer( 'editcontentmodel', $titleWithNewContentModel, $status ); diff --git a/includes/import/WikiImporter.php b/includes/import/WikiImporter.php index 3001304e28d..6eeaaf87b2e 100644 --- a/includes/import/WikiImporter.php +++ b/includes/import/WikiImporter.php @@ -1327,13 +1327,6 @@ class WikiImporter { return false; } - - if ( !$title->exists() && !$this->permissionManager->userCan( 'create', $user, $title ) ) { - # Do not import if the importing wiki user cannot create this page - $this->notice( 'import-error-create', $title->getPrefixedText() ); - - return false; - } } return [ $title, $foreignTitle ]; diff --git a/includes/page/Article.php b/includes/page/Article.php index 3ced9c676d2..7a109e9d2ce 100644 --- a/includes/page/Article.php +++ b/includes/page/Article.php @@ -1475,8 +1475,7 @@ class Article implements Page { $text = wfMessage( 'missing-revision', $oldid )->plain(); } - } elseif ( $this->getContext()->getAuthority()->probablyCan( 'create', $title ) && - $this->getContext()->getAuthority()->probablyCan( 'edit', $title ) + } elseif ( $this->getContext()->getAuthority()->probablyCan( 'edit', $title ) ) { $message = $isRegistered ? 'noarticletext' : 'noarticletextanon'; $text = wfMessage( $message )->plain(); diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php index 38ea975cc2a..06ae0753c14 100644 --- a/includes/skins/SkinTemplate.php +++ b/includes/skins/SkinTemplate.php @@ -1058,10 +1058,7 @@ class SkinTemplate extends Skin { } // Checks if user can edit the current page if it exists or create it otherwise - if ( $this->getAuthority()->probablyCan( 'edit', $title ) && - ( $title->exists() || - $this->getAuthority()->probablyCan( 'create', $title ) ) - ) { + if ( $this->getAuthority()->probablyCan( 'edit', $title ) ) { // Builds CSS class for talk page links $isTalkClass = $isTalk ? ' istalk' : ''; // Whether the user is editing the page diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 24d3d109743..5d64cc6ad8e 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -594,7 +594,6 @@ class SpecialSearch extends SpecialPage { } elseif ( $this->contentHandlerFactory->getContentHandler( $title->getContentModel() ) ->supportsDirectEditing() - && $this->getAuthority()->probablyCan( 'create', $title ) && $this->getAuthority()->probablyCan( 'edit', $title ) ) { $messageName = 'searchmenu-new'; diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 4bdfab81995..064bb5a93ab 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -660,9 +660,6 @@ abstract class UploadBase { $status = PermissionStatus::newEmpty(); $performer->authorizeWrite( 'edit', $nt, $status ); $performer->authorizeWrite( 'upload', $nt, $status ); - if ( !$nt->exists() ) { - $performer->authorizeWrite( 'create', $nt, $status ); - } if ( !$status->isGood() ) { return $status->toLegacyErrorArray(); } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index b135d383a23..e801e8f19d7 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3033,7 +3033,6 @@ "import-token-mismatch": "Loss of session data.\n\nYou might have been logged out. '''Please verify that you're still logged in and try again'''.\nIf it still does not work, try [[Special:UserLogout|logging out]] and logging back in, and check that your browser allows cookies from this site.", "import-invalid-interwiki": "Cannot import from the specified wiki.", "import-error-edit": "Page \"$1\" was not imported because you are not allowed to edit it.", - "import-error-create": "Page \"$1\" was not imported because you are not allowed to create it.", "import-error-interwiki": "Page \"$1\" was not imported because its name is reserved for external linking (interwiki).", "import-error-special": "Page \"$1\" was not imported because it belongs to a special namespace that does not allow pages.", "import-error-invalid": "Page \"$1\" was not imported because the name to which it would be imported is invalid on this wiki.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 27730cbd03a..77909d721cf 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3257,7 +3257,6 @@ "import-token-mismatch": "Used as error message in [[Special:Import]].\n\nSee also:\n* {{msg-mw|import-invalid-interwiki}}\n* {{msg-mw|Importunknownsource}}\n\n{{Identical|Loss of session data}}", "import-invalid-interwiki": "Used as error message in [[Special:Import]].\n\nSee also:\n* {{msg-mw|import-token-mismatch}}\n* {{msg-mw|import-invalid-interwiki}}\n* {{msg-mw|Importunknownsource}}", "import-error-edit": "Import error message displayed when importing user has no edit rights for a page.\n\nParameters:\n* $1 - a page name\n{{Related|Import-error}}", - "import-error-create": "Import error message displayed when importing user has no create rights for a page.\n\nParameters:\n* $1 - a page name\n{{Related|Import-error}}", "import-error-interwiki": "Used as error message when importing pages. Parameters:\n* $1 - page title\n{{Related|Import-error}}", "import-error-special": "Used as error message when importing pages. Parameters:\n* $1 - page title\n{{Related|Import-error}}", "import-error-invalid": "Used as error message when importing pages. Parameters:\n* $1 - page title\n{{Related|Import-error}}", diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index cd464884725..5929684df72 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -3198,7 +3198,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase { /** * @dataProvider provideGetJsVarsEditable - * @covers OutputPage::performerCanEditOrCreate + * @covers OutputPage::getJSVars */ public function testGetJsVarsEditable( Authority $performer, array $expectedEditableConfig ) { $op = $this->newInstance( [], null, null, $performer );