mwoffliner 1.12.1 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/README.md +21 -9
  2. package/lib/Downloader.d.ts +28 -27
  3. package/lib/Downloader.js +199 -179
  4. package/lib/Downloader.js.map +1 -1
  5. package/lib/Dump.d.ts +1 -0
  6. package/lib/Dump.js +5 -2
  7. package/lib/Dump.js.map +1 -1
  8. package/lib/Logger.d.ts +8 -10
  9. package/lib/Logger.js +41 -32
  10. package/lib/Logger.js.map +1 -1
  11. package/lib/MediaWiki.d.ts +61 -28
  12. package/lib/MediaWiki.js +236 -82
  13. package/lib/MediaWiki.js.map +1 -1
  14. package/lib/RedisStore.d.ts +13 -13
  15. package/lib/RedisStore.js +67 -54
  16. package/lib/RedisStore.js.map +1 -1
  17. package/lib/S3.d.ts +8 -2
  18. package/lib/S3.js +74 -43
  19. package/lib/S3.js.map +1 -1
  20. package/lib/Templates.d.ts +3 -2
  21. package/lib/Templates.js +6 -13
  22. package/lib/Templates.js.map +1 -1
  23. package/lib/cli.js +8 -12
  24. package/lib/cli.js.map +1 -1
  25. package/lib/config.d.ts +7 -2
  26. package/lib/config.js +14 -7
  27. package/lib/config.js.map +1 -1
  28. package/lib/mwoffliner.lib.js +125 -149
  29. package/lib/mwoffliner.lib.js.map +1 -1
  30. package/lib/parameterList.d.ts +4 -3
  31. package/lib/parameterList.js +29 -27
  32. package/lib/parameterList.js.map +1 -1
  33. package/lib/renderers/abstract.renderer.d.ts +82 -0
  34. package/lib/renderers/abstract.renderer.js +588 -0
  35. package/lib/renderers/abstract.renderer.js.map +1 -0
  36. package/lib/renderers/abstractDesktop.render.d.ts +11 -0
  37. package/lib/renderers/abstractDesktop.render.js +47 -0
  38. package/lib/renderers/abstractDesktop.render.js.map +1 -0
  39. package/lib/renderers/abstractMobile.render.d.ts +12 -0
  40. package/lib/renderers/abstractMobile.render.js +45 -0
  41. package/lib/renderers/abstractMobile.render.js.map +1 -0
  42. package/lib/renderers/renderer.builder.d.ts +6 -0
  43. package/lib/renderers/renderer.builder.js +95 -0
  44. package/lib/renderers/renderer.builder.js.map +1 -0
  45. package/lib/renderers/rest-api.renderer.d.ts +7 -0
  46. package/lib/renderers/rest-api.renderer.js +58 -0
  47. package/lib/renderers/rest-api.renderer.js.map +1 -0
  48. package/lib/renderers/visual-editor.renderer.d.ts +7 -0
  49. package/lib/renderers/visual-editor.renderer.js +71 -0
  50. package/lib/renderers/visual-editor.renderer.js.map +1 -0
  51. package/lib/renderers/wikimedia-desktop.renderer.d.ts +4 -0
  52. package/lib/renderers/wikimedia-desktop.renderer.js +7 -0
  53. package/lib/renderers/wikimedia-desktop.renderer.js.map +1 -0
  54. package/lib/renderers/wikimedia-mobile.renderer.d.ts +18 -0
  55. package/lib/renderers/wikimedia-mobile.renderer.js +223 -0
  56. package/lib/renderers/wikimedia-mobile.renderer.js.map +1 -0
  57. package/lib/sanitize-argument.d.ts +7 -0
  58. package/lib/sanitize-argument.js +69 -5
  59. package/lib/sanitize-argument.js.map +1 -1
  60. package/lib/util/builders/url/api.director.d.ts +14 -0
  61. package/lib/util/builders/url/api.director.js +53 -0
  62. package/lib/util/builders/url/api.director.js.map +1 -0
  63. package/lib/util/builders/url/base.director.d.ts +13 -0
  64. package/lib/util/builders/url/base.director.js +45 -0
  65. package/lib/util/builders/url/base.director.js.map +1 -0
  66. package/lib/util/builders/url/basic.director.d.ts +13 -0
  67. package/lib/util/builders/url/basic.director.js +22 -0
  68. package/lib/util/builders/url/basic.director.js.map +1 -0
  69. package/lib/util/builders/url/desktop.director.d.ts +8 -0
  70. package/lib/util/builders/url/desktop.director.js +14 -0
  71. package/lib/util/builders/url/desktop.director.js.map +1 -0
  72. package/lib/util/builders/url/mobile.director.d.ts +8 -0
  73. package/lib/util/builders/url/mobile.director.js +14 -0
  74. package/lib/util/builders/url/mobile.director.js.map +1 -0
  75. package/lib/util/builders/url/rest-api.director.d.ts +8 -0
  76. package/lib/util/builders/url/rest-api.director.js +17 -0
  77. package/lib/util/builders/url/rest-api.director.js.map +1 -0
  78. package/lib/util/builders/url/url.builder.d.ts +39 -0
  79. package/lib/util/builders/url/url.builder.js +68 -0
  80. package/lib/util/builders/url/url.builder.js.map +1 -0
  81. package/lib/util/builders/url/visual-editor.director.d.ts +9 -0
  82. package/lib/util/builders/url/visual-editor.director.js +17 -0
  83. package/lib/util/builders/url/visual-editor.director.js.map +1 -0
  84. package/lib/util/builders/url/web.director.d.ts +8 -0
  85. package/lib/util/builders/url/web.director.js +17 -0
  86. package/lib/util/builders/url/web.director.js.map +1 -0
  87. package/lib/util/categories.d.ts +3 -3
  88. package/lib/util/categories.js +11 -10
  89. package/lib/util/categories.js.map +1 -1
  90. package/lib/util/const.d.ts +6 -1
  91. package/lib/util/const.js +10 -1
  92. package/lib/util/const.js.map +1 -1
  93. package/lib/util/dump.d.ts +2 -3
  94. package/lib/util/dump.js +49 -21
  95. package/lib/util/dump.js.map +1 -1
  96. package/lib/util/index.d.ts +1 -1
  97. package/lib/util/index.js +1 -1
  98. package/lib/util/index.js.map +1 -1
  99. package/lib/util/metaData.d.ts +1 -0
  100. package/lib/util/metaData.js +69 -0
  101. package/lib/util/metaData.js.map +1 -0
  102. package/lib/util/misc.d.ts +22 -1
  103. package/lib/util/misc.js +112 -35
  104. package/lib/util/misc.js.map +1 -1
  105. package/lib/util/mw-api.d.ts +13 -2
  106. package/lib/util/mw-api.js +57 -5
  107. package/lib/util/mw-api.js.map +1 -1
  108. package/lib/util/rewriteUrls.d.ts +2 -3
  109. package/lib/util/rewriteUrls.js +18 -17
  110. package/lib/util/rewriteUrls.js.map +1 -1
  111. package/lib/util/saveArticles.d.ts +2 -13
  112. package/lib/util/saveArticles.js +74 -612
  113. package/lib/util/saveArticles.js.map +1 -1
  114. package/lib/util/url.helper.d.ts +7 -0
  115. package/lib/util/url.helper.js +30 -0
  116. package/lib/util/url.helper.js.map +1 -0
  117. package/package.json +25 -22
  118. package/res/templates/pageWikimediaDesktop.html +24 -0
  119. package/res/templates/pageWikimediaMobile.html +24 -0
  120. package/res/wm_mobile_override_script.js +15 -0
  121. package/res/wm_mobile_override_style.css +20 -0
  122. package/translation/ar.json +11 -0
  123. package/translation/bn.json +9 -0
  124. package/translation/br.json +8 -0
  125. package/translation/dag.json +9 -0
  126. package/translation/de.json +11 -0
  127. package/translation/es.json +6 -4
  128. package/translation/fi.json +9 -0
  129. package/translation/fr.json +8 -4
  130. package/translation/ha.json +11 -0
  131. package/translation/he.json +11 -0
  132. package/translation/hi.json +10 -0
  133. package/translation/ia.json +10 -0
  134. package/translation/id.json +10 -0
  135. package/translation/ig.json +11 -0
  136. package/translation/it.json +10 -0
  137. package/translation/kaa.json +10 -0
  138. package/translation/ko.json +10 -0
  139. package/translation/lb.json +8 -0
  140. package/translation/mk.json +10 -0
  141. package/translation/nb.json +10 -0
  142. package/translation/nl.json +10 -0
  143. package/translation/nqo.json +8 -0
  144. package/translation/or.json +10 -0
  145. package/translation/pt-br.json +11 -0
  146. package/translation/pt.json +10 -0
  147. package/translation/qqq.json +9 -4
  148. package/translation/ru.json +6 -4
  149. package/translation/sc.json +10 -0
  150. package/translation/scn.json +8 -0
  151. package/translation/sl.json +10 -0
  152. package/translation/sq.json +10 -0
  153. package/translation/sv.json +10 -0
  154. package/translation/sw.json +10 -0
  155. package/translation/te.json +10 -0
  156. package/translation/tn.json +10 -0
  157. package/translation/tr.json +10 -0
  158. package/translation/zh-hans.json +10 -0
  159. package/translation/zh-hant.json +10 -0
  160. package/lib/util/articleRenderers.d.ts +0 -4
  161. package/lib/util/articleRenderers.js +0 -182
  162. package/lib/util/articleRenderers.js.map +0 -1
  163. package/lib/util/redirects.d.ts +0 -3
  164. package/lib/util/redirects.js +0 -16
  165. package/lib/util/redirects.js.map +0 -1
  166. package/res/templates/page.html +0 -31
