Skip to content

Commit

Permalink
Make default mwWikiPath as empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimKovalenkoSNF committed Nov 9, 2023
1 parent a3c98d0 commit c2f2b87
Show file tree
Hide file tree
Showing 22 changed files with 10 additions and 43 deletions.
5 changes: 2 additions & 3 deletions src/MediaWiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ class MediaWiki {
}

set wikiPath(value: string) {
// Empty string is a valid parameter for the wikiPath
if (value !== null && typeof value !== 'undefined') {
if (value) {
this.#wikiPath = value
this.initApiURLDirector()
}
Expand Down Expand Up @@ -135,7 +134,7 @@ class MediaWiki {

this.#actionApiPath = 'w/api.php'
this.#restApiPath = 'api/rest_v1'
this.#wikiPath = 'wiki/'
this.#wikiPath = ''
this.#modulePathOpt = 'w/load.php'

this.namespaces = {}
Expand Down
2 changes: 1 addition & 1 deletion src/parameterList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const parameterDescriptions = {
format:
'Specify a flavour for the scraping. If missing, scrape all article contents. Each --format argument will cause a new local file to be created but options can be combined. Supported options are:\n * novid: no video & audio content\n * nopic: no pictures (implies "novid")\n * nopdf: no PDF files\n * nodet: only the first/head paragraph (implies "novid")\nFormat names can also be aliased using a ":"\nExample: "... --format=nopic:mini --format=novid,nopdf"',
keepEmptyParagraphs: 'Keep all paragraphs, even empty ones.',
mwWikiPath: 'Mediawiki wiki base path (per default "/wiki/")',
mwWikiPath: 'Mediawiki wiki base path (per default empty string)',
mwActionApiPath: 'Mediawiki API path (per default "/w/api.php")',
mwRestApiPath: 'Mediawiki Rest API path (per default "/api/rest_v1")',
mwModulePath: 'Mediawiki module load path (per default "/w/load.php")',
Expand Down
4 changes: 3 additions & 1 deletion src/sanitize-argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export async function sanitize_all(argv: any) {
export function sanitizeWikiPath(mwWikiPath = '') {
mwWikiPath = sanitizeApiPathParam(mwWikiPath)

if (mwWikiPath?.endsWith('/')) {
// Make sure wikiPath always has forward slash at the end for the correct URL building
if (!mwWikiPath?.endsWith('/')) {
mwWikiPath += '/'
}

Expand All @@ -134,6 +135,7 @@ export function sanitizeApiPathParam(apiPathParam: string) {
return
}

// No api params should start from forward slash
if (apiPathParam.startsWith('/')) {
apiPathParam = apiPathParam.slice(1)
}
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/apiPathParamsSanitizing.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { zimcheck } from '../util.js'
import 'dotenv/config.js'
import { jest } from '@jest/globals'
import rimraf from 'rimraf'
import { sanitizeApiPathParam, sanitizeWikiPath } from '../../src/sanitize-argument.js'
import { sanitizeApiPathParam } from '../../src/sanitize-argument.js'

jest.setTimeout(60000)

Expand All @@ -14,7 +14,6 @@ const parameters = {
mwActionApiPath: sanitizeApiPathParam('/w/api.php'),
mwRestApiPath: sanitizeApiPathParam('/api/rest_v1'),
mwModulePath: sanitizeApiPathParam('/w/load.php'),
mwWikiPath: sanitizeWikiPath('/'),
}

await testAllRenders(parameters, async (outFiles) => {
Expand All @@ -27,7 +26,7 @@ await testAllRenders(parameters, async (outFiles) => {
expect(outFiles[0].mwMetaData.restApiPath).toBe('api/rest_v1')
})

test('Mediawiki wikiPath option', () => {
test('Mediawiki default empty wikiPath option', () => {
expect(outFiles[0].mwMetaData.wikiPath).toBe('')
})

Expand Down
2 changes: 0 additions & 2 deletions test/e2e/articleLists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const parameters = {
articleListToIgnore,
redis: process.env.REDIS,
format: ['nopic'],
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(parameters, async (outFiles) => {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/bm.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const parameters = {
adminEmail: '[email protected]',
redis: process.env.REDIS,
format: ['nopic'],
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(parameters, async (outFiles) => {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/downloadImage.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const parameters = {
articleList: 'Paris',
format: ['nodet'],
optimisationCacheUrl: process.env.S3_URL,
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(parameters, async (outFiles) => {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/en.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const parameters = {
mwUrl: 'https://en.wikipedia.org',
articleList: 'BMW',
adminEmail: '[email protected]',
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(parameters, async (outFiles) => {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/en10.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const parameters = {
redis: process.env.REDIS,
// format: ['nopic', 'novid', 'nopdf', 'nodet'],
format: ['nopic', 'nopdf'],
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(parameters, async (outFiles) => {
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/extra.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ describe('Extra', () => {
redis: process.env.REDIS,
format: ['nopic'],
forceRender: 'WikimediaDesktop',
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
mwRestApiPath: 'api/rest_v1',
mwModulePath: 'w/load.php',
})

// Created 1 outputs
Expand Down
1 change: 0 additions & 1 deletion test/e2e/forceRender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('forceRender', () => {
format: ['nopic'],
articleList: 'France',
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

beforeAll(async () => {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/formatParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const parameters = {
mwUrl: 'https://en.wikipedia.org',
adminEmail: '[email protected]',
redis: process.env.REDIS,
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders({ ...parameters, format: 'nopic', articleList: 'BMW' }, async (outFiles) => {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/multimediaContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const parameters = {
redis: process.env.REDIS,
customZimDescription: 'Example of the description',
forceRender: 'WikimediaDesktop',
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/treatMedia.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const parameters = {
adminEmail: '[email protected]',
articleList: 'Read_my_lips:_no_new_taxes',
redis: process.env.REDIS,
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(parameters, async (outFiles) => {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/vikidia.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const parameters = {
redis: process.env.REDIS,
articleList: 'Alaska',
customZimDescription: 'Alaska article',
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/wikisource.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const parameters = {
redis: process.env.REDIS,
format: ['nopic'],
noLocalParserFallback: true,
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/zimMetadata.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const parameters = {
customZimLongDescription: 'Example of the long description',
customZimTitle: 'Example of the title',
publisher: 'Example of the publisher',
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
}

await testAllRenders(parameters, async (outFiles) => {
Expand Down
1 change: 0 additions & 1 deletion test/unit/downloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('Downloader class', () => {

beforeAll(async () => {
MediaWiki.base = 'https://en.wikipedia.org'
MediaWiki.wikiPath = '/'
MediaWiki.getCategories = true

downloader = new Downloader({ uaString: `${config.userAgent} ([email protected])`, speed: 1, reqTimeout: 1000 * 60, webp: true, optimisationCacheUrl: '' })
Expand Down
3 changes: 0 additions & 3 deletions test/unit/mwApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('mwApi', () => {
await RedisStore.articleDetailXId.flush()

MediaWiki.base = 'https://en.wikipedia.org'
MediaWiki.wikiPath = '/'
MediaWiki.getCategories = true
downloader = new Downloader({ uaString: `${config.userAgent} ([email protected])`, speed: 1, reqTimeout: 1000 * 60, webp: false, optimisationCacheUrl: '' })

Expand Down Expand Up @@ -103,7 +102,6 @@ describe('mwApi', () => {
})

test('extracting title from href', () => {
MediaWiki.wikiPath = '/wiki/'
const titleWithWiki = MediaWiki.extractPageTitleFromHref('/wiki/Hades')
// Title with hrefs contaning /wiki
expect(titleWithWiki).toEqual('Hades')
Expand Down Expand Up @@ -133,7 +131,6 @@ describe('Test blacklisted NSs', () => {
await RedisStore.articleDetailXId.flush()

MediaWiki.base = 'https://id.wikipedia.org'
MediaWiki.wikiPath = '/'
MediaWiki.getCategories = true

downloader = new Downloader({ uaString: `${config.userAgent} ([email protected])`, speed: 1, reqTimeout: 1000 * 60, webp: false, optimisationCacheUrl: '' })
Expand Down
2 changes: 1 addition & 1 deletion test/unit/treatments/media.treatment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('MediaTreatment', () => {

describe('treatSubtitle', () => {
test('treat one subtitle', async () => {
const { dump } = await setupScrapeClasses({ format: '', mwWikiPath: '/' })
const { dump } = await setupScrapeClasses({ format: '' })

// Wikicode is taken from article "Mechanical energy" which has a video with subtitle
const wikicode =
Expand Down
2 changes: 0 additions & 2 deletions test/unit/webpAndRedirection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ Real-time computer graphics`
outputDirectory: testId,
redis: process.env.REDIS,
webp: true,
mwActionApiPath: 'w/api.php',
mwWikiPath: '/',
})

const zimFile = new ZimReader(outFiles[0].outFile)
Expand Down
2 changes: 1 addition & 1 deletion test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function makeLink($doc: Document, href: string, rel: string, title: strin
return $link
}

export async function setupScrapeClasses({ mwUrl = 'https://en.wikipedia.org', format = '', mwWikiPath = '/wiki' } = {}) {
export async function setupScrapeClasses({ mwUrl = 'https://en.wikipedia.org', format = '', mwWikiPath = '' } = {}) {
MediaWiki.base = mwUrl
MediaWiki.wikiPath = mwWikiPath

Expand Down

0 comments on commit c2f2b87

Please sign in to comment.