r1529 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r1528‎ | r1529 | r1530 >
Date:18:31, 7 August 2003
Author:matjordan
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/SpecialUserlogin.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
@@ -20,7 +20,10 @@
2121 $wgMathDirectory = "{$wgUploadDirectory}/math";
2222 $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
2323 $wgEmergencyContact = "wikiadmin@" . getenv( "SERVER_NAME" );
 24+#$wgPasswordSender = "Wikipedia Mail <apache@www.wikipedia.org>";
 25+$wgPasswordSender = "Wikipedia Mail <apache@www.wikipedia.org>\r\nReply-To: webmaster@www.wikipedia.org";
2426
 27+
2528 # MySQL settings
2629 #
2730 $wgDBserver = "localhost";
@@ -62,10 +65,36 @@
6366 $wgLogQueries = false;
6467 $wgUseBetterLinksUpdate = true;
6568
 69+
 70+# The following three config variables are used to define
 71+# the rights of users in your system.
 72+#
6673 # If wgWhitelistEdit is set to true, only logged in users
6774 # are allowed to edit articles.
68 -# $wgWhitelistEdit = true;
 75+# If wgWhitelistRead is set to true, only logged in users
 76+# are allowed to read articles.
 77+#
 78+# wgWhitelistAccount lists user types that can add user accounts:
 79+# "key" => 1 defines permission if user has right "key".
 80+#
 81+# Typical setups are:
 82+#
 83+# Everything goes (this is the default behaviour):
 84+# $wgWhitelistEdit = false;
 85+# $wgWhitelistRead = false;
 86+# $wgWhitelistAccount = array ( "user" => 1, "sysop" => 1, "developer" => 1 );
 87+#
 88+# Invitation-only closed shop type of system
 89+# $wgWhitelistEdit = true;
 90+# $wgWhitelistRead = true;
 91+# $wgWhitelistAccount = array ( "user" => 0, "sysop" => 1, "developer" => 1 );
 92+#
 93+# Public website, closed editorial team
 94+# $wgWhitelistEdit = true;
 95+# $wgWhitelistRead = false;
 96+# $wgWhitelistAccount = array ( "user" => 0, "sysop" => 1, "developer" => 1 );
6997
 98+
