Nov. branch merge. Various features backported from stable, various bug fixes.
[lhc/web/wiklou.git] / includes / SpecialUserlogin.php
index 803cafd..66f8d83 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,19 +23,78 @@ 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();
+       if (mailPasswordInternal($u) == NULL)
+       {
+               return;  
+       }
+
+       $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 (!$wgUser->isAllowedToCreateAccount()) {
+               userNotPrivilegedMessage();
+               return;
+       }
+
        if ( 0 != strcmp( $wpPassword, $wpRetype ) ) {
                mainLoginForm( wfMsg( "badretype" ) );
                return;
        }
        $wpName = trim( $wpName );
        if ( ( "" == $wpName ) ||
-         preg_match( "/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/", $wpName ) ) 
-{
+         preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $wpName ) ||
+         (strpos( $wpName, "/" ) !== false) ) 
+       {
                mainLoginForm( wfMsg( "noname" ) );
                return;
        }
@@ -52,12 +114,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;
@@ -117,6 +180,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 $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
+       global $wgPasswordSender;
+
        if ( "" == $u->getEmail() ) {
                $m = str_replace( "$1", $u->getName(), wfMsg( "noemail" ) );
                mainLoginForm( $m );
@@ -135,17 +212,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;
@@ -162,6 +241,25 @@ function wfSpecialUserlogin()
        $wgOut->returnToMain();
 }
 
+
+
+
+
+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;
@@ -177,6 +275,7 @@ function wfSpecialUserlogin()
        $nuo = wfMsg( "newusersonly" );
        $li = wfMsg( "login" );
        $ca = wfMsg( "createaccount" );
+       $cam = wfMsg( "createaccountmail" );
        $ye = wfMsg( "youremail" );
        $efl = wfMsg( "emailforlost" );
        $mmp = wfMsg( "mailmypassword" );
@@ -215,43 +314,57 @@ 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 name='userlogin' method=post action=\"{$action}\">
+<form id=\"userlogin\" method=\"post\" action=\"{$action}\">
 <table border=0><tr>
 <td align=right>$yn:</td>
 <td colspan=2 align=left>
-<input tabindex=1 type=text name='wpName' value=\"{$name}\" size=20>
+<input tabindex=1 type=text name=\"wpName\" value=\"{$name}\" size=20>
 </td></tr><tr>
 <td align=right>$yp:</td>
 <td align=left>
-<input tabindex=2 type=password name='wpPassword' value=\"{$pwd}\" size=20>
+<input tabindex=2 type=password name=\"wpPassword\" value=\"{$pwd}\" size=20>
 </td>
 <td align=left>
-<input tabindex=3 type=submit name='wpLoginattempt' value=\"{$li}\">
-</td></tr>
-<tr><td colspan=3>&nbsp;</td></tr><tr>
+<input tabindex=3 type=submit name=\"wpLoginattempt\" value=\"{$li}\">
+</td></tr>");
+
+       if ($wgUser->isAllowedToCreateAccount()) {
+
+$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}\" 
+<input tabindex=4 type=password name=\"wpRetype\" value=\"{$wpRetype}\" 
 size=20>
 </td><td>$nuo</td></tr>
 <tr>
 <td align=right>$ye:</td>
 <td align=left>
-<input tabindex=5 type=text name='wpEmail' value=\"{$wpEmail}\" 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>
+<input tabindex=6 type=submit name=\"wpCreateaccount\" value=\"{$ca}\">
+$cambutton
+</td></tr>");
+       }
+
+       $wgOut->addHTML("
 <tr>
 <td colspan=3 align=left>
-<input tabindex=7 type=checkbox name='wpRemember' value='1'$checked>$rmp
+<input tabindex=7 type=checkbox name=\"wpRemember\" value=\"1\" id=\"wpRemember\"$checked><label for=\"wpRemember\">$rmp</label>
 </td></tr>
 <tr><td colspan=3>&nbsp;</td></tr><tr>
 <td colspan=3 align=left>
 <p>$efl<br>
-<input tabindex=8 type=submit name='wpMailmypassword' value=\"{$mmp}\">
+<input tabindex=8 type=submit name=\"wpMailmypassword\" value=\"{$mmp}\">
 </td></tr></table>
 </form>\n" );
+
+
+
 }
 
 ?>