jenkins-bot has submitted this change and it was merged.

Change subject: EditPage: Don't throw exceptions for invalid content models
......................................................................


EditPage: Don't throw exceptions for invalid content models

If a user tries to use an unrecognized content model using the "model"
request parameter, show a nice, localized error instead of an exception.

Bug: T145367
Change-Id: I50e7d332727c9afc22c1658d32c981db4305185b
---
M includes/EditPage.php
M languages/i18n/en.json
M languages/i18n/qqq.json
3 files changed, 15 insertions(+), 3 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/EditPage.php b/includes/EditPage.php
index 7e4e411..ed3e212 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -1008,9 +1008,17 @@
                // May be overridden by revision.
                $this->contentFormat = $request->getText( 'format', 
$this->contentFormat );
 
-               if ( !ContentHandler::getForModelID( $this->contentModel )
-                       ->isSupportedFormat( $this->contentFormat )
-               ) {
+               try {
+                       $handler = ContentHandler::getForModelID( 
$this->contentModel );
+               } catch ( MWUnknownContentModelException $e ) {
+                       throw new ErrorPageError(
+                               'editpage-invalidcontentmodel-title',
+                               'editpage-invalidcontentmodel-text',
+                               [ $this->contentModel ]
+                       );
+               }
+
+               if ( !$handler->isSupportedFormat( $this->contentFormat ) ) {
                        throw new ErrorPageError(
                                'editpage-notsupportedcontentformat-title',
                                'editpage-notsupportedcontentformat-text',
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index cc7466b..ad2b6b6 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -777,6 +777,8 @@
        "invalid-content-data": "Invalid content data",
        "content-not-allowed-here": "\"$1\" content is not allowed on page 
[[$2]]",
        "editwarning-warning": "Leaving this page may cause you to lose any 
changes you have made.\nIf you are logged in, you can disable this warning in 
the \"{{int:prefs-editing}}\" section of your preferences.",
+       "editpage-invalidcontentmodel-title": "Content model not supported",
+       "editpage-invalidcontentmodel-text": "The content model \"$1\" is not a 
supported.",
        "editpage-notsupportedcontentformat-title": "Content format not 
supported",
        "editpage-notsupportedcontentformat-text": "The content format $1 is 
not supported by the content model $2.",
        "content-model-wikitext": "wikitext",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index 924d25f..023af97 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -961,6 +961,8 @@
        "invalid-content-data": "Error message indicating that the page's 
content can not be saved because it is invalid. This may occurr for content 
types with internal consistency constraints.",
        "content-not-allowed-here": "Error message indicating that the desired 
content model is not supported in given localtion.\n* $1 - the human readable 
name of the content model: {{msg-mw|Content-model-wikitext}}, 
{{msg-mw|Content-model-javascript}}, {{msg-mw|Content-model-css}} or 
{{msg-mw|Content-model-text}}\n* $2 - the title of the page in question",
        "editwarning-warning": "Uses {{msg-mw|Prefs-editing}}",
+       "editpage-invalidcontentmodel-title": "Title of error page shown when 
using an unrecognized content model on EditPage",
+       "editpage-invalidcontentmodel-text": "Error message shown when using an 
unrecognized content model on EditPage. $1 is the user's invalid input",
        "editpage-notsupportedcontentformat-title": "Title of error page shown 
when using an incompatible format on EditPage.\n\nUsed as title for the 
following error message:\n* 
{{msg-mw|Editpage-notsupportedcontentformat-text}}.",
        "editpage-notsupportedcontentformat-text": "Error message shown when 
using an incompatible format on EditPage.\n\nThe title for this error is 
{{msg-mw|Editpage-notsupportedcontentformat-title}}.\n\nParameters:\n* $1 - the 
format id\n* $2 - the content model name",
        "content-model-wikitext": "Name for the wikitext content model, used 
when decribing what type of content a page contains.\n\nThis message is 
substituted 
in:\n*{{msg-mw|Bad-target-model}}\n*{{msg-mw|Content-not-allowed-here}}",

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I50e7d332727c9afc22c1658d32c981db4305185b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Tpt <thoma...@hotmail.fr>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to