package/README.md CHANGED
@@ -1,25 +1,30 @@
1
1
  # MWoffliner
2
2
 
3
3
  MWoffliner is a tool for making a local offline HTML snapshot of any
4
- online [Mediawiki](https://mediawiki.org) instance. It goes through
4
+ online [MediaWiki](https://mediawiki.org) instance. It goes through
5
5
  all online articles (or a selection if specified) and create the
6
6
  corresponding [ZIM](https://openzim.org) file. It has mainly been
7
7
  tested against Wikimedia projects like
8
- [Wikipedia](https://wikipedia.org),
9
- [Wiktionary](https://wiktionary.org), ... But it should also work for
10
- any recent Mediawiki.
8
+ [Wikipedia](https://wikipedia.org) and
9
+ [Wiktionary](https://wiktionary.org) --- but it should also work for
10
+ any recent MediaWiki.
11
11
 
12
12
  Read [CONTRIBUTING.md](./CONTRIBUTING.md) to know more about
13
13
  MWoffliner development.
14
14
 
15
+ User Help is available in the for a a
16
+ [FAQ](https://github.com/openzim/mwoffliner/wiki/Frequently-Asked-Questions).
17
+
15
18
  [![NPM](https://nodei.co/npm/mwoffliner.png)](https://www.npmjs.com/package/mwoffliner)
16
19
 
17
20
  [![npm](https://img.shields.io/npm/v/mwoffliner.svg)](https://www.npmjs.com/package/mwoffliner)
18
- [![Docker Image](https://img.shields.io/docker/v/openzim/mwoffliner?arch=amd64&label=docker&sort=semver)](https://hub.docker.com/r/openzim/mwoffliner)
21
+ [![node](https://img.shields.io/node/v/mwoffliner.svg)](https://www.npmjs.com/package/mwoffliner)
22
+ [![Docker](https://ghcr-badge.egpl.dev/openzim/mwoffliner/latest_tag?label=container)](https://ghcr.io/openzim/mwoffliner)
19
23
  [![Build Status](https://github.com/openzim/mwoffliner/workflows/CI/badge.svg?query=branch%3Amain)](https://github.com/openzim/mwoffliner/actions/workflows/ci.yml?query=branch%3Amain)
20
24
  [![codecov](https://codecov.io/gh/openzim/mwoffliner/branch/main/graph/badge.svg)](https://codecov.io/gh/openzim/mwoffliner)
21
25
  [![CodeFactor](https://www.codefactor.io/repository/github/openzim/mwoffliner/badge)](https://www.codefactor.io/repository/github/openzim/mwoffliner)
22
26
  [![License](https://img.shields.io/npm/l/mwoffliner.svg)](LICENSE)
27
+ [![Join Slack](https://img.shields.io/badge/Join%20us%20on%20Slack%20%23mwoffliner-2EB67D)](https://slack.kiwix.org)
23
28
 
24
29
  ## Features
25
30
 
@@ -42,7 +47,7 @@ Run `mwoffliner --help` to get all the possible options.
42
47
  machine (packages `libjpeg-dev`, `libglu1`, `autoconf`, `automake`, `gcc` on
43
48
  Debian/Ubuntu)
44
49
 
45
- ... and an online Mediawiki with its API available.
50
+ ... and an online MediaWiki with its API available.
46
51
 
47
52
  ## Usage
48
53
 
@@ -55,7 +60,7 @@ You might need to run this command with the `sudo` command, depending
55
60
  how your `npm` is configured.
56
61
 
57
62
  `npm` permission checking can be a bit annoying for a
58
- newcommer. Please read the documentation carefully if you hit
63
+ newcomer. Please read the documentation carefully if you hit
59
64
  problems: https://docs.npmjs.com/cli/v7/using-npm/scripts#user
60
65
 
61
66
  Then to run it:
@@ -63,6 +68,12 @@ Then to run it:
63
68
  mwoffliner --help
64
69
  ```
65
70
 
71
+ To install and run it locally:
72
+ ```bash
73
+ npm i
74
+ npm run mwoffliner -- --help
75
+ ```
76
+
66
77
  To use MWoffliner with a S3 cache, you should provide a S3 URL like
67
78
  this:
68
79
  ```bash
@@ -72,9 +83,10 @@ this:
72
83
  ## API
73
84
 
74
85
  MWoffliner provides also an API and therefore can be used as a NodeJS
75
- library. Here a stub example:
86
+ library. Here a stub example that could go in your index.mjs file:
76
87
  ```javascript
77
- const mwoffliner = require('mwoffliner');
88
+ import * as mwoffliner from 'mwoffliner';
89
+
78
90
  const parameters = {
79
91
  mwUrl: "https://es.wikipedia.org",
80
92
  adminEmail: "foo@bar.net",
@@ -3,9 +3,7 @@ import type { BackoffStrategy } from 'backoff';
3
3
  import { AxiosRequestConfig } from 'axios';
4
4
  import S3 from './S3.js';
5
5
  import { Dump } from './Dump.js';
6
- import MediaWiki from './MediaWiki.js';
7
6
  interface DownloaderOpts {
8
- mw: MediaWiki;
9
7
  uaString: string;
10
8
  speed: number;
11
9
  reqTimeout: number;
@@ -13,6 +11,8 @@ interface DownloaderOpts {
13
11
  s3?: S3;
14
12
  webp: boolean;
15
13
  backoffOptions?: BackoffOptions;
14
+ mwWikiPath?: string;
15
+ insecure?: boolean;
16
16
  }
17
17
  interface BackoffOptions {
18
18
  strategy: BackoffStrategy;
@@ -20,55 +20,50 @@ interface BackoffOptions {
20
20
  retryIf: (error?: any) => boolean;
21
21
  backoffHandler: (number: number, delay: number, error?: any) => void;
22
22
  }
23
- export interface MWCapabilities {
24
- apiAvailable: boolean;
25
- veApiAvailable: boolean;
26
- coordinatesAvailable: boolean;
27
- desktopRestApiAvailable: boolean;
28
- mobileRestApiAvailable: boolean;
29
- }
23
+ export declare const defaultStreamRequestOptions: AxiosRequestConfig;
24
+ /**
25
+ * Downloader is a class providing content retrieval functionalities for both Mediawiki and S3 remote instances.
26
+ */
30
27
  declare class Downloader {
31
- readonly mw: MediaWiki;
32
28
  loginCookie: string;
33
29
  readonly speed: number;
34
- baseUrl: string;
35
- baseUrlForMainPage: string;
36
30
  cssDependenceUrls: KVS<boolean>;
37
31
  readonly webp: boolean;
38
32
  readonly requestTimeout: number;
33
+ arrayBufferRequestOptions: AxiosRequestConfig;
34
+ jsonRequestOptions: AxiosRequestConfig;
35
+ streamRequestOptions: AxiosRequestConfig;
36
+ wikimediaMobileJsDependenciesList: string[];
37
+ wikimediaMobileStyleDependenciesList: string[];
39
38
  private readonly uaString;
40
39
  private activeRequests;
41
40
  private maxActiveRequests;
42
- private readonly urlPartCache;
43
41
  private readonly backoffOptions;
44
42
  private readonly optimisationCacheUrl;
45
43
  private s3;
46
- private mwCapabilities;
47
- arrayBufferRequestOptions: AxiosRequestConfig;
48
- jsonRequestOptions: AxiosRequestConfig;
49
- streamRequestOptions: AxiosRequestConfig;
50
- constructor({ mw, uaString, speed, reqTimeout, optimisationCacheUrl, s3, webp, backoffOptions }: DownloaderOpts);
51
- serializeUrl(url: string): string;
52
- deserializeUrl(url: string): string;
53
- setBaseUrls(): Promise<void>;
54
- checkApiAvailabilty(url: string): Promise<boolean>;
55
- checkCapabilities(testArticleId?: string): Promise<void>;
44
+ private apiUrlDirector;
45
+ private articleUrlDirector;
46
+ private mainPageUrlDirector;
47
+ private readonly insecure;
48
+ constructor({ uaString, speed, reqTimeout, optimisationCacheUrl, s3, webp, backoffOptions, insecure }: DownloaderOpts);
49
+ private getUrlDirector;
50
+ setUrlsDirectors(mainPageRenderer: any, articlesRenderer: any): void;
51
+ getArticleUrl(articleId: string): string;
52
+ getMainPageUrl(articleId: string): string;
56
53
  removeEtagWeakPrefix(etag: string): string;
57
- query(query: string): KVS<any>;
54
+ query(): KVS<any>;
58
55
  getArticleDetailsIds(articleIds: string[], shouldGetThumbnail?: boolean): Promise<QueryMwRet>;
59
56
  getArticleDetailsNS(ns: number, gapcontinue?: string): Promise<{
60
57
  gapContinue: string;
61
58
  articleDetails: QueryMwRet;
62
59
  }>;
63
- getArticle(articleId: string, dump: Dump, articleDetailXId: RKVS<ArticleDetail>, articleDetail?: ArticleDetail): Promise<RenderedArticle[]>;
60
+ getArticle(webp: boolean, _moduleDependencies: any, articleId: string, articleDetailXId: RKVS<ArticleDetail>, articleRenderer: any, articleUrl: any, dump: Dump, articleDetail?: ArticleDetail, isMainPage?: boolean): Promise<any>;
64
61
  getJSON<T>(_url: string): Promise<T>;
65
62
  downloadContent(_url: string, retry?: boolean): Promise<{
66
63
  content: Buffer | string;
67
64
  responseHeaders: any;
68
65
  }>;
69
66
  canGetUrl(url: string): Promise<boolean>;
70
- private getArticleUrl;
71
- private stripNonContinuedProps;
72
67
  private static handleMWWarningsAndErrors;
73
68
  private getArticleQueryOpts;
74
69
  private setArticleSubCategories;
@@ -81,5 +76,11 @@ declare class Downloader {
81
76
  private errHandler;
82
77
  private getSubCategories;
83
78
  private backoffCall;
79
+ getModuleDependencies(title: string): Promise<{
80
+ jsConfigVars: string;
81
+ jsDependenciesList: string[];
82
+ styleDependenciesList: string[];
83
+ }>;
84
+ private streamToBuffer;
84
85
  }
85
86
  export default Downloader;