Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fluff: Allow for a list of custom edit summaries #1283

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion modules/twinkleconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,14 @@ Twinkle.config.sections = [
type: 'enum',
enumValues: Twinkle.config.watchlistEnums
},

{
name: 'customReversionSummaryList',
label: 'Custom reversion edit summaries to display',
helptip: 'These appear as options in the enter reversion edit summary dialog',
type: 'customList',
customListValueTitle: 'Edit summary',
customListLabelTitle: 'Text to show in the dialog'
},
// TwinkleConfig.offerReasonOnNormalRevert (boolean)
// If to offer a prompt for extra summary reason for normal reverts, default to true
{
Expand Down
89 changes: 63 additions & 26 deletions modules/twinklefluff.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Twinkle.fluff.revert = function revertPage(type, vandal, rev, page) {
type: 'csrf',
format: 'json'
};
var wikipedia_api = new Morebits.wiki.api('Grabbing data of earlier revisions', query, Twinkle.fluff.callbacks.main);
var wikipedia_api = new Morebits.wiki.api('Grabbing data of earlier revisions', query, Twinkle.fluff.getSummary);
wikipedia_api.params = params;
wikipedia_api.post();
};
Expand All @@ -395,13 +395,61 @@ Twinkle.fluff.revertToRevision = function revertToRevision(oldrev) {
type: 'csrf',
format: 'json'
};
var wikipedia_api = new Morebits.wiki.api('Grabbing data of the earlier revision', query, Twinkle.fluff.callbacks.toRevision);
wikipedia_api.params = { rev: oldrev };
var wikipedia_api = new Morebits.wiki.api('Grabbing data of the earlier revision', query, Twinkle.fluff.getSummary);
wikipedia_api.params = { rev: oldrev, type: 'torev' };
wikipedia_api.post();
};

Twinkle.fluff.getSummary = function getSummary(apiobj) {
Twinkle.fluff.apiobj = apiobj;
var params = apiobj.params;
var type = params.type;
if (type === 'vand' || (type === 'norm' && !Twinkle.getPref('offerReasonOnNormalRevert'))) {
Twinkle.fluff.callbacks.main('noSummary');
} else {
Twinkle.fluff.simpleWindow = new Morebits.simpleWindow(600, 350);
TheTVExpert marked this conversation as resolved.
Show resolved Hide resolved
Twinkle.fluff.simpleWindow.setTitle('Enter reversion edit summary');
Twinkle.fluff.simpleWindow.setScriptName('Twinkle');
TheTVExpert marked this conversation as resolved.
Show resolved Hide resolved
Twinkle.fluff.simpleWindow.addFooterLink('Revert and rollback prefs', 'WP:TW/PREF#fluff');
Twinkle.fluff.simpleWindow.addFooterLink('Twinkle help', 'WP:TW/DOC#fluff');
TheTVExpert marked this conversation as resolved.
Show resolved Hide resolved
var form = new Morebits.quickForm(type === 'torev' ? Twinkle.fluff.callbacks.toRevision : Twinkle.fluff.callbacks.main);
if (Twinkle.getPref('customReversionSummaryList').length) {
form.append({
type: 'radio',
name: 'summaryList',
list: Twinkle.getPref('customReversionSummaryList'),
event: function(event) {
var esForm = event.target.form;
esForm.summary.value = this.value;
event.stopPropagation();
}
});
}
form.append({
id: 'editSummaryInput',
type: 'input',
TheTVExpert marked this conversation as resolved.
Show resolved Hide resolved
TheTVExpert marked this conversation as resolved.
Show resolved Hide resolved
name: 'summary',
label: 'Edit summary: '
});
form.append({ type: 'submit' });
var result = form.render();
Twinkle.fluff.simpleWindow.setContent(result);
Twinkle.fluff.simpleWindow.display();
TheTVExpert marked this conversation as resolved.
Show resolved Hide resolved
document.getElementById('editSummaryInput').focus();
}
};

