User:Caburum/global.js

// Caburum's global JS v3

window.dev = window.dev || {}; window.caburum = { // Declare static stuff, extended in the main JS	wg: mw.config.get([		'isGamepedia',		'profileUserId',		'skin',		'wgCanonicalSpecialPageName',		'wgCityId',		'wgContentLanguage',		'wgNamespaceIds',		'wgNamespaceNumber',		'wgScriptPath',		'wgUserGroups',		'wgUserName'	]), init: function { // Runs main JS		if (mw.util.getParamValue('useglobaljs') || mw.util.getParamValue('usecabjs')) return this.log('Did not execute global.js from Community Central, disabled'); this.main(this, window.mediaWiki, window.jQuery); },	log: function { // Formatted console.log console.log.apply(null, Array.prototype.concat('%c[CABURUM]', 'color: #00D6D6; background-color: #111;', Array.prototype.slice.call(arguments))); } };

window.caburum.main = function(cab, mw, $) { if (cab.mainJSLoaded) return; // Already loaded cab.mainJSLoaded = true;

// Set the current user's groups to true in groups object cab.groups = {}; cab.wg.wgUserGroups.forEach(function(group) {		cab.groups[group] = true;	});

cab.isBotAccount = /bot/i.test(cab.wg.wgUserName);

// Script config $.extend(/* deep copy = */ true, window, {		AjaxRename: { // w:c:dev:AjaxRename			check: {				leaveredirect: false,				watch: false,				movetalk: true			},			renameReasons: {				'Normal': {					'Misnamed': 'Misnamed',					'Better name': 'Better name',					'Fixing capitalization': 'Fixing capitalization'				},				'Other': {					'Page does not belong in namespace': 'Page does not belong in namespace',				}			}		},		andrewds1021: {			view_notifications_users: { // w:c:dev:ViewNotificationsUsers				all_types: true,				content: 'name'			},			ignore_notifications: { // w:c:dev:IgnoreNotifications				ignore_errors: true,				filters: [					{ types: 'discussion-upvote' },					// { wiki_ids: [], types: 'announcement-target' }				]			}		},		AutoCreateUserPagesConfig: { // w:c:dev:MediaWiki:AutoCreateUserPages.js			content: {				2: cab.wg.isGamepedia ?					'' : // Temp GP fix					(cab.isBotAccount ? '{{raw:w::User:{{subst:' + 'PAGENAME' + '}}' // Bot CC userpage : '{{raw:w::User:{{subst:' + 'PAGENAME' + '}}/Profile' + ((cab.wg.wgUserName === 'Caburum' && [ 'fr' ].includes(cab.wg.wgContentLanguage)) ? cab.wg.wgContentLanguage : '') + '}}' // User template ),				3: false,				1202: false			},			summary: 'Automated user page creation'		},		dev: {			i18n: {overrides: { // i18n overrides				Rollback: {					summary: 'Reverted edits by $1 (talk) to last version by $2'				}			}}		},		fdButtons: [ // w:c:dev:FastDelete			{ summary: 'Housekeeping', label: 'HK' },			{ summary: 'Vandalism', label: 'V' },			{ summary: 'Spam', label: 'S' },			{ summary: 'Duplicate', label: 'Dp' }		],		globalNavButtons: [], // w:c:dev:GlobalNavButtons, populated below		lastEdited: { // w:c:dev:LastEdited			avatar: false,			diffModal: false // Use w:c:dev:QuickDiff instead		},		MessageBlock: { // w:c:dev:MessageBlock			title: 'Blocked',			message: 'You have received a $2 block for the reason: \'$1\'. Unless otherwise stated, you may appeal your block on my message wall at Community Central.',			autocheck: true }	});

// w:c:dev:GlobalNavButtons cab.globalNavLink = function(title, url, args) { // Creates a GlobalNavButtons object for an external link args = { p: args.p || undefined, m: args.m || false, i: (args.i || {}).outerHTML || args.i || undefined };		return { text: title, url: url, isMain: args.m ? true : false, whoIsMain: args.m ? false : args.p, shortName: args.m ? args.m : title, icon: args.i		}; };

cab.globalNavPage = function(title, page, args) { // Creates a GlobalNavButtons object for an internal page return cab.globalNavLink(title, mw.util.getUrl(page) + (args.r ? '?' + args.r : ''), args); };

mw.hook('dev.wds').add(function(wds) {		window.globalNavButtons.push( /* Patrolling */ cab.globalNavPage('Recent Changes', 'Special:RecentChanges', {m: 'RC', i: wds.icon('activity-small')}), cab.globalNavPage('New files', 'Special:NewFiles', {p: 'RC'}), cab.globalNavPage('New pages', 'Special:NewPages', {p: 'RC'}), cab.globalNavPage('New messages', 'Special:SocialActivity', {p: 'RC', r: 'containerTypes=WALL'}), cab.globalNavPage('New comments', 'Special:SocialActivity', {p: 'RC', r: 'containerTypes=ARTICLE_COMMENT'}), /* Social */ cab.globalNavLink('Forum', cab.wg.wgScriptPath + '/f', {m: false, p: false, i: wds.icon('discussions-small')}), /* MediaWiki */ cab.globalNavPage('MediaWiki', 'Special:AllPages/MediaWiki:', {m: 'MW', i: wds.icon('controls-small')}), cab.globalNavPage('Common CSS', 'MediaWiki:Common.css', {p: 'MW'}), cab.globalNavPage('Common JavaScript', 'MediaWiki:Common.js', {p: 'MW'}), cab.globalNavPage('FandomDesktop CSS', 'MediaWiki:Fandomdesktop.css', {p: 'MW'}), cab.globalNavPage('FandomDesktop JavaScript', 'MediaWiki:Fandomdesktop.js', {p: 'MW'}), cab.globalNavPage('ImportJS', 'MediaWiki:ImportJS', {p: 'MW'}), cab.globalNavPage('Wiki navigation', 'MediaWiki:Wiki-navigation', {p: 'MW'}), cab.globalNavPage('Oasis CSS', 'MediaWiki:Wikia.css', {p: 'MW'}), cab.globalNavPage('Oasis JS', 'MediaWiki:Wikia.js', {p: 'MW'}), /* Personal */ cab.globalNavPage('Me', 'Special:MyPage', {m: 'ME', i: wds.icon('user-small')}), cab.globalNavPage('Sandbox', 'Special:MyPage/Sandbox', {p: 'ME'}), cab.globalNavPage('Subpages', 'Special:PrefixIndex/', {p: 'ME'}), cab.globalNavPage('Local JavaScript', 'Special:MyPage/common.js', {p: 'ME'}), cab.globalNavPage('Local CSS', 'Special:MyPage/common.css', {p: 'ME'}), cab.globalNavLink('Global JavaScript', 'https://community.fandom.com/wiki/Special:MyPage/global.js', {p: 'ME'}), cab.globalNavLink('Global CSS', 'https://community.fandom.com/wiki/Special:MyPage/global.css', {p: 'ME'}), /* Wikis */ cab.globalNavLink('Wikis', 'https://caburum.fandom.com/wiki/User:Caburum/RecentChanges', {m: 'W', i: wds.icon('wikis-small')}), cab.globalNavLink('Among Us Wiki', 'https://among-us.fandom.com/wiki/', {p: 'W'}), cab.globalNavLink('Community Central', 'https://community.fandom.com/wiki/', {p: 'W'}), cab.globalNavLink('Dev Wiki', 'https://dev.fandom.com/wiki/', {p: 'W'}), cab.globalNavLink('Discord Wiki', 'https://discord.fandom.com/wiki/', {p: 'W'}), cab.globalNavLink('Test Wiki', 'https://caburum.fandom.com/wiki/', {p: 'W'}), cab.globalNavLink('Customize Your Wiki', 'https://custom.fandom.com/wiki/', {p: 'W'}) );	});

if (cab.groups.sysop || cab.groups['content-moderator'] || cab.groups.threadmoderator) { window.globalNavButtons.push(			cab.globalNavLink('Reported posts', cab.wg.wgScriptPath + '/f/reported', {p: 'RC'})		); }

if (cab.wg.wgNamespaceIds.gadget) { window.globalNavButtons.push(			cab.globalNavPage('Gadgets', 'Special:Gadgets', {p: 'MW'})		); }

// Execute local JS only if main JS ran if (mw.util.getParamValue('uselocaljs')) { cab.log('Did not execute common.js, disabled'); } else { mw.hook('caburum.runLocalJS').fire(cab); }

// Scripts to import per source, dependent on user groups cab.scripts = [ { // Dev Wiki prefix: 'u:dev:MediaWiki:', scripts: { // Libraries 'WDSIcons/code': 1,

// Maintenance 'AjaxBatchDelete': ['sysop', 'content-moderator'], 'AjaxRename/code': 1, 'BulkVideoUpload': cab.isBotAccount, 'FastDelete/code': ['sysop', 'content-moderator'], 'Rollback/code': 1, 'AnchoredRollback/code': 1, 'ListFiles/code': ['Listfiles', 'Unusedimages', 'Uncategorizedimages'].includes(cab.wg.wgCanonicalSpecialPageName), 'MassCategorization': 1, 'MassNullEdit/code': 1,

// Admin //'AjaxBlock/code': ['sysop'], // Conflicts with MessageBlock 'MessageBlock/code': cab.wg.wgCanonicalSpecialPageName === 'Block' ? 'sysop' : false, 'SOAPReport': cab.wg.wgCanonicalSpecialPageName === 'Contributions', 'WHAM/code.2': cab.wg.wgCanonicalSpecialPageName === 'Contributions' ? ['sysop', 'content-moderator', 'threadmoderator', 'rollback'] : false,

// Tools 'QuickDiff/code': 1, 'UploadMultipleFiles': cab.wg.wgCanonicalSpecialPageName === 'Upload', 'LastEdited/code': 1, // 'FastCreate': 1, 'QuickPurge': 1, 'CopyTitle': 1, 'DiscussionTemplates': { ns: 1200 },

// Personal 'DisplayTimer/code': 1, 'AutoCreateUserPages': 1, 'GlobalNavButtons': 1,

// Social // 'ViewNotificationsUsers': 1, 'IgnoreNotifications': 1, 'UserAndIPTools': cab.wg.profileUserId,

// Editing 'ImageMapEdit': { ns: 6 } }		},		{ // Caburum Testing Wiki prefix: 'u:caburum:MediaWiki:', scripts: { 'BadgeStatusUpdater': document.getElementsByClassName('UserProfileAchievementsModule').length > 0, 'RecentWikiActivityDiff': 1, 'ThemeSwitcher': { skin: 'fandomdesktop' } }		},		{ // Personal prefix: 'u:caburum:User:Caburum/', scripts: { 'MassEdit': 1 }		}	];

// Load scripts based on criteria var articles = []; cab.scripts.forEach(function(source) {		$.each(source.scripts, function(script, data) { var g = []; if (Array.isArray(data)) { // Array of group rights g = data; } else if (typeof data === 'string') { // Single group g = [data]; } else if (typeof data === 'object' && data !== null) { // Advanced config g = g.concat(data.groups || data.group || true); if ((data.skins || data.skin) && ![].concat(data.skins || data.skin).includes(cab.wg.skin)) return; if ((data.wikis || data.wiki) && ![].concat(data.wikis || data.wiki).includes(cab.wg.wgCityId)) return; if (data.ns && ![].concat(data.ns).includes(cab.wg.wgNamespaceNumber)) return; } else if (Boolean(data)) { // true boolean g = true; } else return;

// If all other checks pass, then check groups if (g === true || g.filter(function(group) { return cab.groups[group]; }).length > 0) { articles.push(source.prefix + script + '.js'); }		});	});

importArticles({		type: 'script',		articles: articles	});

cab.log('Executed global.js from Community Central'); };

mw.loader.using('mediawiki.util', function {	$(window.caburum.init.bind(window.caburum)); });