Whitespace fixes
[lhc/web/wiklou.git] / includes / Preferences.php
index 77f9d3d..1331181 100644 (file)
@@ -36,16 +36,21 @@ class Preferences {
                        'searchlimit' => array( 'Preferences', 'filterIntval' ),
        );
 
+       /**
+        * @throws MWException
+        * @param $user User
+        * @return array|null
+        */
        static function getPreferences( $user ) {
-               if ( self::$defaultPreferences )
+               if ( self::$defaultPreferences ) {
                        return self::$defaultPreferences;
+               }
 
                $defaultPreferences = array();
 
                self::profilePreferences( $user, $defaultPreferences );
                self::skinPreferences( $user, $defaultPreferences );
                self::filesPreferences( $user, $defaultPreferences );
-               self::mathPreferences( $user, $defaultPreferences );
                self::datetimePreferences( $user, $defaultPreferences );
                self::renderingPreferences( $user, $defaultPreferences );
                self::editingPreferences( $user, $defaultPreferences );
@@ -92,7 +97,14 @@ class Preferences {
                return $defaultPreferences;
        }
 
-       // Pull option from a user account. Handles stuff like array-type preferences.
+       /**
+        * Pull option from a user account. Handles stuff like array-type preferences.
+        *
+        * @param $name
+        * @param $info
+        * @param $user User
+        * @return array|String
+        */
        static function getOptionFromUser( $name, $info, $user ) {
                $val = $user->getOption( $name );
 
@@ -113,6 +125,11 @@ class Preferences {
                return $val;
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences
+        * @return void
+        */
        static function profilePreferences( $user, &$defaultPreferences ) {
                global $wgLang, $wgUser;
                ## User info #####################################
@@ -207,7 +224,7 @@ class Preferences {
                );
 
                if ( $wgAuth->allowPasswordChange() ) {
-                       $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'Resetpass' ),
+                       $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ChangePassword' ),
                                wfMsgHtml( 'prefs-resetpass' ), array(),
                                array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) );
 
@@ -296,7 +313,7 @@ class Preferences {
                global $wgMaxSigChars, $wgOut, $wgParser;
 
                // show a preview of the old signature first
-               $oldsigWikiText = $wgParser->preSaveTransform( "~~~", new Title , $user, new ParserOptions );
+               $oldsigWikiText = $wgParser->preSaveTransform( "~~~", new Title, $user, new ParserOptions );
                $oldsigHTML = $wgOut->parseInline( $oldsigWikiText );
                $defaultPreferences['oldsig'] = array(
                        'type' => 'info',
@@ -445,6 +462,11 @@ class Preferences {
                }
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences
+        * @return void
+        */
        static function skinPreferences( $user, &$defaultPreferences ) {
                ## Skin #####################################
                global $wgLang, $wgAllowUserCss, $wgAllowUserJs;
@@ -495,19 +517,6 @@ class Preferences {
                }
        }
 
-       static function mathPreferences( $user, &$defaultPreferences ) {
-               ## Math #####################################
-               global $wgUseTeX, $wgLang;
-               if ( $wgUseTeX ) {
-                       $defaultPreferences['math'] = array(
-                               'type' => 'radio',
-                               'options' => array_flip( array_map( 'wfMsgHtml', $wgLang->getMathNames() ) ),
-                               'label' => ' ',
-                               'section' => 'rendering/math',
-                       );
-               }
-       }
-
        static function filesPreferences( $user, &$defaultPreferences ) {
                ## Files #####################################
                $defaultPreferences['imagesize'] = array(
@@ -524,6 +533,11 @@ class Preferences {
                );
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences
+        * @return void
+        */
        static function datetimePreferences( $user, &$defaultPreferences ) {
                global $wgLang;
 
@@ -539,10 +553,11 @@ class Preferences {
                }
 
                // Info
+               $now = wfTimestampNow();
                $nowlocal = Xml::element( 'span', array( 'id' => 'wpLocalTime' ),
-                       $wgLang->time( $now = wfTimestampNow(), true ) );
+                       $wgLang->time( $now, true ) );
                $nowserver = $wgLang->time( $now, false ) .
-                       Html::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) );
+                       Html::hidden( 'wpServerTime', (int)substr( $now, 8, 2 ) * 60 + (int)substr( $now, 10, 2 ) );
 
                $defaultPreferences['nowserver'] = array(
                        'type' => 'info',
@@ -743,7 +758,7 @@ class Preferences {
                        'label-message' => 'tog-forceeditsummary',
                );
 
-                               
+
                $defaultPreferences['uselivepreview'] = array(
                        'type' => 'toggle',
                        'section' => 'editing/advancedediting',
@@ -807,6 +822,11 @@ class Preferences {
                }
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences
+        * @return void
+        */
        static function watchlistPreferences( $user, &$defaultPreferences ) {
                global $wgUseRCPatrol, $wgEnableAPI;
 
@@ -910,18 +930,6 @@ class Preferences {
                        'section' => 'searchoptions/displaysearchoptions',
                        'min' => 0,
                );
-               $defaultPreferences['contextlines'] = array(
-                       'type' => 'int',
-                       'label-message' => 'contextlines',
-                       'section' => 'searchoptions/displaysearchoptions',
-                       'min' => 0,
-               );
-               $defaultPreferences['contextchars'] = array(
-                       'type' => 'int',
-                       'label-message' => 'contextchars',
-                       'section' => 'searchoptions/displaysearchoptions',
-                       'min' => 0,
-               );
 
                global $wgEnableMWSuggest;
                if ( $wgEnableMWSuggest ) {
@@ -931,7 +939,7 @@ class Preferences {
                                'section' => 'searchoptions/displaysearchoptions',
                        );
                }
-               
+
                global $wgVectorUseSimpleSearch;
                if ( $wgVectorUseSimpleSearch ) {
                        $defaultPreferences['vector-simplesearch'] = array(
@@ -947,9 +955,6 @@ class Preferences {
                        'section' => 'searchoptions/advancedsearchoptions',
                );
 
-               // Searchable namespaces back-compat with old format
-               $searchableNamespaces = SearchEngine::searchableNamespaces();
-
                $nsOptions = array();
 
                foreach ( $wgContLang->getNamespaces() as $ns => $name ) {
@@ -1004,7 +1009,7 @@ class Preferences {
        }
 
        /**
-        * @param $user The User object
+        * @param $user User The User object
         * @return Array: text/links to display as key; $skinkey as value
         */
        static function generateSkinOptions( $user ) {
@@ -1146,7 +1151,7 @@ class Preferences {
        }
 
        static function validateEmail( $email, $alldata ) {
-               if ( $email && !User::isValidEmailAddr( $email ) ) {
+               if ( $email && !Sanitizer::validateEmail( $email ) ) {
                        return wfMsgExt( 'invalidemailaddress', 'parseinline' );
                }
 
@@ -1227,7 +1232,7 @@ class Preferences {
                }
                return $opt;
        }
-       
+
        static function filterIntval( $value, $alldata ){
                return intval( $value );
        }
@@ -1288,7 +1293,8 @@ class Preferences {
                                if ( $wgEmailAuthentication ) {
                                        # Mail a temporary password to the dirty address.
                                        # User can come back through the confirmation URL to re-enable email.
-                                       $result = $wgUser->sendConfirmationMail( $oldaddr != '' );
+                                       $type = $oldaddr != '' ? 'changed' : 'set';
+                                       $result = $wgUser->sendConfirmationMail( $type );
                                        if ( !$result->isGood() ) {
                                                return htmlspecialchars( $result->getWikiText( 'mailerror' ) );
                                        } elseif ( $entryPoint == 'ui' ) {
@@ -1314,6 +1320,16 @@ class Preferences {
                        unset( $formData[$b] );
                }
 
+               # If users have saved a value for a preference which has subsequently been disabled
+               # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
+               # is subsequently re-enabled
+               # TODO: maintenance script to actually delete these
+               foreach( $wgHiddenPrefs as $pref ){
+                       # If the user has not set a non-default value here, the default will be returned
+                       # and subsequently discarded
+                       $formData[$pref] = $wgUser->getOption( $pref, null, true );
+               }
+
                //  Keeps old preferences from interfering due to back-compat
                //  code, etc.
                $wgUser->resetOptions();
@@ -1348,6 +1364,10 @@ class Preferences {
                return Status::newGood();
        }
 
+       /**
+        * @param $user User
+        * @return array
+        */
        public static function loadOldSearchNs( $user ) {
                $searchableNamespaces = SearchEngine::searchableNamespaces();
                // Back compat with old format