From 946bd6ae0bfd9264be99d69e0b6ae04c30cd2750 Mon Sep 17 00:00:00 2001 From: Matthias Jordan Date: Thu, 7 Aug 2003 18:31:42 +0000 Subject: [PATCH] Added support for whitelists for reading and writing articles and for creating user accounts. See DefaultSettings.php for details. Also localized the password reminder eMail sender. --- includes/DefaultSettings.php | 31 ++++++- includes/SpecialUserlogin.php | 149 ++++++++++++++++++++++++++++++---- languages/Language.php | 11 ++- 3 files changed, 174 insertions(+), 17 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f15ea34f57..f5dc756f2b 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -20,6 +20,9 @@ $wgMathPath = "{$wgUploadPath}/math"; $wgMathDirectory = "{$wgUploadDirectory}/math"; $wgTmpDirectory = "{$wgUploadDirectory}/tmp"; $wgEmergencyContact = "wikiadmin@" . getenv( "SERVER_NAME" ); +#$wgPasswordSender = "Wikipedia Mail "; +$wgPasswordSender = "Wikipedia Mail \r\nReply-To: webmaster@www.wikipedia.org"; + # MySQL settings # @@ -62,9 +65,35 @@ $wgSqlLogFile = "{$wgUploadDirectory}/sqllog_mFhyRe6"; $wgLogQueries = false; $wgUseBetterLinksUpdate = true; + +# The following three config variables are used to define +# the rights of users in your system. +# # If wgWhitelistEdit is set to true, only logged in users # are allowed to edit articles. -# $wgWhitelistEdit = true; +# If wgWhitelistRead is set to true, only logged in users +# are allowed to read articles. +# +# wgWhitelistAccount lists user types that can add user accounts: +# "key" => 1 defines permission if user has right "key". +# +# Typical setups are: +# +# Everything goes (this is the default behaviour): +# $wgWhitelistEdit = false; +# $wgWhitelistRead = false; +# $wgWhitelistAccount = array ( "user" => 1, "sysop" => 1, "developer" => 1 ); +# +# Invitation-only closed shop type of system +# $wgWhitelistEdit = true; +# $wgWhitelistRead = true; +# $wgWhitelistAccount = array ( "user" => 0, "sysop" => 1, "developer" => 1 ); +# +# Public website, closed editorial team +# $wgWhitelistEdit = true; +# $wgWhitelistRead = false; +# $wgWhitelistAccount = array ( "user" => 0, "sysop" => 1, "developer" => 1 ); + # Client-side caching: $wgCachePages = true; # Allow client-side caching of pages diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index e409e494b8..8b143cd941 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -2,7 +2,8 @@ function wfSpecialUserlogin() { - global $wpCreateaccount, $wpLoginattempt, $wpMailmypassword; + global $wpCreateaccount, $wpCreateaccountMail; + global $wpLoginattempt, $wpMailmypassword; global $action; $fields = array( "wpName", "wpPassword", "wpName", @@ -11,6 +12,8 @@ function wfSpecialUserlogin() if ( isset( $wpCreateaccount ) ) { addNewAccount(); + } else if ( isset( $wpCreateaccountMail ) ) { + addNewAccountMailPassword(); } else if ( isset( $wpMailmypassword ) ) { mailPassword(); } else if ( "submit" == $action || isset( $wpLoginattempt ) ) { @@ -20,11 +23,66 @@ function wfSpecialUserlogin() } } + +/* private */ function addNewAccountMailPassword() +{ + global $wgOut, $wpEmail, $wpName; + + if ("" == $wpEmail) { + $m = str_replace( "$1", $wpName, wfMsg( "noemail" ) ); + mainLoginForm( $m ); + return; + } + + $u = addNewaccountInternal(); + + if ($u == NULL) { + return; + } + + $u->saveSettings(); + mailPasswordInternal($u); + + $wgOut->setPageTitle( wfMsg( "accmailtitle" ) ); + $wgOut->setRobotpolicy( "noindex,nofollow" ); + $wgOut->setArticleFlag( false ); + + $m = str_replace( "$1", $u->getName(), wfMsg( "accmailtext" ) ); + $m = str_replace( "$2", $u->getEmail(), $m ); + $wgOut->addWikiText( $m ); + $wgOut->returnToMain( false ); + + $u = 0; +} + + /* private */ function addNewAccount() { global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember; global $wpEmail, $wgDeferredUpdateList; + $u = addNewAccountInternal(); + + if ($u == NULL) { + return; + } + + $wgUser = $u; + $m = str_replace( "$1", $wgUser->getName(), wfMsg( "welcomecreation" ) ); + successfulLogin( $m ); +} + + +/* private */ function addNewAccountInternal() +{ + global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember; + global $wpEmail, $wgDeferredUpdateList; + + if (!userAllowedToCreateAccount()) { + userNotPrivilegedMessage(); + return; + } + if ( 0 != strcmp( $wpPassword, $wpRetype ) ) { mainLoginForm( wfMsg( "badretype" ) ); return; @@ -33,7 +91,7 @@ function wfSpecialUserlogin() if ( ( "" == $wpName ) || preg_match( "/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/", $wpName ) || (strpos( $wpName, "/" ) !== false) ) -{ + { mainLoginForm( wfMsg( "noname" ) ); return; } @@ -53,12 +111,13 @@ function wfSpecialUserlogin() if ( 1 == $wpRemember ) { $r = 1; } else { $r = 0; } $u->setOption( "rememberpassword", $r ); - - $wgUser = $u; - $m = str_replace( "$1", $wgUser->getName(), wfMsg( "welcomecreation" ) ); - successfulLogin( $m ); + + return $u; } + + + /* private */ function processLogin() { global $wgUser, $wpName, $wpPassword, $wpRemember; @@ -118,6 +177,20 @@ function wfSpecialUserlogin() $u->setId( $id ); $u->loadFromDatabase(); + if (mailPasswordInternal($u) == NULL) { + return; + } + + $m = str_replace( "$1", $u->getName(), wfMsg( "passwordsent" ) ); + mainLoginForm( $m ); +} + + +/* private */ function mailPasswordInternal( $u ) +{ + global $wgUser, $wpName, $wgDeferredUpdateList, $wgOutputEncoding; + global $wgPasswordSender; + if ( "" == $u->getEmail() ) { $m = str_replace( "$1", $u->getName(), wfMsg( "noemail" ) ); mainLoginForm( $m ); @@ -136,17 +209,19 @@ function wfSpecialUserlogin() $m = str_replace( "$2", $u->getName(), $m ); $m = str_replace( "$3", $np, $m ); - #FIXME: Generilize the email addresses for 3rd party sites... mail( $u->getEmail(), wfMsg( "passwordremindertitle" ), $m, "MIME-Version: 1.0\r\n" . "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" . "Content-transfer-encoding: 8bit\r\n" . - "From: Wikipedia Mail \r\n" . - "Reply-To: webmaster@www.wikipedia.org" ); - $m = str_replace( "$1", $u->getName(), wfMsg( "passwordsent" ) ); - mainLoginForm( $m ); + "From: $wgPasswordSender" ); + + return $u; } + + + + /* private */ function successfulLogin( $msg ) { global $wgUser, $wgOut, $returnto; @@ -163,6 +238,37 @@ function wfSpecialUserlogin() $wgOut->returnToMain(); } + + +/* private */ function userAllowedToCreateAccount() +{ + global $wgUser, $wgWhitelistAccount; + $allowed = false; + + if (!$wgWhitelistAccount) { return 1; }; // default behaviour + foreach ($wgWhitelistAccount as $right => $ok) { + $userHasRight = (!strcmp($right, "user") || in_array($right, $wgUser->getRights())); + $allowed |= ($ok && $userHasRight); + } + return $allowed; +} + + +function userNotPrivilegedMessage() +{ + global $wgOut, $wgUser, $wgLang; + + $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) ); + $wgOut->setRobotpolicy( "noindex,nofollow" ); + $wgOut->setArticleFlag( false ); + + $wgOut->addWikiText( wfMsg( "whitelistacctext" ) ); + $wgOut->returnToMain( false ); +} + + + + /* private */ function mainLoginForm( $err ) { global $wgUser, $wgOut, $wgLang, $returnto; @@ -178,6 +284,7 @@ function wfSpecialUserlogin() $nuo = wfMsg( "newusersonly" ); $li = wfMsg( "login" ); $ca = wfMsg( "createaccount" ); + $cam = wfMsg( "createaccountmail" ); $ye = wfMsg( "youremail" ); $efl = wfMsg( "emailforlost" ); $mmp = wfMsg( "mailmypassword" ); @@ -216,6 +323,10 @@ color='red'>$err\n" ); $wpRetype = wfEscapeHTML( $wpRetype ); $wpEmail = wfEscapeHTML( $wpEmail ); + if ($wgUser->getID() != 0) { + $cambutton = ""; + } + $wgOut->addHTML( "
@@ -229,8 +340,11 @@ color='red'>$err\n" ); - +"); + + if (userAllowedToCreateAccount($wgUser)) { + +$wgOut->addHTML(" +$cambutton +"); + } + + $wgOut->addHTML("
-
 
 
$ypa: -
$rmp @@ -253,6 +371,9 @@ size=20>
\n" ); + + + } ?> diff --git a/languages/Language.php b/languages/Language.php index f7d29dfa6c..24b165126f 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -467,6 +467,7 @@ that it be to the address you give.
\n", "userlogout" => "Log out", "notloggedin" => "Not logged in", "createaccount" => "Create new account", +"createaccountmail" => "by eMail", "badretype" => "The passwords you entered do not match.", "userexists" => "The user name you entered is already in use. Please choose a different name.", "youremail" => "Your e-mail*", @@ -506,8 +507,14 @@ Please log in again after you receive it.", "blockedtext" => "Your user name or IP address has been blocked by $1. The reason given is this:
''$2''

You may contact $1 or one of the other [[Wikipedia:administrators|administrators]] to discuss the block.", -"whitelistedittitle" => "User not logged in", -"whitelistedittext" => "You have to [[Spezial:Userlogin|login]] to edit articles.", +"whitelistedittitle" => "Login required to edit", +"whitelistedittext" => "You have to [[Special:Userlogin|login]] to edit articles.", +"whitelistreadtitle" => "Login required to read", +"whitelistreadtext" => "You have to [[Special:Userlogin|login]] to read articles.", +"whitelistacctitle" => "You are not allowed to create an account", +"whitelistacctext" => "To be allowed to create accounts in this Wiki you have to [[Special:Userlogin|log]] in and have the appropriate permissions.", +"accmailtitle" => "Password sent.", +"accmailtext" => "The Password for '$1' has been sent to $2.", "newarticle" => "(New)", "newarticletext" => "You've followed a link to a page that doesn't exist yet. -- 2.20.1