Skip to content

Commit

Permalink
if <script> with 'mw.config.set' is not found then grab <script> with…
Browse files Browse the repository at this point in the history
… config variables
  • Loading branch information
pavel-karatsiuba committed Feb 3, 2023
1 parent cb81441 commit 35465da
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/util/saveArticles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ async function getModuleDependencies(articleId: string, mw: MediaWiki, downloade
let styleDependenciesList: string[] = []

const articleApiUrl = mw.articleApiUrl(articleId)

console.log(11111, articleApiUrl)
const articleData = await downloader.getJSON<any>(articleApiUrl)

if (articleData.error) {
Expand Down Expand Up @@ -411,10 +411,12 @@ async function getModuleDependencies(articleId: string, mw: MediaWiki, downloade
for (let i = 0; i < scriptTags.length; i += 1) {
if (scriptTags[i].text.includes('mw.config.set')) {
jsConfigVars = regex.exec(scriptTags[i].text)[0] || ''
jsConfigVars = `(window.RLQ=window.RLQ||[]).push(function() {${jsConfigVars}});`
} else if (scriptTags[i].text.includes('RLCONF') || scriptTags[i].text.includes('RLSTATE') || scriptTags[i].text.includes('RLPAGEMODULES')) {
jsConfigVars = scriptTags[i].text
}
}

jsConfigVars = `(window.RLQ=window.RLQ||[]).push(function() {${jsConfigVars}});`
jsConfigVars = jsConfigVars.replace('nosuchaction', 'view') // to replace the wgAction config that is set to 'nosuchaction' from api but should be 'view'

return { jsConfigVars, jsDependenciesList, styleDependenciesList }
Expand Down

0 comments on commit 35465da

Please sign in to comment.