Wrap message querypage-no-updates into a class
[lhc/web/wiklou.git] / includes / Preferences.php
index a9f7456..9ec3b64 100644 (file)
@@ -1,4 +1,25 @@
 <?php
+/**
+ * Form to edit user perferences.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
 /**
  * We're now using the HTMLForm object with some customisation to generate the
  * Preferences form. This object handles generic submission, CSRF protection,
@@ -24,7 +45,6 @@
  * Once fields have been retrieved and validated, submission logic is handed
  * over to the tryUISubmit static method of this class.
  */
-
 class Preferences {
        static $defaultPreferences = null;
        static $saveFilters = array(
@@ -916,6 +936,7 @@ class Preferences {
 
                if ( $wgEnableAPI ) {
                        # Some random gibberish as a proposed default
+                       // @fixme This should use CryptRand but we may not want to read urandom on every view
                        $hash = sha1( mt_rand() . microtime( true ) );
 
                        $defaultPreferences['watchlisttoken'] = array(
@@ -1431,39 +1452,21 @@ class Preferences {
         * Try to set a user's email address.
         * This does *not* try to validate the address.
         * Caller is responsible for checking $wgAuth.
+        *
+        * @deprecated in 1.20; use User::setEmailWithConfirmation() instead.
         * @param $user User
         * @param $newaddr string New email address
         * @return Array (true on success or Status on failure, info string)
         */
        public static function trySetUserEmail( User $user, $newaddr ) {
-               global $wgEnableEmail, $wgEmailAuthentication;
-               $info = ''; // none
+               wfDeprecated( __METHOD__, '1.20' );
 
-               if ( $wgEnableEmail ) {
-                       $oldaddr = $user->getEmail();
-                       if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) {
-                               # The user has supplied a new email address on the login page
-                               # new behaviour: set this new emailaddr from login-page into user database record
-                               $user->setEmail( $newaddr );
-                               if ( $wgEmailAuthentication ) {
-                                       # Mail a temporary password to the dirty address.
-                                       # User can come back through the confirmation URL to re-enable email.
-                                       $type = $oldaddr != '' ? 'changed' : 'set';
-                                       $result = $user->sendConfirmationMail( $type );
-                                       if ( !$result->isGood() ) {
-                                               return array( $result, 'mailerror' );
-                                       }
-                                       $info = 'eauth';
-                               }
-                       } elseif ( $newaddr != $oldaddr ) { // if the address is the same, don't change it
-                               $user->setEmail( $newaddr );
-                       }
-                       if ( $oldaddr != $newaddr ) {
-                               wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) );
-                       }
+               $result = $user->setEmailWithConfirmation( $newaddr );
+               if ( $result->isGood() ) {
+                       return array( true, $result->value );
+               } else {
+                       return array( $result, 'mailerror' );
                }
-
-               return array( true, $info );
        }
 
        /**