User:GabMaster/common.js
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.
$('#content').css('border', '10px solid navy');
// alert("Hello" + mw.user.getName() );
/*****
* importScript('http://www.mediawiki.org/wiki/MediaWiki:Tutorial-QuickRC.js');
*/
mw.loader.using(['jquery.ui'], function() {
function renderQuickRCDialog( pageLinks ) {
var $dialog = $( '<div></div>' )
.html(
'<strong>Welcome, ' + mw.user.getName() +
'!</strong> The following pages have been recently modified:<br/><ul><li>' +
pageLinks.join( '<br /><li>' ) + '</ul>'
)
.dialog({
autoOpen: true,
title: 'Hello there!',
width: '70%',
modal: true
});
}
function quickRC() {
var myPageLinks = [];
var myTitles = [];
// Fetch recent changes from the API by one of jQuery's AJAX functions
jQuery.getJSON(
mw.util.wikiScript( 'api' ),
{
'format': 'json',
'action': 'query',
'list': 'recentchanges',
'rclimit' : 25
},
function( data ) {
// Build a unique array of links, using the mw.html library to format them.
$.each ( data.query.recentchanges , function( index , rc ) {
// Don't link to this title if we've seen this title already
if ( $.inArray( rc.title, myTitles ) === -1 ) {
myPageLinks.push(
mw.html.element(
'a', { href: mw.util.getUrl( rc.title ) }, rc.title
)
);
}
myTitles.push( rc.title );
} ) ;
renderQuickRCDialog( myPageLinks );
}
);
}
$(document).ready( function() {
// Add a link to the toolbox
var link = mw.util.addPortletLink(
'p-tb',
'#',
'Quick changelog',
't-prettylinkwidget',
'Show a quick overview of changes',
null,
'#t-whatlinkshere'
);
// Create a jQuery object for this link so that we get
// to use jQuery awesomeness like .click() for binding functions to events
// and methods like e.preventDefault();
$(link).click( function( e ) {
// Avoid the browser going to '#'
e.preventDefault();
// Initiate quickRC!
quickRC();
});
});
});
/****************/
var customizeToolbar = function() {
/* Your code goes here */
// ADD A TOOLBAR SECTION
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'emoticons': {
'type': 'toolbar', // Can also be 'booklet'
'label': 'Emoticons'
// or 'labelMsg': 'section-emoticons-label' for a localized label
}
}
} );
// ADD A GROUP to an existing toolbar SECTION
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'emoticons',
'groups': {
'faces': {
'label': 'Faces' // or use labelMsg for a localized label, see above
}
}
} );
// ADD A BUTTON to an existing toolbar GROUP
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'emoticons',
'group': 'faces',
'tools': {
'smile': {
label: 'Smile!', // or use labelMsg for a localized label, see above
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png',
action: {
type: 'encapsulate',
options: {
pre: ":)" // text to be inserted
}
}
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'info': {
'type': 'booklet',
'label': 'Info'
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'info',
'pages': {
'colors': {
'layout': 'table',
'label': 'Colors',
'headings': [
{ text: 'Name' }, // or use textMsg for localization, see also above
{ text: 'Temperature' },
{ text: 'Swatch' }
],
'rows': [
{
'name': { text: 'Red' },
'temp': { text: 'Warm' },
'swatch': { html: '<div style="width:10px;height:10px;background-color:red;">' }
},
{
'name': { text: 'Blue' },
'temp': { text: 'Cold' },
'swatch': { html: '<div style="width:10px;height:10px;background-color:blue;">' }
},
{
'name': { text: 'Silver' },
'temp': { text: 'Neutral' },
'swatch': { html: '<div style="width:10px;height:10px;background-color:silver;">' }
}
]
}
}
} );
};
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
mw.loader.using( 'user.options', function () {
if ( mw.user.options.get('usebetatoolbar') ) {
mw.loader.using( 'ext.wikiEditor', function () {
$(document).ready( customizeToolbar );
} );
}
} );
}