Files
mediawiki-extensions-Univer…/UniversalLanguageSelector.php
Niklas Laxström 6b143320ad Introduced $wgULSAnonCanChangeLanguage
This allows us to enable web fonts and input methods for all
users by disabling just the interface language selection.

Updated the documentation of the variables to make it clearer
what each does. Summary:
* Enabling: $wgULSEnable and $wgULSEnableAnon
* Workarounds: $wgULSAnonCanChangeLanguage and $wgULSLanguageDetection

Cleaned up hooks, in particular rewritten getLanguage to separate
the logged in vs. logged out steps for easier understanding.

A followup commit is needed to disable language selection UI for
anon if $wgULSAnonCanChangeLanguage is false.

Change-Id: Ia8d21c394ff5efac0ce94664710c97dc3b74ec18
2013-04-26 12:21:23 +00:00

142 lines
4.8 KiB
PHP

<?php
/**
* Initialisation file for MediaWiki extension UniversalLanguageSelector.
*
* Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
* contributors. See CREDITS for a list.
*
* UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't
* have to do anything special to choose one license or the other and you don't
* have to notify anyone which license you are using. You are free to use
* UniversalLanguageSelector in commercial projects as long as the copyright
* header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
*
* @file
* @ingroup Extensions
* @licence GNU General Public Licence 2.0 or later
* @licence MIT License
*/
if ( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( -1 );
}
/**
* Version number used in extension credits and in other placed where needed.
*/
define( 'ULS_VERSION', '2013-04-27' );
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'UniversalLanguageSelector',
'version' => ULS_VERSION,
'author' => array(
'Alolita Sharma',
'Amir Aharoni',
'Arun Ganesh',
'Brandon Harris',
'Niklas Laxström',
'Pau Giner',
'Santhosh Thottingal',
'Siebrand Mazeland'
),
'url' => 'https://www.mediawiki.org/wiki/Extension:UniversalLanguageSelector',
'descriptionmsg' => 'uls-desc',
);
/**
* ULS can use geolocation services to suggest languages based on the
* country the user is vising from. Setting this to false will prevent
* builtin geolocation from being used. You can provide your own geolocation
* by setting window.Geo to object which has key 'country_code' or 'country'.
* This is what Wikipedia does.
*
* The service should return jsonp that uses the supplied callback parameter.
*/
$wgULSGeoService = 'http://freegeoip.net/json/';
/**
* Enable language selection, input methods and webfonts for everyone, unless
* the behavior is overridden by the configuration variables below.
*
* Even if false the classes and resource loader modules are registered for the
* use of other extensions. Language changing via cookie or setlang query
* parameter is not possible.
*/
$wgULSEnable = true;
/**
* Equivalent to $wgULSEnable for anonymous users only.
*
* Does not have any effect if $wgULSEnable is false.
*/
$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 possible values are:
* 'personal': as a link near the username or the log in link in
* the personal toolbar (default).
* 'interlanguage': as an icon near the header of the list of interlanguage
* links in the sidebar.
*
* @since 2013.04
*/
$wgULSPosition = 'personal';
$dir = __DIR__;
// Internationalization
$wgExtensionMessagesFiles['UniversalLanguageSelector'] = "$dir/UniversalLanguageSelector.i18n.php";
// Register auto load for the page class
$wgAutoloadClasses['UniversalLanguageSelectorHooks'] = "$dir/UniversalLanguageSelector.hooks.php";
$wgAutoloadClasses['ApiLanguageSearch'] = "$dir/api/ApiLanguageSearch.php";
$wgAutoloadClasses['LanguageNameSearch'] = "$dir/data/LanguageNameSearch.php";
$wgHooks['BeforePageDisplay'][] = 'UniversalLanguageSelectorHooks::addModules';
$wgHooks['PersonalUrls'][] = 'UniversalLanguageSelectorHooks::addPersonalBarTrigger';
$wgHooks['ResourceLoaderTestModules'][] = 'UniversalLanguageSelectorHooks::addTestModules';
$wgHooks['ResourceLoaderGetConfigVars'][] = 'UniversalLanguageSelectorHooks::addConfig';
$wgHooks['MakeGlobalVariablesScript'][] = 'UniversalLanguageSelectorHooks::addVariables';
$wgAPIModules['languagesearch'] = 'ApiLanguageSearch';
$wgHooks['UserGetLanguageObject'][] = 'UniversalLanguageSelectorHooks::getLanguage';
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'UniversalLanguageSelectorHooks::onSkinTemplateOutputPageBeforeExec';
$wgDefaultUserOptions['uls-preferences'] = '';
$wgHooks['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences';
require( "$dir/Resources.php" );