Skip to content

Commit

Permalink
cci: use row anchor target instead of title
Browse files Browse the repository at this point in the history
Matching between row element and wikitext line was
failing due to the anchor text changing depending on
the Chinese variant used by the user. This is not
an issue restricted to Chinese, but any language
which uses LanguageConverter.

Using the anchor target (which doesn't change, even
when overriding the current variant being used; e.g.
`/zh-cn/` instead of `/wiki/`) should make matching
between row element and line much more reliable.

Discovered with the help of @fee1-dead.
  • Loading branch information
ChlodAlejandro committed Jul 8, 2024
1 parent 208f52b commit 5523baa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/ui/root/DeputyContributionSurveySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import DeputyExtraneousElement from './DeputyExtraneousElement';
import classMix from '../../util/classMix';
import dangerModeConfirm from '../../util/dangerModeConfirm';
import normalizeWikiHeading, { WikiHeading } from '../../wiki/util/normalizeWikiHeading';
import parseDiffUrl from '../../wiki/util/parseDiffUrl';

/**
* The contribution survey section UI element. This includes a list of revisions
Expand Down Expand Up @@ -356,8 +357,15 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
const anchor: HTMLElement = li.querySelector( 'a:first-of-type' );
// Avoid enlisting if the anchor can't be found (invalid row).
if ( anchor ) {
rowElements[ new mw.Title( anchor.innerText ).getPrefixedText() ] =
li as HTMLLIElement;
const anchorLinkTarget = parseDiffUrl(
new URL( anchor.getAttribute( 'href' ), window.location.href )
).title;
if ( !anchorLinkTarget ) {
warn( 'Could not parse target of anchor', anchor );
} else {
rowElements[ new mw.Title( anchorLinkTarget ).getPrefixedText() ] =
li as HTMLLIElement;
}
}
}
}
Expand All @@ -384,6 +392,7 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
);
} else {
// Element somehow not in list. Just keep line as-is.
warn( `Could not find row element for "${csr.title.getPrefixedText()}"` );
rowElement = line;
}
} catch ( e ) {
Expand Down
4 changes: 3 additions & 1 deletion src/wiki/util/parseDiffUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface DiffInfo {
* or `oldid` from a URL. This is useful for converting diff URLs into actual
* diff information, and especially useful for {{copied}} templates.
*
* If diff parameters were not found (no `diff` or `oldid`), they will be `null`.
*
* @param url The URL to parse
* @return Parsed info: `diff` or `oldid` revision IDs, and/or the page title.
*/
Expand Down Expand Up @@ -66,7 +68,7 @@ export default function parseDiffUrl( url: URL | string ): DiffInfo {
const articlePathRegex = new RegExp( mw.util.getUrl( '(.*)' ) )
.exec( url.pathname );
if ( articlePathRegex != null ) {
title = articlePathRegex[ 1 ];
title = decodeURIComponent( articlePathRegex[ 1 ] );
break tryConvert;
}
}
Expand Down

0 comments on commit 5523baa

Please sign in to comment.