예제 #1
0
 static function getPreferences($user)
 {
     if (self::$defaultPreferences) {
         return self::$defaultPreferences;
     }
     global $wgRCMaxAge;
     $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);
     self::rcPreferences($user, $defaultPreferences);
     self::watchlistPreferences($user, $defaultPreferences);
     self::searchPreferences($user, $defaultPreferences);
     self::miscPreferences($user, $defaultPreferences);
     wfRunHooks('GetPreferences', array($user, &$defaultPreferences));
     ## Remove preferences that wikis don't want to use
     global $wgHiddenPrefs;
     foreach ($wgHiddenPrefs as $pref) {
         if (isset($defaultPreferences[$pref])) {
             unset($defaultPreferences[$pref]);
         }
     }
     ## Prod in defaults from the user
     global $wgDefaultUserOptions;
     foreach ($defaultPreferences as $name => &$info) {
         $prefFromUser = self::getOptionFromUser($name, $info, $user);
         $field = HTMLForm::loadInputFromParameters($info);
         // For validation
         $defaultOptions = User::getDefaultOptions();
         $globalDefault = isset($defaultOptions[$name]) ? $defaultOptions[$name] : null;
         // If it validates, set it as the default
         if (isset($info['default'])) {
             // Already set, no problem
             continue;
         } elseif (!is_null($prefFromUser) && $field->validate($prefFromUser, $user->mOptions) === true) {
             $info['default'] = $prefFromUser;
         } elseif ($field->validate($globalDefault, $user->mOptions) === true) {
             $info['default'] = $globalDefault;
         } else {
             throw new MWException("Global default '{$globalDefault}' is invalid for field {$name}");
         }
     }
     self::$defaultPreferences = $defaultPreferences;
     return $defaultPreferences;
 }
예제 #2
0
	/**
	 * @throws MWException
	 * @param $user User
	 * @param $context IContextSource
	 * @return array|null
	 */
	static function getPreferences( $user, IContextSource $context ) {
		if ( self::$defaultPreferences ) {
			return self::$defaultPreferences;
		}

		$defaultPreferences = array();

		self::profilePreferences( $user, $context, $defaultPreferences );
		self::skinPreferences( $user, $context, $defaultPreferences );
		self::filesPreferences( $user, $context, $defaultPreferences );
		self::datetimePreferences( $user, $context, $defaultPreferences );
		self::renderingPreferences( $user, $context, $defaultPreferences );
		self::editingPreferences( $user, $context, $defaultPreferences );
		self::rcPreferences( $user, $context, $defaultPreferences );
		self::watchlistPreferences( $user, $context, $defaultPreferences );
		self::searchPreferences( $user, $context, $defaultPreferences );
		self::miscPreferences( $user, $context, $defaultPreferences );

		wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );

		## Remove preferences that wikis don't want to use
		global $wgHiddenPrefs;
		foreach ( $wgHiddenPrefs as $pref ) {
			if ( isset( $defaultPreferences[$pref] ) ) {
				unset( $defaultPreferences[$pref] );
			}
		}

		## Make sure that form fields have their parent set. See bug 41337.
		$dummyForm = new HTMLForm( array(), $context );

		$disable = !$user->isAllowed( 'editmyoptions' );

		## Prod in defaults from the user
		foreach ( $defaultPreferences as $name => &$info ) {
			$prefFromUser = self::getOptionFromUser( $name, $info, $user );
			if ( $disable && !in_array( $name, self::$saveBlacklist ) ) {
				$info['disabled'] = 'disabled';
			}
			$field = HTMLForm::loadInputFromParameters( $name, $info ); // For validation
			$field->mParent = $dummyForm;
			$defaultOptions = User::getDefaultOptions();
			$globalDefault = isset( $defaultOptions[$name] )
				? $defaultOptions[$name]
				: null;

			// If it validates, set it as the default
			if ( isset( $info['default'] ) ) {
				// Already set, no problem
				continue;
			} elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
					$field->validate( $prefFromUser, $user->getOptions() ) === true ) {
				$info['default'] = $prefFromUser;
			} elseif ( $field->validate( $globalDefault, $user->getOptions() ) === true ) {
				$info['default'] = $globalDefault;
			} else {
				throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
			}
		}

		self::$defaultPreferences = $defaultPreferences;

		return $defaultPreferences;
	}
예제 #3
0
 /**
  * @throws MWException
  * @param User $user
  * @param IContextSource $context
  * @return array|null
  */
 static function getPreferences($user, IContextSource $context)
 {
     if (self::$defaultPreferences) {
         return self::$defaultPreferences;
     }
     $defaultPreferences = array();
     self::profilePreferences($user, $context, $defaultPreferences);
     self::skinPreferences($user, $context, $defaultPreferences);
     self::datetimePreferences($user, $context, $defaultPreferences);
     self::filesPreferences($user, $context, $defaultPreferences);
     self::renderingPreferences($user, $context, $defaultPreferences);
     self::editingPreferences($user, $context, $defaultPreferences);
     self::rcPreferences($user, $context, $defaultPreferences);
     self::watchlistPreferences($user, $context, $defaultPreferences);
     self::searchPreferences($user, $context, $defaultPreferences);
     self::miscPreferences($user, $context, $defaultPreferences);
     Hooks::run('GetPreferences', array($user, &$defaultPreferences));
     self::loadPreferenceValues($user, $context, $defaultPreferences);
     self::$defaultPreferences = $defaultPreferences;
     return $defaultPreferences;
 }