summaryrefslogtreecommitdiff
path: root/includes/Preferences.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /includes/Preferences.php
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/Preferences.php')
-rw-r--r--includes/Preferences.php527
1 files changed, 243 insertions, 284 deletions
diff --git a/includes/Preferences.php b/includes/Preferences.php
index c9caf4f7..84cf5af0 100644
--- a/includes/Preferences.php
+++ b/includes/Preferences.php
@@ -46,14 +46,17 @@
* over to the tryUISubmit static method of this class.
*/
class Preferences {
- static $defaultPreferences = null;
- static $saveFilters = array(
- 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
- 'cols' => array( 'Preferences', 'filterIntval' ),
- 'rows' => array( 'Preferences', 'filterIntval' ),
- 'rclimit' => array( 'Preferences', 'filterIntval' ),
- 'wllimit' => array( 'Preferences', 'filterIntval' ),
- 'searchlimit' => array( 'Preferences', 'filterIntval' ),
+ /** @var array */
+ protected static $defaultPreferences = null;
+
+ /** @var array */
+ protected static $saveFilters = array(
+ 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
+ 'cols' => array( 'Preferences', 'filterIntval' ),
+ 'rows' => array( 'Preferences', 'filterIntval' ),
+ 'rclimit' => array( 'Preferences', 'filterIntval' ),
+ 'wllimit' => array( 'Preferences', 'filterIntval' ),
+ 'searchlimit' => array( 'Preferences', 'filterIntval' ),
);
// Stuff that shouldn't be saved as a preference.
@@ -63,9 +66,16 @@ class Preferences {
);
/**
+ * @return array
+ */
+ static function getSaveBlacklist() {
+ return self::$saveBlacklist;
+ }
+
+ /**
* @throws MWException
- * @param $user User
- * @param $context IContextSource
+ * @param User $user
+ * @param IContextSource $context
* @return array|null
*/
static function getPreferences( $user, IContextSource $context ) {
@@ -77,8 +87,8 @@ class Preferences {
self::profilePreferences( $user, $context, $defaultPreferences );
self::skinPreferences( $user, $context, $defaultPreferences );
- self::filesPreferences( $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 );
@@ -88,9 +98,22 @@ class Preferences {
wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
+ self::loadPreferenceValues( $user, $context, $defaultPreferences );
+ self::$defaultPreferences = $defaultPreferences;
+ return $defaultPreferences;
+ }
+
+ /**
+ * Loads existing values for a given array of preferences
+ * @throws MWException
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences Array to load values for
+ * @return array|null
+ */
+ static function loadPreferenceValues( $user, $context, &$defaultPreferences ) {
## Remove preferences that wikis don't want to use
- global $wgHiddenPrefs;
- foreach ( $wgHiddenPrefs as $pref ) {
+ foreach ( $context->getConfig()->get( 'HiddenPrefs' ) as $pref ) {
if ( isset( $defaultPreferences[$pref] ) ) {
unset( $defaultPreferences[$pref] );
}
@@ -128,18 +151,16 @@ class Preferences {
}
}
- self::$defaultPreferences = $defaultPreferences;
-
return $defaultPreferences;
}
/**
* Pull option from a user account. Handles stuff like array-type preferences.
*
- * @param $name
- * @param $info
- * @param $user User
- * @return array|String
+ * @param string $name
+ * @param array $info
+ * @param User $user
+ * @return array|string
*/
static function getOptionFromUser( $name, $info, $user ) {
$val = $user->getOption( $name );
@@ -179,18 +200,15 @@ class Preferences {
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $defaultPreferences
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences
* @return void
*/
static function profilePreferences( $user, IContextSource $context, &$defaultPreferences ) {
- global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode,
- $wgDisableTitleConversion, $wgDisableLangConversion, $wgMaxSigChars,
- $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication,
- $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress,
- $wgSecureLogin;
+ global $wgAuth, $wgContLang, $wgParser;
+ $config = $context->getConfig();
// retrieving user name for GENDER and misc.
$userName = $user->getName();
@@ -203,13 +221,6 @@ class Preferences {
'section' => 'personal/info',
);
- $defaultPreferences['userid'] = array(
- 'type' => 'info',
- 'label-message' => array( 'uid', $userName ),
- 'default' => $user->getId(),
- 'section' => 'personal/info',
- );
-
# Get groups to which the user belongs
$userEffectiveGroups = $user->getEffectiveGroups();
$userGroups = $userMembers = array();
@@ -294,16 +305,8 @@ class Preferences {
'section' => 'personal/info',
);
}
- if ( $wgCookieExpiration > 0 ) {
- $defaultPreferences['rememberpassword'] = array(
- 'type' => 'toggle',
- 'label' => $context->msg( 'tog-rememberpassword' )->numParams(
- ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )->text(),
- 'section' => 'personal/info',
- );
- }
- // Only show preferhttps if secure login is turned on
- if ( $wgSecureLogin && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) {
+ // Only show prefershttps if secure login is turned on
+ if ( $config->get( 'SecureLogin' ) && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) {
$defaultPreferences['prefershttps'] = array(
'type' => 'toggle',
'label-message' => 'tog-prefershttps',
@@ -314,8 +317,9 @@ class Preferences {
// Language
$languages = Language::fetchLanguageNames( null, 'mw' );
- if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
- $languages[$wgLanguageCode] = $wgLanguageCode;
+ $languageCode = $config->get( 'LanguageCode' );
+ if ( !array_key_exists( $languageCode, $languages ) ) {
+ $languages[$languageCode] = $languageCode;
}
ksort( $languages );
@@ -346,7 +350,7 @@ class Preferences {
);
// see if there are multiple language variants to choose from
- if ( !$wgDisableLangConversion ) {
+ if ( !$config->get( 'DisableLangConversion' ) ) {
foreach ( LanguageConverter::$languagesWithVariants as $langCode ) {
if ( $langCode == $wgContLang->getCode() ) {
$variants = $wgContLang->getVariants();
@@ -374,14 +378,6 @@ class Preferences {
'section' => 'personal/i18n',
'help-message' => 'prefs-help-variant',
);
-
- if ( !$wgDisableTitleConversion ) {
- $defaultPreferences['noconvertlink'] = array(
- 'type' => 'toggle',
- 'section' => 'personal/i18n',
- 'label-message' => 'tog-noconvertlink',
- );
- }
} else {
$defaultPreferences["variant-$langCode"] = array(
'type' => 'api',
@@ -403,7 +399,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',
@@ -414,7 +415,7 @@ class Preferences {
);
$defaultPreferences['nickname'] = array(
'type' => $wgAuth->allowPropChange( 'nickname' ) ? 'text' : 'info',
- 'maxlength' => $wgMaxSigChars,
+ 'maxlength' => $config->get( 'MaxSigChars' ),
'label-message' => 'yournick',
'validation-callback' => array( 'Preferences', 'validateSignature' ),
'section' => 'personal/signature',
@@ -423,19 +424,20 @@ 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'
);
## Email stuff
- if ( $wgEnableEmail ) {
+ if ( $config->get( 'EnableEmail' ) ) {
if ( $canViewPrivateInfo ) {
- $helpMessages[] = $wgEmailConfirmToEdit
+ $helpMessages[] = $config->get( 'EmailConfirmToEdit' )
? 'prefs-help-email-required'
: 'prefs-help-email';
- if ( $wgEnableUserEmail ) {
+ if ( $config->get( 'EnableUserEmail' ) ) {
// additional messages when users can send email to each other
$helpMessages[] = 'prefs-help-email-others';
}
@@ -467,7 +469,7 @@ class Preferences {
$disableEmailPrefs = false;
- if ( $wgEmailAuthentication ) {
+ if ( $config->get( 'EmailAuthentication' ) ) {
$emailauthenticationclass = 'mw-email-not-authenticated';
if ( $user->getEmail() ) {
if ( $user->getEmailAuthenticationTimestamp() ) {
@@ -512,7 +514,7 @@ class Preferences {
}
}
- if ( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) {
+ if ( $config->get( 'EnableUserEmail' ) && $user->isAllowed( 'sendemail' ) ) {
$defaultPreferences['disablemail'] = array(
'type' => 'toggle',
'invert' => true,
@@ -528,7 +530,7 @@ class Preferences {
);
}
- if ( $wgEnotifWatchlist ) {
+ if ( $config->get( 'EnotifWatchlist' ) ) {
$defaultPreferences['enotifwatchlistpages'] = array(
'type' => 'toggle',
'section' => 'personal/email',
@@ -536,7 +538,7 @@ class Preferences {
'disabled' => $disableEmailPrefs,
);
}
- if ( $wgEnotifUserTalk ) {
+ if ( $config->get( 'EnotifUserTalk' ) ) {
$defaultPreferences['enotifusertalkpages'] = array(
'type' => 'toggle',
'section' => 'personal/email',
@@ -544,7 +546,7 @@ class Preferences {
'disabled' => $disableEmailPrefs,
);
}
- if ( $wgEnotifUserTalk || $wgEnotifWatchlist ) {
+ if ( $config->get( 'EnotifUserTalk' ) || $config->get( 'EnotifWatchlist' ) ) {
$defaultPreferences['enotifminoredits'] = array(
'type' => 'toggle',
'section' => 'personal/email',
@@ -552,7 +554,7 @@ class Preferences {
'disabled' => $disableEmailPrefs,
);
- if ( $wgEnotifRevealEditorAddress ) {
+ if ( $config->get( 'EnotifRevealEditorAddress' ) ) {
$defaultPreferences['enotifrevealaddr'] = array(
'type' => 'toggle',
'section' => 'personal/email',
@@ -565,35 +567,41 @@ class Preferences {
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $defaultPreferences
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences
* @return void
*/
static function skinPreferences( $user, IContextSource $context, &$defaultPreferences ) {
## Skin #####################################
- global $wgAllowUserCss, $wgAllowUserJs;
- $defaultPreferences['skin'] = array(
- 'type' => 'radio',
- 'options' => self::generateSkinOptions( $user, $context ),
- 'label' => '&#160;',
- 'section' => 'rendering/skin',
- );
+ // Skin selector, if there is at least one valid skin
+ $skinOptions = self::generateSkinOptions( $user, $context );
+ if ( $skinOptions ) {
+ $defaultPreferences['skin'] = array(
+ 'type' => 'radio',
+ 'options' => $skinOptions,
+ 'label' => '&#160;',
+ 'section' => 'rendering/skin',
+ );
+ }
+ $config = $context->getConfig();
+ $allowUserCss = $config->get( 'AllowUserCss' );
+ $allowUserJs = $config->get( 'AllowUserJs' );
# Create links to user CSS/JS pages for all skins
# This code is basically copied from generateSkinOptions(). It'd
# be nice to somehow merge this back in there to avoid redundancy.
- if ( $wgAllowUserCss || $wgAllowUserJs ) {
+ if ( $allowUserCss || $allowUserJs ) {
$linkTools = array();
$userName = $user->getName();
- if ( $wgAllowUserCss ) {
+ if ( $allowUserCss ) {
$cssPage = Title::makeTitleSafe( NS_USER, $userName . '/common.css' );
$linkTools[] = Linker::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
}
- if ( $wgAllowUserJs ) {
+ if ( $allowUserJs ) {
$jsPage = Title::makeTitleSafe( NS_USER, $userName . '/common.js' );
$linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
}
@@ -609,9 +617,9 @@ class Preferences {
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $defaultPreferences Array
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences
*/
static function filesPreferences( $user, IContextSource $context, &$defaultPreferences ) {
## Files #####################################
@@ -630,9 +638,9 @@ class Preferences {
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $defaultPreferences
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences
* @return void
*/
static function datetimePreferences( $user, IContextSource $context, &$defaultPreferences ) {
@@ -643,7 +651,7 @@ class Preferences {
'type' => 'radio',
'options' => $dateOptions,
'label' => '&#160;',
- 'section' => 'datetime/dateformat',
+ 'section' => 'rendering/dateformat',
);
}
@@ -660,7 +668,7 @@ class Preferences {
'raw' => 1,
'label-message' => 'servertime',
'default' => $nowserver,
- 'section' => 'datetime/timeoffset',
+ 'section' => 'rendering/timeoffset',
);
$defaultPreferences['nowlocal'] = array(
@@ -668,7 +676,7 @@ class Preferences {
'raw' => 1,
'label-message' => 'localtime',
'default' => $nowlocal,
- 'section' => 'datetime/timeoffset',
+ 'section' => 'rendering/timeoffset',
);
// Grab existing pref.
@@ -682,8 +690,8 @@ class Preferences {
$minDiff = $tz[1];
$tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 );
} elseif ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
- !in_array( $tzOffset, HTMLFormField::flattenOptions( $tzOptions ) ) )
- {
+ !in_array( $tzOffset, HTMLFormField::flattenOptions( $tzOptions ) )
+ ) {
# Timezone offset can vary with DST
$userTZ = timezone_open( $tz[2] );
if ( $userTZ !== false ) {
@@ -698,14 +706,14 @@ class Preferences {
'options' => $tzOptions,
'default' => $tzSetting,
'size' => 20,
- 'section' => 'datetime/timeoffset',
+ 'section' => 'rendering/timeoffset',
);
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $defaultPreferences Array
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences
*/
static function renderingPreferences( $user, IContextSource $context, &$defaultPreferences ) {
## Diffs ####################################
@@ -721,8 +729,7 @@ class Preferences {
);
## Page Rendering ##############################
- global $wgAllowUserCssPrefs;
- if ( $wgAllowUserCssPrefs ) {
+ if ( $context->getConfig()->get( 'AllowUserCssPrefs' ) ) {
$defaultPreferences['underline'] = array(
'type' => 'select',
'options' => array(
@@ -742,39 +749,18 @@ 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',
@@ -783,21 +769,12 @@ class Preferences {
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $defaultPreferences Array
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences
*/
static function editingPreferences( $user, IContextSource $context, &$defaultPreferences ) {
- 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',
@@ -809,7 +786,7 @@ class Preferences {
'label-message' => 'tog-editondblclick',
);
- if ( $wgAllowUserCssPrefs ) {
+ if ( $context->getConfig()->get( 'AllowUserCssPrefs' ) ) {
$defaultPreferences['editfont'] = array(
'type' => 'select',
'section' => 'editing/editor',
@@ -878,22 +855,22 @@ class Preferences {
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $defaultPreferences Array
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences
*/
static function rcPreferences( $user, IContextSource $context, &$defaultPreferences ) {
- global $wgRCMaxAge, $wgRCShowWatchingUsers;
-
+ $config = $context->getConfig();
+ $rcMaxAge = $config->get( 'RCMaxAge' );
## RecentChanges #####################################
$defaultPreferences['rcdays'] = array(
'type' => 'float',
'label-message' => 'recentchangesdays',
'section' => 'rc/displayrc',
'min' => 1,
- 'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
+ 'max' => ceil( $rcMaxAge / ( 3600 * 24 ) ),
'help' => $context->msg( 'recentchangesdays-max' )->numParams(
- ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )->text()
+ ceil( $rcMaxAge / ( 3600 * 24 ) ) )->text()
);
$defaultPreferences['rclimit'] = array(
'type' => 'int',
@@ -925,7 +902,7 @@ class Preferences {
);
}
- if ( $wgRCShowWatchingUsers ) {
+ if ( $config->get( 'RCShowWatchingUsers' ) ) {
$defaultPreferences['shownumberswatching'] = array(
'type' => 'toggle',
'section' => 'rc/advancedrc',
@@ -935,14 +912,13 @@ class Preferences {
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $defaultPreferences
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences
*/
static function watchlistPreferences( $user, IContextSource $context, &$defaultPreferences ) {
- global $wgUseRCPatrol, $wgEnableAPI, $wgRCMaxAge;
-
- $watchlistdaysMax = ceil( $wgRCMaxAge / ( 3600 * 24 ) );
+ $config = $context->getConfig();
+ $watchlistdaysMax = ceil( $config->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
## Watchlist #####################################
$defaultPreferences['watchlistdays'] = array(
@@ -993,7 +969,7 @@ class Preferences {
'label-message' => 'tog-watchlisthideliu',
);
- if ( $wgUseRCPatrol ) {
+ if ( $context->getConfig()->get( 'UseRCPatrol' ) ) {
$defaultPreferences['watchlisthidepatrolled'] = array(
'type' => 'toggle',
'section' => 'watchlist/advancedwatchlist',
@@ -1012,10 +988,15 @@ class Preferences {
$watchTypes['read'] = 'watchcreations';
}
+ if ( $user->isAllowed( 'rollback' ) ) {
+ $watchTypes['rollback'] = 'watchrollback';
+ }
+
foreach ( $watchTypes as $action => $pref ) {
if ( $user->isAllowed( $action ) ) {
// Messages:
// tog-watchdefault, tog-watchmoves, tog-watchdeletion, tog-watchcreations
+ // tog-watchrollback
$defaultPreferences[$pref] = array(
'type' => 'toggle',
'section' => 'watchlist/advancedwatchlist',
@@ -1024,7 +1005,7 @@ class Preferences {
}
}
- if ( $wgEnableAPI ) {
+ if ( $config->get( 'EnableAPI' ) ) {
$defaultPreferences['watchlisttoken'] = array(
'type' => 'api',
);
@@ -1039,56 +1020,16 @@ class Preferences {
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $defaultPreferences Array
+ * @param User $user
+ * @param IContextSource $context
+ * @param array $defaultPreferences
*/
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',
+ foreach ( MWNamespace::getValidNamespaces() as $n ) {
+ $defaultPreferences['searchNs' . $n] = array(
+ 'type' => 'api',
);
}
-
- $defaultPreferences['disablesuggest'] = array(
- 'type' => 'toggle',
- 'label-message' => 'mwsuggest-disable',
- 'section' => 'searchoptions/displaysearchoptions',
- );
-
- $defaultPreferences['searcheverything'] = array(
- 'type' => 'toggle',
- 'label-message' => 'searcheverything-enable',
- 'section' => 'searchoptions/advancedsearchoptions',
- );
-
- $nsOptions = $wgContLang->getFormattedNamespaces();
- $nsOptions[0] = $context->msg( 'blanknamespace' )->text();
- foreach ( $nsOptions as $ns => $name ) {
- if ( $ns < 0 ) {
- unset( $nsOptions[$ns] );
- }
- }
-
- $defaultPreferences['searchnamespaces'] = array(
- 'type' => 'multiselect',
- 'label-message' => 'defaultns',
- 'options' => array_flip( $nsOptions ),
- 'section' => 'searchoptions/advancedsearchoptions',
- 'prefix' => 'searchNs',
- );
}
/**
@@ -1098,20 +1039,18 @@ class Preferences {
}
/**
- * @param $user User The User object
- * @param $context IContextSource
- * @return Array: text/links to display as key; $skinkey as value
+ * @param User $user The User object
+ * @param IContextSource $context
+ * @return array Text/links to display as key; $skinkey as value
*/
static function generateSkinOptions( $user, IContextSource $context ) {
- global $wgDefaultSkin, $wgAllowUserCss, $wgAllowUserJs;
$ret = array();
$mptitle = Title::newMainPage();
$previewtext = $context->msg( 'skin-preview' )->text();
- # Only show members of Skin::getSkinNames() rather than
- # $skinNames (skins is all skin names from Language.php)
- $validSkinNames = Skin::getUsableSkins();
+ # Only show skins that aren't disabled in $wgSkipSkins
+ $validSkinNames = Skin::getAllowedSkins();
# Sort by UI skin name. First though need to update validSkinNames as sometimes
# the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
@@ -1123,12 +1062,19 @@ class Preferences {
}
asort( $validSkinNames );
+ $config = $context->getConfig();
+ $defaultSkin = $config->get( 'DefaultSkin' );
+ $allowUserCss = $config->get( 'AllowUserCss' );
+ $allowUserJs = $config->get( 'AllowUserJs' );
+
+ $foundDefault = false;
foreach ( $validSkinNames as $skinkey => $sn ) {
$linkTools = array();
# Mark the default skin
- if ( $skinkey == $wgDefaultSkin ) {
+ if ( $skinkey == $defaultSkin ) {
$linkTools[] = $context->msg( 'default' )->escaped();
+ $foundDefault = true;
}
# Create preview link
@@ -1136,25 +1082,34 @@ class Preferences {
$linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
# Create links to user CSS/JS pages
- if ( $wgAllowUserCss ) {
+ if ( $allowUserCss ) {
$cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.css' );
$linkTools[] = Linker::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
}
- if ( $wgAllowUserJs ) {
+ if ( $allowUserJs ) {
$jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.js' );
$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;
}
+ if ( !$foundDefault ) {
+ // If the default skin is not available, things are going to break horribly because the
+ // default value for skin selector will not be a valid value. Let's just not show it then.
+ return array();
+ }
+
return $ret;
}
/**
- * @param $context IContextSource
+ * @param IContextSource $context
* @return array
*/
static function getDateOptions( IContextSource $context ) {
@@ -1169,7 +1124,7 @@ class Preferences {
// Bug 19237
}
- // KLUGE: site default might not be valid for user language
+ // FIXME KLUGE: site default might not be valid for user language
global $wgDefaultUserOptions;
if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
$wgDefaultUserOptions['date'] = 'default';
@@ -1189,16 +1144,14 @@ class Preferences {
}
/**
- * @param $context IContextSource
+ * @param IContextSource $context
* @return array
*/
static function getImageSizes( IContextSource $context ) {
- global $wgImageLimits;
-
$ret = array();
$pixels = $context->msg( 'unit-pixel' )->text();
- foreach ( $wgImageLimits as $index => $limits ) {
+ foreach ( $context->getConfig()->get( 'ImageLimits' ) as $index => $limits ) {
$display = "{$limits[0]}×{$limits[1]}" . $pixels;
$ret[$display] = $index;
}
@@ -1207,16 +1160,14 @@ class Preferences {
}
/**
- * @param $context IContextSource
+ * @param IContextSource $context
* @return array
*/
static function getThumbSizes( IContextSource $context ) {
- global $wgThumbLimits;
-
$ret = array();
$pixels = $context->msg( 'unit-pixel' )->text();
- foreach ( $wgThumbLimits as $index => $size ) {
+ foreach ( $context->getConfig()->get( 'ThumbLimits' ) as $index => $size ) {
$display = $size . $pixels;
$ret[$display] = $index;
}
@@ -1225,29 +1176,35 @@ class Preferences {
}
/**
- * @param $signature string
- * @param $alldata array
- * @param $form HTMLForm
+ * @param string $signature
+ * @param array $alldata
+ * @param HTMLForm $form
* @return bool|string
*/
static function validateSignature( $signature, $alldata, $form ) {
- global $wgParser, $wgMaxSigChars;
- if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
+ global $wgParser;
+ $maxSigChars = $form->getConfig()->get( 'MaxSigChars' );
+ if ( mb_strlen( $signature ) > $maxSigChars ) {
return Xml::element( 'span', array( 'class' => 'error' ),
- $form->msg( 'badsiglength' )->numParams( $wgMaxSigChars )->text() );
+ $form->msg( 'badsiglength' )->numParams( $maxSigChars )->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;
}
}
/**
- * @param $signature string
- * @param $alldata array
- * @param $form HTMLForm
+ * @param string $signature
+ * @param array $alldata
+ * @param HTMLForm $form
* @return string
*/
static function cleanSignature( $signature, $alldata, $form ) {
@@ -1263,13 +1220,18 @@ class Preferences {
}
/**
- * @param $user User
- * @param $context IContextSource
- * @param $formClass string
- * @param array $remove array of items to remove
+ * @param User $user
+ * @param IContextSource $context
+ * @param string $formClass
+ * @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 );
@@ -1300,22 +1262,29 @@ class Preferences {
}
/**
- * @param $context IContextSource
+ * @param IContextSource $context
* @return array
*/
static function getTimezoneOptions( IContextSource $context ) {
$opt = array();
- global $wgLocalTZoffset;
+ $localTZoffset = $context->getConfig()->get( 'LocalTZoffset' );
$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();
+ // Check that the LocalTZoffset is the same as the local time zone offset
+ if ( $localTZoffset == $timestamp->format( 'Z' ) / 60 ) {
+ $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( $localTZoffset / 60 ),
+ abs( $localTZoffset ) % 60
+ );
$server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
}
- $opt[$server_tz_msg] = "System|$wgLocalTZoffset";
+ $opt[$server_tz_msg] = "System|$localTZoffset";
$opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
$opt[$context->msg( 'guesstimezone' )->text()] = 'guess';
@@ -1367,8 +1336,8 @@ class Preferences {
}
/**
- * @param $value
- * @param $alldata
+ * @param string $value
+ * @param array $alldata
* @return int
*/
static function filterIntval( $value, $alldata ) {
@@ -1376,8 +1345,8 @@ class Preferences {
}
/**
- * @param $tz
- * @param $alldata
+ * @param string $tz
+ * @param array $alldata
* @return string
*/
static function filterTimezoneInput( $tz, $alldata ) {
@@ -1410,15 +1379,15 @@ class Preferences {
/**
* Handle the form submission if everything validated properly
*
- * @param $formData
- * @param $form PreferencesForm
- * @param $entryPoint string
+ * @param array $formData
+ * @param PreferencesForm $form
* @return bool|Status|string
*/
- static function tryFormSubmit( $formData, $form, $entryPoint = 'internal' ) {
- global $wgHiddenPrefs, $wgAuth;
+ static function tryFormSubmit( $formData, $form ) {
+ global $wgAuth;
$user = $form->getModifiedUser();
+ $hiddenPrefs = $form->getConfig()->get( 'HiddenPrefs' );
$result = true;
if ( !$user->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
@@ -1435,7 +1404,10 @@ 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', $hiddenPrefs )
+ && $user->isAllowed( 'editmyprivateinfo' )
+ && array_key_exists( 'realname', $formData )
+ ) {
$realName = $formData['realname'];
$user->setRealName( $realName );
}
@@ -1448,8 +1420,7 @@ 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 ) {
+ foreach ( $hiddenPrefs as $pref ) {
# If the user has not set a non-default value here, the default will be returned
# and subsequently discarded
$formData[$pref] = $user->getOption( $pref, null, true );
@@ -1462,6 +1433,7 @@ class Preferences {
$user->setOption( $key, $value );
}
+ wfRunHooks( 'PreferencesFormPreSave', array( $formData, $form, $user, &$result ) );
$user->saveSettings();
}
@@ -1471,12 +1443,12 @@ class Preferences {
}
/**
- * @param $formData
- * @param $form PreferencesForm
+ * @param array $formData
+ * @param PreferencesForm $form
* @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 );
@@ -1501,10 +1473,10 @@ class Preferences {
* Caller is responsible for checking $wgAuth and 'editmyprivateinfo'
* right.
*
- * @deprecated in 1.20; use User::setEmailWithConfirmation() instead.
- * @param $user User
+ * @deprecated since 1.20; use User::setEmailWithConfirmation() instead.
+ * @param User $user
* @param string $newaddr New email address
- * @return Array (true on success or Status on failure, info string)
+ * @return array (true on success or Status on failure, info string)
*/
public static function trySetUserEmail( User $user, $newaddr ) {
wfDeprecated( __METHOD__, '1.20' );
@@ -1516,27 +1488,6 @@ class Preferences {
return array( $result, 'mailerror' );
}
}
-
- /**
- * @deprecated in 1.19
- * @param $user User
- * @return array
- */
- public static function loadOldSearchNs( $user ) {
- wfDeprecated( __METHOD__, '1.19' );
-
- $searchableNamespaces = SearchEngine::searchableNamespaces();
- // Back compat with old format
- $arr = array();
-
- foreach ( $searchableNamespaces as $ns => $name ) {
- if ( $user->getOption( 'searchNs' . $ns ) ) {
- $arr[] = $ns;
- }
- }
-
- return $arr;
- }
}
/** Some tweaks to allow js prefs to work */
@@ -1547,7 +1498,7 @@ class PreferencesForm extends HTMLForm {
private $modifiedUser;
/**
- * @param $user User
+ * @param User $user
*/
public function setModifiedUser( $user ) {
$this->modifiedUser = $user;
@@ -1575,8 +1526,8 @@ class PreferencesForm extends HTMLForm {
}
/**
- * @param $html string
- * @return String
+ * @param string $html
+ * @return string
*/
function wrapForm( $html ) {
$html = Xml::tags( 'div', array( 'id' => 'preferences' ), $html );
@@ -1585,9 +1536,16 @@ class PreferencesForm extends HTMLForm {
}
/**
- * @return String
+ * @return string
*/
function getButtons() {
+ global $wgUseMediaWikiUIEverywhere;
+
+ $attrs = array( 'id' => 'mw-prefs-restoreprefs' );
+ if ( $wgUseMediaWikiUIEverywhere ) {
+ $attrs['class'] = 'mw-ui-button mw-ui-quiet';
+ }
+
if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
return '';
}
@@ -1597,7 +1555,8 @@ class PreferencesForm extends HTMLForm {
if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
$t = SpecialPage::getTitleFor( 'Preferences', 'reset' );
- $html .= "\n" . Linker::link( $t, $this->msg( 'restoreprefs' )->escaped() );
+ $html .= "\n" . Linker::link( $t, $this->msg( 'restoreprefs' )->escaped(),
+ $attrs );
$html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
}
@@ -1608,7 +1567,7 @@ class PreferencesForm extends HTMLForm {
/**
* Separate multi-option preferences into multiple preferences, since we
* have to store them separately
- * @param $data array
+ * @param array $data
* @return array
*/
function filterDataForSubmit( $data ) {
@@ -1637,7 +1596,7 @@ class PreferencesForm extends HTMLForm {
/**
* Get the "<legend>" for a given section key. Normally this is the
* prefs-$key message but we'll allow extensions to override it.
- * @param $key string
+ * @param string $key
* @return string
*/
function getLegend( $key ) {