MediaWiki:Common.js

Revision as of 20:17, 13 March 2023 by Gifted9 (talk | contribs) (+ subpages, user rights)

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// add a bunch of stuff to the default p-cactions dropdown. documentation at [[mw:ResourceLoader/Core modules]] and https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.util-method-addPortletLink
var conf = mw.config.get([
    'wgCanonicalNamespace',
    'wgPageName',
]);

// Only do the following not in the Special: namespace. 
if (conf.wgCanonicalNamespace !== 'Special') {

    // First wait for mediawiki.util to load, and the page to be ready.
    mw.loader.using('mediawiki.util', function() {

            // General usage pattern: mw.util.addPortletLink( portletId, href, text /* Optional: , id, tooltip, accesskey, nextnode */ );

            // add logs for this page
            mw.util.addPortletLink(
                'p-cactions',
                mw.util.getUrl('Special:Log/' + conf.wgPageName),
                'Logs', ,
                'Logs for this page');

            // add extension-enabled report for the latest revision
            mw.util.addPortletLink(
                'p-cactions',
                mw.util.getUrl('Special:Report/' + mw.config.get('wgCurRevisionId')),
                'Report a problem', 
              	,
                'Report a problem');

            // add list of subpages
            mw.util.addPortletLink(
                'p-cactions',
                mw.util.getUrl('Special:PrefixIndex/' + conf.wgPageName),
                'Subpages', 
              	,
                'Subpages');

            // only do the following if in user namespace
            if (conf.wgCanonicalNamespace == 'User') {

                // add user rights
                mw.util.addPortletLink(
                    'p-cactions',
                    mw.util.getUrl('Special:UserRights/' + conf.wgPageName)
                    'User rights', 
                  	,
                    'User rights');
            });
    }