13,401
edits
(Created page with "// <nowiki> /* * Draftify * * This gadget allows you to move a user page to a different location (usually * the Draft namespace), notify the user, and optionally soft-block them. * * To install the script, add the following to your personal .js page: importScript( 'User:WikiDwarf/Draftify.js' ); // Linkback: User:WikiDwarf/Draftify.js * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated docume...") |
m (WikiDwarf moved page User:WikiDwarf/Draftify.js to MediaWiki:Gadget-Draftify.js without leaving a redirect) |
||
(One intermediate revision by the same user not shown) | |||
Line 10: | Line 10: | ||
importScript( 'User:WikiDwarf/Draftify.js' ); // Linkback: [[User:WikiDwarf/Draftify.js]] | importScript( 'User:WikiDwarf/Draftify.js' ); // Linkback: [[User:WikiDwarf/Draftify.js]] | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | * of this software and associated documentation files (the "Software"), to deal | ||
Line 90: | Line 89: | ||
// The edit summary to use when moving the page. | // The edit summary to use when moving the page. | ||
'dfy-move-summary': 'the [[ | 'dfy-move-summary': 'the [[BP:DRAFTS|Draft namespace]] is the preferred location for [[BP:AFC|Articles for Creation]] submissions', | ||
// The template invocation to use when tagging drafts. | // The template invocation to use when tagging drafts. | ||
Line 122: | Line 121: | ||
// Edit summary to leave when notifying the user that their draft has | // Edit summary to leave when notifying the user that their draft has | ||
// been moved and suggesting that they rename their account. | // been moved and suggesting that they rename their account. | ||
'dfy-notify-summary-suggestrename': 'Your draft page has been moved, and you may need to change your [[ | 'dfy-notify-summary-suggestrename': 'Your draft page has been moved, and you may need to change your [[BP:U|username]]', | ||
// Edit summary to leave when notifying the user that their draft has | // Edit summary to leave when notifying the user that their draft has | ||
// been moved and that they have been soft-blocked. | // been moved and that they have been soft-blocked. | ||
'dfy-notify-summary-softblock': 'Your draft page has been moved, and you have been indefinitely blocked from editing because your [[ | 'dfy-notify-summary-softblock': 'Your draft page has been moved, and you have been indefinitely blocked from editing because your [[BP:U|username]] gives the impression that the account represents a group, organization or website', | ||
// Boilerplate text to add at the end of the edit summary. | // Boilerplate text to add at the end of the edit summary. | ||
'dfy-summary-suffix': '([[ | 'dfy-summary-suffix': '([[BP:DFY|DFY]])', | ||
// The talk heading to be used for the talkpage notification. | // The talk heading to be used for the talkpage notification. | ||
Line 153: | Line 152: | ||
'dfy-softblock-checkbox-label': 'Soft-block the user and leave a block notice', | 'dfy-softblock-checkbox-label': 'Soft-block the user and leave a block notice', | ||
// Label for the watch checkbox | // Label for the watch user talk checkbox | ||
'dfy-watch-checkbox-label': 'Watch source page and target page', | 'dfy-watch-user-talk-checkbox-label': 'Watch user talk page', | ||
// Label for the watch draft checkbox | |||
'dfy-watch-draft-checkbox-label': 'Watch source page and target page', | |||
// Label for the move progress indicator | // Label for the move progress indicator | ||
Line 248: | Line 250: | ||
softblock: false, | softblock: false, | ||
suggestrename: false, | suggestrename: false, | ||
watchusertalk: true, | |||
watchdraft: true, | |||
menulocation: 'p-cactions', | menulocation: 'p-cactions', | ||
menuposition: null | menuposition: null | ||
}; | }; | ||
// Find the preferences to use from the defaults and | // Define aliases for config keys. | ||
config.aliases = { | |||
watchdraft: [ "watch" ] // For backwards compatibility with old options | |||
} | |||
// Find the preferences to use from the defaults, aliases, and user preferences. | |||
config.prefs = {}; | config.prefs = {}; | ||
$.each( config.defaults, function ( key, value ) { | $.each( config.defaults, function ( key, value ) { | ||
if ( config.rawPrefs[ key ] !== undefined ) { | if ( config.rawPrefs[ key ] !== undefined ) { | ||
config.prefs[ key ] = config.rawPrefs[ key ]; | config.prefs[ key ] = config.rawPrefs[ key ]; | ||
} else { | } else if ( config.aliases[ key ] !== undefined ) { | ||
$.each( config.aliases[ key ], function ( index, alias ) { | |||
if ( config.rawPrefs[ alias ] !== undefined ) { | |||
config.prefs[ key ] = config.rawPrefs[ alias ]; | |||
return false; // Break the loop if we find an alias | |||
} | |||
} ); | |||
} | |||
if ( config.prefs[ key ] === undefined ) { | |||
config.prefs[ key ] = value; | config.prefs[ key ] = value; | ||
} | } | ||
Line 441: | Line 457: | ||
ApiManager.prototype.editPage = function ( options ) { | ApiManager.prototype.editPage = function ( options ) { | ||
options = options || {}; | options = options || {}; | ||
return this.api. | return this.api.postWithEditToken( { | ||
format: 'json', | format: 'json', | ||
action: 'edit', | action: 'edit', | ||
Line 448: | Line 464: | ||
notminor: '', | notminor: '', | ||
text: options.content, | text: options.content, | ||
watchlist: | watchlist: options.watch ? 'watch' : 'unwatch' | ||
} ); | } ); | ||
}; | }; | ||
Line 474: | Line 490: | ||
' ' + | ' ' + | ||
mw.message( 'dfy-summary-suffix' ).plain(), | mw.message( 'dfy-summary-suffix' ).plain(), | ||
watchlist: options. | watchlist: options.watchdraft ? 'watch' : 'unwatch' | ||
}; | }; | ||
if ( !options.redirect ) { | if ( !options.redirect ) { | ||
apiArgs.noredirect = 1; | apiArgs.noredirect = 1; | ||
} | } | ||
return self.api. | return self.api.postWithEditToken( apiArgs ).then( function () { | ||
return contentObj; | return contentObj; | ||
} ); | } ); | ||
Line 503: | Line 519: | ||
title: this.getTargetDraftTitle().getPrefixedText(), | title: this.getTargetDraftTitle().getPrefixedText(), | ||
editSummary: mw.message( 'dfy-tag-summary', this.getTargetUser() ).plain(), | editSummary: mw.message( 'dfy-tag-summary', this.getTargetUser() ).plain(), | ||
content: content | content: content, | ||
watch: options.watchdraft | |||
} ); | } ); | ||
}; | }; | ||
ApiManager.prototype.softBlockUser = function ( options ) { | ApiManager.prototype.softBlockUser = function ( options ) { | ||
return this.api. | return this.api.postWithEditToken( { | ||
format: 'json', | format: 'json', | ||
action: 'block', | action: 'block', | ||
Line 571: | Line 588: | ||
title: contentObj.title, | title: contentObj.title, | ||
editSummary: summary, | editSummary: summary, | ||
content: content | content: content, | ||
watch: options.watchusertalk | |||
} ); | } ); | ||
} ); | } ); | ||
Line 698: | Line 716: | ||
this.softblockCheckbox = new OO.ui.CheckboxInputWidget(); | this.softblockCheckbox = new OO.ui.CheckboxInputWidget(); | ||
this.softblockCheckbox.setDisabled( true ); | this.softblockCheckbox.setDisabled( true ); | ||
this. | this.watchUserTalkCheckbox = new OO.ui.CheckboxInputWidget( { | ||
selected: apiManager.getPreference( ' | selected: apiManager.getPreference( 'watchusertalk' ) | ||
} ); | |||
this.watchDraftCheckbox = new OO.ui.CheckboxInputWidget( { | |||
selected: apiManager.getPreference( 'watchdraft' ) | |||
} ); | } ); | ||
Line 727: | Line 748: | ||
align: 'inline' | align: 'inline' | ||
} ), | } ), | ||
new OO.ui.FieldLayout( this. | new OO.ui.FieldLayout( this.watchUserTalkCheckbox, { | ||
label: mw.message( 'dfy-watch-checkbox-label' ).plain(), | label: mw.message( 'dfy-watch-user-talk-checkbox-label' ).plain(), | ||
align: 'inline' | |||
} ), | |||
new OO.ui.FieldLayout( this.watchDraftCheckbox, { | |||
label: mw.message( 'dfy-watch-draft-checkbox-label' ).plain(), | |||
align: 'inline' | align: 'inline' | ||
} ) | } ) | ||
Line 835: | Line 860: | ||
this.onSoftblockChange(); | this.onSoftblockChange(); | ||
} | } | ||
this.onNotifyChange(); | |||
this.onTitleChange(); | this.onTitleChange(); | ||
Line 840: | Line 866: | ||
this.softblockCheckbox.on( 'change', this.onSoftblockChange, null, this ); | this.softblockCheckbox.on( 'change', this.onSoftblockChange, null, this ); | ||
this.suggestrenameCheckbox.on( 'change', this.onSuggestrenameChange, null, this ); | this.suggestrenameCheckbox.on( 'change', this.onSuggestrenameChange, null, this ); | ||
this.notifyCheckbox.on( 'change', this.onNotifyChange, null, this ); | |||
this.titleInput.on( 'change', this.onTitleChange, null, this ); | this.titleInput.on( 'change', this.onTitleChange, null, this ); | ||
Line 858: | Line 885: | ||
this.notifyCheckbox.setDisabled( false ); | this.notifyCheckbox.setDisabled( false ); | ||
} | } | ||
this.onNotifyChange(); | |||
}; | }; | ||
Line 869: | Line 897: | ||
this.suggestrenameCheckbox.setDisabled( false ); | this.suggestrenameCheckbox.setDisabled( false ); | ||
this.notifyCheckbox.setDisabled( false ); | this.notifyCheckbox.setDisabled( false ); | ||
} | |||
this.onNotifyChange(); | |||
}; | |||
Dialog.prototype.onNotifyChange = function () { | |||
if ( this.notifyCheckbox.isSelected() ) { | |||
this.watchUserTalkCheckbox.setDisabled( false ); | |||
} else { | |||
this.watchUserTalkCheckbox.setSelected( false ); | |||
this.watchUserTalkCheckbox.setDisabled( true ); | |||
} | } | ||
}; | }; | ||
Line 903: | Line 941: | ||
suggestrename: this.suggestrenameCheckbox.isSelected(), | suggestrename: this.suggestrenameCheckbox.isSelected(), | ||
softblock: this.softblockCheckbox.isSelected(), | softblock: this.softblockCheckbox.isSelected(), | ||
watchusertalk: this.watchUserTalkCheckbox.isSelected(), | |||
watchdraft: this.watchDraftCheckbox.isSelected() | |||
}; | }; | ||
Line 970: | Line 1,009: | ||
label.setLabel( $( '<span>' ) | label.setLabel( $( '<span>' ) | ||
.addClass( 'success' ) | .addClass( 'draftify-success' ) | ||
.text( mw.message( 'dfy-progress-success' ).text() ) | .text( mw.message( 'dfy-progress-success' ).text() ) | ||
); | ); | ||
Line 984: | Line 1,023: | ||
if ( obj && obj.error && obj.error.info ) { | if ( obj && obj.error && obj.error.info ) { | ||
label.setLabel( $( '<span>' ) | label.setLabel( $( '<span>' ) | ||
.addClass( 'error' ) | .addClass( 'draftify-error' ) | ||
.text( mw.message( | .text( mw.message( | ||
'dfy-progress-failed', | 'dfy-progress-failed', | ||
Line 1,031: | Line 1,070: | ||
function main() { | function main() { | ||
// Load CSS | |||
importStylesheet( "User:WikiDwarf/Draftify.css" ); | |||
// Set up objects | |||
var portletLink, windowManager, | var portletLink, windowManager, | ||
draftifyDialog = new Dialog( { size: 'medium' } ), | draftifyDialog = new Dialog( { size: 'medium' } ), |
edits