Mattflaschen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/207984

Change subject: Make sure allowCreation existence status is right, use Status
......................................................................

Make sure allowCreation existence status is right, use Status

Also, add some better logging/error output in Importer and ApiFlow.

Bug: T94953
Change-Id: I47de90108e96c511788f63e64c0e870feff76655
(cherry picked from commit 1fbc345a691e4162ac94dec867ab6a352e6e6dbb)
---
M i18n/en.json
M i18n/qqq.json
M includes/Api/ApiFlow.php
M includes/Import/Importer.php
M includes/Specials/SpecialEnableFlow.php
M includes/TalkpageManager.php
6 files changed, 37 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/84/207984/1

diff --git a/i18n/en.json b/i18n/en.json
index e9448d9..1a8891c 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.<br />The error message 
received was: $1",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 4f381bb..f90cb63 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 6ff81e9..cdc96ca 100644
--- a/includes/Api/ApiFlow.php
+++ b/includes/Api/ApiFlow.php
@@ -107,8 +107,9 @@
                        // 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 7fc35e4..a28848a 100644
--- a/includes/Import/Importer.php
+++ b/includes/Import/Importer.php
@@ -526,10 +526,15 @@
                $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 e89282d..7eaa358 100644
--- a/includes/Specials/SpecialEnableFlow.php
+++ b/includes/Specials/SpecialEnableFlow.php
@@ -82,7 +82,8 @@
                        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 079542b..fed52a7 100644
--- a/includes/TalkpageManager.php
+++ b/includes/TalkpageManager.php
@@ -30,10 +30,13 @@
        /**
         * @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 @@
         * @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 @@
                // 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 @@
                 */
                $this->allowCreation[] = $title->getPrefixedDBkey();
 
-               return true;
+               return Status::newGood();
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/207984
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I47de90108e96c511788f63e64c0e870feff76655
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: wmf/1.26wmf4
Gerrit-Owner: Mattflaschen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to