Jump to content

User:NguoiDungKhongDinhDanh/Dashboard.js/me.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// jshint esversion: 10

(function() {
	let v = {
		page: mw.config.get('wgPageName'),
		user: mw.config.get('wgUserName'),
		tuser: mw.config.get('wgRelevantUserName'),
		lang: mw.config.get('wgContentLanguage'),
		ns: mw.config.get('wgNamespaceNumber'),
		cns: mw.config.get('wgCanonicalNamespace'),
		sv: mw.config.get('wgServerName'),
		path: mw.config.get('wgArticlePath')
	};
	
	let locallink = function(t, p, s) {
		var link = t ? v.path.replace('$1', t.replace(/ /g, '_')) : '';
		if (p != undefined && typeof p === 'object') {
			link += (s || '?') + $.param(p);
		}
		return link;
	};
	
	window.dashboardFunction = {
		get: {
			namespace: function() {
				mw.notify(`Namespace: ${v.cns || '(Main)'} (${v.ns})`, {
					autoHide: true,
					autoHideSeconds: 10
				});
			},
			protection: function() {
				var a = ['Edit', 'Move', 'Create', 'Upload'];
				var r = [];
				for (let e of a) {
					r.push(`${e}: ${(mw.config.get(`wgRestriction${e}`) || '').toString() || 'none'}`);
				}
				mw.notify($('<div>').html(r.join('<br>')), {
					autoHide: true,
					autoHideSeconds: 10
				});
			}
		},
		post: {
			nulledit: function() {
				mw.notify('Null-editing...', {
					autoHide: false,
					tag: 'dashboardFunction-post-nulledit'
				});
				(new mw.Api()).postWithToken('csrf', {
					action: 'edit',
					title: v.page,
					nocreate: true,
					appendtext: '',
					format: 'json',
					formatversion: 2
				}).done(function(response) {
					mw.notify('Null-edited the page.', {
						type: 'success',
						autoHide: true,
						autoHideSeconds: 10,
						tag: 'dashboardFunction-post-nulledit'
					});
				}).fail(function(error, response) {
					mw.notify(`API error: ${response.error.info}`, {
						type: 'warn',
						autoHide: true,
						autoHideSeconds: 10,
						tag: 'dashboardFunction-post-nulledit'
					});
				});
			},
			blank: function() {
				var s;
				try {
					c = prompt('Edit summary:').trim();
				} catch {
					return;
				}
				mw.notify('Blanking...', {
					autoHide: false,
					tag: 'dashboardFunction-post-blank'
				});
				(new mw.Api()).postWithToken('csrf', {
					action: 'edit',
					title: v.page,
					text: '',
					summary: c || 'Blanking',
					minor: true,
					nocreate: true,
					format: 'json',
					formatversion: 2
				}).done(function(response) {
					mw.notify('Blanked.', {
						type: 'success',
						autoHide: true,
						autoHideSeconds: 10,
						tag: 'dashboardFunction-post-blank'
					});
				}).fail(function(error, response) {
					mw.notify(`API error: ${response.error.info}`, {
						type: 'warn',
						autoHide: true,
						autoHideSeconds: 10,
						tag: 'dashboardFunction-post-blank'
					});
				});
			}
		},
		behaviour: {}
	};
	
	window.dashboardContent = [
		{
			h: 'This wiki',
			s: v.sv,
			c: [
				{
					l: locallink('Special:MyPage/common.js'),
					t: 'c.js'
				},
				{
					l: locallink('Special:MyPage/common.css'),
					t: 'c.css'
				},
				{
					l: locallink('Special:ExpandTemplates', {
						wpInput: 
							`{{#language:${v.lang}}}\n` +
							`{{#language:${v.lang}|en}}\n` +
							`{{#language:${v.lang}|vi}}\n`,
					}),
					t: 'Lang'
				},
				{
					l: locallink(`Special:PrefixIndex/User:${v.user}/`),
					t: 'Subp'
				},
				{
					l: locallink('Special:RecentChanges'),
					t: 'RC'
				},
				{
					l: locallink('Special:BlankPage/RTRC'),
					t: 'RTRC'
				},
				{
					l: locallink('Special:ApiSandbox'),
					t: 'ApiSbx'
				},
				{
					l: locallink('Special:ExpandTemplates'),
					t: 'ExpTemp'
				},
				{
					l: locallink('Project:AutoWikiBrowser/Script'),
					t: 'JWB'
				},
				{
					l: locallink('Project:AutoWikiBrowser/Script', {
						uselang: 'he'
					}),
					t: '(rtl)'
				},
				{
					l: locallink('Project:AutoWikiBrowser/Script', {
						noJWB: 1
					}),
					t: 'No JWB'
				},
				{
					l: locallink('Project:AutoWikiBrowser/Script', {
						uselang: 'he',
						noJWB: 1
					}),
					t: '(rtl)'
				}
			]
		},
		{
			h: 'This wiki (logs)',
			s: v.sv,
			c: [
				{
					l: locallink('Special:Log/create'),
					t: 'create'
				},
				{
					l: locallink('Special:Log/create', {
						limit: 5000
					}),
					t: '(5000)'
				},
				{
					l: locallink('Special:Log/delete'),
					t: 'delete'
				},
				{
					l: locallink('Special:Log/rights'),
					t: 'rights'
				}
			]
		},
		{
			h: 'This page',
			c: [
				{
					l: 'get.namespace',
					f: true,
					t: 'Ns'
				},
				{
					l: 'get.protection',
					f: true,
					t: 'Prot'
				},
				{
					l: 'post.nulledit',
					f: true,
					t: 'Null'
				},
				{
					l: 'post.blank',
					f: true,
					t: 'Blank'
				},
				{
					l: locallink('Special:Search', (function() {
						var o = {
							search: `insource:/${v.page.replace(
								/[-[\]{}()*+?.,\\\/^$|#\s]/g, '\\$&'
							).replace(/_/g, '[_ ]+?').replace()}/i`,
							profile: 'advanced',
							fulltext: 1
						};
						var a = [
							0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
							11, 12, 13, 14, 15, 710, 711,
							828, 829, 2300, 2301, 2302, 2303
						];
						
						for (let i of a) {
							o['ns' + i] = 1;
						}
						
						return o;
					})()),
					t: 'Links'
				}
			]
		},
		{
			h: 'This user',
			d: !v.tuser,
			c: [
				{
					l: locallink(`User:${v.tuser}/common.js`),
					t: 'c.js'
				},
				{
					l: locallink(`User:${v.tuser}/common.css`),
					t: 'c.css'
				},
				{
					l: `//meta.wikimedia.org/wiki/User:${v.tuser}/global.js`,
					t: 'g.js'
				},
				{
					l: `//meta.wikimedia.org/wiki/User:${v.tuser}/global.css`,
					t: 'g.css'
				}
			]
		},
		{
			h: 'Global',
			s: 'www.wikimedia.org',
			c: [
				{
					l: '//meta.wikimedia.org/wiki/Special:MyPage/global.js',
					t: 'g.js'
				},
				{
					l: '//meta.wikimedia.org/wiki/Special:MyPage/scriptManager.js',
					t: 's.js'
				},
				{
					l: '//meta.wikimedia.org/wiki/Steward_requests/Global',
					t: 'SRG'
				},
				{
					l: '//meta.wikimedia.org/wiki/Steward_requests/Global_permissions',
					t: 'SRGP'
				},
				{
					l: '//meta.wikimedia.org/wiki/Steward_requests/Username_changes',
					t: 'SRUC'
				},
				{
					l: '//meta.wikimedia.org/wiki/Steward_requests/Permissions',
					t: 'SRP'
				},
				{
					l: '//meta.wikimedia.org/wiki/Steward_requests/Miscellaneous',
					t: 'SRM'
				},
				{
					l: '//meta.wikimedia.org/wiki/Steward_requests/Checkuser',
					t: 'SRCU'
				},
				{
					l: '//meta.wikimedia.org/wiki/Steward_requests/Bot_status',
					t: 'SRB'
				},
				{
					l: '//meta.wikimedia.org/wiki/Stewards\'_noticeboard',
					t: 'SN'
				},
				{
					l: '//meta.wikimedia.org/wiki/Global_sysops/Requests',
					t: 'GSR'
				},
				{
					l: '//meta.wikimedia.org/wiki/Global_sysops/Speedy_delete_requests',
					t: 'GSS'
				},
				{
					l: '//meta.wikimedia.org/wiki/Talk:Spam_blacklist',
					t: 'SBL'
				},
				{
					l: '//meta.wikimedia.org/wiki/Talk:Title_blacklist',
					t: 'TBL'
				},
				{
					l: '//meta.wikimedia.org/wiki/Requests_for_comment',
					t: 'RfC'
				},
				{
					l: '//meta.wikimedia.org/wiki/Special:GlobalWatchlist',
					t: 'GW'
				}
			],
		},
		{
			h: 'Meta',
			s: 'meta.wikimedia.org',
			c: [
				{
					l: `//meta.wikimedia.org/wiki/Special:PrefixIndex/User:${v.user}/`,
					t: 'Subp'
				},
				{
					l: '//meta.wikimedia.org/wiki/Special:MyPage/common.js',
					t: 'c.js'
				},
				{
					l: '//meta.wikimedia.org/wiki/Meta:Requests_for_help_from_a_sysop_or_bureaucrat',
					t: 'RfH'
				},
				{
					l: '//meta.wikimedia.org/wiki/Meta:Requests_for_CheckUser_information',
					t: 'RfCU'
				},
				{
					l: '//meta.wikimedia.org/wiki/Meta:Requests_for_deletion',
					t: 'RfD'
				},
				{
					l: '//meta.wikimedia.org/wiki/Meta:Proposed_page_moves',
					t: 'PPM'
				},
				{
					l: '//meta.wikimedia.org/wiki/Meta:Requests_for_comment',
					t: 'RfC'
				},
				{
					l: '//meta.wikimedia.org/wiki/Meta:Requests_for_adminship',
					t: 'RfA'
				},
				{
					l: '//meta.wikimedia.org/wiki/Proposals_for_new_projects',
					t: 'PNP'
				},
				{
					l: '//meta.wikimedia.org/wiki/Proposals_for_closing_projects',
					t: 'PCP'
				},
				{
					l: '//meta.wikimedia.org/wiki/Requests_for_new_languages',
					t: 'RFL'
				},
				{
					l: '//meta.wikimedia.org/wiki/Wikimedia_Forum',
					t: 'Forum'
				},
				{
					l: '//meta.wikimedia.org/wiki/Meta:Babel',
					t: 'Babel'
				},
				{
					l: '//meta.wikimedia.org/wiki/Meta:Babylon',
					t: 'Babylon'
				},
				{
					l: '//meta.wikimedia.org/wiki/Template:Votings',
					t: 'V'
				},
				{
					l: '//meta.wikimedia.org/wiki/Template:Votings-global',
					t: 'V-G'
				}
			]
		},
		{
			h: 'Commons',
			s: 'commons.wikimedia.org',
			c: [
				{
					l: `//commons.wikimedia.org/wiki/Special:PrefixIndex/User:${v.user}/`,
					t: 'Subp'
				},
				{
					l: '//commons.wikimedia.org/wiki/Special:MyPage/common.js',
					t: 'c.js'
				},
				{
					l: '//commons.wikimedia.org/wiki/Commons:Administrators\'_noticeboard',
					t: 'AN'
				},
				{
					l: '//commons.wikimedia.org/wiki/Commons:Administrators\'_noticeboard/User_problems',
					t: 'ANU'
				},
				{
					l: '//commons.wikimedia.org/wiki/Commons:Administrators\'_noticeboard/Blocks_and_protections',
					t: 'ANB'
				},
				{
					l: '//commons.wikimedia.org/wiki/Commons:Administrators\'_noticeboard/Vandalism',
					t: 'ANV'
				},
				{
					l: '//commons.wikimedia.org/wiki/Category:Commons_protected_edit_requests_(template_protected)',
					t: 'PER'
				},
				{
					l: '//commons.wikimedia.org/wiki/Category:Media_requiring_renaming',
					t: 'MRR'
				},
				{
					l: '//commons.wikimedia.org/wiki/Category:Non-empty_category_redirects',
					t: 'NECR'
				},
				{
					l: '//commons.wikimedia.org/wiki/Special:MyPage/CSD-in-a-nutshell',
					t: 'CSD'
				}
			]
		},
		{
			h: 'Wikidata',
			s: 'www.wikidata.org',
			c: [
				{
					l: `//www.wikidata.org/wiki/Special:PrefixIndex/User:${v.user}/`,
					t: 'Subp'
				},
				{
					l: '//www.wikidata.org/wiki/Special:MyPage/common.js',
					t: 'c.js'
				},
				{
					l: '//www.wikidata.org/Wikidata:Administrators\'_noticeboard',
					t: 'AN'
				}
			]
		},
		{
			h: 'enwiki',
			s: 'en.wikipedia.org',
			c: [
				{
					l: `//en.wikipedia.org/wiki/Special:PrefixIndex/User:${v.user}/`,
					t: 'Subp'
				},
				{
					l: '//en.wikipedia.org/wiki/Special:MyPage/common.js',
					t: 'c.js'
				},
				{
					l: '//en.wikipedia.org/wiki/Wikipedia:Village_pump_(technical)',
					t: 'VPT'
				},
				{
					l: '//en.wikipedia.org/wiki/Wikipedia:Edit_filter_noticeboard',
					t: 'EFN'
				},
				{
					l: '//en.wikipedia.org/wiki/Wikipedia:User_scripts/List',
					t: 'USL'
				},
				{
					l: '//en.wikipedia.org/wiki/Wikipedia:User_scripts/Requests',
					t: 'USR'
				}
			]
		},
		{
			h: 'viwiki',
			s: 'vi.wikipedia.org',
			c: [
				{
					l: `//vi.wikipedia.org/wiki/Special:PrefixIndex/User:${v.user}/`,
					t: 'Subp'
				},
				{
					l: '//vi.wikipedia.org/wiki/Special:MyPage/common.js',
					t: 'c.js'
				},
				{
					l: '//vi.wikipedia.org/wiki/Wikipedia:Tin_nhắn_cho_bảo_quản_viên#footer',
					t: 'TNCBQV'
				},
				{
					l: '//vi.wikipedia.org/wiki/Wikipedia:Biểu_quyết_xoá_bài',
					t: 'BQXB'
				},
				{
					l: '//vi.wikipedia.org/wiki/Thể_loại:Chờ_xóa',
					t: 'TL:CX'
				},
				{
					l: '//vi.wikipedia.org/wiki/Special:MyTalk/Danh_sách_việc_cần_làm',
					t: 'Todo'
				}
			]
		},
		{
			h: 'testwiki',
			s: 'test.wikipedia.org',
			c: [
				{
					l: `//test.wikipedia.org/wiki/Special:PrefixIndex/User:${v.user}/`,
					t: 'Subp'
				},
				{
					l: '//test.wikipedia.org/wiki/Special:MyPage/common.js',
					t: 'c.js'
				},
				{
					l: '//test.wikipedia.org/wiki/Project:AutoWikiBrowser/Script',
					t: 'JWB'
				},
				{
					l: '//test.wikipedia.org/wiki/Project:AutoWikiBrowser/Script?uselang=he',
					t: '(rtl)'
				},
				{
					l: '//test.wikipedia.org/wiki/Project:AutoWikiBrowser/Script?noJWB=1',
					t: 'No JWB'
				},
				{
					l: '//test.wikipedia.org/wiki/Project:AutoWikiBrowser/Script?noJWB=1&uselang=he',
					t: '(rtl)'
				}
			]
		},
		{
			h: 'Help',
			c: [
				{
					l: '//www.mediawiki.org/wiki/Help:Magic_words',
					t: 'MW'
				},
				{
					l: '//www.mediawiki.org/wiki/Help:Extension:ParserFunctions',
					t: 'PF'
				},
				{
					l: '//www.mediawiki.org/wiki/Extension:AbuseFilter/Rules_format',
					t: 'AF'
				},
				{
					l: '//www.mediawiki.org/wiki/Help:CirrusSearch',
					t: 'CS'
				},
				{
					l: '//www.mediawiki.org/wiki/Help:Range_blocks',
					t: 'CIDR'
				},
				{
					l: '//www.mediawiki.org/wiki/ResourceLoader/Core_modules',
					t: 'RL/Core'
				},
				{
					l: '//www.mediawiki.org/wiki/Help:Extension:Translate/Page_translation_administration',
					t: 'PT'
				},
				{
					l: '//meta.wikimedia.org/wiki/Meta:Internationalization_guidelines',
					t: 'i18n'
				},
				{
					l: '//www.mediawiki.org/wiki/Lua/Tutorial',
					t: 'Lua/T'
				},
				{
					l: '//www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual',
					t: 'Lua/M'
				},
				{
					l: '//www.mediawiki.org/wiki/Manual:Database_layout',
					t: 'DBLayout'
				},
				{
					l: '//www.mediawiki.org/wiki/Template:Wikimedia_extension_database_tables',
					t: 'DBTables'
				},
				{
					l: '//www.mediawiki.org/wiki/Help:Images',
					t: 'Images'
				},
				{
					l: '//en.wikipedia.org/wiki/Help:Gallery_tag',
					t: 'Gallery'
				}
			]
		},
		{
			h: 'Toolforge',
			s: 'admin.toolforge.org',
			c: [
				{
					l: '//global-search.toolforge.org',
					t: 'GS'
				},
				{
					l: '//swviewer.toolforge.org',
					t: 'SWV'
				},
				{
					l: `//meta.toolforge.org/crossactivity/${v.user}`,
					t: 'M/CA'
				},
				{
					l: '//meta.toolforge.org/userpages',
					t: 'M/UP'
				},
				{
					l: '//fontcdn.toolforge.org',
					t: 'Fonts'
				},
				{
					l: '//ftools.toolforge.org/general/ip-range-calc.html',
					t: 'IPRCalc'
				},
				{
					l: '//wdvd.toolforge.org',
					t: 'WDVD'
				}
			]
		},
		{
			h: 'Dev Wiki',
			s: 'dev.fandom.org',
			c: [
				{
					l: '//dev.fandom.com/wiki/Special:MyPage/JWB.js',
					t: 'JWB.js'
				},
				{
					l: '//dev.fandom.com/wiki/Special:MyPage/JWB.css',
					t: 'JWB.css'
				},
				{
					l: '//dev.fandom.com/wiki/Special:MyPage/JWB.js/i18n.js',
					t: 'i18n.js'
				},
				{
					l: '//dev.fandom.com/wiki/Special:MyPage/JWB.js/i18n-vi.js',
					t: 'i18n-vi.js'
				},
				{
					l: '//dev.fandom.com/wiki/Special:MyPage/JWB.js/worker.js',
					t: 'worker.js'
				},
				{
					l: '//dev.fandom.com/wiki/Special:MyPage/JWB.js/RETF.js',
					t: 'RETF.js'
				}
			]
		},
		{
			h: 'Miscellaneous',
			c: [
				{
					l: '//phabricator.wikimedia.org',
					t: 'Phab'
				},
				{
					l: '//gerrit.wikimedia.org',
					t: 'Gerrit'
				},
				{
					l: '//quarry.wmcloud.org',
					t: 'Quarry'
				},
				{
					l: '//translatewiki.net/wiki/Translating:MediaWiki',
					t: 'Trans'
				},
				{
					l: '//meta.miraheze.org/',
					t: 'Miraheze'
				},
				{
					l: '//testwiki.wiki',
					t: 'TW'
				}
			]
		},
		{
			h: 'Dashboard',
			c: [
				{
					l: '//meta.wikimedia.org/wiki/Special:MyPage/Dashboard.js',
					t: 'core.js'
				},
				{
					l: '//meta.wikimedia.org/wiki/Special:MyPage/Dashboard.js/me.js',
					t: 'me.js'
				}
			]
		}
	];
	
	mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:NguoiDungKhongDinhDanh/Dashboard.js&action=raw&ctype=text/javascript');
})();