本文整理汇总了PHP中Preferences::defaultPreferences方法的典型用法代码示例。如果您正苦于以下问题:PHP Preferences::defaultPreferences方法的具体用法?PHP Preferences::defaultPreferences怎么用?PHP Preferences::defaultPreferences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Preferences
的用法示例。
在下文中一共展示了Preferences::defaultPreferences方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPreferences
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: getPreferences
/**
* @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: getPreferences
/**
* @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;
}