Preferences.php: avoid "Undefined index" if key 'realname' don't exist in $formdata
[lhc/web/wiklou.git] / includes / Preferences.php
index cf4d5c9..b47115b 100644 (file)
@@ -62,6 +62,13 @@ class Preferences {
                'emailaddress',
        );
 
+       /**
+        * @return array
+        */
+       static function getSaveBlacklist() {
+               return self::$saveBlacklist;
+       }
+
        /**
         * @throws MWException
         * @param $user User
@@ -403,7 +410,12 @@ class Preferences {
                }
 
                // show a preview of the old signature first
-               $oldsigWikiText = $wgParser->preSaveTransform( "~~~", $context->getTitle(), $user, ParserOptions::newFromContext( $context ) );
+               $oldsigWikiText = $wgParser->preSaveTransform(
+                       '~~~',
+                       $context->getTitle(),
+                       $user,
+                       ParserOptions::newFromContext( $context )
+               );
                $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true );
                $defaultPreferences['oldsig'] = array(
                        'type' => 'info',
@@ -423,7 +435,8 @@ class Preferences {
                $defaultPreferences['fancysig'] = array(
                        'type' => 'toggle',
                        'label-message' => 'tog-fancysig',
-                       'help-message' => 'prefs-help-signature', // show general help about signature at the bottom of the section
+                       // show general help about signature at the bottom of the section
+                       'help-message' => 'prefs-help-signature',
                        'section' => 'personal/signature'
                );
 
@@ -742,39 +755,19 @@ class Preferences {
                }
 
                $defaultPreferences['stubthreshold'] = array(
-                       'type' => 'selectorother',
+                       'type' => 'select',
                        'section' => 'rendering/advancedrendering',
                        'options' => $stubThresholdOptions,
                        'size' => 20,
                        'label-raw' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
                );
 
-               if ( $wgAllowUserCssPrefs ) {
-                       $defaultPreferences['showtoc'] = array(
-                               'type' => 'toggle',
-                               'section' => 'rendering/advancedrendering',
-                               'label-message' => 'tog-showtoc',
-                       );
-               }
-               $defaultPreferences['nocache'] = array(
-                       'type' => 'toggle',
-                       'label-message' => 'tog-nocache',
-                       'section' => 'rendering/advancedrendering',
-               );
                $defaultPreferences['showhiddencats'] = array(
                        'type' => 'toggle',
                        'section' => 'rendering/advancedrendering',
                        'label-message' => 'tog-showhiddencats'
                );
 
-               if ( $wgAllowUserCssPrefs ) {
-                       $defaultPreferences['justify'] = array(
-                               'type' => 'toggle',
-                               'section' => 'rendering/advancedrendering',
-                               'label-message' => 'tog-justify',
-                       );
-               }
-
                $defaultPreferences['numberheadings'] = array(
                        'type' => 'toggle',
                        'section' => 'rendering/advancedrendering',
@@ -791,13 +784,6 @@ class Preferences {
                global $wgAllowUserCssPrefs;
 
                ## Editing #####################################
-               if ( $wgAllowUserCssPrefs ) {
-                       $defaultPreferences['editsection'] = array(
-                               'type' => 'toggle',
-                               'section' => 'editing/advancedediting',
-                               'label-message' => 'tog-editsection',
-                       );
-               }
                $defaultPreferences['editsectiononrightclick'] = array(
                        'type' => 'toggle',
                        'section' => 'editing/advancedediting',
@@ -1044,23 +1030,7 @@ class Preferences {
         * @param $defaultPreferences Array
         */
        static function searchPreferences( $user, IContextSource $context, &$defaultPreferences ) {
-               global $wgContLang, $wgVectorUseSimpleSearch;
-
-               ## Search #####################################
-               $defaultPreferences['searchlimit'] = array(
-                       'type' => 'int',
-                       'label-message' => 'resultsperpage',
-                       'section' => 'searchoptions/displaysearchoptions',
-                       'min' => 0,
-               );
-
-               if ( $wgVectorUseSimpleSearch ) {
-                       $defaultPreferences['vector-simplesearch'] = array(
-                               'type' => 'toggle',
-                               'label-message' => 'vector-simplesearch-preference',
-                               'section' => 'searchoptions/displaysearchoptions',
-                       );
-               }
+               global $wgContLang;
 
                $defaultPreferences['searcheverything'] = array(
                        'type' => 'toggle',
@@ -1140,7 +1110,10 @@ class Preferences {
                                $linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
                        }
 
-                       $display = $sn . ' ' . $context->msg( 'parentheses', $context->getLanguage()->pipeList( $linkTools ) )->text();
+                       $display = $sn . ' ' . $context->msg(
+                               'parentheses',
+                               $context->getLanguage()->pipeList( $linkTools )
+                       )->text();
                        $ret[$display] = $skinkey;
                }
 
@@ -1231,8 +1204,13 @@ class Preferences {
                                $form->msg( 'badsiglength' )->numParams( $wgMaxSigChars )->text() );
                } elseif ( isset( $alldata['fancysig'] ) &&
                                $alldata['fancysig'] &&
-                               false === $wgParser->validateSig( $signature ) ) {
-                       return Xml::element( 'span', array( 'class' => 'error' ), $form->msg( 'badsig' )->text() );
+                               $wgParser->validateSig( $signature ) === false
+               ) {
+                       return Xml::element(
+                               'span',
+                               array( 'class' => 'error' ),
+                               $form->msg( 'badsig' )->text()
+                       );
                } else {
                        return true;
                }
