Skip to content

Commit 9ecbc4a

Browse files
add change tag support
1 parent 5207cbb commit 9ecbc4a

9 files changed

Lines changed: 50 additions & 12 deletions

src/Deputy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ class Deputy {
5959

6060
/**
6161
* This version of Deputy.
62-
*
63-
* @type {string}
6462
*/
65-
readonly version = deputyVersion;
63+
readonly version: string = deputyVersion;
6664
/**
6765
* The current page as an mw.Title.
6866
*/
@@ -129,12 +127,14 @@ class Deputy {
129127
* sub-components as well.
130128
*/
131129
async init() {
130+
// Attach modules to respective names
132131
window.CopiedTemplateEditor = this.ante;
133132
window.InfringementAssistant = this.ia;
133+
134134
mw.hook( 'deputy.preload' ).fire( this );
135135

136136
// Initialize the configuration
137-
this.config = await UserConfiguration.load();
137+
this.config = UserConfiguration.load();
138138
window.deputyLang = this.config.core.language.get();
139139

140140
// Inject CSS

src/config/WikiConfiguration.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
listingWikitext
1616
} from '../wiki/TemplatePolyfills';
1717
import ConfigurationReloadBanner from '../ui/config/ConfigurationReloadBanner';
18+
import changeTag from './changeTag';
1819

1920
export type WikiPageConfiguration = {
2021
title: mw.Title,
@@ -233,6 +234,10 @@ export default class WikiConfiguration extends ConfigurationBase {
233234
defaultValue: new URL( 'https://deputy.toolforge.org/' ),
234235
displayOptions: { type: 'text' },
235236
alwaysSave: true
237+
} ),
238+
changeTag: new Setting<string, string>( {
239+
defaultValue: null,
240+
displayOptions: { type: 'text' }
236241
} )
237242
};
238243

@@ -462,6 +467,7 @@ export default class WikiConfiguration extends ConfigurationBase {
462467
// Update last edited number
463468
this.core.lastEdited.set( Date.now() );
464469
await MwApi.action.postWithEditToken( {
470+
...changeTag( await window.deputy.getWikiConfig() ),
465471
action: 'edit',
466472
title: this.sourcePage.getPrefixedText(),
467473
text: this.serialize()

src/config/changeTag.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import WikiConfiguration from './WikiConfiguration';
2+
3+
/**
4+
* Automatically applies a change tag to edits made by the user if
5+
* a change tag was provided in the configuration.
6+
*
7+
* @param config
8+
* @return A spreadable Object containing the `tags` parameter for `action=edit`.
9+
*/
10+
export default function changeTag( config: WikiConfiguration ): { tags?: string } {
11+
return config.core.changeTag.get() ?
12+
{ tags: config.core.changeTag.get() } :
13+
{};
14+
}

src/modules/ante/ui/CopiedTemplateEditorDialog.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import DeputyReviewDialog from '../../../ui/root/DeputyReviewDialog';
1818
import normalizeTitle from '../../../wiki/util/normalizeTitle';
1919
import getPageContent from '../../../wiki/util/getPageContent';
2020
import openWindow from '../../../wiki/util/openWindow';
21+
import changeTag from '../../../config/changeTag';
2122

2223
interface CopiedTemplateEditorDialogData {
2324
main: CopiedTemplateEditor;
@@ -234,13 +235,13 @@ function initCopiedTemplateEditorDialog() {
234235
framed: false,
235236
invisibleLabel: true,
236237
label: mw.msg( 'deputy.ante.mergeAll' ),
237-
title: mw.msg( 'deputy.ante.mergeAll' ),
238+
title: mw.msg( 'deputy.ante.mergeAll' )
238239
} );
239240
this.mergeButton.on( 'click', () => {
240241
const notices = this.parsoid.findRowedNoticesByHref();
241-
const noticeCount = Object.values(notices)
242+
const noticeCount = Object.values( notices )
242243
.filter( v => v.length > 1 )
243-
.reduce( (p, n) => p + n.length, 0 );
244+
.reduce( ( p, n ) => p + n.length, 0 );
244245
return noticeCount ?
245246
OO.ui.confirm(
246247
mw.message(
@@ -252,8 +253,8 @@ function initCopiedTemplateEditorDialog() {
252253
return;
253254
}
254255

255-
for ( const noticeSet of Object.values(notices)) {
256-
TemplateMerger.merge(noticeSet);
256+
for ( const noticeSet of Object.values( notices ) ) {
257+
TemplateMerger.merge( noticeSet );
257258
}
258259
} ) :
259260
OO.ui.alert( 'There are no templates to merge.' );
@@ -324,13 +325,15 @@ function initCopiedTemplateEditorDialog() {
324325

325326
this.layout.on( 'remove', () => {
326327
this.mergeButton.setDisabled(
327-
!Object.values(this.parsoid.findRowedNoticesByHref()).some( v => v.length > 1 )
328+
!Object.values( this.parsoid.findRowedNoticesByHref() )
329+
.some( v => v.length > 1 )
328330
);
329331
deleteButton.setDisabled( this.parsoid.findNotices().length === 0 );
330332
} );
331333
this.parsoid.addEventListener( 'templateInsert', () => {
332334
this.mergeButton.setDisabled(
333-
!Object.values(this.parsoid.findRowedNoticesByHref()).some( v => v.length > 1 )
335+
!Object.values( this.parsoid.findRowedNoticesByHref() )
336+
.some( v => v.length > 1 )
334337
);
335338
deleteButton.setDisabled( this.parsoid.findNotices().length === 0 );
336339
} );
@@ -439,7 +442,7 @@ function initCopiedTemplateEditorDialog() {
439442

440443
// Recheck state of merge button
441444
this.mergeButton.setDisabled(
442-
!Object.values(this.parsoid.findRowedNoticesByHref())
445+
!Object.values( this.parsoid.findRowedNoticesByHref() )
443446
.some( v => v.length > 1 )
444447
);
445448

@@ -478,6 +481,7 @@ function initCopiedTemplateEditorDialog() {
478481
// Saves the page.
479482
process.next( async () => {
480483
return new mw.Api().postWithEditToken( {
484+
...changeTag( await window.CopiedTemplateEditor.getWikiConfig() ),
481485
action: 'edit',
482486
format: 'json',
483487
formatversion: '2',

src/modules/ia/models/CopyrightProblemsListing.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import normalizeTitle from '../../../wiki/util/normalizeTitle';
44
import anchorToTitle from '../../../wiki/util/anchorToTitle';
55
import decorateEditSummary from '../../../wiki/util/decorateEditSummary';
66
import MwApi from '../../../MwApi';
7+
import changeTag from '../../../config/changeTag';
78

89
interface FullCopyrightProblemsListingData {
910
basic: false;
@@ -55,6 +56,9 @@ export default class CopyrightProblemsListing {
5556
* @return A regular expression.
5657
*/
5758
static get articleCvRegex(): RegExp {
59+
// Acceptable level of danger; global configuration is found only in trusted
60+
// places (see WikiConfiguration documentation).
61+
// eslint-disable-next-line security/detect-non-literal-regexp
5862
return new RegExp( window.InfringementAssistant.wikiConfig.ia.listingWikitextMatch.get() );
5963
}
6064

@@ -391,6 +395,7 @@ export default class CopyrightProblemsListing {
391395
const newWikitext = await this.addComment( message, indent );
392396

393397
await MwApi.action.postWithEditToken( {
398+
...changeTag( await window.InfringementAssistant.getWikiConfig() ),
394399
action: 'edit',
395400
format: 'json',
396401
formatversion: '2',

src/modules/ia/models/CopyrightProblemsPage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import normalizeTitle from '../../../wiki/util/normalizeTitle';
22
import getPageContent from '../../../wiki/util/getPageContent';
33
import decorateEditSummary from '../../../wiki/util/decorateEditSummary';
44
import MwApi from '../../../MwApi';
5+
import changeTag from '../../../config/changeTag';
56

67
/**
78
* A class that represents a `Wikipedia:Copyright problems` page, a page that lists
@@ -172,6 +173,7 @@ export default class CopyrightProblemsPage {
172173
// The `catch` statement here can theoretically create an infinite loop given
173174
// enough race conditions. Don't worry about it too much, though.
174175
await MwApi.action.postWithEditToken( {
176+
...changeTag( await window.InfringementAssistant.getWikiConfig() ),
175177
action: 'edit',
176178
title: listingPage.getPrefixedText(),
177179
...textParameters,

src/modules/ia/ui/SinglePageWorkflowDialog.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { TripleCompletionAction } from '../../shared/CompletionAction';
1111
import equalTitle from '../../../util/equalTitle';
1212
import msgEval from '../../../wiki/util/msgEval';
1313
import CCICaseInputWidget from './CCICaseInputWidget';
14+
import changeTag from '../../../config/changeTag';
1415

1516
export interface SinglePageWorkflowDialogData {
1617
page: TitleLike;
@@ -577,6 +578,7 @@ function initSinglePageWorkflowDialog() {
577578
}
578579

579580
await MwApi.action.postWithEditToken( {
581+
...changeTag( await window.InfringementAssistant.getWikiConfig() ),
580582
action: 'edit',
581583
title: this.page.getPrefixedText(),
582584
text: finalPageContent,

src/ui/root/DeputyContributionSurveySection.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { generateTrace } from '../../models/DeputyTrace';
2121
import DeputyMessageWidget from '../shared/DeputyMessageWidget';
2222
import sectionHeadingN from '../../wiki/util/sectionHeadingN';
2323
import last from '../../util/last';
24+
import changeTag from '../../config/changeTag';
2425

2526
/**
2627
* The contribution survey section UI element. This includes a list of revisions
@@ -427,6 +428,7 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
427428
}
428429

429430
return MwApi.action.postWithEditToken( {
431+
...changeTag( await window.deputy.getWikiConfig() ),
430432
action: 'edit',
431433
pageid: this.casePage.pageId,
432434
section: sectionId,

src/wiki/TalkPage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import normalizeTitle from './util/normalizeTitle';
22
import decorateEditSummary from './util/decorateEditSummary';
33
import nsId from './util/nsId';
44
import MwApi from '../MwApi';
5+
import changeTag from '../config/changeTag';
6+
import WikiConfiguration from '../config/WikiConfiguration';
57

68
/**
79
* Options for performing edits with {@link TalkPage}.
@@ -57,6 +59,7 @@ export default class TalkPage {
5759
nsId( 'user_talk' )
5860
}, editOptions, {
5961
// Non-overridable options
62+
...changeTag( await WikiConfiguration.load() ),
6063
action: 'edit',
6164
title: this.talkPage.getPrefixedText(),
6265
summary: decorateEditSummary( options.summary ),

0 commit comments

Comments
 (0)