14,091
edits
m (1 revision imported: Trying MediaWiki:Gadget-Twinkle.js) |
|||
(One intermediate revision by the same user not shown) | |||
Line 15: | Line 15: | ||
* | * | ||
* This is AzaToth's Twinkle, the popular script sidekick for newbies, admins, and | * This is AzaToth's Twinkle, the popular script sidekick for newbies, admins, and | ||
* every Wikipedian in between. Visit [[ | * every Wikipedian in between. Visit [[WP:TW]] for more information. | ||
*/ | */ | ||
//<nowiki> | |||
// | /* global Morebits */ | ||
( function ( window, document, $, undefined ) { // Wrap with anonymous function | ( function ( window, document, $, undefined ) { // Wrap with anonymous function | ||
Line 44: | Line 45: | ||
*/ | */ | ||
Twinkle.defaultConfig.twinkle = { | Twinkle.defaultConfig.twinkle = { | ||
// General | |||
summaryAd: " ([[ | summaryAd: " ([[WP:TW|TW]])", | ||
deletionSummaryAd: " ([[ | deletionSummaryAd: " ([[WP:TW|TW]])", | ||
protectionSummaryAd: " ([[ | protectionSummaryAd: " ([[WP:TW|TW]])", | ||
userTalkPageMode: " | userTalkPageMode: "tab", | ||
dialogLargeFont: false, | dialogLargeFont: false, | ||
// ARV | |||
spiWatchReport: "yes", | |||
// Block | |||
blankTalkpageOnIndefBlock: false, | |||
// Fluff (revert and rollback) | |||
openTalkPage: [ "agf", "norm", "vand" ], | openTalkPage: [ "agf", "norm", "vand" ], | ||
openTalkPageOnAutoRevert: false, | openTalkPageOnAutoRevert: false, | ||
Line 58: | Line 66: | ||
confirmOnFluff: false, | confirmOnFluff: false, | ||
showRollbackLinks: [ "diff", "others" ], | showRollbackLinks: [ "diff", "others" ], | ||
// DI (twinkleimage) | |||
notifyUserOnDeli: true, | notifyUserOnDeli: true, | ||
deliWatchPage: "default", | deliWatchPage: "default", | ||
deliWatchUser: "default", | deliWatchUser: "default", | ||
// PROD | |||
watchProdPages: true, | watchProdPages: true, | ||
prodReasonDefault: "", | prodReasonDefault: "", | ||
logProdPages: false, | logProdPages: false, | ||
prodLogPageName: "PROD log", | prodLogPageName: "PROD log", | ||
// CSD | |||
speedySelectionStyle: "buttonClick", | speedySelectionStyle: "buttonClick", | ||
watchSpeedyPages: [ "g3", "g5", "g10", "g11", "g12" ], | watchSpeedyPages: [ "g3", "g5", "g10", "g11", "g12" ], | ||
markSpeedyPagesAsPatrolled: | markSpeedyPagesAsPatrolled: false, | ||
// these next two should probably be identical by default | // these next two should probably be identical by default | ||
notifyUserOnSpeedyDeletionNomination: [ "db", "g1", "g2", "g3", "g4", "g6", "g10", "g11", "g12", "g13", "a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", "f1", "f2", "f3", "f7", "f9", "f10", "u3", "t2", "t3", "p1", "p2" ], | notifyUserOnSpeedyDeletionNomination: [ "db", "g1", "g2", "g3", "g4", "g6", "g10", "g11", "g12", "g13", "g14", "a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", "f1", "f2", "f3", "f7", "f9", "f10", "u3", "u5", "t2", "t3", "p1", "p2" ], | ||
welcomeUserOnSpeedyDeletionNotification: [ "db", "g1", "g2", "g3", "g4", "g6", "g10", "g11", "g12", "g13", "a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", "f1", "f2", "f3", "f7", "f9", "f10", "u3", "t2", "t3", "p1", "p2" ], | welcomeUserOnSpeedyDeletionNotification: [ "db", "g1", "g2", "g3", "g4", "g6", "g10", "g11", "g12", "g13", "g14", "a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", "f1", "f2", "f3", "f7", "f9", "f10", "u3", "u5", "t2", "t3", "p1", "p2" ], | ||
promptForSpeedyDeletionSummary: [ | promptForSpeedyDeletionSummary: [], | ||
openUserTalkPageOnSpeedyDelete: [ "db", "g1", "g2", "g3", "g4", "g5", "g10", "g11", "g12", "a1", "a3", "a7", "a9", "a10", "a11", "f3", "f7", "f9", "u3", "t2", "p1" ], | openUserTalkPageOnSpeedyDelete: [ "db", "g1", "g2", "g3", "g4", "g5", "g10", "g11", "g12", "a1", "a3", "a7", "a9", "a10", "a11", "f3", "f7", "f9", "u3", "u5", "t2", "p1" ], | ||
deleteTalkPageOnDelete: | deleteTalkPageOnDelete: true, | ||
deleteRedirectsOnDelete: true, | deleteRedirectsOnDelete: true, | ||
deleteSysopDefaultToTag: false, | deleteSysopDefaultToTag: false, | ||
Line 85: | Line 96: | ||
speedyLogPageName: "CSD log", | speedyLogPageName: "CSD log", | ||
noLogOnSpeedyNomination: [ "u1" ], | noLogOnSpeedyNomination: [ "u1" ], | ||
unlinkNamespaces: [ "0", "100" ], | // Unlink | ||
unlinkNamespaces: [ "0", "10", "100", "118" ], | |||
// Warn | |||
defaultWarningGroup: "1", | defaultWarningGroup: "1", | ||
showSharedIPNotice: true, | showSharedIPNotice: true, | ||
watchWarnings: true, | watchWarnings: true, | ||
customWarningList: [], | customWarningList: [], | ||
// XfD | |||
xfdWatchDiscussion: "default", | xfdWatchDiscussion: "default", | ||
xfdWatchList: "no", | xfdWatchList: "no", | ||
xfdWatchPage: "default", | xfdWatchPage: "default", | ||
xfdWatchUser: "default", | xfdWatchUser: "default", | ||
markXfdPagesAsPatrolled: true, | |||
// Hidden preferences | |||
revertMaxRevisions: 50, | revertMaxRevisions: 50, | ||
batchdeleteChunks: 50, | batchdeleteChunks: 50, | ||
batchMax: 5000, | batchMax: 5000, | ||
batchProtectChunks: 50, | batchProtectChunks: 50, | ||
batchundeleteChunks: 50, | batchundeleteChunks: 50, | ||
proddeleteChunks: 50 | proddeleteChunks: 50 | ||
}; | }; | ||
Line 128: | Line 138: | ||
Twinkle.defaultConfig.friendly = { | Twinkle.defaultConfig.friendly = { | ||
// Tag | |||
groupByDefault: true, | groupByDefault: true, | ||
watchTaggedPages: true, | watchTaggedPages: true, | ||
Line 136: | Line 146: | ||
tagArticleSortOrder: "cat", | tagArticleSortOrder: "cat", | ||
customTagList: [], | customTagList: [], | ||
// Welcome | |||
topWelcomes: false, | topWelcomes: false, | ||
watchWelcomes: true, | watchWelcomes: true, | ||
Line 147: | Line 158: | ||
customWelcomeList: [], | customWelcomeList: [], | ||
customWelcomeSignature: true, | customWelcomeSignature: true, | ||
// Talkback | |||
markTalkbackAsMinor: true, | markTalkbackAsMinor: true, | ||
insertTalkbackSignature: true, // always sign talkback templates | insertTalkbackSignature: true, // always sign talkback templates | ||
Line 153: | Line 165: | ||
adminNoticeHeading: "Notice", | adminNoticeHeading: "Notice", | ||
mailHeading: "You've got mail!", | mailHeading: "You've got mail!", | ||
// Shared | |||
markSharedIPAsMinor: true | markSharedIPAsMinor: true | ||
}; | }; | ||
Line 188: | Line 201: | ||
return result; | return result; | ||
}; | }; | ||
/** | /** | ||
Line 299: | Line 314: | ||
outerDiv.appendChild( h5 ); | outerDiv.appendChild( h5 ); | ||
var innerDiv = null; | |||
if ( type === "menu" ) { | if ( type === "menu" ) { | ||
innerDiv = document.createElement( "div" ); | |||
innerDiv.className = innerDivClass; | innerDiv.className = innerDivClass; | ||
outerDiv.appendChild(innerDiv); | outerDiv.appendChild(innerDiv); | ||
Line 323: | Line 339: | ||
} | } | ||
var link = mw.util.addPortletLink( Twinkle.getPref( "portletId" ), typeof task === "string" ? task : "#", text, id, tooltip ); | var link = mw.util.addPortletLink( Twinkle.getPref( "portletId" ), typeof task === "string" ? task : "#", text, id, tooltip ); | ||
$('.client-js .skin-vector #p-cactions').css('margin-right', 'initial'); | |||
if ( typeof task === "function" ) { | |||
$( link ).click(function ( ev ) { | $( link ).click(function ( ev ) { | ||
task(); | task(); | ||
Line 348: | Line 365: | ||
dataType: "text" | dataType: "text" | ||
}) | }) | ||
.fail(function () { mw. | .fail(function () { mw.notify( "Could not load twinkleoptions.js" ); }) | ||
.done(function ( optionsText ) { | .done(function ( optionsText ) { | ||
Line 365: | Line 382: | ||
try { | try { | ||
var options = | var options = JSON.parse( optionsText ); | ||
// Assuming that our options evolve, we will want to transform older versions: | // Assuming that our options evolve, we will want to transform older versions: | ||
Line 383: | Line 400: | ||
} | } | ||
catch ( e ) { | catch ( e ) { | ||
mw. | mw.notify("Could not parse twinkleoptions.js"); | ||
} | } | ||
}) | }) | ||
Line 394: | Line 411: | ||
Twinkle.load = function () { | Twinkle.load = function () { | ||
// Don't activate on special pages other than those on the whitelist so that | |||
var isSpecialPage = ( mw.config.get('wgNamespaceNumber') === -1 | // they load faster, especially the watchlist. | ||
var specialPageWhitelist = [ 'Contributions', 'DeletedContributions', 'Prefixindex' ]; | |||
var isSpecialPage = ( mw.config.get('wgNamespaceNumber') === -1 && | |||
specialPageWhitelist.indexOf( mw.config.get('wgCanonicalSpecialPageName') ) === -1 ); | |||
// Also, Twinkle is incompatible with Internet Explorer versions 8 or lower, | |||
// so don't load there either. | |||
var 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 ) { | if ( isSpecialPage || isOldIE || !Twinkle.userAuthorized ) { | ||
return; | return; | ||
} | } | ||
// Load the modules in the order that the tabs should | // Prevent clickjacking | ||
if ( window.top !== window.self ) { | |||
return; | |||
} | |||
// Set custom Api-User-Agent header, for server-side logging purposes | |||
Morebits.wiki.api.setApiUserAgent( 'Twinkle/2.0 (' + mw.config.get( 'wgDBname' ) + ')' ); | |||
// Load the modules in the order that the tabs should appear | |||
// User/user talk-related | // User/user talk-related | ||
Twinkle.arv(); | Twinkle.arv(); | ||
Twinkle.warn(); | Twinkle.warn(); | ||
if ( Morebits.userIsInGroup('sysop') ) { | |||
Twinkle.block(); | |||
} | |||
Twinkle.welcome(); | Twinkle.welcome(); | ||
Twinkle.shared(); | Twinkle.shared(); | ||
Line 428: | Line 459: | ||
Twinkle.fluff.init(); | Twinkle.fluff.init(); | ||
if ( Morebits.userIsInGroup('sysop') ) { | if ( Morebits.userIsInGroup('sysop') ) { | ||
Twinkle.deprod(); | Twinkle.deprod(); | ||
Twinkle.batchdelete(); | Twinkle.batchdelete(); | ||
Line 435: | Line 465: | ||
} | } | ||
// Run the initialization callbacks for any custom modules | // Run the initialization callbacks for any custom modules | ||
Twinkle.initCallbacks.forEach(function ( func ) { func(); }); | |||
Twinkle.addInitCallback = function ( func ) { func(); }; | Twinkle.addInitCallback = function ( func ) { func(); }; | ||
Line 447: | Line 477: | ||
} ( window, document, jQuery )); // End wrap with anonymous function | } ( window, document, jQuery )); // End wrap with anonymous function | ||
// </nowiki> | //</nowiki> |