}
}
+ /**
+ * If the user is not logged in, throws UserNotLoggedIn error.
+ *
+ * Default error message includes a link to Special:Userlogin with properly set 'returnto' query
+ * parameter.
+ *
+ * @since 1.23
+ * @param string|Message $reasonMsg [optional] Passed on to UserNotLoggedIn constructor. Strings
+ * will be used as message keys. If a string is given, the message will also receive a
+ * formatted login link (generated using the 'loginreqlink' message) as first parameter. If a
+ * Message is given, it will be passed on verbatim.
+ * @param string|Message $titleMsg [optional] Passed on to UserNotLoggedIn constructor. Strings
+ * will be used as message keys.
+ * @throws UserNotLoggedIn
+ */
+ public function requireLogin( $reasonMsg = null, $titleMsg = null ) {
+ if ( $this->getUser()->isAnon() ) {
+ // Use default messages if not given or explicit null passed
+ if ( !$reasonMsg ) {
+ $reasonMsg = 'exception-nologin-text-manual';
+ }
+ if ( !$titleMsg ) {
+ $titleMsg = 'exception-nologin';
+ }
+
+ // Convert to Messages with current context
+ if ( is_string( $reasonMsg ) ) {
+ $loginreqlink = Linker::linkKnown(
+ SpecialPage::getTitleFor( 'Userlogin' ),
+ $this->msg( 'loginreqlink' )->escaped(),
+ array(),
+ array( 'returnto' => $this->getTitle()->getPrefixedText() )
+ );
+ $reasonMsg = $this->msg( $reasonMsg )->rawParams( $loginreqlink );
+ }
+ if ( is_string( $titleMsg ) ) {
+ $titleMsg = $this->msg( $titleMsg );
+ }
+
+ throw new UserNotLoggedIn( $reasonMsg, $titleMsg );
+ }
+ }
+
/**
* Sets headers - this should be called from the execute() method of all derived classes!
*/
$user = $this->getUser();
$request = $this->getRequest();
- if ( !$user->isLoggedIn() ) {
- $this->error( 'changeemail-no-info' );
-
- return;
- }
+ $this->requireLogin( 'changeemail-no-info' );
if ( $request->wasPosted() && $request->getBool( 'wpCancel' ) ) {
$this->doReturnTo();
// This could also let someone check the current email address, so
// require both permissions.
- if ( !$this->getUser()->isAllowed( 'viewmyprivateinfo' ) ) {
+ if ( !$user->isAllowed( 'viewmyprivateinfo' ) ) {
throw new PermissionsError( 'viewmyprivateinfo' );
}
$this->getOutput()->disallowUserJs();
$request = $this->getRequest();
+
+ if ( !$request->wasPosted() ) {
+ $this->requireLogin( 'resetpass-no-info' );
+ }
+
$this->mUserName = trim( $request->getVal( 'wpName' ) );
$this->mOldpass = $request->getVal( 'wpPassword' );
$this->mNewpass = $request->getVal( 'wpNewPassword' );
$this->mDomain = $request->getVal( 'wpDomain' );
$user = $this->getUser();
- if ( !$request->wasPosted() && !$user->isLoggedIn() ) {
- $this->error( $this->msg( 'resetpass-no-info' )->text() );
-
- return;
- }
if ( $request->wasPosted() && $request->getBool( 'wpCancel' ) ) {
$titleObj = Title::newFromText( $request->getVal( 'returnto' ) );
$this->checkReadOnly();
$this->checkPermissions();
+ $this->requireLogin( 'confirmemail_needlogin' );
+
// This could also let someone check the current email address, so
// require both permissions.
if ( !$this->getUser()->isAllowed( 'viewmyprivateinfo' ) ) {
}
if ( $code === null || $code === '' ) {
- if ( $this->getUser()->isLoggedIn() ) {
- if ( Sanitizer::validateEmail( $this->getUser()->getEmail() ) ) {
- $this->showRequestForm();
- } else {
- $this->getOutput()->addWikiMsg( 'confirmemail_noemail' );
- }
+ if ( Sanitizer::validateEmail( $this->getUser()->getEmail() ) ) {
+ $this->showRequestForm();
} else {
- $llink = Linker::linkKnown(
- SpecialPage::getTitleFor( 'Userlogin' ),
- $this->msg( 'loginreqlink' )->escaped(),
- array(),
- array( 'returnto' => $this->getTitle()->getPrefixedText() )
- );
- $this->getOutput()->addHTML(
- $this->msg( 'confirmemail_needlogin' )->rawParams( $llink )->parse()
- );
+ $this->getOutput()->addWikiMsg( 'confirmemail_noemail' );
}
} else {
$this->attemptConfirm( $code );
public function execute( $mode ) {
$this->setHeaders();
- $out = $this->getOutput();
-
# Anons don't get a watchlist
- if ( $this->getUser()->isAnon() ) {
- $out->setPageTitle( $this->msg( 'watchnologin' ) );
- $llink = Linker::linkKnown(
- SpecialPage::getTitleFor( 'Userlogin' ),
- $this->msg( 'loginreqlink' )->escaped(),
- array(),
- array( 'returnto' => $this->getTitle()->getPrefixedText() )
- );
- $out->addHTML( $this->msg( 'watchlistanontext' )->rawParams( $llink )->parse() );
+ $this->requireLogin( 'watchlistanontext', 'watchnologin' );
- return;
- }
+ $out = $this->getOutput();
$this->checkPermissions();
$this->checkReadOnly();
$out = $this->getOutput();
$out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
- $user = $this->getUser();
- if ( $user->isAnon() ) {
- throw new ErrorPageError(
- 'prefsnologin',
- 'prefsnologintext',
- array( $this->getTitle()->getPrefixedDBkey() )
- );
- }
+ $this->requireLogin( 'prefsnologintext2', 'prefsnologin' );
$this->checkReadOnly();
if ( $par == 'reset' ) {
);
}
- $htmlForm = Preferences::getFormObject( $user, $this->getContext() );
+ $htmlForm = Preferences::getFormObject( $this->getUser(), $this->getContext() );
$htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) );
$htmlForm->show();
public function execute( $par ) {
// This is a preferences page, so no user JS for y'all.
$this->getOutput()->disallowUserJs();
+ $this->requireLogin();
parent::execute( $par );
$output = $this->getOutput();
# Anons don't get a watchlist
- if ( $user->isAnon() ) {
- $output->setPageTitle( $this->msg( 'watchnologin' ) );
- $output->setRobotPolicy( 'noindex,nofollow' );
- $llink = Linker::linkKnown(
- SpecialPage::getTitleFor( 'Userlogin' ),
- $this->msg( 'loginreqlink' )->escaped(),
- array(),
- array( 'returnto' => $this->getTitle()->getPrefixedText() )
- );
- $output->addHTML( $this->msg( 'watchlistanontext' )->rawParams( $llink )->parse() );
- return;
- }
+ $this->requireLogin( 'watchlistanontext', 'watchnologin' );
// Check permissions
$this->checkPermissions();
'invalidtitle-knownnamespace' => 'Invalid title with namespace "$2" and text "$3"',
'invalidtitle-unknownnamespace' => 'Invalid title with unknown namespace number $1 and text "$2"',
'exception-nologin' => 'Not logged in',
-'exception-nologin-text' => 'This page or action requires you to be logged in on this wiki.',
+'exception-nologin-text' => 'Please [[Special:Userlogin|log in]] to be able to access this page or action.',
+'exception-nologin-text-manual' => 'Please $1 to be able to access this page or action.',
# Virus scanner
'virus-badscanner' => "Bad configuration: Unknown virus scanner: ''$1''",
'mypreferences' => 'Preferences',
'prefs-edits' => 'Number of edits:',
'prefsnologin' => 'Not logged in',
-'prefsnologintext' => 'You must be <span class="plainlinks">[{{fullurl:{{#Special:UserLogin}}|returnto=$1}} logged in]</span> to set user preferences.',
+'prefsnologintext2' => 'Please $1 to set user preferences.',
'changepassword' => 'Change password',
'changepassword-summary' => '', # do not translate or duplicate this message to other languages
'prefs-skin' => 'Skin',
'exception-nologin' => 'Generic page title used on error page when a user is not logged in. Message used by the UserNotLoggedIn exception.
{{Identical|Not logged in}}',
'exception-nologin-text' => 'Generic reason displayed on error page when a user is not logged in. Message used by the UserNotLoggedIn exception.',
+'exception-nologin-text-manual' => 'Generic reason displayed on error page when a user is not logged in.
+
+Parameters:
+* $1 - a link to [[Special:UserLogin]] with {{msg-mw|loginreqlink}} as link description',
# Virus scanner
'virus-badscanner' => 'Used as error message. Parameters:
{{Identical|Preferences}}',
'prefs-edits' => 'In user preferences.',
'prefsnologin' => '{{Identical|Not logged in}}',
-'prefsnologintext' => 'Parameters:
-* $1 - URI for "returnto" argument',
+'prefsnologintext2' => 'Parameters:
+* $1 - a link to [[Special:UserLogin]] with {{msg-mw|loginreqlink}} as link description',
'changepassword' => "Section heading on [[Special:Preferences]], tab 'User profile'.
{{Identical|Change password}}",
'prefs-skin' => 'Used in user preferences.
prefs
prefsection
prefsnologin
-prefsnologintext
+prefsnologintext2
prefsubmit
preload
preloads
'invalidtitle-unknownnamespace',
'exception-nologin',
'exception-nologin-text',
+ 'exception-nologin-text-manual',
),
'virus' => array(
'virus-badscanner',
'mypreferences',
'prefs-edits',
'prefsnologin',
- 'prefsnologintext',
+ 'prefsnologintext2',
'changepassword',
'changepassword-summary',
'prefs-skin',