Florianschmidtwelzow has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/376050 )
Change subject: Redirect to Special:UserLogin on private wikis when user is not
logged in
......................................................................
Redirect to Special:UserLogin on private wikis when user is not logged in
Instead of showing a simple error message "You need to login to view this page",
the OutputPage now throws an USerNotLoggedIn exception, which will redirect
to Special:UserLogin if the error message is whitelisted. The userlogin page
will then show the error message (why a login is required) as a warning and
directly provides the form to login.
Bug: T17484
Change-Id: Idf8224d947b786dc0150a515603d04117b172824
---
M RELEASE-NOTES-1.30
M includes/OutputPage.php
M includes/exception/UserNotLoggedIn.php
M includes/specials/helpers/LoginHelper.php
M languages/i18n/en.json
M languages/i18n/qqq.json
6 files changed, 36 insertions(+), 50 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/50/376050/1
diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30
index fb69bfd..8e509724 100644
--- a/RELEASE-NOTES-1.30
+++ b/RELEASE-NOTES-1.30
@@ -66,6 +66,10 @@
** This is currently gated by $wgCommentTableSchemaMigrationStage. Most wikis
can set this to MIGRATION_NEW and run maintenance/migrateComments.php as
soon as any necessary extensions are updated.
+* (T17484) On private wikis (where only logged in users have access to read
pages),
+ users who try to read a page while not being logged in will automatically re-
+ directed to the login page (Special:UserLogin) with an appropriate message
why
+ they need to login to continue.
=== External library changes in 1.30 ===
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index dd21194..cf9b8b5 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -2529,55 +2529,23 @@
&& ( User::groupHasPermission( 'user', $action )
|| User::groupHasPermission( 'autoconfirmed', $action )
)
) {
- $displayReturnto = null;
-
# Due to T34276, if a user does not have read
permissions,
# $this->getTitle() will just give Special:Badtitle,
which is
# not especially useful as a returnto parameter. Use
the title
# from the request instead, if there was one.
$request = $this->getRequest();
$returnto = Title::newFromText( $request->getVal(
'title', '' ) );
- if ( $action == 'edit' ) {
- $msg = 'whitelistedittext';
- $displayReturnto = $returnto;
- } elseif ( $action == 'createpage' || $action ==
'createtalk' ) {
- $msg = 'nocreatetext';
- } elseif ( $action == 'upload' ) {
- $msg = 'uploadnologintext';
+ if ( $action === 'edit' ) {
+ $msg = 'whitelistedit-nologin-text';
+ } elseif ( $action === 'createpage' || $action ===
'createtalk' ) {
+ $msg = 'create-nologin-text';
+ } elseif ( $action === 'upload' ) {
+ $msg = 'upload-nologin-text';
} else { # Read
- $msg = 'loginreqpagetext';
- $displayReturnto = Title::newMainPage();
+ $msg = 'exception-nologin-text';
}
- $query = [];
-
- if ( $returnto ) {
- $query['returnto'] =
$returnto->getPrefixedText();
-
- if ( !$request->wasPosted() ) {
- $returntoquery = $request->getValues();
- unset( $returntoquery['title'] );
- unset( $returntoquery['returnto'] );
- unset( $returntoquery['returntoquery']
);
- $query['returntoquery'] = wfArrayToCgi(
$returntoquery );
- }
- }
- $linkRenderer =
MediaWikiServices::getInstance()->getLinkRenderer();
- $loginLink = $linkRenderer->makeKnownLink(
- SpecialPage::getTitleFor( 'Userlogin' ),
- $this->msg( 'loginreqlink' )->text(),
- [],
- $query
- );
-
- $this->prepareErrorPage( $this->msg( 'loginreqtitle' )
);
- $this->addHTML( $this->msg( $msg )->rawParams(
$loginLink )->parse() );
-
- # Don't return to a page the user can't read otherwise
- # we'll end up in a pointless loop
- if ( $displayReturnto && $displayReturnto->userCan(
'read', $this->getUser() ) ) {
- $this->returnToMain( null, $displayReturnto );
- }
+ throw new UserNotLoggedIn( $msg, 'exception-nologin',
[], $returnto );
} else {
$this->prepareErrorPage( $this->msg(
'permissionserrors' ) );
$this->addWikiText(
$this->formatPermissionsErrorMessage( $errors, $action ) );
diff --git a/includes/exception/UserNotLoggedIn.php
b/includes/exception/UserNotLoggedIn.php
index 6086d55..088e303 100644
--- a/includes/exception/UserNotLoggedIn.php
+++ b/includes/exception/UserNotLoggedIn.php
@@ -53,6 +53,11 @@
class UserNotLoggedIn extends ErrorPageError {
/**
+ * @var Title|null
+ */
+ private $returnTo;
+
+ /**
* @note The value of the $reasonMsg parameter must be put into
LoginForm::validErrorMessages or
* set with the LoginFormValidErrorMessages Hook.
* if you want the user to be automatically redirected to the login
form.
@@ -63,13 +68,20 @@
* Optional, default: 'exception-nologin'
* @param array $params Parameters to wfMessage().
* Optional, default: []
+ * @param Title|null $returnTo The return to target after a succesfull
login, if a redirect
+ * to login will happen. Optional: Defaults to
RequestContext::getMain()->getTitle
*/
public function __construct(
$reasonMsg = 'exception-nologin-text',
$titleMsg = 'exception-nologin',
- $params = []
+ $params = [],
+ $returnTo = null
) {
parent::__construct( $titleMsg, $reasonMsg, $params );
+ $this->returnTo = RequestContext::getMain()->getTitle();
+ if ( $returnTo instanceof Title ) {
+ $this->returnTo = $returnTo;
+ }
}
/**
@@ -83,8 +95,7 @@
parent::report();
}
- // Message is valid. Redirec to Special:Userlogin
-
+ // Message is valid. Redirect to Special:Userlogin
$context = RequestContext::getMain();
$output = $context->getOutput();
@@ -94,7 +105,7 @@
// Redirect to Special:Userlogin
$output->redirect( SpecialPage::getTitleFor( 'Userlogin'
)->getFullURL( [
// Return to this page when the user logs in
- 'returnto' => $context->getTitle()->getFullText(),
+ 'returnto' => $this->returnTo->getFullText(),
'returntoquery' => wfArrayToCgi( $query ),
'warning' => $this->msg,
] ) );
diff --git a/includes/specials/helpers/LoginHelper.php
b/includes/specials/helpers/LoginHelper.php
index a35a420..db3dfcf 100644
--- a/includes/specials/helpers/LoginHelper.php
+++ b/includes/specials/helpers/LoginHelper.php
@@ -20,6 +20,9 @@
*/
public static $validErrorMessages = [
'exception-nologin-text',
+ 'upload-nologin-text',
+ 'create-nologin-text',
+ 'whitelistedit-nologin-text',
'watchlistanontext',
'changeemail-no-info',
'resetpass-no-info',
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index a22e3f0..b9a9a79 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -657,7 +657,7 @@
"autoblockedtext": "Your IP address has been automatically blocked
because it was used by another user, who was blocked by $1.\nThe reason given
is:\n\n:<em>$2</em>\n\n* Start of block: $8\n* Expiration of block: $6\n*
Intended blockee: $7\n\nYou may contact $1 or one of the other
[[{{MediaWiki:Grouppage-sysop}}|administrators]] to discuss the block.\n\nNote
that you may not use the \"email this user\" feature unless you have a valid
email address registered in your [[Special:Preferences|user preferences]] and
you have not been blocked from using it.\n\nYour current IP address is $3, and
the block ID is #$5.\nPlease include all above details in any queries you
make.",
"systemblockedtext": "Your username or IP address has been
automatically blocked by MediaWiki.\nThe reason given is:\n\n:<em>$2</em>\n\n*
Start of block: $8\n* Expiration of block: $6\n* Intended blockee: $7\n\nYour
current IP address is $3.\nPlease include all above details in any queries you
make.",
"blockednoreason": "no reason given",
- "whitelistedittext": "Please $1 to edit pages.",
+ "whitelistedit-nologin-text": "Please login to edit pages.",
"confirmedittext": "You must confirm your email address before editing
pages.\nPlease set and validate your email address through your
[[Special:Preferences|user preferences]].",
"nosuchsectiontitle": "Cannot find section",
"nosuchsectiontext": "You tried to edit a section that does not
exist.\nIt may have been moved or deleted while you were viewing the page.",
@@ -728,6 +728,7 @@
"edittools": "<!-- Text here will be shown below edit and upload forms.
-->",
"edittools-upload": "-",
"nocreatetext": "{{SITENAME}} has restricted the ability to create new
pages.\nYou can go back and edit an existing page, or [[Special:UserLogin|log
in or create an account]].",
+ "create-nologin-text": "Please login to create new pages.",
"nocreate-loggedin": "You do not have permission to create new pages.",
"sectioneditnotsupported-title": "Section editing not supported",
"sectioneditnotsupported-text": "Section editing is not supported in
this page.",
@@ -1530,8 +1531,7 @@
"uploadbtn": "Upload file",
"reuploaddesc": "Cancel upload and return to the upload form",
"upload-tryagain": "Submit modified file description",
- "uploadnologin": "Not logged in",
- "uploadnologintext": "Please $1 to upload files.",
+ "upload-nologin-text": "Please login to be able to upload files.",
"upload_directory_missing": "The upload directory ($1) is missing and
could not be created by the webserver.",
"upload_directory_read_only": "The upload directory ($1) is not
writable by the webserver.",
"uploaderror": "Upload error",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index c30ac2d..8464e6d 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -847,7 +847,7 @@
"autoblockedtext": "Text displayed to automatically blocked
users.\n\n\"email this user\" should be consistent with
{{msg-mw|Emailuser}}.\n\nParameters:\n* $1 - the blocking sysop (with a link to
his/her userpage)\n* $2 - the reason for the block (in case of autoblocks:
{{msg-mw|autoblocker}})\n* $3 - the current IP address of the blocked user\n*
$4 - (Unused) the blocking sysop's username (plain text, without the link). Use
it for GENDER.\n* $5 - the unique numeric identifier of the applied
autoblock\n* $6 - the expiry of the block\n* $7 - the intended target of the
block (what the blocking user specified in the blocking form)\n* $8 - the
timestamp when the block started\nSee also:\n* {{msg-mw|Grouppage-sysop}}\n*
{{msg-mw|Blockedtext}}\n* {{msg-mw|Systemblockedtext}}",
"systemblockedtext": "Text displayed to requests blocked by MediaWiki
configuration.\n\n\"email this user\" should be consistent with
{{msg-mw|Emailuser}}.\n\nParameters:\n* $1 - (Unused) A dummy user attributed
as the blocker, possibly as a link to a user page.\n* $2 - the reason for the
block\n* $3 - the current IP address of the blocked user\n* $4 - (Unused) the
dummy blocking user's username (plain text, without the link).\n* $5 - A short
string indicating the type of system block.\n* $6 - the expiry of the block\n*
$7 - the intended target of the block\n* $8 - the timestamp when the block
started\nSee also:\n* {{msg-mw|Grouppage-sysop}}\n* {{msg-mw|Blockedtext}}\n*
{{msg-mw|Autoblockedtext}}",
"blockednoreason": "Substituted with <code>$2</code> in the following
message if the reason is not given:\n*
{{msg-mw|cantcreateaccount-text}}.\n{{Identical|No reason given}}",
- "whitelistedittext": "Used as error message. Parameters:\n* $1 - a link
to [[Special:UserLogin]] with {{msg-mw|loginreqlink}} as link description\nSee
also:\n* {{msg-mw|Nocreatetext}}\n* {{msg-mw|Uploadnologintext}}\n*
{{msg-mw|Loginreqpagetext}}",
+ "whitelistedit-nologin-text": "Error message displayed on error page
when a user is not logged in and tries to edit when it requires login. Message
used by the UserNotLoggedIn exception.",
"confirmedittext": "Used as error message.",
"nosuchsectiontitle": "Used as error message when the user has
attempted to edit a nonexistent section.",
"nosuchsectiontext": "This message is displayed when a user tries to
edit a section that does not exist.",
@@ -918,6 +918,7 @@
"edittools": "{{optional}}\nThis text will be shown below edit and
upload forms. It can be used to offer special characters not present on most
keyboards for copying/pasting, and also often makes them clickable for
insertion via a JavaScript. Since these are seen as specific to a wiki,
however, this message should not contain anything but an html comment
explaining how it should be used once the wiki has been installed.",
"edittools-upload": "{{optional}}\nThis text will be shown below upload
forms. It will default to the contents of edittools.",
"nocreatetext": "Used as error message.\n\nSee also:\n*
{{msg-mw|Nocreate-loggedin}}\n* {{msg-mw|Whitelistedittext}}\n*
{{msg-mw|Uploadnologintext}}\n* {{msg-mw|Loginreqpagetext}}",
+ "create-nologin-text": "Error message displayed on error page when a
user is not logged in and tries to create a new page when it requires login.
Message used by the UserNotLoggedIn exception.",
"nocreate-loggedin": "Used as error message.\n\nSee also:\n*
{{msg-mw|Nocreatetext}}",
"sectioneditnotsupported-title": "Page title of special page, which
presumably appears when someone tries to edit a section, and section editing is
disabled. Explanation of section editing on
[[meta:Help:Section_editing#Section_editing|meta]].",
"sectioneditnotsupported-text": "I think this is the text of an error
message, which presumably appears when someone tries to edit a section, and
section editing is disabled. Explanation of section editing on
[[meta:Help:Section_editing#Section_editing|meta]].",
@@ -1720,8 +1721,7 @@
"uploadbtn": "Button name in [[Special:Upload]].\n\nSee also:\n*
{{msg-mw|Uploadbtn}}\n* {{msg-mw|Accesskey-upload}}\n*
{{msg-mw|Tooltip-upload}}\n{{Identical|Upload file}}",
"reuploaddesc": "Used as button text in the Upload form on
[[Special:Upload]].\n\nSee also:\n* {{msg-mw|upload-tryagain|Submit button
text}}\n* {{msg-mw|ignorewarning|button text}}",
"upload-tryagain": "Used as Submit button text in
[[Special:Upload]].\n\nSee also:\n* {{msg-mw|Uploaderror|section header}}\n*
{{msg-mw|ignorewarning|button text}}\n* {{msg-mw|reuploaddesc|button text}}",
- "uploadnologin": "Used as title of the error message
{{msg-mw|Uploadnologintext}}.\n{{Identical|Not logged in}}",
- "uploadnologintext": "Used as error message.\n\nThe title for this
message is {{msg-mw|Uploadnologin}}.\n\nParameters:\n* $1 - link text
{{msg-mw|Loginreqlink}}. The link points to [[Special:UserLogin]].\nSee
also:\n* {{msg-mw|Whitelistedittext}}\n* {{msg-mw|Nocreatetext}}\n*
{{msg-mw|Loginreqpagetext}}",
+ "upload-nologin-text": "Error message displayed on error page when a
user is not logged in and accesses [[Special:Upload]] when it requires login.
Message used by the UserNotLoggedIn exception.",
"upload_directory_missing": "Parameters:\n* $1 - directory name",
"upload_directory_read_only": "Parameters:\n* $1 - directory name",
"uploaderror": "Used as section header in [[Special:Upload]].\n\nSee
also:\n* {{msg-mw|upload-tryagain|Submit text}}",
--
To view, visit https://gerrit.wikimedia.org/r/376050
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idf8224d947b786dc0150a515603d04117b172824
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits