Permalink
Browse files

warn: add custom warning feature

You can set up custom warning templates using TWPREFS and then apply
them the usual way. Quite simple, really.
  • Loading branch information...
1 parent 74adc20 commit 68750c513306639821b4ff752b30fa23f6e141ba @atlight atlight committed Mar 30, 2013
Showing with 61 additions and 11 deletions.
  1. +19 −1 modules/twinkleconfig.js
  2. +41 −10 modules/twinklewarn.js
  3. +1 −0 twinkle.header.js
View
@@ -579,7 +579,17 @@ Twinkle.config.sections = [
name: "defaultWarningGroup",
label: "Default warning level",
type: "enum",
- enumValues: { "1": "Level 1", "2": "Level 2", "3": "Level 3", "4": "Level 4", "5": "Level 4im", "6": "Single-issue notices", "7": "Single-issue warnings", "8": "Block (admin only)" }
+ enumValues: {
+ "1": "Level 1",
+ "2": "Level 2",
+ "3": "Level 3",
+ "4": "Level 4",
+ "5": "Level 4im",
+ "6": "Single-issue notices",
+ "7": "Single-issue warnings",
+ "9": "Custom warnings",
+ "8": "Block (admin only)"
+ }
},
// TwinkleConfig.showSharedIPNotice may take arguments:
@@ -608,6 +618,14 @@ Twinkle.config.sections = [
helptip: "See <a href=\"" + mw.util.wikiGetlink("WP:UW#Indefinitely blocked users") + "\">WP:UW</a> for more information.",
adminOnly: true,
type: "boolean"
+ },
+ {
+ name: "customWarningList",
+ label: "Custom warning templates to display",
+ helptip: "You can add templates or user subpages. To add a series of warnings, add each template individually (e.g. uw-plotsum1, uw-plotsum2, etc).",
+ type: "customList",
+ customListValueTitle: "Template name (no curly brackets)",
+ customListLabelTitle: "Text to show in warning list (also used as edit summary)"
}
]
},
View
@@ -65,6 +65,9 @@ Twinkle.warn.callback = function twinklewarnCallback() {
main_group.append( { type:'option', label:'Only warning (4im)', value:'level4im', selected: ( defaultGroup === 5 ) } );
main_group.append( { type:'option', label:'Single issue notices', value:'singlenotice', selected: ( defaultGroup === 6 ) } );
main_group.append( { type:'option', label:'Single issue warnings', value:'singlewarn', selected: ( defaultGroup === 7 ) } );
+ if( Twinkle.getPref( 'customWarningList' ).length ) {
+ main_group.append( { type:'option', label:'Custom warnings', value:'custom', selected: ( defaultGroup === 9 ) } );
+ }
if( Morebits.userIsInGroup( 'sysop' ) ) {
main_group.append( { type:'option', label:'Blocking', value:'block', selected: ( defaultGroup === 8 ) } );
}
@@ -1357,14 +1360,17 @@ Twinkle.warn.callback.change_category = function twinklewarnCallbackChangeCatego
// worker function to create the combo box entries
var createEntries = function( contents, container ) {
$.each( contents, function( itemKey, itemProperties ) {
+ var key = (typeof itemKey === "string") ? itemKey : itemProperties.value;
+
var selected = false;
- if( old_subvalue && old_subvalue_re.test( itemKey ) ) {
+ if( old_subvalue && old_subvalue_re.test( key ) ) {
selected = true;
}
+
var elem = new Morebits.quickForm.element( {
type: 'option',
- label: "{{" + itemKey + "}}: " + itemProperties.label,
- value: itemKey,
+ label: "{{" + key + "}}: " + itemProperties.label,
+ value: key,
selected: selected
} );
var elemRendered = container.appendChild( elem.render() );
@@ -1375,6 +1381,8 @@ Twinkle.warn.callback.change_category = function twinklewarnCallbackChangeCatego
if( value === "singlenotice" || value === "singlewarn" || value === "block" ) {
// no categories, just create the options right away
createEntries( Twinkle.warn.messages[ value ], sub_group );
+ } else if( value === "custom" ) {
+ createEntries( Twinkle.getPref("customWarningList"), sub_group );
} else {
// create the option-groups
$.each( Twinkle.warn.messages[ value ], function( groupLabel, groupContents ) {
@@ -1602,7 +1610,7 @@ Twinkle.warn.callbacks = {
main: function( pageobj ) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
- var messageData = params.messageData;//Twinkle.warn.messages[params.main_group][params.sub_group];
+ var messageData = params.messageData;
var history_re = /<!-- Template:(uw-.*?) -->.*?(\d{1,2}:\d{1,2}, \d{1,2} \w+ \d{4}) \(UTC\)/g;
var history = {};
@@ -1672,12 +1680,35 @@ Twinkle.warn.callbacks = {
text += "\n{{subst:SharedIPAdvice}}";
}
- var summary = messageData.summary;
- if ( messageData.suppressArticleInSummary !== true && params.article ) {
- if ( params.sub_group === "uw-socksuspect" ) { // this template requires a username
- summary += " of [[User:" + params.article + "]]";
- } else {
- summary += " on [[" + params.article + "]]";
+ // build the edit summary
+ var summary;
+ if( params.main_group === 'custom' ) {
+ switch( params.sub_group.substr( -1 ) ) {
+ case "1":
+ summary = "General note";
+ break;
+ case "2":
+ summary = "Caution";
+ break;
+ case "3":
+ summary = "Warning";
+ break;
+ case "4":
+ summary = "Final warning";
+ break;
+ default:
+ summary = "Notice";
+ break;
+ }
+ summary += ": " + Morebits.string.toUpperCaseFirstChar(messageData.label);
+ } else {
+ summary = messageData.summary;
+ if ( messageData.suppressArticleInSummary !== true && params.article ) {
+ if ( params.sub_group === "uw-socksuspect" ) { // this template requires a username
+ summary += " of [[User:" + params.article + "]]";
+ } else {
+ summary += " on [[" + params.article + "]]";
+ }
}
}
summary += "." + Twinkle.getPref("summaryAd");
View
@@ -88,6 +88,7 @@ Twinkle.defaultConfig.twinkle = {
showSharedIPNotice: true,
watchWarnings: true,
blankTalkpageOnIndefBlock: false,
+ customWarningList: [],
// XfD
xfdWatchDiscussion: "default",
xfdWatchList: "no",

0 comments on commit 68750c5

Please sign in to comment.