On Friday 23 April 2004 13:46, Brion Vibber wrote:
On Apr 23, 2004, at 03:57, Nikola Smolenski wrote:
I have managed to make changes to code which
enable users to choose
their user
interface language, feature sought at Wikisource, Wiktionary etc. To
whom
should I send the code?
Same place you're posting this question. :)
Since that message, I've noticed some bugs and had no time to fix them, but
now I think I can present a beta version. Note I worked against 1.2.0rc3 and
not against the CVS; this because if I did something in the wrong way, and a
rewrite is needed, I didn't want to adapt to CVS changes at the same time. I
hope this will be no problem. I have to say that I have a SF account and know
how to work with the CVS, so I can submit the code changes directly to it, if
needed. Differences follow:
I think that this is quite selfexplanatory. If $wgLanguageCode is a string,
then there is old-fashioned monolingual interface. If it is an array, then a
multilingual interface.
LocalSettings.php:
$wgLanguageCode = array("en","de","sr");
Changes in SpecialPreferences.php were the most straightforward. If
$wpLanguage is satisfying name, they may go to the CVS, they do no harm even
if nothing else is imlepmented. I have put language chooser at the very top,
since users who do not know the main language will need it the most.
***
../../Documents/Download/mediawiki-1.2.0rc3/includes/SpecialPreferences.phpWed
Feb 18 03:14:56 2004
--- ./SpecialPreferences.php Sat May 8 11:30:09 2004
***************
*** 87,92 ****
--- 87,93 ----
global $wpSkin, $wpMath, $wpDate, $wpUserEmail, $wpEmailFlag, $wpNick,
$wpSearch, $wpRecent;
global $wpSearchLines, $wpSearchChars, $wpStubs;
global $wpRows, $wpCols, $wpHourDiff, $HTTP_POST_VARS;
+ global $wpLanguage;
if ( "" != $wpNewpass ) {
if ( $wpNewpass != $wpRetypePass ) {
***************
*** 116,121 ****
--- 117,123 ----
$wgUser->setOption( "cols", validateInt( $wpCols, 4, 1000 ) );
$wgUser->setOption( "stubthreshold", validateIntOrNull( $wpStubs )
);
$wgUser->setOption( "timecorrection", validateTimeZone( $wpHourDiff,
-12, 14 ) );
+ $wgUser->setOption( "language", $wpLanguage );
$namespaces = $wgLang->getNamespaces();
# Set search namespace options
***************
*** 151,156 ****
--- 153,159 ----
global $wpRows, $wpCols, $wpSkin, $wpMath, $wpDate, $wpUserEmail,
$wpEmailFlag, $wpNick;
global $wpSearch, $wpRecent, $HTTP_POST_VARS;
global $wpHourDiff, $wpSearchLines, $wpSearchChars;
+ global $wpLanguage;
$wpOldpass = $wpNewpass = $wpRetypePass = "";
$wpUserEmail = $wgUser->getEmail();
***************
*** 170,175 ****
--- 173,179 ----
$wpSearchLines = $wgUser->getOption( "contextlines" );
$wpSearchChars = $wgUser->getOption( "contextchars" );
$wpRecent = $wgUser->getOption( "rclimit" );
+ $wpLanguage = $wgUser->getOption( "language" );
$togs = $wgLang->getUserToggles();
foreach ( $togs as $tname => $ttext ) {
***************
*** 213,223 ****
/* private */ function mainPrefsForm( $err )
{
! global $wgUser, $wgOut, $wgLang, $wgUseDynamicDates;
global $wpQuickbar, $wpOldpass, $wpNewpass, $wpRetypePass;
global $wpSkin, $wpMath, $wpDate, $wpUserEmail, $wpEmailFlag, $wpNick,
$wpSearch, $wpRecent;
global $wpRows, $wpCols, $wpSaveprefs, $wpReset, $wpHourDiff;
global $wpSearchLines, $wpSearchChars, $wpStubs, $wgValidSkinNames;
$wgOut->setPageTitle( wfMsg( "preferences" ) );
$wgOut->setArticleRelated( false );
--- 217,228 ----
/* private */ function mainPrefsForm( $err )
{
! global $wgUser, $wgOut, $wgLang,
$wgUseDynamicDates,$wgLanguageArray,$wgLanguageCode,$wgLanguageNames;
global $wpQuickbar, $wpOldpass, $wpNewpass, $wpRetypePass;
global $wpSkin, $wpMath, $wpDate, $wpUserEmail, $wpEmailFlag, $wpNick,
$wpSearch, $wpRecent;
global $wpRows, $wpCols, $wpSaveprefs, $wpReset, $wpHourDiff;
global $wpSearchLines, $wpSearchChars, $wpStubs, $wgValidSkinNames;
+ global $wpLanguage;
$wgOut->setPageTitle( wfMsg( "preferences" ) );
$wgOut->setArticleRelated( false );
***************
*** 269,275 ****
$dsn = wfMsg( "defaultns" );
$wgOut->addHTML( "<form id=\"preferences\"
name=\"preferences\"
action=\"$action\"
! method=\"post\"><table border=\"1\"><tr><td
valign=top
nowrap><b>$qb:</b><br>\n" );
# Quickbar setting
#
--- 274,290 ----
$dsn = wfMsg( "defaultns" );
$wgOut->addHTML( "<form id=\"preferences\"
name=\"preferences\"
action=\"$action\"
! method=\"post\"><table border=\"1\">");
!
! if(is_array($wgLanguageArray)) {
! $wgOut->addHTML("<tr><td
colspan=2><b>Language:</b>");
! $wgOut->addHTML("<select
name=\"wpLanguage\">");
! foreach($wgLanguageArray as $v)
! $wgOut->addHTML("<option value=\"$v\"
".(($v==$wpLanguage)?"selected":"").">{$wgLanguageNames[$v]}</option>");
! $wgOut->addHTML("</select></td></tr>");
! }
!
! $wgOut->addHTML("<tr><td valign=top
nowrap><b>$qb:</b><br>\n" );
# Quickbar setting
#
Most changes were needed to the Setup.php. Creation of an user and loading of
the language had to be executed earlier, but that is not a problem. But here
there was a big problem with circular dependency. User.php requires
Language.php because some default user settings are language-dependent. But,
apparently, an user must be created in order to know which language settings
to choose! I have not solved this in a satisfactory enough way, and all users
have, let's call them, international default settings:
*** ../../Documents/Download/mediawiki-1.2.0rc3/includes/Setup.php Thu
Feb 26 14:37:26 2004
--- ./Setup.php Sat May 8 11:46:25 2004
***************
*** 123,129 ****
--- 123,146 ----
wfProfileOut( "$fname-memcached" );
wfProfileIn( "$fname-misc" );
+ if( !$wgCommandLineMode && isset( $_COOKIE[ini_get("session.name")] )
) {
+ User::SetupSession();
+ }
+
include_once( "Language.php" );
+ $wgUser = User::loadFromSession();
+ if(is_array($wgLanguageCode)) {
+ $wgLanguageArray=$wgLanguageCode;
+
if($_GET['language']&&in_array($_GET['language'],$wgLanguageArray))
{
+ $wgLanguageCode=$_GET['language'];
+ } else
if($_POST['wpLanguage']&&in_array($_POST['wpLanguage'],$wgLanguageArray))
{
+ $wgLanguageCode=$_POST['wpLanguage'];
+ } else {
+ $wgLanguageCode = $wgUser->getOption("language");
+ }
+ }
+ @include_once( "Language" . ucfirst( $wgLanguageCode ) . ".php" );
+ if(is_array($wgLanguageArray)) eval("\$wgNamespaceNames".ucfirst(
$wgLanguageCode )."=\$wgNamespaceNamesEn;");
$wgMessageCache = new MessageCache;
***************
*** 148,159 ****
$wgDateFormatter = new DateFormatter;
}
- if( !$wgCommandLineMode && isset( $_COOKIE[ini_get("session.name")] )
) {
- User::SetupSession();
- }
-
$wgBlockCache = new BlockCache( true );
- $wgUser = User::loadFromSession();
$wgDeferredUpdateList = array();
$wgLinkCache = new LinkCache();
$wgMagicWords = array();
--- 165,171 ----
I have copied these international settings from English settings:
*** ../../Documents/Download/mediawiki-1.2.0rc3/includes/User.php Sun
Mar 7 11:07:17 2004
--- ./User.php Sat May 8 11:18:45 2004
***************
*** 11,16 ****
--- 11,26 ----
/* private */ var $mBlockedby, $mBlockreason;
/* private */ var $mTouched;
/* private */ var $mCookiePassword;
+ /* private */ var $wgDefaultUserOptions = array(
+ "quickbar" => 1, "underline" => 1,
"hover" => 1,
+ "cols" => 80, "rows" => 25,
"searchlimit" => 20,
+ "contextlines" => 5, "contextchars" => 50,
+ "skin" => 0, "math" => 1, "rcdays"
=> 7, "rclimit" => 50,
+ "highlightbroken" => 1, "stubthreshold" => 0,
+ "previewontop" => 1,
"editsection"=>1,"editsectiononrightclick"=>0,
"showtoc"=>1,
+ "showtoolbar" =>1,
+ "date" => 0, "language" => "en"
+ );
function User()
{
***************
*** 70,76 ****
function loadDefaults()
{
! global $wgLang, $wgIP;
global $wgNamespacesToBeSearchedDefault;
$this->mId = $this->mNewtalk = 0;
--- 80,86 ----
function loadDefaults()
{
! global $wgLang, $wgIP, $wgLanguageCode;
global $wgNamespacesToBeSearchedDefault;
$this->mId = $this->mNewtalk = 0;
***************
*** 78,84 ****
$this->mEmail = "";
$this->mPassword = $this->mNewpassword = "";
$this->mRights = array();
! $defOpt = $wgLang->getDefaultUserOptions() ;
foreach ( $defOpt as $oname => $val ) {
$this->mOptions[$oname] = $val;
}
--- 88,94 ----
$this->mEmail = "";
$this->mPassword = $this->mNewpassword = "";
$this->mRights = array();
! $defOpt = $this->wgDefaultUserOptions;
foreach ( $defOpt as $oname => $val ) {
$this->mOptions[$oname] = $val;
}
Unrelated to multilingual interface, this is needed because some PHP versions
stupidly throw an error when the file is not present:
*** ../../Documents/Download/mediawiki-1.2.0rc3/includes/GlobalFunctions.php
Thu Feb 26 21:08:45 2004
--- ./GlobalFunctions.php Fri Mar 12 12:27:18 2004
***************
*** 231,237 ****
global $wgReadOnlyFile;
if ( "" == $wgReadOnlyFile ) { return false; }
! return is_file( $wgReadOnlyFile );
}
$wgReplacementKeys = array( "$1", "$2", "$3",
"$4", "$5", "$6", "$7", "$8",
"$9" );
--- 231,237 ----
global $wgReadOnlyFile;
if ( "" == $wgReadOnlyFile ) { return false; }
! return @is_file( $wgReadOnlyFile );
}
$wgReplacementKeys = array( "$1", "$2", "$3",
"$4", "$5", "$6", "$7", "$8",
"$9" );
So, what do you think?