X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FEditPage.php;h=6ae4371a104b5fc5a0fc24b5aeb9a60b92aa6c47;hb=e3e33ce99c909103b4b2b861c8361729441eccc8;hp=74ec883a0629eead6dd1150a5a3fce41ce93b1f1;hpb=285cbfde618577a4d8338edfa0205d9bf31d43ab;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 74ec883a06..6ae4371a10 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -689,10 +689,6 @@ class EditPage { # checking, etc. if ( $this->formtype == 'initial' || $this->firsttime ) { if ( $this->initialiseForm() === false ) { - $out = $this->context->getOutput(); - if ( $out->getRedirect() === '' ) { // mcrundo hack redirects, don't override it - $this->noSuchSectionPage(); - } return; } @@ -1131,7 +1127,7 @@ class EditPage { * @return string|null */ protected function importContentFormData( &$request ) { - return; // Don't do anything, EditPage already extracted wpTextbox1 + return null; // Don't do anything, EditPage already extracted wpTextbox1 } /** @@ -1145,8 +1141,26 @@ class EditPage { $content = $this->getContentObject( false ); # TODO: track content object?! if ( $content === false ) { + $out = $this->context->getOutput(); + if ( $out->getRedirect() === '' ) { // mcrundo hack redirects, don't override it + $this->noSuchSectionPage(); + } + return false; + } + + if ( !$this->isSupportedContentModel( $content->getModel() ) ) { + $modelMsg = $this->getContext()->msg( 'content-model-' . $content->getModel() ); + $modelName = $modelMsg->exists() ? $modelMsg->text() : $content->getModel(); + + $out = $this->context->getOutput(); + $out->showErrorPage( + 'modeleditnotsupported-title', + 'modeleditnotsupported-text', + $modelName + ); return false; } + $this->textbox1 = $this->toEditText( $content ); $user = $this->context->getUser(); @@ -1593,7 +1607,8 @@ class EditPage { // This is needed since PageUpdater no longer checks these rights! // Allow bots to exempt some edits from bot flagging - $bot = $this->context->getUser()->isAllowed( 'bot' ) && $this->bot; + $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); + $bot = $permissionManager->userHasRight( $this->context->getUser(), 'bot' ) && $this->bot; $status = $this->internalAttemptSave( $resultDetails, $bot ); Hooks::run( 'EditPage::attemptSave:after', [ $this, $status, $resultDetails ] ); @@ -1784,8 +1799,11 @@ class EditPage { } elseif ( !$status->isOK() ) { # ...or the hook could be expecting us to produce an error // FIXME this sucks, we should just use the Status object throughout + if ( !$status->getErrors() ) { + // Provide a fallback error message if none was set + $status->fatal( 'hookaborted' ); + } $this->hookError = $this->formatStatusErrors( $status ); - $status->fatal( 'hookaborted' ); $status->value = self::AS_HOOK_ERROR_EXPECTED; return false; } @@ -1870,6 +1888,7 @@ ERROR; public function internalAttemptSave( &$result, $bot = false ) { $status = Status::newGood(); $user = $this->context->getUser(); + $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); if ( !Hooks::run( 'EditPage::attemptSave', [ $this ] ) ) { wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" ); @@ -1918,7 +1937,7 @@ ERROR; # Check image redirect if ( $this->mTitle->getNamespace() == NS_FILE && $textbox_content->isRedirect() && - !$user->isAllowed( 'upload' ) + !$permissionManager->userHasRight( $user, 'upload' ) ) { $code = $user->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED; $status->setResult( false, $code ); @@ -1968,7 +1987,7 @@ ERROR; return $status; } - if ( $user->isBlockedFrom( $this->mTitle ) ) { + if ( $permissionManager->isBlockedFrom( $user, $this->mTitle ) ) { // Auto-block user's IP if the account was "hard" blocked if ( !wfReadOnly() ) { $user->spreadAnyEditBlock(); @@ -1988,7 +2007,7 @@ ERROR; return $status; } - if ( !$user->isAllowed( 'edit' ) ) { + if ( !$permissionManager->userHasRight( $user, 'edit' ) ) { if ( $user->isAnon() ) { $status->setResult( false, self::AS_READ_ONLY_PAGE_ANON ); return $status; @@ -1999,15 +2018,13 @@ ERROR; } } - $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); - $changingContentModel = false; if ( $this->contentModel !== $this->mTitle->getContentModel() ) { if ( !$config->get( 'ContentHandlerUseDB' ) ) { $status->fatal( 'editpage-cannot-use-custom-model' ); $status->value = self::AS_CANNOT_USE_CUSTOM_MODEL; return $status; - } elseif ( !$user->isAllowed( 'editcontentmodel' ) ) { + } elseif ( !$permissionManager->userHasRight( $user, 'editcontentmodel' ) ) { $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL ); return $status; } @@ -4152,14 +4169,15 @@ ERROR; * - 'legacy-name' (optional): short name for backwards-compatibility * @param array $checked Array of checkbox name (matching the 'legacy-name') => bool, * where bool indicates the checked status of the checkbox - * @return array + * @return array[] */ public function getCheckboxesDefinition( $checked ) { $checkboxes = []; $user = $this->context->getUser(); // don't show the minor edit checkbox if it's a new page or section - if ( !$this->isNew && $user->isAllowed( 'minoredit' ) ) { + $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); + if ( !$this->isNew && $permissionManager->userHasRight( $user, 'minoredit' ) ) { $checkboxes['wpMinoredit'] = [ 'id' => 'wpMinoredit', 'label-message' => 'minoredit', @@ -4446,8 +4464,8 @@ ERROR; protected function addPageProtectionWarningHeaders() { $out = $this->context->getOutput(); if ( $this->mTitle->isProtected( 'edit' ) && - MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels( - $this->mTitle->getNamespace() + MediaWikiServices::getInstance()->getPermissionManager()->getNamespaceRestrictionLevels( + $this->getTitle()->getNamespace() ) !== [ '' ] ) { # Is the title semi-protected?