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. */
// 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);
}
});
}() );