User:Mike Dillon/Scripts/namespaces.js
From Wikipedia, the free encyclopedia
If a message on your talk page led you here, please be wary of who left it. Code that you insert on this page could contain malicious content capable of compromising your account. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. If this is a .js page, the code will be executed when previewing the page.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// <pre><nowiki> var wgNsMedia = -2; var wgNsSpecial = -1; var wgNsMain = 0; var wgNsTalk = 1; var wgNsUser = 2; var wgNsUserTalk = 3; var wgNsProject = 4; var wgNsProjectTalk = 5; var wgNsImage = 6; var wgNsImageTalk = 7; var wgNsMediawiki = 8; var wgNsMediawikiTalk = 9; var wgNsTemplate = 10; var wgNsTemplateTalk = 11; var wgNsHelp = 12; var wgNsHelpTalk = 13; var wgNsCategory = 14; var wgNsCategoryTalk = 15; var wgNamespaceNames = { // Standard namespaces '-2': 'Media', '-1': 'Special', '0': 'Main', '1': 'Talk', '2': 'User', '3': 'User talk', '4': 'Wikipedia', '5': 'Wikipedia talk', '6': 'Image', '7': 'Image talk', '8': 'Mediawiki', '9': 'Mediawiki talk', '10': 'Template', '11': 'Template talk', '12': 'Help', '13': 'Help talk', '14': 'Category', '15': 'Category talk', // Custom namespaces '100': 'Portal', '101': 'Portal talk', }; function getNamespaceNumber(title) { if (title && title.match) { for (var num in wgNamespaceNames) { if (num == wgNsMain) continue; if (title.replace("_", " ").match(wgNamespaceNames[num] + ":")) { return num; } } } return wgNsMain; } function getNamespaceName(title) { return wgNamespaceNames[getNamespaceNumber(title)]; } // </nowiki></pre>

