This week I’m at the Wikimedia Technical Conference in Atlanta, Georgia. I’ve attended a bunch of great sessions and I’m getting a lot out of my attendance. Today I attended a session about “user scripts” that piqued my interest.

MediaWiki user scripts are powerful user-customizations, written in JavaScript, that themselves exists as pages on the wiki and are used to modify a user’s view of MediaWiki page. There are many available user scripts, and you can also write your own directly in your common.js user page (or in any lowercase user page).

I’m enamoured by all of this. Going into this session, I wasn’t too terribly familiar with gadgets and user scripts – but I learned a ton! The folks in the community know best the kinds of customizations that will improve their lives, and here’s the mechanism by which they’re empowered to make that happen. There are, however, some issues with this approach.

I love wikipages, but I was, long-ago, crippled by Vim and I can’t edit any long-form text outside of Vim and a wikipage is not Vim. Further, code review for user scripts seems, from what I’m told anyway, a bit ad hoc.

One of the projects I spend a lot of time digging in is git; particularly in the contrib folder of the project. There are all sorts of strange and wonderful scripts there. One contrib script that I’ve been aware of for years is mw-to-git which is a perl module that provides a custom MediaWiki remote for git repos. This, to me, seems like a potential solution to this problem.

Setup and usage

After you’ve installed git-mediawiki and have that in your path and the perl module installed, the process is not too involved.

First, you initialize a git repo setting the “pages” variable on the remote to limit it only to the pages you’re interested in. In this instance, I’m interested in my user’s common.js file:

Now I have a file in that directory, User:Thcipriani%2Fcommon.js.mw, that contains the contents of my common.js page. From here I can make slight modifications to the page and push it backup via the same git remote.

$ chmod 600 .git/config  # Since we'll end up with a password in there
$ git config remote.origin.mwUser 'Thcipriani'
$ git config remote.origin.mwPassword 'NotMyPassword1234'
$ git push
Last local mediawiki revision found is 926066361.
Logged in mediawiki user "thcipriani".
Listing pages on remote wiki...
1 pages found.
Getting last revision id on tracked pages...
Last remote revision found is 926066361.
Computing path from local to remote ...
Namespace User:Thcipriani/common.js.mw not found in cache, querying the wiki ...
No such namespace User:Thcipriani/common.js.mw on MediaWiki, known namespaces: Book Book_talk Category Category_talk Draft Draft_talk Education_Progra$
 Education_Program_talk File File_talk Gadget Gadget_definition Gadget_definition_talk Gadget_talk Help Help_talk Media MediaWiki MediaWiki_talk Modul$
 Module_talk Portal Portal_talk Project Project_talk Special Talk Template Template_talk TimedText TimedText_talk User User_talk Wikipedia Wikipedia_t$
lk
Pushed file: 3f1cfc54f8c831f47aff3f05d33e5e12fd9d3df8 - User:Thcipriani/common.js
To mediawiki::https://en.wikipedia.org/w
 * [new branch]      master -> master

I also added a github remote for this repo. I could see, for example (if I had a popular user script) allowing pull-requests via github, code reviewing on github, merging, and pushing back up to Wikipedia post-merge.

There are undoubtedly issues here, but I had this idea kicking around my head and wanted to get it committed to pixels before it slipped out of my mind.

BIG GIANT DISCLAIMER OF DOOM

My views are my own. My views do not represent the views of any employer I've had/have: past, present, or future. I'm probably not even qualified to have these views. I am an egg.