From 14fd7a40baab2aeeec1c997d3ee6d1fd8df2032e Mon Sep 17 00:00:00 2001 From: Vadim Kovalenko Date: Fri, 18 Aug 2023 17:20:07 +0300 Subject: [PATCH] Add temporary workaround for article treatment to bypass test/e2e/cmd.e2e.test.ts --- src/util/saveArticles.ts | 1 + src/util/treatments/article.treatment.ts | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/util/saveArticles.ts b/src/util/saveArticles.ts index 920139eb..09dc1f11 100644 --- a/src/util/saveArticles.ts +++ b/src/util/saveArticles.ts @@ -209,6 +209,7 @@ async function saveArticle( const { finalHTML, mediaDependencies, subtitles } = await articleTreatment.processArticleHtml( articleHtml, redisStore, + MediaWiki, dump, articleId, articleDetail, diff --git a/src/util/treatments/article.treatment.ts b/src/util/treatments/article.treatment.ts index 724ec7e6..faf3f161 100644 --- a/src/util/treatments/article.treatment.ts +++ b/src/util/treatments/article.treatment.ts @@ -12,7 +12,15 @@ import DOMUtils from '../../DOMUtils.js' import mediaTreatment from './media.treatment.js' class ArticleTreatment { - async processArticleHtml(html: string, redisStore: RS, dump: Dump, articleId: string, articleDetail: ArticleDetail, _moduleDependencies: any, webp: boolean) { + /** + * TODO: add temporary workaround to bypass 'test/e2e/cmd.e2e.test.ts' + * Once article treatments will be replaced to render() method, + * there should not be a problem to access to MediaWiki singleton + */ + private mw: typeof MediaWiki + + async processArticleHtml(html: string, redisStore: RS, mw: any, dump: Dump, articleId: string, articleDetail: ArticleDetail, _moduleDependencies: any, webp: boolean) { + this.mw = mw let mediaDependencies: Array<{ url: string; path: string }> = [] let subtitles: Array<{ url: string; path: string }> = [] let doc = domino.createDocument(html) @@ -100,7 +108,7 @@ class ArticleTreatment { const htmlTemplateDoc = domino.createDocument( htmlTemplateCode(articleId) - .replace('__ARTICLE_CANONICAL_LINK__', genCanonicalLink(config, MediaWiki.webUrl.href, articleId)) + .replace('__ARTICLE_CANONICAL_LINK__', genCanonicalLink(config, this.mw.webUrl.href, articleId)) .replace('__ARTICLE_CONFIGVARS_LIST__', jsConfigVars !== '' ? genHeaderScript(config, 'jsConfigVars', articleId, config.output.dirs.mediawiki) : '') .replace( '__ARTICLE_JS_LIST__', @@ -159,7 +167,7 @@ class ArticleTreatment { const creatorLink = '` + + `href="${this.mw.webUrl.href}?title=${encodeURIComponent(articleId)}&oldid=${articleDetail.revisionId}">` + `${dump.mwMetaData.creator}` const licenseLink = `${dump.strings.LICENSE_NAME}` @@ -194,7 +202,7 @@ class ArticleTreatment { private isSubpage(id: string) { if (id && id.indexOf('/') >= 0) { const namespace = id.indexOf(':') >= 0 ? id.substring(0, id.indexOf(':')) : '' - const ns = MediaWiki.namespaces[namespace] // namespace already defined + const ns = this.mw.namespaces[namespace] // namespace already defined if (ns !== undefined) { return ns.allowedSubpages }