Added support for whitelists for reading and writing articles and for
authorMatthias Jordan <matjordan@users.mediawiki.org>
Thu, 7 Aug 2003 18:31:42 +0000 (18:31 +0000)
committerMatthias Jordan <matjordan@users.mediawiki.org>
Thu, 7 Aug 2003 18:31:42 +0000 (18:31 +0000)
creating user accounts. See DefaultSettings.php for details.

Also localized the password reminder eMail sender.

includes/DefaultSettings.php
includes/SpecialUserlogin.php
languages/Language.php

index f15ea34..f5dc756 100644 (file)
@@ -20,6 +20,9 @@ $wgMathPath         = "{$wgUploadPath}/math";
 $wgMathDirectory    = "{$wgUploadDirectory}/math";
 $wgTmpDirectory     = "{$wgUploadDirectory}/tmp";
 $wgEmergencyContact = "wikiadmin@" . getenv( "SERVER_NAME" );
+#$wgPasswordSender     = "Wikipedia Mail <apache@www.wikipedia.org>";
+$wgPasswordSender      = "Wikipedia Mail <apache@www.wikipedia.org>\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
index e409e49..8b143cd 100644 (file)
@@ -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 <apache@www.wikipedia.org>\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</font>\n" );
        $wpRetype = wfEscapeHTML( $wpRetype );
        $wpEmail = wfEscapeHTML( $wpEmail );
 
+       if ($wgUser->getID() != 0) {
+               $cambutton = "<input tabindex=6 type=submit name=\"wpCreateaccountMail\" value=\"{$cam}\">";
+       }
+
        $wgOut->addHTML( "
 <form id=\"userlogin\" method=\"post\" action=\"{$action}\">
 <table border=0><tr>
@@ -229,8 +340,11 @@ color='red'>$err</font>\n" );
 </td>
 <td align=left>
 <input tabindex=3 type=submit name=\"wpLoginattempt\" value=\"{$li}\">
-</td></tr>
-<tr><td colspan=3>&nbsp;</td></tr><tr>
+</td></tr>");
+
+       if (userAllowedToCreateAccount($wgUser)) {
+
+$wgOut->addHTML("<tr><td colspan=3>&nbsp;</td></tr><tr>
 <td align=right>$ypa:</td>
 <td align=left>
 <input tabindex=4 type=password name=\"wpRetype\" value=\"{$wpRetype}\" 
@@ -242,7 +356,11 @@ size=20>
 <input tabindex=5 type=text name=\"wpEmail\" value=\"{$wpEmail}\" size=20>
 </td><td align=left>
 <input tabindex=6 type=submit name=\"wpCreateaccount\" value=\"{$ca}\">
-</td></tr>
+$cambutton
+</td></tr>");
+       }
+
+       $wgOut->addHTML("
 <tr>
 <td colspan=3 align=left>
 <input tabindex=7 type=checkbox name=\"wpRemember\" value=\"1\"$checked>$rmp
@@ -253,6 +371,9 @@ size=20>
 <input tabindex=8 type=submit name=\"wpMailmypassword\" value=\"{$mmp}\">
 </td></tr></table>
 </form>\n" );
+
+
+
 }
 
 ?>
index f7d29df..24b1651 100644 (file)
@@ -467,6 +467,7 @@ that it be to the address you give.<br>\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:<br>''$2''<p>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.