User:Mike Dillon/Scripts/namespaces.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

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': 'Appendix',
    '101': 'Appendix talk',
    '102': 'Concordance',
    '103': 'Concordance talk',
    '104': 'Index',
    '105': 'Index talk',
    '106': 'Rhymes',
    '107': 'Rhymes talk',
    '108': 'Transwiki',
    '109': 'Transwiki talk',
    '110': 'Wikisaurus',
    '111': 'Wikisaurus talk',
    '112': 'WT',
    '113': 'WT talk',
    '114': 'Citations',
    '115': 'Citations 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)];
}