config.ts•1.7 kB
import * as fs from 'fs';
export interface WikiConfig {
/**
* Corresponds to the $wgSitename setting in MediaWiki.
*/
sitename: string;
/**
* Corresponds to the $wgServer setting in MediaWiki.
*/
server: string;
/**
* Corresponds to the $wgArticlePath setting in MediaWiki.
*/
articlepath: string;
/**
* Corresponds to the $wgScriptPath setting in MediaWiki.
*/
scriptpath: string;
/**
* OAuth consumer token requested from Extension:OAuth.
*/
token?: string | null;
/**
* Username requested from Special:BotPasswords.
*/
username?: string | null;
/**
* Password requested from Special:BotPasswords.
*/
password?: string | null;
/**
* If the wiki always requires auth to access.
* $wgGroupPermissions['*']['read'] = false; in MediaWiki
*/
private?: boolean;
}
export type PublicWikiConfig = Omit<WikiConfig, 'token' | 'username' | 'password'>;
export interface Config {
wikis: { [key: string]: WikiConfig };
defaultWiki: string;
}
export const defaultConfig: Config = {
defaultWiki: 'en.wikipedia.org',
wikis: {
'en.wikipedia.org': {
sitename: 'Wikipedia',
server: 'https://en.wikipedia.org',
articlepath: '/wiki',
scriptpath: '/w',
token: null,
private: false
},
'localhost:8080': {
sitename: 'Local MediaWiki Docker',
server: 'http://localhost:8080',
articlepath: '/wiki',
scriptpath: '/w',
token: null,
private: false
}
}
};
const configPath = process.env.CONFIG || 'config.json';
export function loadConfigFromFile(): Config {
if ( !fs.existsSync( configPath ) ) {
return defaultConfig;
}
const rawData = fs.readFileSync( configPath, 'utf-8' );
return JSON.parse( rawData ) as Config;
}