* Validate e-mail address if provided
authorChad Horohoe <demon@users.mediawiki.org>
Wed, 5 Jan 2011 22:37:14 +0000 (22:37 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Wed, 5 Jan 2011 22:37:14 +0000 (22:37 +0000)
* Actually setEmail() on the sysop account we're creating
* Reinstate "subscribe to mediawiki-announce" feature (reverts r79089) which actually works

includes/installer/CoreInstaller.php
includes/installer/Installer.i18n.php
includes/installer/WebInstallerPage.php

index 54b6234..b8380a3 100644 (file)
@@ -178,6 +178,20 @@ abstract class CoreInstaller extends Installer {
                ),
        );
 
+       /**
+        * URL to mediawiki-announce subscription
+        */
+       protected $mediaWikiAnnounceUrl = 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce';
+
+       /**
+        * Supported language codes for Mailman
+        */
+       protected $mediaWikiAnnounceLanguages = array(
+               'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu',
+               'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru',
+               'sl', 'sr', 'sv', 'tr', 'uk'
+       );
+
        /**
         * TODO: document
         *
@@ -185,7 +199,6 @@ abstract class CoreInstaller extends Installer {
         */
        public abstract function showStatusMessage( Status $status );
 
-
        /**
         * Constructor, always call this from child classes.
         */
@@ -480,10 +493,39 @@ abstract class CoreInstaller extends Installer {
 
                        $user->addGroup( 'sysop' );
                        $user->addGroup( 'bureaucrat' );
+                       if( $this->getVar( '_AdminEmail' ) ) {
+                               $user->setEmail( $this->getVar( '_AdminEmail' ) );
+                       }
                        $user->saveSettings();
                }
+               $status = Status::newGood();
 
-               return Status::newGood();
+               if( $this->getVar( '_Subscribe' ) && $this->getVar( '_AdminEmail' ) ) {
+                       $this->subscribeToMediaWikiAnnounce( $status );
+               }
+
+               return $status;
+       }
+
+       private function subscribeToMediaWikiAnnounce( Status $s ) {
+               $params = array( 
+                       'email'    => $this->getVar( '_AdminEmail' ),
+                       'language' => 'en',
+                       'digest'   => 0
+               );
+
+               // Mailman doesn't support as many languages as we do, so check to make
+               // sure their selected language is available
+               $myLang = $this->getVar( '_UserLang' );
+               if( in_array( $myLang, $this->mediaWikiAnnounceLanguages ) ) {
+                       $myLang = $myLang == 'pt-br' ? 'pt_BR' : $myLang; // rewrite to Mailman's pt_BR
+                       $params['language'] = $myLang;
+               }
+
+               $res = Http::post( $this->mediaWikiAnnounceUrl, array( 'postData' => $params ) );
+               if( !$res ) {
+                       $s->warning( 'config-install-subscribe-fail' );
+               }
        }
 
        /**
index 0934b15..da67390 100644 (file)
@@ -343,6 +343,7 @@ Specify a different username.',
        'config-admin-email-help'         => 'Enter an e-mail address here to allow you to receive e-mail from other users on the wiki, reset your password, and be notified of changes to pages on your watchlist.',
        'config-admin-error-user'         => 'Internal error when creating an admin with the name "<nowiki>$1</nowiki>".',
        'config-admin-error-password'     => 'Internal error when setting a password for the admin "<nowiki>$1</nowiki>": <pre>$2</pre>',
+       'config-admin-error-bademail'     => 'You have entered an invalid e-mail address',
        'config-subscribe'                => 'Subscribe to the [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce release announcements mailing list].',
        'config-subscribe-help'           => 'This is a low-volume mailing list used for release announcements, including important security announcements.
 You should subscribe to it and update your MediaWiki installation when new versions come out.',
@@ -465,6 +466,7 @@ Skipping default list.",
 Consider changing it manually.",
        'config-install-upgradekey'        => 'Generating default upgrade key',
        'config-install-sysop'            => 'Creating administrator user account',
+       'config-install-subscribe-fail'   => 'Unable to subscribe to mediawiki-announce',
        'config-install-mainpage'         => 'Creating main page with default content',
        'config-install-mainpage-failed'  => 'Could not insert main page.',
        'config-install-done'             => "'''Congratulations!'''
index ed745b7..c3e5d26 100644 (file)
@@ -596,16 +596,11 @@ class WebInstaller_Name extends WebInstallerPage {
                                'label' => 'config-admin-email',
                                'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
                        ) ) .
-                       /**
-                        * Uncomment this feature once we've got some sort of API to mailman
-                        * to handle these subscriptions. Some dummy wrapper script on the
-                        * mailman box that shell's out to mailman/bin/add_members would do
-                               $this->parent->getCheckBox( array(
+                       $this->parent->getCheckBox( array(
                                'var' => '_Subscribe',
                                'label' => 'config-subscribe',
                                'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
                        ) ) .
-                        */
                        $this->getFieldSetEnd() .
                        $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
                        $this->parent->getRadioSet( array(
@@ -708,6 +703,14 @@ class WebInstaller_Name extends WebInstallerPage {
                        $this->setVar( '_AdminPassword2', '' );
                        $retVal = false;
                }
+
+               // Validate e-mail if provided
+               $email = $this->getVar( '_AdminEmail' );
+               if( $email && !User::isValidEmailAddr( $email ) ) {
+                       $this->parent->showError( 'config-admin-error-bademail' );
+                       $retVal = false;
+               }
+
                return $retVal;
        }