MediaWiki:Gadget-Twinkle.js: Difference between revisions

m
Text replace - "WP" to "EFD"
m (1 revision)
imported>Mlpearc
m (Text replace - "WP" to "EFD")
Line 15:
*
* This is AzaToth's Twinkle, the popular script sidekick for newbies, admins, and
* every Wikipedian in between. Visit [[WPEFD:TW]] for more information.
*/
 
//<nowiki>
 
( function ( window, document, $, undefined ) { // Wrap with anonymous function
 
var Twinkle = {};
window.Twinkle = Twinkle; // allow global access
 
// Check if account is experienced enough to use Twinkle
Twinkle.userAuthorized = Morebits.userIsInGroup( "autoconfirmed" ) || Morebits.userIsInGroup( "confirmed" );
 
// for use by custom modules (normally empty)
Twinkle.initCallbacks = [];
Twinkle.addInitCallback = function twinkleAddInitCallback( func ) {
Twinkle.initCallbacks.push( func );
};
 
Twinkle.defaultConfig = {};
/**
Line 45:
Twinkle.defaultConfig.twinkle = {
// General
summaryAd: " ([[TWEFD:TW|TW]])",
deletionSummaryAd: " ([[TWEFD:TW|TW]])",
protectionSummaryAd: " ([[TWEFD:TW|TW]])",
userTalkPageMode: "window",
dialogLargeFont: false,
Line 111:
proddeleteChunks: 50
};
 
// now some skin dependent config.
if ( mw.config.get( "skin" ) === "vector" ) {
Line 126:
Twinkle.defaultConfig.twinkle.portletNext = null;
}
 
Twinkle.defaultConfig.friendly = {
// Tag
Line 156:
markSharedIPAsMinor: true
};
 
Twinkle.getPref = function twinkleGetPref( name ) {
var result;
Line 166:
result = window.TwinkleConfig[name];
}
 
if ( result === undefined ) {
return Twinkle.defaultConfig.twinkle[name];
Line 172:
return result;
};
 
Twinkle.getFriendlyPref = function twinkleGetFriendlyPref(name) {
var result;
Line 182:
result = window.FriendlyConfig[ name ];
}
 
if ( result === undefined ) {
return Twinkle.defaultConfig.friendly[ name ];
Line 188:
return result;
};
 
 
 
/**
* **************** Twinkle.addPortlet() ****************
Line 226:
return null;
}
 
var item = document.getElementById( id );
if ( item ) {
Line 234:
return null;
}
 
var nextnode;
if ( nextnodeid ) {
nextnode = document.getElementById(nextnodeid);
}
 
//verify/normalize input
type = ( skin === "vector" && type === "menu" && ( navigation === "left-navigation" || navigation === "right-navigation" )) ? "menu" : "";
Line 266:
break;
}
 
// Build the DOM elements.
var outerDiv = document.createElement( "div" );
Line 281:
root.appendChild( outerDiv );
}
 
var h5 = document.createElement( "h3" );
if ( type === "menu" ) {
Line 287:
span.appendChild( document.createTextNode( text ) );
h5.appendChild( span );
 
var a = document.createElement( "a" );
a.href = "#";
 
$( a ).click(function ( e ) {
e.preventDefault();
 
if ( !Twinkle.userAuthorized ) {
alert("Sorry, your account is too new to use Twinkle.");
}
});
 
span = document.createElement( "span" );
span.appendChild( document.createTextNode( text ) );
Line 307:
}
outerDiv.appendChild( h5 );
 
var innerDiv = document.createElement( "div" ); // Not strictly necessary with type vectorTabs, or other skins.
innerDiv.className = innerDivClass;
outerDiv.appendChild(innerDiv);
 
var ul = document.createElement( "ul" );
innerDiv.appendChild( ul );
 
return outerDiv;
};
 
 
/**
* **************** Twinkle.addPortletLink() ****************
Line 337:
}
return link;
};
 
 
/**
* **************** General initialization code ****************
*/
 
var scriptpathbefore = mw.util.wikiScript( "index" ) + "?title=",
scriptpathafter = "&action=raw&ctype=text/javascript&happy=yes";
 
// Retrieve the user's Twinkle preferences
$.ajax({
url: scriptpathbefore + "User:" + encodeURIComponent( mw.config.get("wgUserName")) + "/twinkleoptions.js" + scriptpathafter,
dataType: "text",
})
error: function () { mw.util.jsMessage( "Could not load twinkleoptions.js" ); },
.fail(function () { mw.util.jsMessage( "Could not load twinkleoptions.js" ); })
success: function ( optionsText ) {
.done(function ( optionsText ) {
 
// Quick pass if user has no options
if ( optionsText === "" ) {
return;
}
 
// Twinkle options are basically a JSON object with some comments. Strip those:
optionsText = optionsText.replace( /(?:^(?:\/\/[^\n]*\n)*\n*|(?:\/\/[^\n]*(?:\n|$))*$)/g, "" );
 
// First version of options had some boilerplate code to make it eval-able -- strip that too. This part may become obsolete down the line.
if ( optionsText.lastIndexOf( "window.Twinkle.prefs = ", 0 ) === 0 ) {
optionsText = optionsText.replace( /(?:^window.Twinkle.prefs = |;\n*$)/g, "" );
}
 
try {
var options = $.parseJSON( optionsText );
 
// Assuming that our options evolve, we will want to transform older versions:
//if ( options.optionsVersion === undefined ) {
Line 378 ⟶ 381:
//}
// At the same time, twinkleconfig.js needs to be adapted to write a higher version number into the options.
 
if ( options ) {
Twinkle.prefs = options;
Line 386 ⟶ 389:
mw.util.jsMessage("Could not parse twinkleoptions.js");
}
},)
complete: .always(function () {
$( Twinkle.load );
});
 
});
// Developers: you can import custom Twinkle modules here
// For example, mw.loader.load(scriptpathbefore + "User:UncleDouggie/morebits-test.js" + scriptpathafter);
 
Twinkle.load = function () {
// Don't activate on special pages other than "Contributions" so that they load faster, especially the watchlist.
Line 400 ⟶ 402:
&& mw.config.get('wgCanonicalSpecialPageName') !== "Contributions"
&& mw.config.get('wgCanonicalSpecialPageName') !== "Prefixindex" ),
 
// Also, Twinkle is incompatible with Internet Explorer versions 8 or lower, so don't load there either.
isOldIE = ( $.client.profile().name === 'msie' && $.client.profile().versionNumber < 9 );
 
// Prevent users that are not autoconfirmed from loading Twinkle as well.
if ( isSpecialPage || isOldIE || !Twinkle.userAuthorized ) {
return;
}
 
// Load the modules in the order that the tabs should appears
// User/user talk-related
Line 414 ⟶ 416:
Twinkle.warn();
Twinkle.welcome();
Twinkle.shared();
Twinkle.talkback();
// Deletion
Twinkle.speedy();
Twinkle.prod();
Twinkle.xfd();
Twinkle.image();
// Maintenance
Twinkle.protect();
Twinkle.tag();
// Misc. ones last
Twinkle.diff();
Line 435 ⟶ 441:
$( Twinkle.initCallbacks ).each(function ( k, v ) { v(); });
Twinkle.addInitCallback = function ( func ) { func(); };
 
// Increases text size in Twinkle dialogs, if so configured
if ( Twinkle.getPref( "dialogLargeFont" ) ) {
Line 442 ⟶ 448:
}
};
 
} ( window, document, jQuery )); // End wrap with anonymous function
 
// </nowiki>
Anonymous user