Skip to content

Instantly share code, notes, and snippets.

@siddharthvp
siddharthvp / webpack.config.js
Created December 30, 2021 09:26
Webpack configuration to transpile banana-i18n to ES5
// Webpack configuration to transpile banana-i18n to ES5. Run:
// $ npm i -D webpack webpack-cli @babel/core @babel/preset-env babel-loader
// $ npx webpack
// Find output in dist/banana-i18n.js
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
mode: 'production',
@siddharthvp
siddharthvp / webpack.config.js
Last active December 30, 2021 08:27
Webpack config for transpiling orange-i18n or banana-i18n to ES5
// Webpack configuration to transpile ES module library to MW environment
// Run:
// $ npm i -D webpack webpack-cli @babel/core @babel/preset-env babel-loader
// $ npx webpack
// Find output in dist/banana-i18n.js
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
@siddharthvp
siddharthvp / server.js
Last active December 6, 2021 14:40
Dev-server for AFCH without HTTPS
/* eslint-env node, es2021 */
/* eslint-disable */
// Serves the script from localhost for development purposes.
const http = require('http');
const fs = require('fs/promises');
const argv = require('minimist')(process.argv);
async function readFile(path) {
@siddharthvp
siddharthvp / Dockerfile
Created October 15, 2021 18:02
MW dev env on macOS
FROM mediawiki
WORKDIR /var/www
RUN rm -rf html
WORKDIR /var/www/html
/* eslint-env es6 */
class ApiManager {
constructor(config = {}) {
this.userAgent = config.userAgent ?? 'New-Morebits.js';
this.defaultParams = $.extend({
action: 'query',
format: 'json',
formatversion: '2',
assert: 'user',
class TwinkleModule {
attachMenu() {
Twinkle.addPortletLink(this.makeWindow, this.portletName, this.portletId, this.portletTooltip)
}
}
// Init: Twinkle.addInitCallback(function() { new Twinkle(); }, 'Tag');
class Tag extends TwinkleModule {
// Override to change modes available,
// each mode is a class extending TagMode
// How to run: copy paste to console in a tab with WP open
Morebits.taskManager = function () {
this.taskDependencyMap = new Map();
this.deferreds = new Map();
this.allDeferreds = []; // Hack: IE doesn't support Map.prototype.values
/**
* Register a task along with its dependencies (tasks which should have finished
* execution before we can begin this one). Each task is a function that must return
@siddharthvp
siddharthvp / morebits-date.js
Created December 16, 2019 17:07
Date class for Morebits
/*************** Morebits.date ********************/
/**
* @constructor
* Create a date object. MediaWiki timestamp format is also acceptable,
* in addition to everything that JS Date() accepts.
*/
Morebits.date = function() {
var args = Array.prototype.slice.call(arguments);
// Declare fallbacks
Date.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
Date.monthNamesAbbrev = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
$.ajax({
url: mw.util.wikiScript('api'),
data: $.param({ action: 'query', format: 'json', utf8: 'y', meta: 'allmessages',
ammessages: 'january|february|march|april|may|june|july|august|september|october|november|december' +
'|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec',
amlang: mw.config.get('wgContentLanguage')