Jump to content

Wikia code/includes/Preferences.php

From mediawiki.org
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\Preferences.php	2011-07-18 22:31:28.308593800 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\Preferences.php	2011-08-17 15:28:46.643554700 +0100
@@ -82,6 +82,7 @@
 			} elseif( $field->validate( $globalDefault, $user->mOptions ) === true ) {
 				$info['default'] = $globalDefault;
 			} else {
+				Wikia::log( __METHOD__, 'JKU', "Global default '$globalDefault' is invalid for field $name" );
 				throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
 			}
 		}
@@ -171,15 +172,16 @@
 					'section' => 'personal/info',
 				);
 
-		if( $user->getRegistration() ) {
+		$user_registration = $user->getRegistration();
+		if( $user_registration ) {
 			$defaultPreferences['registrationdate'] =
 					array(
 						'type' => 'info',
 						'label-message' => 'prefs-registration',
 						'default' => wfMsgExt( 'prefs-registration-date-time', 'parsemag',
-							$wgLang->timeanddate( $user->getRegistration(), true ),
-							$wgLang->date( $user->getRegistration(), true ),
-							$wgLang->time( $user->getRegistration(), true ) ),
+							$wgLang->timeanddate( $user_registration, true ),
+							$wgLang->date( $user_registration, true ),
+							$wgLang->time( $user_registration, true ) ),
 						'section' => 'personal/info',
 					);
 		}
@@ -330,11 +332,12 @@
 		if ($wgEnableEmail) {
 		
 			global $wgEmailConfirmToEdit;
+			$user_email = $user->getEmail();			
 	
 			$defaultPreferences['emailaddress'] =
 					array(
 						'type' => $wgAuth->allowPropChange( 'emailaddress' ) ? 'email' : 'info',
-						'default' => $user->getEmail(),
+						'default' => $user_email,
 						'section' => 'personal/email',
 						'label-message' => 'youremail',
 						'help-message' => $wgEmailConfirmToEdit
@@ -348,21 +351,22 @@
 			$disableEmailPrefs = false;
 	
 			if ( $wgEmailAuthentication ) {
-				if ( $user->getEmail() ) {
-					if( $user->getEmailAuthenticationTimestamp() ) {
+				if ( $user_email ) {
+					$user_emailauthts = $user->getEmailAuthenticationTimestamp();
+					if( $user_emailauthts ) {
 						// date and time are separate parameters to facilitate localisation.
 						// $time is kept for backward compat reasons.
 						// 'emailauthenticated' is also used in SpecialConfirmemail.php
-						$time = $wgLang->timeAndDate( $user->getEmailAuthenticationTimestamp(), true );
-						$d = $wgLang->date( $user->getEmailAuthenticationTimestamp(), true );
-						$t = $wgLang->time( $user->getEmailAuthenticationTimestamp(), true );
+						$time = $wgLang->timeAndDate( $user_emailauthts, true );
+						$d = $wgLang->date( $user_emailauthts, true );
+						$t = $wgLang->time( $user_emailauthts, true );
 						$emailauthenticated = wfMsgExt( 'emailauthenticated', 'parseinline',
 												array($time, $d, $t ) ) . '<br />';
 						$disableEmailPrefs = false;
 					} else {
 						$disableEmailPrefs = true;
 						$skin = $wgUser->getSkin();
-						$emailauthenticated = wfMsgExt( 'emailnotauthenticated', 'parseinline' ) . '<br />' .
+						$emailauthenticated = '<span class="error" >'.wfMsgExt( 'emailnotauthenticated', 'parseinline' ).'</span><br />' .
 							$skin->link(
 								SpecialPage::getTitleFor( 'Confirmemail' ),
 								wfMsg( 'emailconfirmlink' ),
@@ -441,6 +445,23 @@
 						'label-message' => 'tog-enotifrevealaddr',
 						'disabled' => $disableEmailPrefs,
 					);
+
+			/* Wikia change begin - @author: Inez */
+			$defaultPreferences['htmlemails'] =
+					array(
+						'type' => 'toggle',
+						'section' => 'personal/email',
+						'label-message' => 'tog-htmlemails',
+					);					
+
+			$defaultPreferences['marketingallowed'] =
+					array(
+						'type' => 'toggle',
+						'section' => 'personal/email',
+						'label-message' => 'tog-marketingallowed',
+					);
+			/* Wikia change end */					
+					
 		}
 	}
 
@@ -635,7 +655,11 @@
 	}
 
 	static function editingPreferences( $user, &$defaultPreferences ) {
-		global $wgUseExternalEditor, $wgLivePreview;
+		global $wgUseExternalEditor, $wgLivePreview, $wgAllowUserCssPrefs;
+
+		/* Wikia change begin - @author: Macbre */
+		wfRunHooks( 'EditingPreferencesBefore', array($user, &$defaultPreferences ) );
+		/* Wikia change end */
 
 		## Editing #####################################
 		$defaultPreferences['cols'] =
@@ -655,6 +679,7 @@
 					'max' => 1000,
 				);
 
+		if ( $wgAllowUserCssPrefs ) {
 		$defaultPreferences['editfont'] =
 				array(
 					'type' => 'select',
@@ -667,6 +692,8 @@
 						wfMsg( 'editfont-serif' ) => 'serif',
 					)
 				);
+		}
+		
 		$defaultPreferences['previewontop'] =
 				array(
 					'type' => 'toggle',
@@ -806,6 +833,11 @@
 	}
 
 	static function watchlistPreferences( $user, &$defaultPreferences ) {
+
+		if(!wfRunHooks( 'WatchlistPreferencesBefore', array($user, &$defaultPreferences ) )) {
+			return true;
+		}
+		
 		global $wgUseRCPatrol, $wgEnableAPI;
 		## Watchlist #####################################
 		$defaultPreferences['watchlistdays'] =
@@ -1150,8 +1182,8 @@
 
 	static function getFormObject( $user ) {
 		$formDescriptor = Preferences::getPreferences( $user );
-		$htmlForm = new PreferencesForm( $formDescriptor, 'prefs' );
 
+		$htmlForm = new PreferencesForm( $formDescriptor, 'prefs' );
 		$htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
 		$htmlForm->setTitle( SpecialPage::getTitleFor( 'Preferences' ) );
 		$htmlForm->setSubmitID( 'prefsubmit' );
@@ -1258,6 +1290,7 @@
 		$saveBlacklist = array(
 			'realname',
 			'emailaddress',
+			'avatarupload'
 		);
 
 		if( $wgEnableEmail ) {
@@ -1299,7 +1332,7 @@
 
 		//  Keeps old preferences from interfering due to back-compat
 		//  code, etc.
-		$wgUser->resetOptions();
+		//$wgUser->resetOptions(); RT#144314
 
 		foreach( $formData as $key => $value ) {
 			$wgUser->setOption( $key, $value );
@@ -1311,6 +1344,13 @@
 	}
 
 	public static function tryUISubmit( $formData ) {
+		
+		$error = null;
+		
+		if(!wfRunHooks('SavePreferences', array(&$formData, &$error))) {
+			return $error;
+		}
+		
 		$res = self::tryFormSubmit( $formData, 'ui' );
 
 		if( $res ) {