MediaWiki:Gadget-twinkleconfig.js: Difference between revisions
Jump to navigation
Jump to search
m (1 revision imported) |
(localise) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
*** twinkleconfig.js: Preferences module | *** twinkleconfig.js: Preferences module | ||
**************************************** | **************************************** | ||
* Mode of invocation: Adds configuration form to | * Mode of invocation: Adds configuration form to Sarkarverse:Twinkle/Preferences and user | ||
subpages named "/Twinkle preferences", and adds ad box to the top of user | subpages named "/Twinkle preferences", and adds ad box to the top of user | ||
subpages belonging to the currently logged-in user which end in '.js' | subpages belonging to the currently logged-in user which end in '.js' | ||
Line 16: | Line 16: | ||
I, [[User:This, that and the other]], originally wrote this. If the code is misbehaving, or you have any | I, [[User:This, that and the other]], originally wrote this. If the code is misbehaving, or you have any | ||
questions, don't hesitate to ask me. (This doesn't at all imply [[ | questions, don't hesitate to ask me. (This doesn't at all imply [[SV:OWN]]ership - it's just meant to | ||
point you in the right direction.) -- TTO | point you in the right direction.) -- TTO | ||
*/ | */ | ||
Line 31: | Line 31: | ||
csdCriteria: { | csdCriteria: { | ||
db: "Custom rationale ({{db}})", | db: "Custom rationale ({{db}})", | ||
g1: "G1", g2: "G2", g3: "G3", g4: "G4", g5: "G5", g6: "G6", g7: "G7", g8: "G8", g10: "G10", g11: "G11", g12: "G12", g13: "G13", | g1: "G1", g2: "G2", g3: "G3", g4: "G4", g5: "G5", g6: "G6", g7: "G7", g8: "G8", g10: "G10", g11: "G11", g12: "G12", g13: "G13", g14: "G14", | ||
a1: "A1", a2: "A2", a3: "A3", a5: "A5", a7: "A7", a9: "A9", a10: "A10", a11: "A11", | a1: "A1", a2: "A2", a3: "A3", a5: "A5", a7: "A7", a9: "A9", a10: "A10", a11: "A11", | ||
u1: "U1", u2: "U2", u3: "U3", u5: "U5", | u1: "U1", u2: "U2", u3: "U3", u5: "U5", | ||
Line 37: | Line 37: | ||
c1: "C1", | c1: "C1", | ||
t2: "T2", t3: "T3", | t2: "T2", t3: "T3", | ||
r2: "R2", r3: "R3", | r2: "R2", r3: "R3", r4: "R4", | ||
p1: "P1", p2: "P2" | p1: "P1", p2: "P2" | ||
}, | }, | ||
csdCriteriaDisplayOrder: [ | csdCriteriaDisplayOrder: [ | ||
"db", | "db", | ||
"g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g10", "g11", "g12", "g13", | "g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g10", "g11", "g12", "g13", "g14", | ||
"a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", | "a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", | ||
"u1", "u2", "u3", "u5", | "u1", "u2", "u3", "u5", | ||
Line 48: | Line 48: | ||
"c1", | "c1", | ||
"t2", "t3", | "t2", "t3", | ||
"r2", "r3", | "r2", "r3", "r4", | ||
"p1", "p2" | "p1", "p2" | ||
], | ], | ||
Line 54: | Line 54: | ||
db: "Custom rationale ({{db}})", | db: "Custom rationale ({{db}})", | ||
g1: "G1", g2: "G2", g3: "G3", g4: "G4", g6: 'G6 ("unnecessary disambig." and "copy-paste move" only)', | g1: "G1", g2: "G2", g3: "G3", g4: "G4", g6: 'G6 ("unnecessary disambig." and "copy-paste move" only)', | ||
g10: "G10", g11: "G11", g12: "G12", g13: "G13", | g10: "G10", g11: "G11", g12: "G12", g13: "G13", g14: "G14", | ||
a1: "A1", a2: "A2", a3: "A3", a5: "A5", a7: "A7", a9: "A9", a10: "A10", a11: "A11", | a1: "A1", a2: "A2", a3: "A3", a5: "A5", a7: "A7", a9: "A9", a10: "A10", a11: "A11", | ||
u3: "U3", u5: "U5", | u3: "U3", u5: "U5", | ||
Line 60: | Line 60: | ||
c1: "C1", | c1: "C1", | ||
t2: "T2", t3: "T3", | t2: "T2", t3: "T3", | ||
r2: "R2", r3: "R3", | r2: "R2", r3: "R3", r4: "R4", | ||
p1: "P1", p2: "P2" | p1: "P1", p2: "P2" | ||
}, | }, | ||
csdCriteriaNotificationDisplayOrder: [ | csdCriteriaNotificationDisplayOrder: [ | ||
"db", | "db", | ||
"g1", "g2", "g3", "g4", "g6", "g10", "g11", "g12", "g13", | "g1", "g2", "g3", "g4", "g6", "g10", "g11", "g12", "g13", "g14", | ||
"a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", | "a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", | ||
"u3", "u5", | "u3", "u5", | ||
Line 71: | Line 71: | ||
"c1", | "c1", | ||
"t2", "t3", | "t2", "t3", | ||
"r2", "r3", | "r2", "r3", "r4", | ||
"p1", "p2" | "p1", "p2" | ||
], | ], | ||
csdAndDICriteria: { | csdAndDICriteria: { | ||
db: "Custom rationale ({{db}})", | db: "Custom rationale ({{db}})", | ||
g1: "G1", g2: "G2", g3: "G3", g4: "G4", g5: "G5", g6: "G6", g7: "G7", g8: "G8", g10: "G10", g11: "G11", g12: "G12", g13: "G13", | g1: "G1", g2: "G2", g3: "G3", g4: "G4", g5: "G5", g6: "G6", g7: "G7", g8: "G8", g10: "G10", g11: "G11", g12: "G12", g13: "G13", g14: "G14", | ||
a1: "A1", a2: "A2", a3: "A3", a5: "A5", a7: "A7", a9: "A9", a10: "A10", a11: "A11", | a1: "A1", a2: "A2", a3: "A3", a5: "A5", a7: "A7", a9: "A9", a10: "A10", a11: "A11", | ||
u1: "U1", u2: "U2", u3: "U3", u5: "U5", | u1: "U1", u2: "U2", u3: "U3", u5: "U5", | ||
Line 82: | Line 82: | ||
c1: "C1", | c1: "C1", | ||
t2: "T2", t3: "T3", | t2: "T2", t3: "T3", | ||
r2: "R2", r3: "R3", | r2: "R2", r3: "R3", r4: "R4", | ||
p1: "P1", p2: "P2" | p1: "P1", p2: "P2" | ||
}, | }, | ||
csdAndDICriteriaDisplayOrder: [ | csdAndDICriteriaDisplayOrder: [ | ||
"db", | "db", | ||
"g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g10", "g11", "g12", "g13", | "g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g10", "g11", "g12", "g13", "g14", | ||
"a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", | "a1", "a2", "a3", "a5", "a7", "a9", "a10", "a11", | ||
"u1", "u2", "u3", "u5", | "u1", "u2", "u3", "u5", | ||
Line 93: | Line 93: | ||
"c1", | "c1", | ||
"t2", "t3", | "t2", "t3", | ||
"r2", "r3", | "r2", "r3", "r4", | ||
"p1", "p2" | "p1", "p2" | ||
], | ], | ||
Line 224: | Line 224: | ||
preferences: [ | preferences: [ | ||
// TwinkleConfig.blankTalkpageOnIndefBlock (boolean) | // TwinkleConfig.blankTalkpageOnIndefBlock (boolean) | ||
// if true, blank the talk page when issuing an indef block notice (per [[ | // if true, blank the talk page when issuing an indef block notice (per [[SV:UWUL#Indefinitely blocked users]]) | ||
{ | { | ||
name: "blankTalkpageOnIndefBlock", | name: "blankTalkpageOnIndefBlock", | ||
label: "Blank the talk page when indefinitely blocking users", | label: "Blank the talk page when indefinitely blocking users", | ||
helptip: "See <a href=\"" + mw.util.getUrl(" | helptip: "See <a href=\"" + mw.util.getUrl("Sarkarverse:WikiProject_User_warnings/Usage_and_layout#Indefinitely_blocked_users") + "\">SV:UWUL</a> for more information.", | ||
type: "boolean" | type: "boolean" | ||
} | } | ||
Line 403: | Line 403: | ||
name: "markSpeedyPagesAsPatrolled", | name: "markSpeedyPagesAsPatrolled", | ||
label: "Mark page as patrolled when tagging (if possible)", | label: "Mark page as patrolled when tagging (if possible)", | ||
type: "boolean" | type: "boolean" | ||
}, | }, | ||
Line 636: | Line 635: | ||
name: "showSharedIPNotice", | name: "showSharedIPNotice", | ||
label: "Add extra notice on shared IP talk pages", | label: "Add extra notice on shared IP talk pages", | ||
helptip: "Notice used is {{ | helptip: "Notice used is {{Shared IP advice}}", | ||
type: "boolean" | type: "boolean" | ||
}, | }, | ||
Line 655: | Line 654: | ||
customListValueTitle: "Template name (no curly brackets)", | customListValueTitle: "Template name (no curly brackets)", | ||
customListLabelTitle: "Text to show in warning list (also used as edit summary)" | customListLabelTitle: "Text to show in warning list (also used as edit summary)" | ||
}, | |||
{ | |||
name: "markXfdPagesAsPatrolled", | |||
label: "Mark page as patrolled when nominating for AFD (if possible)", | |||
type: "boolean" | |||
} | } | ||
] | ] | ||
Line 822: | Line 827: | ||
{ | { | ||
name: "batchUndeleteMinCutOff", | name: "batchUndeleteMinCutOff", | ||
type: "integer" | type: "integer" | ||
}, | }, | ||
Line 856: | Line 851: | ||
(mw.config.get("wgNamespaceNumber") === mw.config.get("wgNamespaceIds").user && mw.config.get("wgTitle").lastIndexOf("/Twinkle preferences") === (mw.config.get("wgTitle").length - 20))) && | (mw.config.get("wgNamespaceNumber") === mw.config.get("wgNamespaceIds").user && mw.config.get("wgTitle").lastIndexOf("/Twinkle preferences") === (mw.config.get("wgTitle").length - 20))) && | ||
mw.config.get("wgAction") === "view") { | mw.config.get("wgAction") === "view") { | ||
// create the config page at | // create the config page at Sarkarverse:Twinkle/Preferences, and at user subpages (for testing purposes) | ||
if (!document.getElementById("twinkle-config")) { | if (!document.getElementById("twinkle-config")) { | ||
Line 1,186: | Line 1,181: | ||
// since all the section headers exist now, we can try going to the requested anchor | // since all the section headers exist now, we can try going to the requested anchor | ||
if (location.hash) { | if (location.hash) { | ||
location.hash = location.hash; | window.location.hash = location.hash; | ||
} | } | ||
Line 1,349: | Line 1,344: | ||
addButton.style.minWidth = "8em"; | addButton.style.minWidth = "8em"; | ||
addButton.setAttribute("type", "button"); | addButton.setAttribute("type", "button"); | ||
addButton.addEventListener("click", function( | addButton.addEventListener("click", function() { | ||
Twinkle.config.listDialog.addRow(dlgtbody); | Twinkle.config.listDialog.addRow(dlgtbody); | ||
}, false); | }, false); | ||
Line 1,364: | Line 1,359: | ||
var button = document.createElement("button"); | var button = document.createElement("button"); | ||
button.setAttribute("type", "submit"); // so Morebits.simpleWindow puts the button in the button pane | button.setAttribute("type", "submit"); // so Morebits.simpleWindow puts the button in the button pane | ||
button.addEventListener("click", function( | button.addEventListener("click", function() { | ||
Twinkle.config.listDialog.save($prefbutton, dlgtbody); | Twinkle.config.listDialog.save($prefbutton, dlgtbody); | ||
dialog.close(); | dialog.close(); | ||
Line 1,372: | Line 1,367: | ||
button = document.createElement("button"); | button = document.createElement("button"); | ||
button.setAttribute("type", "submit"); // so Morebits.simpleWindow puts the button in the button pane | button.setAttribute("type", "submit"); // so Morebits.simpleWindow puts the button in the button pane | ||
button.addEventListener("click", function( | button.addEventListener("click", function() { | ||
Twinkle.config.listDialog.reset($prefbutton, dlgtbody); | Twinkle.config.listDialog.reset($prefbutton, dlgtbody); | ||
}, false); | }, false); | ||
Line 1,379: | Line 1,374: | ||
button = document.createElement("button"); | button = document.createElement("button"); | ||
button.setAttribute("type", "submit"); // so Morebits.simpleWindow puts the button in the button pane | button.setAttribute("type", "submit"); // so Morebits.simpleWindow puts the button in the button pane | ||
button.addEventListener("click", function( | button.addEventListener("click", function() { | ||
dialog.close(); // the event parameter on this function seems to be broken | dialog.close(); // the event parameter on this function seems to be broken | ||
}, false); | }, false); | ||
Line 1,473: | Line 1,468: | ||
case "set": | case "set": | ||
$.each(pref.setValues, function(itemkey | $.each(pref.setValues, function(itemkey) { | ||
if (document.getElementById(pref.name + "_" + itemkey)) { | if (document.getElementById(pref.name + "_" + itemkey)) { | ||
document.getElementById(pref.name + "_" + itemkey).checked = ((inFriendlyConfig ? | document.getElementById(pref.name + "_" + itemkey).checked = ((inFriendlyConfig ? | ||
Line 1,520: | Line 1,515: | ||
return false; | return false; | ||
}; | }; | ||
Twinkle.config.writePrefs = function twinkleconfigWritePrefs(pageobj) { | Twinkle.config.writePrefs = function twinkleconfigWritePrefs(pageobj) { | ||
var form = pageobj.getCallbackParameters(); | var form = pageobj.getCallbackParameters(); | ||
// this is the object which gets serialized into JSON | // this is the object which gets serialized into JSON | ||
Line 1,628: | Line 1,537: | ||
// compare({}, {}) === false, but it's good enough for our purposes here | // compare({}, {}) === false, but it's good enough for our purposes here | ||
var compare = function(a, b) { | var compare = function(a, b) { | ||
if ( | if (Array.isArray(a)) { | ||
if (a.length !== b.length) { | if (a.length !== b.length) { | ||
return false; | return false; | ||
Line 1,689: | Line 1,598: | ||
} else { | } else { | ||
// read all the keys in the list of values | // read all the keys in the list of values | ||
$.each(pref.setValues, function(itemkey | $.each(pref.setValues, function(itemkey) { | ||
if (form[pref.name + "_" + itemkey].checked) { | if (form[pref.name + "_" + itemkey].checked) { | ||
userValue.push(itemkey); | userValue.push(itemkey); | ||
Line 1,754: | Line 1,663: | ||
pageobj.setPageText(text); | pageobj.setPageText(text); | ||
pageobj.setEditSummary("Saving Twinkle preferences: automatic edit from [[" + Morebits.pageNameNorm + "]] ([[ | pageobj.setEditSummary("Saving Twinkle preferences: automatic edit from [[:" + Morebits.pageNameNorm + "]] ([[SV:TW|TW]])"); | ||
pageobj.setCreateOption("recreate"); | pageobj.setCreateOption("recreate"); | ||
pageobj.save(Twinkle.config.saveSuccess); | pageobj.save(Twinkle.config.saveSuccess); | ||
Line 1,766: | Line 1,675: | ||
noticebox.style.fontSize = "100%"; | noticebox.style.fontSize = "100%"; | ||
noticebox.style.marginTop = "2em"; | noticebox.style.marginTop = "2em"; | ||
noticebox.innerHTML = "<p><b>Your Twinkle preferences have been saved.</b></p><p>To see the changes, you will need to <b>clear your browser cache entirely</b> (see <a href=\"" + mw.util.getUrl(" | noticebox.innerHTML = "<p><b>Your Twinkle preferences have been saved.</b></p><p>To see the changes, you will need to <b>clear your browser cache entirely</b> (see <a href=\"" + mw.util.getUrl("SV:BYPASS") + "\" title=\"SV:BYPASS\">SV:BYPASS</a> for instructions).</p>"; | ||
Morebits.status.root.appendChild(noticebox); | Morebits.status.root.appendChild(noticebox); | ||
var noticeclear = document.createElement("br"); | var noticeclear = document.createElement("br"); |