EBernhardson has uploaded a new change for review.

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

Change subject: Friendly error message for invalid page within NS_TOPIC
......................................................................

Friendly error message for invalid page within NS_TOPIC

Bug: T75443
Change-Id: I1ab9b575bf43590507e575720da7999877eacf97
---
M autoload.php
M i18n/en.json
M i18n/qqq.json
M includes/Exception/ExceptionHandling.php
M includes/WorkflowLoaderFactory.php
5 files changed, 55 insertions(+), 2 deletions(-)


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

diff --git a/autoload.php b/autoload.php
index 1177875..f83e80c 100644
--- a/autoload.php
+++ b/autoload.php
@@ -125,9 +125,11 @@
        'Flow\\Exception\\InvalidActionException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
        'Flow\\Exception\\InvalidDataException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
        'Flow\\Exception\\InvalidInputException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
+       'Flow\\Exception\\InvalidTopicUuidException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
        'Flow\\Exception\\NoIndexException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
        'Flow\\Exception\\NoParsoidException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
        'Flow\\Exception\\PermissionException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
+       'Flow\\Exception\\UnknownWorkflowIdException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
        'Flow\\Exception\\WikitextException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
        'Flow\\Exception\\WrongNumberArgumentsException' => __DIR__ . 
'/includes/Exception/ExceptionHandling.php',
        'Flow\\FlowActions' => __DIR__ . '/includes/FlowActions.php',
diff --git a/i18n/en.json b/i18n/en.json
index 4737897..4f88828 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -162,6 +162,10 @@
        "flow-error-fetch-after-lock": "An error was encountered when 
requesting the new data. The lock/unlock operation succeeded just fine, though. 
The error message was: $1",
        "flow-error-content-too-long": "The content is too large. Content after 
expansion is limited to $1 {{PLURAL:$1|byte|bytes}}.",
        "flow-error-move": "Moving a discussion board is currently not 
supported.",
+       "flow-error-invalid-topic-uuid-title": "Bad title",
+       "flow-error-invalid-topic-uuid": "The requested page title was invalid. 
Pages in the Topic namespace are automatically created by Flow.",
+       "flow-error-unknown-workflow-id-title": "Unknown topic",
+       "flow-error-unknown-workflow-id": "The requested topic does not exist.",
        "flow-edit-header-placeholder": "Describe this discussion board",
        "flow-edit-header-submit": "Save header",
        "flow-edit-header-submit-overwrite": "Overwrite header",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index f9a9c1a..a489cd8 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -166,6 +166,10 @@
        "flow-error-fetch-after-lock": "Error message to be displayed when 
failing to request the new data after successfully performing lock/unlock 
topic. This is meant to indicate to the user that some error was encountered, 
but that the lock/unlock actually succeeded just fine - we just failed to get 
the new data to display the new status. Parameters:\n* $1 - The error message 
received.",
        "flow-error-content-too-long": "Error message when the expanded(html) 
output of a post is too large.\n\nParameters:\n* $1 - post content lengh limit 
in byte, could be used for plural support.",
        "flow-error-move": "Error message when attempting to move a flow board 
(which is not yet supported)",
+       "flow-error-invalid-topic-uuid-title": "Title displayed at top of page 
and in browser title bar when the user requests a page within the Topic 
namespace that is not a valid UUID",
+       "flow-error-invalid-topic-uuid": "Body of page displayed when the user 
requests a page within the Topic namespace that is not a valid UUID",
+       "flow-error-unknown-workflow-id-title": "Title displayed at top of page 
and in browser title bar when the user requests a page within the Topic 
namespace that is not a known topic",
+       "flow-error-unknown-workflow-id": "Body of page displayed when the user 
requests a page within the Topic namespace that is not a known topic",
        "flow-edit-header-placeholder": "Used as placeholder when editing the 
header of a Flow board",
        "flow-edit-header-submit": "Used as label for the Submit button.",
        "flow-edit-header-submit-overwrite": "Used as label for the Submit 
button, when submitting will overwrite a more recent change.",
diff --git a/includes/Exception/ExceptionHandling.php 
b/includes/Exception/ExceptionHandling.php
index f9bb95f..938047f 100644
--- a/includes/Exception/ExceptionHandling.php
+++ b/includes/Exception/ExceptionHandling.php
@@ -313,3 +313,40 @@
                }
        }
 }
+
+/**
+ * Specific exception thrown when a workflow is requested by id through
+ * WorkflowLoaderFactory and it does not exist.
+ */
+class UnknownWorkflowIdException extends InvalidInputException {
+       protected function getErrorCodeList() {
+               return array( 'invalid-input' );
+       }
+
+       public function getHTML() {
+               return wfMessage( 'flow-error-unknown-workflow-id' )->escaped();
+       }
+
+       public function getPageTitle() {
+               return wfMessage( 'flow-error-unknown-workflow-id-title' 
)->escaped();
+       }
+}
+
+/**
+ * Specific exception thrown when a page within NS_TOPIC is requested
+ * through WorkflowLoaderFactory and it is an invalid uuid
+ */
+class InvalidTopicUuidException extends InvalidInputException {
+       protected function getErrorCodeList() {
+               return array( 'invalid-input' );
+       }
+
+       public function getHTML() {
+               return wfMessage( 'flow-error-invalid-topic-uuid' )->escaped();
+       }
+
+       public function getPageTitle() {
+               return wfMessage( 'flow-error-invalid-topic-uuid-title' 
)->escaped();
+       }
+}
+
diff --git a/includes/WorkflowLoaderFactory.php 
b/includes/WorkflowLoaderFactory.php
index 8ea2547..32598f9 100644
--- a/includes/WorkflowLoaderFactory.php
+++ b/includes/WorkflowLoaderFactory.php
@@ -8,6 +8,8 @@
 use Flow\Exception\CrossWikiException;
 use Flow\Exception\InvalidInputException;
 use Flow\Exception\InvalidDataException;
+use Flow\Exception\InvalidTopicUuidException;
+use Flow\Exception\UnknownWorkflowIdException;
 use Title;
 
 class WorkflowLoaderFactory {
@@ -114,7 +116,7 @@
                /** @var Workflow $workflow */
                $workflow = $this->storage->getStorage( 'Workflow' )->get( 
$workflowId );
                if ( !$workflow ) {
-                       throw new InvalidInputException( 'Invalid workflow 
requested by id', 'invalid-input' );
+                       throw new UnknownWorkflowIdException( 'Invalid workflow 
requested by id', 'invalid-input' );
                }
                if ( $title !== false && !$workflow->matchesTitle( $title ) ) {
                        throw new InvalidInputException( 'Flow workflow is for 
different page', 'invalid-input' );
@@ -147,6 +149,10 @@
                        throw new InvalidInputException( "Title is not from 
NS_TOPIC: $ns", 'invalid-input' );
                }
 
-               return UUID::create( strtolower( $dbKey ) );
+               try {
+                       return UUID::create( strtolower( $dbKey ) );
+               } catch ( InvalidInputException $e ) {
+                       throw new InvalidTopicUuidException( "$dbKey is not a 
valid UUID", 0, $e );
+               }
        }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1ab9b575bf43590507e575720da7999877eacf97
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

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

Reply via email to