From 1ae72a8dc4fcacb9151c2b7af87a2b456b2599e7 Mon Sep 17 00:00:00 2001 From: Reedy Date: Tue, 10 Jul 2018 18:08:33 +0100 Subject: [PATCH] Allow a contact page to require users to be logged in to use it Bug: T199249 Change-Id: I23aad0f6bff14ce80ca8cacc554fcb48ca3473be --- extension.json | 1 + i18n/en.json | 3 ++- i18n/qqq.json | 3 ++- includes/SpecialContact.php | 5 +++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/extension.json b/extension.json index 9a842c9..333ad8e 100644 --- a/extension.json +++ b/extension.json @@ -25,6 +25,7 @@ "SenderName": null, "RequireDetails": false, "IncludeIP": false, + "MustBeLoggedIn": false, "RLModules": [], "RLStyleModules": [], "AdditionalFields": { diff --git a/i18n/en.json b/i18n/en.json index e1ca39e..bb652f5 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -20,5 +20,6 @@ "contactpage-usermailererror": "Mail object returned error:", "contactpage-captcha-error": "CAPTCHA error", "contactpage-config-error-title": "Contact form error", - "contactpage-config-error": "A contact form is either not configured for this page or is configured incorrectly." + "contactpage-config-error": "A contact form is either not configured for this page or is configured incorrectly.", + "contactpage-mustbeloggedin": "Please log in to submit a contact form." } diff --git a/i18n/qqq.json b/i18n/qqq.json index 6de3d5c..59e9d10 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -26,5 +26,6 @@ "contactpage-usermailererror": "Error message displayed when no email could be sent by the MediWiki UserMailer script.", "contactpage-captcha-error": "Error message displayed when there was a CAPTCHA error (i.e. the user failed to enter the correct CAPTCHA, or didn't enter one at all, etc.)", "contactpage-config-error-title": "Page title of Special:Contact when the requested form is configured incorrectly.", - "contactpage-config-error": "Used as the content of Special:Contact when the requested form is configured incorrectly." + "contactpage-config-error": "Used as the content of Special:Contact when the requested form is configured incorrectly.", + "contactpage-mustbeloggedin": "Showed on Special:Userlogin when user tries to use a Contact Page that requires them to be logged in." } diff --git a/includes/SpecialContact.php b/includes/SpecialContact.php index d17a3e3..9cbf186 100644 --- a/includes/SpecialContact.php +++ b/includes/SpecialContact.php @@ -75,6 +75,11 @@ class SpecialContact extends UnlistedSpecialPage { $this->formType = strtolower( $request->getText( 'formtype', $par ) ); $config = $this->getTypeConfig(); + + if ( $config['MustBeLoggedIn'] ) { + $this->requireLogin( 'contactpage-mustbeloggedin' ); + } + if ( !$config['RecipientUser'] ) { $this->getOutput()->showErrorPage( 'contactpage-config-error-title', 'contactpage-config-error' );