Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2751564
ext.uls.preferences.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ext.uls.preferences.js
View Options
/*!
* ULS preferences system for MediaWiki.
* Localstorage for anonymous users, preferences for logged in users.
*
* 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
*/
(
function
()
{
'use strict'
;
var
ULSPreferences
,
instance
;
ULSPreferences
=
function
()
{
// This violates coding conventions for localstorage:
// https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Keys
this
.
preferenceName
=
'uls-preferences'
;
this
.
username
=
mw
.
user
.
getName
();
this
.
isNamed
=
mw
.
user
.
isNamed
();
this
.
preferences
=
null
;
this
.
init
();
};
ULSPreferences
.
prototype
=
{
init
:
function
()
{
if
(
this
.
isNamed
)
{
try
{
this
.
preferences
=
JSON
.
parse
(
mw
.
user
.
options
.
get
(
this
.
preferenceName
)
);
}
catch
(
e
)
{
}
}
else
{
this
.
preferences
=
mw
.
storage
.
getObject
(
this
.
preferenceName
);
}
if
(
!
$
.
isPlainObject
(
this
.
preferences
)
)
{
this
.
preferences
=
{};
}
},
/**
* Set the preference
*
* @param {string} key
* @param {Mixed} value
*/
set
:
function
(
key
,
value
)
{
this
.
preferences
[
key
]
=
value
;
},
/**
* Get a preference value for the given preference name
*
* @param {string} key
* @return {Mixed}
*/
get
:
function
(
key
)
{
return
this
.
preferences
[
key
];
},
/**
* Save the preferences
*
* @param {Function} callback
*/
save
:
function
(
callback
)
{
var
self
=
this
;
callback
=
callback
||
function
()
{};
if
(
this
.
isNamed
)
{
// Registered user. Use MW APIs to change preferences
new
mw
.
Api
().
saveOption
(
this
.
preferenceName
,
JSON
.
stringify
(
this
.
preferences
)
).
done
(
function
()
{
callback
.
call
(
self
,
true
);
}
).
fail
(
function
()
{
callback
.
call
(
self
,
false
);
}
);
}
else
{
// Anonymous user. Save preferences in local storage
mw
.
storage
.
setObject
(
this
.
preferenceName
,
this
.
preferences
);
callback
.
call
(
this
,
true
);
}
}
};
module
.
exports
=
function
()
{
instance
=
instance
||
new
ULSPreferences
();
return
instance
;
};
}()
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jul 3, 18:49 (1 d, 16 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d9/f8/4cdd84a4f8f62fd8fb0785fa337d
Default Alt Text
ext.uls.preferences.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment