MediaWiki:Common.js
Appearance
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. */
// === Create Page Button (sitewide) ===
// Adds a "Create page" button for easy new page creation
( function () {
// Only run when the page is fully loaded
$(function () {
// If you also want it to show for anonymous users, remove the next line
if ( mw.user.isAnon() ) return;
// Function to open the edit page for a new title
function createPage(title) {
if (!title) return;
title = title.trim().replace(/\s+/g, ' ');
var url = mw.config.get('wgScript') + '?title=' + encodeURIComponent(title) + '&action=edit';
window.location.href = url;
}
// Create the button element
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('Enter the title of the new page:');
createPage(title);
});
// Try to add to the top-right user toolbar
var $personal = $('#p-personal ul');
if ($personal.length) {
$personal.append($('<li>').append($btn));
} else {
// Fallback: add to the left sidebar navigation
$('#p-navigation .body ul').append($('<li>').append($btn));
}
});
}() );