Jump to content

MediaWiki:Common.js

From Pure Evil Villains
Revision as of 13:51, 11 October 2025 by Dude of Wealth and Taste (talk | contribs) (Created page with "Any JavaScript here will be loaded for all users on every page load.: // CreatePageButton - add to MediaWiki:Common.js or as a gadget ( function () { if ( mw.user.isAnon() ) return; // optional: only for logged in users function createPage(title) { if (!title) return; title = title.trim().replace(/\s+/g, ' '); window.location.href = mw.config.get('wgScript') + '?title=' + encodeURIComponent(title) + '&action=edit'; } // add toolbar button (Vecto...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.
/* Any JavaScript here will be loaded for all users on every page load. */
// CreatePageButton - add to MediaWiki:Common.js or as a gadget
( function () {
  if ( mw.user.isAnon() ) return; // optional: only for logged in users
  function createPage(title) {
    if (!title) return;
    title = title.trim().replace(/\s+/g, ' ');
    window.location.href = mw.config.get('wgScript') + '?title=' + encodeURIComponent(title) + '&action=edit';
  }

  // add toolbar button (Vector/Timeless/other skins)
  var $btn = $('<a>')
    .attr('id', 'create-new-page-button')
    .attr('href', '#')
    .text('Create page')
    .css({
      'margin-left': '8px',
      'padding': '6px 10px',
      'background': '#2a7ae2',
      'color': '#fff',
      'border-radius': '4px',
      'text-decoration':'none',
      'font-weight':'600'
    })
    .click(function (e) {
      e.preventDefault();
      var title = prompt('Title of the new page:');
      createPage(title);
    });

  // Try to append to the personal toolbar or site actions if present
  $(function () {
    var appended = false;
    // Vector/Timeless
    var $personal = $('#p-personal, .mw-portlet-personal, .vector-user-links, #p-cactions');
    if ($personal.length) {
      $personal.first().append($('<li>').append($btn));
      appended = true;
    }
    if (!appended) {
      // fallback: append to masthead
      $('#mw-panel, #mw-navigation, #p-views').first().append($btn);
    }
  });
}() );
Cookies help us deliver our services. By using our services, you agree to our use of cookies.