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

auto subscribe to user talk messages #337

Merged
merged 13 commits into from
Apr 23, 2024
10 changes: 10 additions & 0 deletions src/less/general.less
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ div.gradient-button, .gradient-button {
.afch-preferences {
label.afch-label {
font-size: 1em;
padding: 0;
}

div + div {
Expand All @@ -150,4 +151,13 @@ div.gradient-button, .gradient-button {
.details {
padding-bottom: 10px;
}

> div {
margin: 5px;

> label,
> [input="checkbox"] {
display: inline;
}
}
}
51 changes: 35 additions & 16 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,13 @@
* @param {Object} options Object with properties ('contents' is required, others are optional):
* contents: {string} the text to add to/replace the page,
* summary: {string} edit summary, will have the edit summary ad at the end,
* createonly: {bool} set to true to only edit the page if it doesn't exist,
* createonly: {boolean} set to true to only edit the page if it doesn't exist,
* mode: {string} 'appendtext' or 'prependtext'; default: (replace everything)
* hide: {bool} Set to true to supress logging in statusWindow
* hide: {boolean} Set to true to supress logging in statusWindow
* statusText: {string} message to show in status; default: "Editing"
* followRedirects: {boolean} true to follow redirects, false to ignore redirects
* watchlist: {string} 'nochange', 'preferences', 'unwatch', or 'watch'
* subscribe: {boolean} when appending a talk page section, whether or not to subscribe to it
* @return {jQuery.Deferred} Resolves if saved with all data
*/
editPage: function ( pagename, options ) {
Expand All @@ -637,13 +638,26 @@
status = AFCH.consts.nullstatus;
}

request = {
action: 'edit',
text: options.contents,
title: pagename,
summary: options.summary + AFCH.consts.summaryAd,
redirect: options.followRedirects
};
if ( !options.subscribe ) {
request = {
action: 'edit',
title: pagename,
text: options.contents,
summary: options.summary + AFCH.consts.summaryAd,
redirect: options.followRedirects
};
} else {
// Because it is easier to do subscriptions with it, use the discussiontoolsedit API instead of the edit API
request = {
action: 'discussiontoolsedit',
paction: 'addtopic',
page: pagename,
sectiontitle: '',
wikitext: options.contents.trim(),
summary: options.summary + AFCH.consts.summaryAd,
autosubscribe: 'yes'
};
}

if ( pagename.indexOf( 'Draft:' ) === 0 ) {
request.nocreate = 'true';
Expand All @@ -661,7 +675,7 @@

// Depending on mode, set appendtext=text or prependtext=text,
// which overrides the default text option
if ( options.mode ) {
if ( !options.subscribe && options.mode ) {
request[ options.mode ] = options.contents;
}

Expand All @@ -674,18 +688,21 @@
AFCH.api.postWithEditToken( request )
.done( function ( data ) {
var $diffLink;
var api = options.subscribe ? 'discussiontoolsedit' : 'edit';
// The success string is capitalized by one API and not the other
var success = options.subscribe ? 'success' : 'Success';

if ( data && data.edit && data.edit.result && data.edit.result === 'Success' ) {
if ( data && data[ api ] && data[ api ].result && data[ api ].result === success ) {
deferred.resolve( data );

if ( data.edit.hasOwnProperty( 'nochange' ) ) {
if ( data[ api ].hasOwnProperty( 'nochange' ) ) {
status.update( 'No changes made to $1' );
return;
}

// Create a link to the diff of the edit
$diffLink = AFCH.makeLinkElementToPage(
'Special:Diff/' + data.edit.oldrevid + '/' + data.edit.newrevid, '(diff)'
'Special:Diff/' + data[ api ].newrevid, '(diff)'
).addClass( 'text-smaller' );

status.update( 'Saved $1 ' + AFCH.jQueryToHtml( $diffLink ) );
Expand Down Expand Up @@ -780,7 +797,7 @@
* @param {string} user
* @param {Object} data object with properties
* - message: {string}
* - summary: {string}
* - summary: {string} edit summary
* - hide: {bool}, default false
* @param options
* @return {jQuery.Deferred} Resolves with success/failure
Expand All @@ -796,7 +813,8 @@
mode: 'appendtext',
statusText: 'Notifying',
hide: options.hide,
followRedirects: true
followRedirects: true,
subscribe: AFCH.prefs.autoSubscribe
} )
.done( function () {
deferred.resolve();
Expand Down Expand Up @@ -1228,7 +1246,8 @@
logCsd: true,
launchLinkPosition: 'p-cactions',
logAfc: false,
noWatch: false
noWatch: false,
autoSubscribe: false
};

/**
Expand Down
5 changes: 5 additions & 0 deletions src/templates/tpl-preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<label for="noWatch" class="afch-label">Do not add pages to watchlist</label>
<input type="checkbox" id="noWatch" class="afch-input" {{#noWatch}}checked{{/noWatch}} />
</div>
<div id="autoSubscribeWrapper">
<label for="autoSubscribe" class="afch-label"><a href="https://www.mediawiki.org/wiki/Help:DiscussionTools#Topic_subscriptions" target="_blank">Receive a notification</a> when a draft author replies to a user talk message you left them</label>
<input type="checkbox" id="autoSubscribe" class="afch-input" {{#autoSubscribe}}checked{{/autoSubscribe}} />
</div>
<!-- When adding new preferences, don't forget to update core.js prefDefaults -->
</div>
<!-- /preferences -->

Expand Down
Loading