diff --git a/i18n/en.json b/i18n/en.json index e9448d979d..1a8891cb85 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -114,6 +114,9 @@ "flow-topic-notification-subscribe-description": "{{GENDER:$1|You}} will receive notifications on all activities on this topic.", "flow-board-notification-subscribe-title": "{{GENDER:$1|You're}} subscribed to this discussion board!", "flow-board-notification-subscribe-description": "{{GENDER:$1|You}} will get a notification when a new topic is created on this board.", + "flow-error-allowcreation-no-usedb": "allowCreation requires $wgContentHandlerUseDB to be true", + "flow-error-allowcreation-already-exists": "Page already exists, but was required not to", + "flow-error-allowcreation-flow-create-board": "User does not have the \"{{int:right-flow-create-board}}\" permission", "flow-error-http": "An error occurred while contacting the server.", "flow-error-other": "An unexpected error occurred.", "flow-error-external": "An error occurred.
The error message received was: $1", diff --git a/i18n/qqq.json b/i18n/qqq.json index 4f381bbc49..f90cb63322 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -119,6 +119,9 @@ "flow-topic-notification-subscribe-description": "Description text for the overlay when a topic is added to watchlist.", "flow-board-notification-subscribe-title": "Title text for the overlay when a board is added to watchlist.", "flow-board-notification-subscribe-description": "Description text for the overlay when a board is added to watchlist.", + "flow-error-allowcreation-no-usedb": "Internal error when allowCreation is used and $wgContentHandlerUseDB is not set to true", + "flow-error-allowcreation-already-exists": "Internal error when allowCreation is called with $mustNotExist true, but the page does already exist", + "flow-error-allowcreation-flow-create-board": "Internal error when allowCreation is called and user does not have flow-create-board", "flow-error-http": "Used as error message on HTTP error.", "flow-error-other": "Used as generic error message.", "flow-error-external": "Uses as error message. Parameters:\n* $1 - error message\nSee also:\n* {{msg-mw|Flow-error-external-multi}}", diff --git a/includes/Api/ApiFlow.php b/includes/Api/ApiFlow.php index 6ff81e9152..cdc96ca39a 100644 --- a/includes/Api/ApiFlow.php +++ b/includes/Api/ApiFlow.php @@ -107,8 +107,9 @@ protected function getPage( $params ) { // just check for permissions, nothing else to do. if the commit // is successful the OccupationListener will see the new revision // and put the flow board in place. - if ( !$controller->allowCreation( $page, $this->getUser() ) ) { - $this->dieUsage( 'Page provided does not have Flow enabled', 'invalid-page' ); + $status = $controller->allowCreation( $page, $this->getUser() ); + if ( !$status->isGood() ) { + $this->dieUsage( "Page provided does not have Flow enabled and allowCreation failed with: " . $status->getMessage()->parse(), 'invalid-page' ); } } diff --git a/includes/Import/Importer.php b/includes/Import/Importer.php index 7fc35e4723..a28848aa7c 100644 --- a/includes/Import/Importer.php +++ b/includes/Import/Importer.php @@ -526,10 +526,15 @@ public function import( PageImportState $state ) { $isNew = $state->boardWorkflow->isNew(); $state->logger->debug( 'Workflow isNew: ' . var_export( $isNew, true ) ); if ( $isNew ) { - $this->occupationController->allowCreation( + $allowCreationStatus = $this->occupationController->allowCreation( $destinationTitle, - $this->occupationController->getTalkpageManager() + $this->occupationController->getTalkpageManager(), + /* $mustNotExist = */ true ); + if ( !$allowCreationStatus->isGood() ) { + throw new ImportException( "allowCreation failed to allow the import destination, with the following error:\n" . $allowCreationStatus->getWikiText() ); + } + $status = $this->occupationController->ensureFlowRevision( new Article( $destinationTitle ), $state->boardWorkflow diff --git a/includes/Specials/SpecialEnableFlow.php b/includes/Specials/SpecialEnableFlow.php index e89282d65a..7eaa358c14 100644 --- a/includes/Specials/SpecialEnableFlow.php +++ b/includes/Specials/SpecialEnableFlow.php @@ -82,7 +82,8 @@ public function onSubmit( array $data ) { return Status::newFatal( 'flow-special-enableflow-board-already-exists', $page ); } - if ( !$this->occupationController->allowCreation( $title, $this->getUser(), false ) ) { + $allowCreationStatus = $this->occupationController->allowCreation( $title, $this->getUser(), false ); + if ( !$allowCreationStatus->isGood() ) { return Status::newFatal( 'flow-special-enableflow-board-creation-not-allowed', $page ); } diff --git a/includes/TalkpageManager.php b/includes/TalkpageManager.php index 079542b21d..fed52a7fb8 100644 --- a/includes/TalkpageManager.php +++ b/includes/TalkpageManager.php @@ -30,10 +30,13 @@ public function ensureFlowRevision( Article $title, Workflow $workflow ); /** * @param Title $title * @param User $user - * @return bool Returns true when the provided user has the rights to - * convert $title from whatever it is now to a flow board. + * @param bool $mustNotExist Whether the page is required to not exist; defaults to + * true. + * @return Status Returns successful status when the provided user has the rights to + * convert $title from whatever it is now to a flow board; otherwise, specifies + * the error. */ - public function allowCreation( Title $title, User $user ); + public function allowCreation( Title $title, User $user, $mustNotExist = true ); /** * Gives a user object used to manage talk pages @@ -169,7 +172,9 @@ public function ensureFlowRevision( Article $article, Workflow $workflow ) { * @param User $user User who wants to create a board * @param bool $mustNotExist Whether the page is required to not exist; defaults to * true. - * @return bool + * @return Status Returns successful status when the provided user has the rights to + * convert $title from whatever it is now to a flow board; otherwise, specifies + * the error. */ public function allowCreation( Title $title, User $user, $mustNotExist = true ) { global $wgContentHandlerUseDB; @@ -177,19 +182,24 @@ public function allowCreation( Title $title, User $user, $mustNotExist = true ) // Arbitrary pages can only be enabled when content handler // can store that content model in the database. if ( !$wgContentHandlerUseDB ) { - return false; + return Status::newFatal( 'flow-error-allowcreation-no-usedb' ); } // Only allow converting a non-existent page to flow - if ( $mustNotExist && $title->exists() ) { - return false; + if ( $mustNotExist ) { + // Make sure existence status is up to date + $title->getArticleID( Title::GAID_FOR_UPDATE ); + + if ( $title->exists() ) { + return Status::newFatal( 'flow-error-allowcreation-already-exists' ); + } } // Gate this on the flow-create-board right, essentially giving // wiki communities control over if flow board creation is allowed // to everyone or just a select few. if ( !$user->isAllowedAll( 'flow-create-board' ) ) { - return false; + return Status::newFatal( 'flow-error-allowcreation-flow-create-board' ); } /* @@ -199,7 +209,7 @@ public function allowCreation( Title $title, User $user, $mustNotExist = true ) */ $this->allowCreation[] = $title->getPrefixedDBkey(); - return true; + return Status::newGood(); } /**