MediaWiki:Common.js

From GladiusRO Wiki
Revision as of 06:36, 2 August 2026 by Ikhwan (talk | contribs)
Jump to navigation Jump to search

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.
/*
 * GladiusRO permanent sidebar configuration.
 */

jQuery(function ($) {
    'use strict';

    function configureGladiusSidebar() {
        var $toc = $('#toc');
        var $tools = $('#p-tb');
        var $sidebar = $('#mw-panel');

        /*
         * Move Contents into the left sidebar.
         */
        if ($toc.length && $sidebar.length) {
            var $container = $('#gladius-sidebar-toc');

            if (!$container.length) {
                $container = $('<div>', {
                    id: 'gladius-sidebar-toc',
                    class: 'portal mw-portlet'
                });
            }

            $container.append($toc);

            /*
             * Place Contents below Tools.
             * If Tools cannot be found, place Contents
             * at the bottom of the sidebar.
             */
            if ($tools.length) {
                $container.insertAfter($tools);
            } else {
                $container.appendTo($sidebar);
            }
        }

        /*
         * Hide technical links from logged-out players.
         * Logged-in administrators can still see everything.
         */
        if (mw.config.get('wgUserName') === null) {
            $('#p-tb').hide();
            $('#n-recentchanges').hide();
            $('#n-randompage').hide();
            $('#n-help').hide();

            /*
             * Fallback for this older MediaWiki skin.
             */
            $('#mw-panel a').each(function () {
                var $link = $(this);
                var text = $.trim($link.text()).toLowerCase();

                var hiddenLinks = [
                    'recent changes',
                    'random page',
                    'help about mediawiki',
                    'what links here',
                    'related changes',
                    'special pages',
                    'printable version',
                    'permanent link',
                    'page information'
                ];

                if ($.inArray(text, hiddenLinks) !== -1) {
                    var $row = $link.closest('li');

                    if ($row.length) {
                        $row.hide();
                    } else {
                        $link.hide();
                    }
                }
            });
        }
    }

    /*
     * Apply immediately and repeat after the older
     * MediaWiki skin has finished loading.
     */
    configureGladiusSidebar();

    window.setTimeout(configureGladiusSidebar, 250);
    window.setTimeout(configureGladiusSidebar, 1000);
});


/*
 * GladiusRO Wiki
 * Show View source and View history only to administrators.
 */
(function (mw) {
    'use strict';

    function updatePageTabs() {
        var userGroups = mw.config.get('wgUserGroups') || [];

        /*
         * MediaWiki administrators belong to the "sysop" group.
         */
        var isAdministrator =
            userGroups.indexOf('sysop') !== -1;

        /*
         * Page tabs used by MediaWiki and compatible skins.
         */
        var restrictedTabs = [
            'ca-viewsource',
            'ca-history'
        ];

     *  restrictedTabs.forEach(function *tabId) {
            var tab = doc*ment.getElementById(tabId);

     *      if (!tab) {
                *eturn;
            }

            *f (isAdministrator) {
            *   tab.style.removeProperty('displ*y');
            } else {
        *       tab.style.setProperty(
    *               'display',
        *           'none',
               *    'important'
                );*            }
        });
    }

 *  if (document.readyState === 'loa*ing') {
        document.addEventL*stener(
            'DOMContentLoa*ed',
            updatePageTabs
  *     );
    } else {
        updat*PageTabs();
    }

    window.addE*entListener(
        'load',
     *  updatePageTabs
    );

    if (m*.hook) {
        mw.hook('wikipage*content').add(function () {
      *     window.setTimeout(
          *     updatePageTabs,
             *  50
            );
        });
  * }

}(mediaWiki));