Skip to content

Commit 083f97d

Browse files
ia: improved link detection
1 parent 7ebf053 commit 083f97d

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/modules/ia/models/CopyrightProblemsListing.ts

+13-18
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,18 @@ export default class CopyrightProblemsListing {
117117
// Get the page title based on the anchor, verified by the link.
118118
// This ensures we're always using the prefixedDb version of the title (as
119119
// provided by the anchor) for stability.
120-
let title: mw.Title;
121120
const prefixedDb = anchor.getAttribute( 'id' );
122121
const href = el.getAttribute( 'href' );
123-
if ( prefixedDb == null ) {
124-
// Not an anchor.
125-
return false;
126-
} else if ( href === mw.util.getUrl( prefixedDb ) ) {
127-
// The page exists and links to the correct page.
128-
title = new mw.Title( prefixedDb );
129-
} else if ( new RegExp(
130-
`[?&]title=${mw.util.escapeRegExp( prefixedDb )}(?:&|$)`
131-
).test( prefixedDb ) ) {
132-
// The page does not exist but it links to the correct page.
133-
title = new mw.Title( prefixedDb );
134-
} else {
135-
// The page does not link to the correct page.
136-
return false;
137-
}
122+
const title = anchorToTitle( el as HTMLAnchorElement );
123+
124+
if ( title === false ) {
125+
// Not a valid link.
126+
return false;
127+
} else if ( title.getPrefixedText() !== new mw.Title( prefixedDb ).getPrefixedText() ) {
128+
// Anchor and link mismatch. Someone tampered with the template?
129+
// In this case, rely on the link instead, as the anchor is merely invisible.
130+
console.warn( `Anchor and link mismatch for "${title.getPrefixedText()}".`, title, prefixedDb );
131+
}
138132

139133
// Checks for the <span class="plainlinks"> element.
140134
// This ensures that the listing came from {{article-cv}} and isn't just a
@@ -371,9 +365,10 @@ export default class CopyrightProblemsListing {
371365
* use `addComment` instead.
372366
*
373367
* @param message
368+
* @param summary
374369
* @param indent
375370
*/
376-
async respond( message: string, indent = false ): Promise<void> {
371+
async respond( message: string, summary?: string, indent = false ): Promise<void> {
377372
const newWikitext = await this.addComment( message, indent );
378373

379374
await MwApi.action.postWithEditToken( {
@@ -385,7 +380,7 @@ export default class CopyrightProblemsListing {
385380
text: newWikitext,
386381
// TODO: l10n
387382
summary: decorateEditSummary(
388-
`Responding to [[${
383+
summary ?? `Responding to [[${
389384
this.listingPage.title.getPrefixedText()
390385
}#${
391386
this.title.getPrefixedText()

src/modules/ia/ui/ListingResponsePanel.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export default class ListingResponsePanel extends EventTarget {
1919
'blanked', 'move', 'deferred', 'ticket', 'backwards', 'purged', 'OTRS', 'unverified',
2020
'viable'
2121
];
22+
static readonly nonClosingResponses = [
23+
'deferred', 'OTRS', 'unverified', 'viable'
24+
];
2225

2326
originLink: HTMLElement;
2427
listing: CopyrightProblemsListing;
@@ -134,7 +137,7 @@ export default class ListingResponsePanel extends EventTarget {
134137
this.submitButton.setDisabled( true );
135138

136139
try {
137-
await this.listing.respond( this.toWikitext(), false );
140+
await this.listing.respond( this.toWikitext(), null, false );
138141
const dd = <dd dangerouslySetInnerHTML={this.previewPanel.innerHTML} />;
139142

140143
// Try to insert at an existing list for better spacing.

0 commit comments

Comments
 (0)