From 46c47693fb81d2cbea707e701e72e3a3daf32391 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 12 Sep 2016 02:52:51 -0700 Subject: [PATCH] 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 --- includes/EditPage.php | 14 +++++++++++--- languages/i18n/en.json | 2 ++ languages/i18n/qqq.json | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 7e4e411d5e..ed3e212599 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1008,9 +1008,17 @@ class EditPage { // 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 cc7466b0de..ad2b6b6da9 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 924d25fca4..023af977bc 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}}", -- 2.20.1