Fandom

Wikia Developers Wiki

Preferences/Api

< Preferences

869pages on
this wiki
Add New Page
Talk0 Share

{{{1}}}.local

{{{1}}}.local()
fetches the user's preferences for the current wiki
{{{1}}}.local(wiki)
fetches the user's preferences for the specified wiki. The name should be the same as in interwiki links - not the wgDBname which is occasionally different. Community Central e.g. has the interwiki name "community" but the wgDBname "wikicities". The interwiki name is identical with the subdomain name: http://community.wikia.com
returns mediaWiki.Map
{{{1}}}.local returns a wrapper for the original data. Any change you will make to the map will be saved.
var map = data.local();
 
// fetch the property "example" from the map and
// returns null if property is not set:
example = map.get('example');
 
// fetch the property "example" from the map and 
// return "hello world" if the property is not set:
example = map.get('example', 'hello world');
 
// set the property "example":
map.set('example', 'hello world');
 
// set multiple properties without overwriting the map:
// map is: { two: 2 }
map.set({ one: 1, three: 3 });
// map is: { one: 1, two: 2, three: 3 }
 
// test if a property "example" is set:
if (map.exists('example')) { /*...*/ }
 
// the objects gets cached, so calling local()
// multiple times will yield the same object:
console.log(data.local() === data.local());
available after {{{2}}}() has fired

{{{1}}}.global

{{{1}}}.global()
fetches the user's preferences for all wikis
returns mediaWiki.Map
{{{1}}}.global returns a wrapper for the original data. Any change you will make to the map will be saved.
var map = data.global();
 
// fetch the property "example" from the map and
// returns null if property is not set:
example = map.get('example');
 
// fetch the property "example" from the map and 
// return "hello world" if the property is not set:
example = map.get('example', 'hello world');
 
// set the property "example":
map.set('example', 'hello world');
 
// set multiple properties without overwriting the map:
// map is: { two: 2 }
map.set({ one: 1, three: 3 });
// map is: { one: 1, two: 2, three: 3 }
 
// test if a property "example" is set:
if (map.exists('example')) { /*...*/ }
 
// the objects gets cached, so calling global()
// multiple times will yield the same object:
console.log(data.global() === data.global());
available after {{{2}}}() has fired

{{{1}}}.shared

{{{1}}}.shared()
fetches the shared object for the current user
{{{1}}}.shared(user)
fetches the shared object for the specified user; will throw an Error if user is not a string
returns mediaWiki.Map
{{{1}}}.shared - unlike {{{1}}}.local and {{{1}}}.global - returns a clone of the original data. Only the user can modify the original shared data. You cannot. Not on Special:Scripts and not on any other page.
var map = data.shared('someUser');
 
// fetch the property "example" from the map and
// returns null if property is not set:
example = data.shared('someUser').get('example');
 
// fetch the property "example" from the map and 
// return "hello world" if the property is not set:
example = map.get('example', 'hello world');
 
// test if a property "example" is set:
if (map.exists('example')) { /*...*/ }
 
// the objects gets cached, so calling shared()
// multiple times will yield the same object:
console.log(data.shared('someUser') === data.shared('someUser'));
available after {{{2}}}() has fired

{{{1}}}.log

{{{1}}}.log()
logs the {{{1}}} object to the console (where available)
returns nothing
data.log();
available after {{{2}}}() has fired

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.