Merge "Introduced $wgULSAnonCanChangeLanguage"
This commit is contained in:
@@ -19,15 +19,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class UniversalLanguageSelectorHooks {
|
class UniversalLanguageSelectorHooks {
|
||||||
|
/**
|
||||||
|
* Whether ULS user toolbar (language selection and settings) is enabled.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function isToolbarEnabled( $user ) {
|
public static function isToolbarEnabled( $user ) {
|
||||||
global $wgULSEnable, $wgULSEnableAnon;
|
global $wgULSEnable, $wgULSEnableAnon;
|
||||||
if ( !$wgULSEnable ) {
|
if ( !$wgULSEnable ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( !$wgULSEnableAnon ) {
|
if ( !$wgULSEnableAnon && $user->isAnon() ) {
|
||||||
if ( $user->isAnon() ) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -141,7 +143,7 @@ class UniversalLanguageSelectorHooks {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function getLanguage( $user, &$code, $context = null ) {
|
public static function getLanguage( $user, &$code, $context = null ) {
|
||||||
global $wgUser, $wgRequest, $wgULSLanguageDetection;
|
global $wgUser, $wgRequest, $wgULSAnonCanChangeLanguage, $wgULSLanguageDetection;
|
||||||
if ( !self::isToolbarEnabled( $user ) ) {
|
if ( !self::isToolbarEnabled( $user ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -167,27 +169,40 @@ class UniversalLanguageSelectorHooks {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$languageToUse = null;
|
// Registered users - simple
|
||||||
if ( self::isSupportedLanguage( $languageToSave ) ) {
|
if ( !$user->isAnon() ) {
|
||||||
if ( $user->isAnon() ) {
|
// Language change
|
||||||
$request->response()->setcookie( 'language', $languageToSave );
|
if ( self::isSupportedLanguage( $languageToSave ) ) {
|
||||||
} else {
|
|
||||||
$user->setOption( 'language', $languageToSave );
|
$user->setOption( 'language', $languageToSave );
|
||||||
$user->saveSettings();
|
$user->saveSettings();
|
||||||
|
// Apply immediately
|
||||||
|
$code = $languageToSave;
|
||||||
}
|
}
|
||||||
$languageToUse = $languageToSave;
|
// Otherwise just use what is stored in preferences
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load from cookie unless overriden
|
// Logged out users - less simple
|
||||||
if ( $languageToUse === null && $user->isAnon() ) {
|
if ( !$wgULSAnonCanChangeLanguage ) {
|
||||||
$languageToUse = $request->getCookie( 'language' );
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether we got valid language from store or
|
// Language change
|
||||||
// explicit language change.
|
if ( self::isSupportedLanguage( $languageToSave ) ) {
|
||||||
|
$request->response()->setcookie( 'language', $languageToSave );
|
||||||
|
$code = $languageToSave;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try cookie
|
||||||
|
$languageToUse = $request->getCookie( 'language' );
|
||||||
if ( self::isSupportedLanguage( $languageToUse ) ) {
|
if ( self::isSupportedLanguage( $languageToUse ) ) {
|
||||||
$code = $languageToUse;
|
$code = $languageToUse;
|
||||||
} elseif ( $user->isAnon() && $wgULSLanguageDetection ) {
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// As last resort, try Accept-Language headers if allowed
|
||||||
|
if ( $wgULSLanguageDetection ) {
|
||||||
$preferred = $request->getAcceptLang();
|
$preferred = $request->getAcceptLang();
|
||||||
$default = self::getDefaultLanguage( $preferred );
|
$default = self::getDefaultLanguage( $preferred );
|
||||||
if ( $default !== '' ) {
|
if ( $default !== '' ) {
|
||||||
@@ -195,7 +210,7 @@ class UniversalLanguageSelectorHooks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to content language
|
// Fall back to other hooks or content language
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,10 +220,14 @@ class UniversalLanguageSelectorHooks {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function addConfig( &$vars ) {
|
public static function addConfig( &$vars ) {
|
||||||
global $wgULSGeoService, $wgULSIMEEnabled;
|
global $wgULSGeoService, $wgULSIMEEnabled, $wgULSPosition,
|
||||||
$vars['wgULSGeoService'] = $wgULSGeoService;
|
$wgULSAnonCanChangeLanguage;
|
||||||
|
|
||||||
|
// Place constant stuff here (not depending on request context)
|
||||||
|
$vars['wgULSGeoService'] = $wgULSGeoService;
|
||||||
$vars['wgULSIMEEnabled'] = $wgULSIMEEnabled;
|
$vars['wgULSIMEEnabled'] = $wgULSIMEEnabled;
|
||||||
|
$vars['wgULSPosition'] = $wgULSPosition;
|
||||||
|
$vars['wgULSAnonCanChangeLanguage'] = $wgULSAnonCanChangeLanguage;
|
||||||
|
|
||||||
// ULS is localized using jquery.i18n library. Unless it knows
|
// ULS is localized using jquery.i18n library. Unless it knows
|
||||||
// the localized locales, it can create 404 response. To avoid that,
|
// the localized locales, it can create 404 response. To avoid that,
|
||||||
@@ -253,12 +272,11 @@ class UniversalLanguageSelectorHooks {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function addVariables( &$vars, OutputPage $out ) {
|
public static function addVariables( &$vars, OutputPage $out ) {
|
||||||
|
// Place request context dependent stuff here
|
||||||
$vars['wgULSLanguages'] = Language::fetchLanguageNames(
|
$vars['wgULSLanguages'] = Language::fetchLanguageNames(
|
||||||
$out->getLanguage()->getCode(), 'mwfile'
|
$out->getLanguage()->getCode(), 'mwfile'
|
||||||
);
|
);
|
||||||
$vars['wgULSAcceptLanguageList'] = array_keys( $out->getRequest()->getAcceptLang() );
|
$vars['wgULSAcceptLanguageList'] = array_keys( $out->getRequest()->getAcceptLang() );
|
||||||
global $wgULSPosition;
|
|
||||||
$vars['wgULSPosition'] = $wgULSPosition;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -284,6 +302,10 @@ class UniversalLanguageSelectorHooks {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !self::isToolbarEnabled( $skin->getUser() ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// A dummy link, just to make sure that the section appears
|
// A dummy link, just to make sure that the section appears
|
||||||
$template->data['language_urls'][] = array(
|
$template->data['language_urls'][] = array(
|
||||||
'href' => '#',
|
'href' => '#',
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
|
|||||||
/**
|
/**
|
||||||
* Version number used in extension credits and in other placed where needed.
|
* Version number used in extension credits and in other placed where needed.
|
||||||
*/
|
*/
|
||||||
define( 'ULS_VERSION', '2013-04-01' );
|
define( 'ULS_VERSION', '2013-04-27' );
|
||||||
|
|
||||||
$wgExtensionCredits['other'][] = array(
|
$wgExtensionCredits['other'][] = array(
|
||||||
'path' => __FILE__,
|
'path' => __FILE__,
|
||||||
@@ -57,32 +57,53 @@ $wgExtensionCredits['other'][] = array(
|
|||||||
$wgULSGeoService = 'http://freegeoip.net/json/';
|
$wgULSGeoService = 'http://freegeoip.net/json/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IME system of ULS can be disabled by setting this value false;
|
* Enable language selection, input methods and webfonts for everyone, unless
|
||||||
*/
|
* the behavior is overridden by the configuration variables below.
|
||||||
$wgULSIMEEnabled = true;
|
*
|
||||||
|
* Even if false the classes and resource loader modules are registered for the
|
||||||
/**
|
* use of other extensions. Language changing via cookie or setlang query
|
||||||
* Try to use preferred interface language for anonymous users.
|
* parameter is not possible.
|
||||||
* Do not use if you are caching anonymous page views without
|
|
||||||
* taking Accept-Language into account.
|
|
||||||
*/
|
|
||||||
$wgULSLanguageDetection = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable language selection. If language selection is disabled, the classes
|
|
||||||
* and RL modules are registered for the use of other extensions, but no
|
|
||||||
* language selection toolbar is shown, and it will not be possible to change
|
|
||||||
* the interface language using a cookie.
|
|
||||||
*/
|
*/
|
||||||
$wgULSEnable = true;
|
$wgULSEnable = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable ULS language selection for anonymous users. Equivalent to $wgULSEnable
|
* Equivalent to $wgULSEnable for anonymous users only.
|
||||||
* except that it only applies to anonymous users. Setting this to false will
|
*
|
||||||
* avoid breaking Squid caches (see bug 41451).
|
* Does not have any effect if $wgULSEnable is false.
|
||||||
*/
|
*/
|
||||||
$wgULSEnableAnon = true;
|
$wgULSEnableAnon = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow anonymous users to change language with cookie and setlang
|
||||||
|
* query param.
|
||||||
|
|
||||||
|
* Do not use if you are caching anonymous page views without
|
||||||
|
* taking cookies into account.
|
||||||
|
*
|
||||||
|
* Does not have any effect if either of $wgULSEnable or
|
||||||
|
* $wgULSEnableAnon is set to false.
|
||||||
|
*
|
||||||
|
* @since 2013.04
|
||||||
|
*/
|
||||||
|
$wgULSAnonCanChangeLanguage = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to use preferred interface language for anonymous users.
|
||||||
|
*
|
||||||
|
* Do not use if you are caching anonymous page views without
|
||||||
|
* taking Accept-Language into account.
|
||||||
|
*
|
||||||
|
* Does not have any effect if any of $wgULSEnable, $wgULSEnableAnon
|
||||||
|
* or $wgULSAnonCanChangeLanguage is set to false.
|
||||||
|
*/
|
||||||
|
$wgULSLanguageDetection = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the input methods feature for all users by default. Can still
|
||||||
|
* be enabled manually by the user.
|
||||||
|
*/
|
||||||
|
$wgULSIMEEnabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The location and the form of the language selection trigger.
|
* The location and the form of the language selection trigger.
|
||||||
* The possible values are:
|
* The possible values are:
|
||||||
|
|||||||
Reference in New Issue
Block a user