@@ -1263,7 +1241,12 @@ class Preferences {
         * @param array $remove array of items to remove
         * @return HtmlForm
         */
-       static function getFormObject( $user, IContextSource $context, $formClass = 'PreferencesForm', array $remove = array() ) {
+       static function getFormObject(
+               $user,
+               IContextSource $context,
+               $formClass = 'PreferencesForm',
+               array $remove = array()
+       ) {
                $formDescriptor = Preferences::getPreferences( $user, $context );
                if ( count( $remove ) ) {
                        $removeKeys = array_flip( $remove );
@@ -1304,9 +1287,16 @@ class Preferences {
                $timestamp = MWTimestamp::getLocalInstance();
                // Check that $wgLocalTZoffset is the same as the local time zone offset
                if ( $wgLocalTZoffset == $timestamp->format( 'Z' ) / 60 ) {
-                       $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $timestamp->getTimezone()->getName() )->text();
+                       $server_tz_msg = $context->msg(
+                               'timezoneuseserverdefault',
+                               $timestamp->getTimezone()->getName()
+                       )->text();
                } else {
-                       $tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 );
+                       $tzstring = sprintf(
+                               '%+03d:%02d',
+                               floor( $wgLocalTZoffset / 60 ),
+                               abs( $wgLocalTZoffset ) % 60
+                       );
                        $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
                }
                $opt[$server_tz_msg] = "System|$wgLocalTZoffset";
@@ -1406,10 +1396,9 @@ class Preferences {
         *
         * @param $formData
         * @param $form PreferencesForm
-        * @param $entryPoint string
         * @return bool|Status|string
         */
-       static function tryFormSubmit( $formData, $form, $entryPoint = 'internal' ) {
+       static function tryFormSubmit( $formData, $form ) {
                global $wgHiddenPrefs, $wgAuth;
 
                $user = $form->getModifiedUser();
@@ -1429,7 +1418,7 @@ class Preferences {
 
                // Fortunately, the realname field is MUCH simpler
                // (not really "private", but still shouldn't be edited without permission)
-               if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->isAllowed( 'editmyprivateinfo' ) ) {
+               if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->isAllowed( 'editmyprivateinfo' ) && array_key_exists( 'realname', $formData ) ) {
                        $realName = $formData['realname'];
                        $user->setRealName( $realName );
                }
@@ -1442,7 +1431,6 @@ class Preferences {
                        # 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
@@ -1456,6 +1444,7 @@ class Preferences {
                                $user->setOption( $key, $value );
                        }
 
+                       wfRunHooks( 'PreferencesFormPreSave', array( $formData, $form, $user, &$result ) );
                        $user->saveSettings();
                }
 
@@ -1470,7 +1459,7 @@ class Preferences {
         * @return Status
         */
        public static function tryUISubmit( $formData, $form ) {
-               $res = self::tryFormSubmit( $formData, $form, 'ui' );
+               $res = self::tryFormSubmit( $formData, $form );
 
                if ( $res ) {
                        $urlOptions = array( 'success' => 1 );