Twinkle.fluff.callbacks = {
toRevision: function(apiobj) {
toRevision: function(e) {
var optional_summary;
if (e !== 'noSummary') {
e.preventDefault();
var form = e.target;
var input = Morebits.quickForm.getInputData(form);
optional_summary = input.summary;
Twinkle.fluff.simpleWindow.close();
}
var apiobj = Twinkle.fluff.apiobj;
var response = apiobj.getResponse();

var loadtimestamp = response.curtimestamp;
Expand All @@ -421,12 +469,6 @@ Twinkle.fluff.callbacks = {
return;
}

var optional_summary = prompt('Please specify a reason for the revert: ', ''); // padded out to widen prompt in Firefox
if (optional_summary === null) {
apiobj.statelem.error('Aborted by user.');
return;
}

var summary = Twinkle.fluff.formatSummary('Restored revision ' + revertToRevID + ' by $USER',
revertToUserHidden ? null : revertToUser, optional_summary);

Expand Down Expand Up @@ -467,7 +509,16 @@ Twinkle.fluff.callbacks = {
wikipedia_api.params = apiobj.params;
wikipedia_api.post();
},
main: function(apiobj) {
main: function(e) {
var extra_summary;
if (e !== 'noSummary') {
e.preventDefault();
var form = e.target;
var input = Morebits.quickForm.getInputData(form);
extra_summary = input.summary;
Twinkle.fluff.simpleWindow.close();
}
var apiobj = Twinkle.fluff.apiobj;
var response = apiobj.getResponse();

var loadtimestamp = response.curtimestamp;
Expand Down Expand Up @@ -601,14 +652,9 @@ Twinkle.fluff.callbacks = {

statelem.status([ ' revision ', Morebits.htmlNode('strong', params.goodid), ' that was made ', Morebits.htmlNode('strong', mw.language.convertNumber(count)), ' revisions ago by ', Morebits.htmlNode('strong', params.gooduserHidden ? Twinkle.fluff.hiddenName : params.gooduser) ]);

var summary, extra_summary;
var summary;
switch (params.type) {
case 'agf':
extra_summary = prompt('An optional comment for the edit summary: ', ''); // padded out to widen prompt in Firefox
if (extra_summary === null) {
statelem.error('Aborted by user.');
return;
}
userHasAlreadyConfirmedAction = true;

summary = Twinkle.fluff.formatSummary('Reverted [[WP:AGF|good faith]] edits by $USER',
Expand All @@ -623,15 +669,6 @@ Twinkle.fluff.callbacks = {
case 'norm':
/* falls through */
default:
if (Twinkle.getPref('offerReasonOnNormalRevert')) {
extra_summary = prompt('An optional comment for the edit summary: ', ''); // padded out to widen prompt in Firefox
if (extra_summary === null) {
statelem.error('Aborted by user.');
return;
}
userHasAlreadyConfirmedAction = true;
}

summary = Twinkle.fluff.formatSummary('Reverted ' + params.count + (params.count > 1 ? ' edits' : ' edit') + ' by $USER',
params.userHidden ? null : params.user, extra_summary);
break;
Expand Down
1 change: 1 addition & 0 deletions twinkle.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Twinkle.defaultConfig = {
markRevertedPagesAsMinor: [ 'vand' ],
watchRevertedPages: [ 'agf', 'norm', 'vand', 'torev' ],
watchRevertedExpiry: 'yes',
customReversionSummaryList: [{value: 'Unsourced addition', label: 'Unsourced'}, {value: 'Unexplained removal of content', label: 'Removal of content'}, {value: 'Potential copyright violation', label: 'Copyright violation'}, {value: 'Disruptive editing', label: 'Disruptive editing'}],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. Would it make more sense to make this list be empty and allow users to provide it themselves, then offer a few options (such as these?) in addition to that list? Kind of like the other customizations (warn/tag/welcome templates). It'd be annoying if you want to remove one, but I think a dropdown would help with that (though see other comment).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed this looks a bit silly. Not so much agreed on the solution. I see that twinkleconfig is missing a "plainlist" data type that would have been the natural solution here. It might be worth adding that just for this usecase.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd have to prepopulate it with something, no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two things to discuss here:

One is how to store the data. A plainlist would be nice, but I don't think customlist is a huge hindrance. The latter might make the display easier to parse for folks if there are multiple options. So maybe "sources: removed reliable sources" and "sources: needs reliable sources" or something. A plainlist does seem simpler given we just need one string of text.

The other is how to incorporate defaults, which I'm more concerned about. With this setup, if someone customizes the list, they are forever left out of any changes we make unless they hit "reset, view the default options, then re-add from memory what they wanted; that's not good. Instead we can do what is done elsewhere, namely include the basic uses in the module, and then add any items from customReversionSummaryList on top of that. The advantage of the former is that users could cull the defaults, though.

offerReasonOnNormalRevert: true,
confirmOnFluff: false,
confirmOnMobileFluff: true,
Expand Down