diff --git a/media/.gitignore b/media/.gitignore index 5e7d273..d171260 100644 --- a/media/.gitignore +++ b/media/.gitignore @@ -2,3 +2,4 @@ * # Except this file !.gitignore +!map.png diff --git a/media/map.png b/media/map.png new file mode 100644 index 0000000..7831cd7 Binary files /dev/null and b/media/map.png differ diff --git a/src/routes.js b/src/routes.js index aed9e1b..a7cad25 100644 --- a/src/routes.js +++ b/src/routes.js @@ -30,7 +30,14 @@ module.exports = (app, utils) => { } if(req.url.startsWith('/media')) { - let media = await proxyMedia(req) + let media + + if(req.url.startsWith('/media/maps_wikimedia_org/')) { + media = await proxyMedia(req, 'maps.wikimedia.org') + } else { + media = await proxyMedia(req) + } + if(media.success === true) { return res.sendFile(media.path) } else { @@ -53,6 +60,10 @@ module.exports = (app, utils) => { return handleWikiPage(req, res, '/w/') }) + app.get('/wiki/Special:Map/*', (req, res, next) => { + return handleWikiPage(req, res, '/wiki/Map') + }) + app.get('/', (req, res, next) => { return handleWikiPage(req, res, '/') }) diff --git a/src/utils.js b/src/utils.js index 25cd1b1..5033058 100644 --- a/src/utils.js +++ b/src/utils.js @@ -140,6 +140,10 @@ module.exports = function(redis) { const upload_wikimedia_regx = /((https:|http:|)\/\/?upload.wikimedia.org)/gm data.html = data.html.replace(upload_wikimedia_regx, '/media') + // replace maps.wikimedia.org with /media + const maps_wikimedia_regx = /((https:|http:|)\/\/?maps.wikimedia.org)/gm + data.html = data.html.replace(maps_wikimedia_regx, '/media/maps_wikimedia_org') + // replace wiki links const wiki_href_regx = /(href=\"(https:|http:|)\/\/([A-z.]+\.)?(wikipedia.org|wikimedia.org|wikidata.org|mediawiki.org))/gm data.html = data.html.replace(wiki_href_regx, `href="${protocol}${config.domain}`) @@ -159,7 +163,7 @@ module.exports = function(redis) { }) } - this.proxyMedia = (req) => { + this.proxyMedia = (req, wiki_domain='') => { return new Promise(async resolve => { let params = new URLSearchParams(req.query).toString() || '' @@ -167,9 +171,20 @@ module.exports = function(redis) { params = '?' + params } - let path = req.url.split('/media')[1] - let wikimedia_path = path + params - let url = new URL(`https://upload.wikimedia.org${wikimedia_path}`) + let path = '' + let domain = 'upload.wikimedia.org' + let wikimedia_path = '' + + if(wiki_domain === 'maps.wikimedia.org') { + path = req.url.split('/media/maps_wikimedia_org')[1] + domain = 'maps.wikimedia.org' + wikimedia_path = path + } else { + path = req.url.split('/media')[1] + wikimedia_path = path + params + } + + url = new URL(`https://${domain}${wikimedia_path}`) let file = await saveFile(url, path) @@ -183,7 +198,13 @@ module.exports = function(redis) { this.saveFile = (url, file_path) => { return new Promise(async resolve => { - const media_path = path.join(__dirname, '../media') + let media_path = '' + if(url.href.startsWith('https://maps.wikimedia.org/')) { + media_path = path.join(__dirname, '../media/maps_wikimedia_org') + } else { + media_path = path.join(__dirname, '../media') + } + const path_with_filename = `${media_path}${file_path}` let path_without_filename = path_with_filename.split('/') path_without_filename.pop() @@ -202,7 +223,7 @@ module.exports = function(redis) { resolve({ success: true, path: path_with_filename }) }) }).on('error', (err) => { - console.log('Error while fetching data...', err) + console.log('Error while fetching data. Details:', err) resolve({ success: false, reason: 'SERVER_ERROR' }) }) } @@ -252,6 +273,12 @@ module.exports = function(redis) { url = `https://${lang}.wikipedia.org/w/${file}` } + if(prefix === '/wiki/Map') { + let page = 'Special:Map' + let sub_page = req.params['0'] || '' + url = `https://${lang}.wikipedia.org/wiki/${page}/${sub_page}` + } + if(prefix === '/') { url = `https://${lang}.wikipedia.org/?lang=${lang}` } @@ -345,9 +372,9 @@ module.exports = function(redis) { this.preferencesPage = (req, res) => { let user_preferences = req.cookies - let lang_select = '' let html = ` @@ -364,7 +392,7 @@ module.exports = function(redis) { - preferences - wikiless + Preferences - Wikiless
diff --git a/static/styles.css b/static/styles.css index 39e66bd..bdf33f0 100644 --- a/static/styles.css +++ b/static/styles.css @@ -74,6 +74,11 @@ details[open] #preferences { } /* END PREFERENCES CSS */ +/* WIKILESS OVERRIDES */ +#mw-specialMap-map { + background-image: url(/media/map.png) !important; +} +/* END WIKILESS OVERRIDES */ /* START WIKIPEDIA CSS */ #p-lang .uls-settings-trigger { @@ -8692,4 +8697,64 @@ div.after-portlet-lang:after { display:block } + +#mw-specialMap-container { + position:relative +} +#mw-specialMap-container .thumbinner { + display:inline-block; + position:relative; + width:256px +} +#mw-specialMap-inner { + height:256px; + position:relative +} +#mw-specialMap-map { + position:absolute; + width:256px; + height:256px; + background-position:center; + background-repeat:no-repeat; + background-size:256px 256px +} + +#mw-specialMap-marker { + position:absolute; + background-color:#7b4e10; + height:10px; + width:10px; + margin-top:-5px; + margin-left:-5px; + border-radius:5px +} +#mw-specialMap-caption { + display:block; + padding-top:0.5em +} +#mw-specialMap-icon { + display:inline-block; + margin:0 12px 0 0; + background-color:#7b4e10; + height:10px; + width:10px; + margin-top:-5px; + margin-left:0.5em; + border-radius:5px +} +#mw-specialMap-attributions { + position:absolute; + bottom:0; + font-size:9px; + right:0; + text-align:right +} + +#p-lang .uls-settings-trigger::-moz-focus-inner { + border:0 +} +#p-lang .uls-settings-trigger:focus { + outline:1px solid #36c +} + /* END WIKIPEDIA CSS */