From 171945efedbf1e7b6810beb71eda94b32c0d9ea6 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Thu, 14 Dec 2006 20:28:38 +0000 Subject: [PATCH] User::getOption now accept a default value to override default user values this makes it consistent with WebRequest::get* methods. Corrected code in various places accordingly. --- RELEASE-NOTES | 3 +++ includes/ImagePage.php | 6 +----- includes/Skin.php | 3 +-- includes/SpecialPreferences.php | 12 +++++------- includes/SpecialRecentchanges.php | 6 ++---- includes/SpecialRecentchangeslinked.php | 4 +--- includes/SpecialSearch.php | 6 ++---- includes/StubObject.php | 4 +--- includes/User.php | 10 ++++++++-- 9 files changed, 24 insertions(+), 30 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 4485307950..d83fb48ffe 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -316,6 +316,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN to replication environments, this will do all accounts in one query). * Allow raw SQL subsections in Database::update() SET portion as well as for WHERE portion. Handy for increments and such. +* User::getOption now accept a default value to override default user values + this makes it consistent with WebRequest::get* methods. Corrected code in + various places accordingly. == Languages updated == diff --git a/includes/ImagePage.php b/includes/ImagePage.php index f0cab0660a..10e9995721 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -170,12 +170,8 @@ class ImagePage extends Article { $full_url = $this->img->getURL(); $anchoropen = ''; $anchorclose = ''; + $sizeSel = intval( $wgUser->getOption( 'imagesize') ); - if( $wgUser->getOption( 'imagesize' ) == '' ) { - $sizeSel = User::getDefaultOption( 'imagesize' ); - } else { - $sizeSel = intval( $wgUser->getOption( 'imagesize' ) ); - } if( !isset( $wgImageLimits[$sizeSel] ) ) { $sizeSel = User::getDefaultOption( 'imagesize' ); } diff --git a/includes/Skin.php b/includes/Skin.php index 982d842924..0e415505a8 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -151,8 +151,7 @@ class Skin extends Linker { global $wgOut, $wgUser; if ( $wgOut->isQuickbarSuppressed() ) { return 0; } - $q = $wgUser->getOption( 'quickbar' ); - if ( '' == $q ) { $q = 0; } + $q = $wgUser->getOption( 'quickbar', 0 ); return $q; } diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index ffe9a09efa..da2d3cd55a 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -337,18 +337,16 @@ class PreferencesForm { * @access private */ function resetPrefs() { - global $wgUser, $wgLang, $wgContLang, $wgAllowRealName; + global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName; $this->mOldpass = $this->mNewpass = $this->mRetypePass = ''; $this->mUserEmail = $wgUser->getEmail(); $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp(); $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : ''; - $this->mUserLanguage = $wgUser->getOption( 'language' ); - if( empty( $this->mUserLanguage ) ) { - # Quick hack for conversions, where this value is blank - global $wgContLanguageCode; - $this->mUserLanguage = $wgContLanguageCode; - } + + # language value might be blank, default to content language + $this->mUserLanguage = $wgUser->getOption( 'language', $wgContLanguageCode ); + $this->mUserVariant = $wgUser->getOption( 'variant'); $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0; $this->mNick = $wgUser->getOption( 'nickname' ); diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index 267d7627f7..86fef6a610 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -43,12 +43,10 @@ function wfSpecialRecentchanges( $par, $specialPage ) { extract($defaults); - $days = $wgUser->getOption( 'rcdays' ); - if ( !$days ) { $days = $defaults['days']; } + $days = $wgUser->getOption( 'rcdays', $defaults['days']); $days = $wgRequest->getInt( 'days', $days ); - $limit = $wgUser->getOption( 'rclimit' ); - if ( !$limit ) { $limit = $defaults['limit']; } + $limit = $wgUser->getOption( 'rclimit', $defaults['limit'] ); # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' ); $limit = $wgRequest->getInt( 'limit', $limit ); diff --git a/includes/SpecialRecentchangeslinked.php b/includes/SpecialRecentchangeslinked.php index 487cdae6f0..2214576c4a 100644 --- a/includes/SpecialRecentchangeslinked.php +++ b/includes/SpecialRecentchangeslinked.php @@ -44,10 +44,8 @@ function wfSpecialRecentchangeslinked( $par = NULL ) { $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'rclsub', $nt->getPrefixedText() ) ) ); if ( ! $days ) { - $days = $wgUser->getOption( 'rcdays' ); - if ( ! $days ) { $days = 7; } + $days = (int)$wgUser->getOption( 'rcdays', 7 ); } - $days = (int)$days; list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' ); $dbr =& wfGetDB( DB_SLAVE ); diff --git a/includes/SpecialSearch.php b/includes/SpecialSearch.php index ac39f292d3..9ecd39efa0 100644 --- a/includes/SpecialSearch.php +++ b/includes/SpecialSearch.php @@ -316,10 +316,8 @@ class SpecialSearch { } $sk =& $wgUser->getSkin(); - $contextlines = $wgUser->getOption( 'contextlines' ); - if ( '' == $contextlines ) { $contextlines = 5; } - $contextchars = $wgUser->getOption( 'contextchars' ); - if ( '' == $contextchars ) { $contextchars = 50; } + $contextlines = $wgUser->getOption( 'contextlines', 5 ); + $contextchars = $wgUser->getOption( 'contextchars', 50 ); $link = $sk->makeKnownLinkObj( $t ); $revision = Revision::newFromTitle( $t ); diff --git a/includes/StubObject.php b/includes/StubObject.php index 0ab44c9daa..1501d96320 100644 --- a/includes/StubObject.php +++ b/includes/StubObject.php @@ -89,9 +89,7 @@ class StubUserLang extends StubObject { function _newObject() { global $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang; - $code = $wgRequest->getVal('uselang', ''); - if ($code == '') - $code = $wgUser->getOption('language'); + $code = $wgRequest->getVal('uselang', $wgUser->getOption('language') ); // if variant is explicitely selected, use it instead the one from wgUser // see bug #7605 diff --git a/includes/User.php b/includes/User.php index 89b1dd0d0d..7f98ee0c0c 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1424,17 +1424,23 @@ class User { /** * @param string $oname The option to check + * @param string $defaultOverride A default value returned if the option does not exist * @return string */ - function getOption( $oname ) { + function getOption( $oname, $defaultOverride = '' ) { $this->load(); + if ( is_null( $this->mOptions ) ) { + if($defaultOverride != '') { + return $defaultOverride; + } $this->mOptions = User::getDefaultOptions(); } + if ( array_key_exists( $oname, $this->mOptions ) ) { return trim( $this->mOptions[$oname] ); } else { - return ''; + return $defaultOverride; } } -- 2.20.1