From 4d1db86843950cee01f3c7ef1066f3b504cf3a91 Mon Sep 17 00:00:00 2001 From: "Felix W. Dekker" Date: Fri, 14 May 2021 20:52:56 +0200 Subject: [PATCH] Correctly preprocess namespaces Fixes an error in some complicated networks. --- package.json | 2 +- src/main/js/MediaWiki.ts | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 94d161e..582cbcd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "interlanguage-checker", - "version": "1.13.3", + "version": "1.13.4", "description": "Check the consistency of MediaWiki interlanguage links in a simple overview.", "author": "Felix W. Dekker", "browser": "dist/bundle.js", diff --git a/src/main/js/MediaWiki.ts b/src/main/js/MediaWiki.ts index 312fa7f..79e06d1 100644 --- a/src/main/js/MediaWiki.ts +++ b/src/main/js/MediaWiki.ts @@ -324,7 +324,7 @@ export class MediaWiki { /** * The namespaces on this wiki. */ - namespaces!: Map; + namespaces!: Map; /** @@ -355,7 +355,13 @@ export class MediaWiki { this.general = query.general; this.interwikiMap = new Map(query.interwikimap.map((it: { prefix: string, url: string }) => [it.prefix, it.url])); - this.namespaces = query.namespaces; + this.namespaces = + new Map( + Object.keys(query.namespaces).map(id => { + const props = query.namespaces[id]; + return [+id, {canonical: props.canonical, "*": props["*"]}]; + }) + ); return this; } @@ -437,9 +443,7 @@ export class MediaWiki { if (titleParts.length < 2) return new InterlangLink(normalLang, link.title); titleParts[0] = [...this.namespaces.values()].reduce( - (titlePart: string, namespace: { id: string, canonical: string, "*": string }) => { - return titlePart === namespace["canonical"] ? namespace["*"] : titlePart; - }, + (titlePart, namespace) => titlePart === namespace["canonical"] ? namespace["*"] : titlePart, titleParts[0] ); const normalTitle = titleParts.join(":");