7099 # Client-side caching:
71100 $wgCachePages = true; # Allow client-side caching of pages
72101
Index: trunk/phase3/includes/SpecialUserlogin.php
@@ -2,7 +2,8 @@
33
44 function wfSpecialUserlogin()
55 {
6 - global $wpCreateaccount, $wpLoginattempt, $wpMailmypassword;
 6+ global $wpCreateaccount, $wpCreateaccountMail;
 7+ global $wpLoginattempt, $wpMailmypassword;
78 global $action;
89
910 $fields = array( "wpName", "wpPassword", "wpName",
@@ -11,6 +12,8 @@
1213
1314 if ( isset( $wpCreateaccount ) ) {
1415 addNewAccount();
 16+ } else if ( isset( $wpCreateaccountMail ) ) {
 17+ addNewAccountMailPassword();
1518 } else if ( isset( $wpMailmypassword ) ) {
1619 mailPassword();
1720 } else if ( "submit" == $action || isset( $wpLoginattempt ) ) {
@@ -20,11 +23,66 @@
2124 }
2225 }
2326
 27+
 28+/* private */ function addNewAccountMailPassword()
 29+{
 30+ global $wgOut, $wpEmail, $wpName;
 31+
 32+ if ("" == $wpEmail) {
 33+ $m = str_replace( "$1", $wpName, wfMsg( "noemail" ) );
 34+ mainLoginForm( $m );
 35+ return;
 36+ }
 37+
 38+ $u = addNewaccountInternal();
 39+
 40+ if ($u == NULL) {
 41+ return;
 42+ }
 43+
 44+ $u->saveSettings();
 45+ mailPasswordInternal($u);
 46+
 47+ $wgOut->setPageTitle( wfMsg( "accmailtitle" ) );
 48+ $wgOut->setRobotpolicy( "noindex,nofollow" );
 49+ $wgOut->setArticleFlag( false );
 50+
 51+ $m = str_replace( "$1", $u->getName(), wfMsg( "accmailtext" ) );
 52+ $m = str_replace( "$2", $u->getEmail(), $m );
 53+ $wgOut->addWikiText( $m );
 54+ $wgOut->returnToMain( false );
 55+
 56+ $u = 0;
 57+}
 58+
 59+
2460 /* private */ function addNewAccount()
2561 {
2662 global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember;
2763 global $wpEmail, $wgDeferredUpdateList;
2864
 65+ $u = addNewAccountInternal();
 66+
 67+ if ($u == NULL) {
 68+ return;
 69+ }
 70+
 71+ $wgUser = $u;
 72+ $m = str_replace( "$1", $wgUser->getName(), wfMsg( "welcomecreation" ) );
 73+ successfulLogin( $m );
 74+}
 75+
 76+
 77+/* private */ function addNewAccountInternal()
 78+{
 79+ global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember;
 80+ global $wpEmail, $wgDeferredUpdateList;
 81+
 82+ if (!userAllowedToCreateAccount()) {
 83+ userNotPrivilegedMessage();
 84+ return;
 85+ }
 86+
2987 if ( 0 != strcmp( $wpPassword, $wpRetype ) ) {
3088 mainLoginForm( wfMsg( "badretype" ) );
3189 return;
@@ -33,7 +91,7 @@
3492 if ( ( "" == $wpName ) ||
3593 preg_match( "/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/", $wpName ) ||
3694 (strpos( $wpName, "/" ) !== false) )
37 -{
 95+ {
3896 mainLoginForm( wfMsg( "noname" ) );
3997 return;
4098 }
@@ -53,12 +111,13 @@
54112 if ( 1 == $wpRemember ) { $r = 1; }
55113 else { $r = 0; }
56114 $u->setOption( "rememberpassword", $r );
57 -
58 - $wgUser = $u;
59 - $m = str_replace( "$1", $wgUser->getName(), wfMsg( "welcomecreation" ) );
60 - successfulLogin( $m );
 115+
 116+ return $u;
61117 }
62118
 119+
 120+
 121+
63122 /* private */ function processLogin()
64123 {
65124 global $wgUser, $wpName, $wpPassword, $wpRemember;
@@ -118,6 +177,20 @@
119178 $u->setId( $id );
120179 $u->loadFromDatabase();
121180
 181+ if (mailPasswordInternal($u) == NULL) {
 182+ return;
 183+ }
 184+
 185+ $m = str_replace( "$1", $u->getName(), wfMsg( "passwordsent" ) );
 186+ mainLoginForm( $m );
 187+}
 188+
 189+
 190+/* private */ function mailPasswordInternal( $u )
 191+{
 192+ global $wgUser, $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
 193+ global $wgPasswordSender;
 194+
122195 if ( "" == $u->getEmail() ) {
123196 $m = str_replace( "$1", $u->getName(), wfMsg( "noemail" ) );
124197 mainLoginForm( $m );
@@ -136,17 +209,19 @@
137210 $m = str_replace( "$2", $u->getName(), $m );
138211 $m = str_replace( "$3", $np, $m );
139212
140 - #FIXME: Generilize the email addresses for 3rd party sites...
141213 mail( $u->getEmail(), wfMsg( "passwordremindertitle" ), $m,
142214 "MIME-Version: 1.0\r\n" .
143215 "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" .
144216 "Content-transfer-encoding: 8bit\r\n" .
145 - "From: Wikipedia Mail <apache@www.wikipedia.org>\r\n" .
146 - "Reply-To: webmaster@www.wikipedia.org" );
147 - $m = str_replace( "$1", $u->getName(), wfMsg( "passwordsent" ) );
148 - mainLoginForm( $m );
 217+ "From: $wgPasswordSender" );
 218+
 219+ return $u;
149220 }
150221
 222+
 223+
 224+
 225+
151226 /* private */ function successfulLogin( $msg )
152227 {
153228 global $wgUser, $wgOut, $returnto;
@@ -163,6 +238,37 @@
164239 $wgOut->returnToMain();
165240 }
166241
 242+
 243+
 244+/* private */ function userAllowedToCreateAccount()
 245+{
 246+ global $wgUser, $wgWhitelistAccount;
 247+ $allowed = false;
 248+
 249+ if (!$wgWhitelistAccount) { return 1; }; // default behaviour
 250+ foreach ($wgWhitelistAccount as $right => $ok) {
 251+ $userHasRight = (!strcmp($right, "user") || in_array($right, $wgUser->getRights()));
 252+ $allowed |= ($ok && $userHasRight);
 253+ }
 254+ return $allowed;
 255+}
 256+
 257+
 258+function userNotPrivilegedMessage()
 259+{
 260+ global $wgOut, $wgUser, $wgLang;
 261+
 262+ $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) );
 263+ $wgOut->setRobotpolicy( "noindex,nofollow" );
 264+ $wgOut->setArticleFlag( false );
 265+
 266+ $wgOut->addWikiText( wfMsg( "whitelistacctext" ) );
 267+ $wgOut->returnToMain( false );
 268+}
 269+
 270+
 271+
 272+
167273 /* private */ function mainLoginForm( $err )
168274 {
169275 global $wgUser, $wgOut, $wgLang, $returnto;
@@ -178,6 +284,7 @@
179285 $nuo = wfMsg( "newusersonly" );
180286 $li = wfMsg( "login" );
181287 $ca = wfMsg( "createaccount" );
 288+ $cam = wfMsg( "createaccountmail" );
182289 $ye = wfMsg( "youremail" );
183290 $efl = wfMsg( "emailforlost" );
184291 $mmp = wfMsg( "mailmypassword" );
@@ -216,6 +323,10 @@
217324 $wpRetype = wfEscapeHTML( $wpRetype );
218325 $wpEmail = wfEscapeHTML( $wpEmail );
219326
 327+ if ($wgUser->getID() != 0) {
 328+ $cambutton = "<input tabindex=6 type=submit name=\"wpCreateaccountMail\" value=\"{$cam}\">";
 329+ }
 330+
220331 $wgOut->addHTML( "
221332 <form id=\"userlogin\" method=\"post\" action=\"{$action}\">
222333 <table border=0><tr>
@@ -229,8 +340,11 @@
230341 </td>
231342 <td align=left>
232343 <input tabindex=3 type=submit name=\"wpLoginattempt\" value=\"{$li}\">
233 -</td></tr>
234 -<tr><td colspan=3>&nbsp;</td></tr><tr>
 344+</td></tr>");
 345+
 346+ if (userAllowedToCreateAccount($wgUser)) {
 347+
 348+$wgOut->addHTML("<tr><td colspan=3>&nbsp;</td></tr><tr>
235349 <td align=right>$ypa:</td>
236350 <td align=left>
237351 <input tabindex=4 type=password name=\"wpRetype\" value=\"{$wpRetype}\"
@@ -242,7 +356,11 @@
243357 <input tabindex=5 type=text name=\"wpEmail\" value=\"{$wpEmail}\" size=20>
244358 </td><td align=left>
245359 <input tabindex=6 type=submit name=\"wpCreateaccount\" value=\"{$ca}\">
246 -</td></tr>
 360+$cambutton
 361+</td></tr>");
 362+ }
 363+
 364+ $wgOut->addHTML("
247365 <tr>
248366 <td colspan=3 align=left>
249367 <input tabindex=7 type=checkbox name=\"wpRemember\" value=\"1\"$checked>$rmp
@@ -253,6 +371,9 @@
254372 <input tabindex=8 type=submit name=\"wpMailmypassword\" value=\"{$mmp}\">
255373 </td></tr></table>
256374 </form>\n" );
 375+
 376+
 377+
257378 }
258379
259380 ?>
Index: trunk/phase3/languages/Language.php
@@ -467,6 +467,7 @@
468468 "userlogout" => "Log out",
469469 "notloggedin" => "Not logged in",
470470 "createaccount" => "Create new account",
 471+"createaccountmail" => "by eMail",
471472 "badretype" => "The passwords you entered do not match.",
472473 "userexists" => "The user name you entered is already in use. Please choose a different name.",
473474 "youremail" => "Your e-mail*",
@@ -506,8 +507,14 @@
507508 "blockedtext" => "Your user name or IP address has been blocked by $1.
508509 The reason given is this:<br>''$2''<p>You may contact $1 or one of the other
509510 [[Wikipedia:administrators|administrators]] to discuss the block.",
510 -"whitelistedittitle" => "User not logged in",
511 -"whitelistedittext" => "You have to [[Spezial:Userlogin|login]] to edit articles.",
 511+"whitelistedittitle" => "Login required to edit",
 512+"whitelistedittext" => "You have to [[Special:Userlogin|login]] to edit articles.",
 513+"whitelistreadtitle" => "Login required to read",
 514+"whitelistreadtext" => "You have to [[Special:Userlogin|login]] to read articles.",
 515+"whitelistacctitle" => "You are not allowed to create an account",
 516+"whitelistacctext" => "To be allowed to create accounts in this Wiki you have to [[Special:Userlogin|log]] in and have the appropriate permissions.",
 517+"accmailtitle" => "Password sent.",
 518+"accmailtext" => "The Password for '$1' has been sent to $2.",
512519 "newarticle" => "(New)",
513520 "newarticletext" =>
514521 "You've followed a link to a page that doesn't exist yet.

Status & tagging log