Tyler Cipriani: pages tagged wikimedia
Tyler Cipriani
https://tylercipriani.com/tags/wikimedia/
Tyler Cipriani
ikiwiki
2019-12-10T19:31:02Z
Maintaining MediaWiki User Scripts via Git
https://tylercipriani.com/blog/2019/11/14/maintaining-wiki-userscripts-via-git/
Tyler Cipriani
Copyright © 2019 Tyler Cipriani
2019-12-10T19:31:02Z
2019-11-14T01:25:48Z
<p>This week I’m at the <a href="https://www.mediawiki.org/wiki/Wikimedia_Technical_Conference/2019">Wikimedia Technical Conference</a> 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.</p>
<p><a href="https://en.wikipedia.org/wiki/WP:US">MediaWiki user scripts</a> are powerful user-customizations, written in JavaScript, that themselves exists as pages <em>on</em> the wiki and are used to modify a user’s view of MediaWiki page. There are many <a href="https://en.wikipedia.org/wiki/WP:USL">available user scripts</a>, and you can also write your own directly in your <a href="https://en.wikipedia.org/wiki/Special:MyPage/common.js">common.js user page</a> (or in any lowercase user page).</p>
<p>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.</p>
<p>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.</p>
<p>One of the projects I spend a lot of time digging in is <a href="https://github.com/git/git">git</a>; particularly in the <code>contrib</code> 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 <a href="https://github.com/git/git/blob/master/contrib/mw-to-git/git-remote-mediawiki.txt"><code>mw-to-git</code></a> 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.</p>
<section id="setup-and-usage" class="level2">
<h2>Setup and usage <a href="https://tylercipriani.com/tags/wikimedia/#setup-and-usage">¶</a></h2>
<p>After you’ve installed <code>git-mediawiki</code> and have that in your path and the perl module installed, the process is not too involved.</p>
<p>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 <code>common.js</code> file:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-1" aria-hidden="true"></a>$ <span class="fu">git</span> init</span>
<span id="cb1-2"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-2" aria-hidden="true"></a><span class="ex">Initialized</span> empty Git repository in /home/thcipriani/Projects/User:Thcipriani/.git/</span>
<span id="cb1-3"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-3" aria-hidden="true"></a>$ <span class="fu">git</span> remote add origin mediawiki::https://en.wikipedia.org/w</span>
<span id="cb1-4"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-4" aria-hidden="true"></a>$ <span class="fu">git</span> config remote.origin.pages <span class="st">'User:Thcipriani/common.js'</span></span>
<span id="cb1-5"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-5" aria-hidden="true"></a>$ <span class="fu">git</span> pull</span>
<span id="cb1-6"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-6" aria-hidden="true"></a><span class="ex">Searching</span> revisions...</span>
<span id="cb1-7"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-7" aria-hidden="true"></a><span class="ex">No</span> previous mediawiki revision found, fetching from beginning.</span>
<span id="cb1-8"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-8" aria-hidden="true"></a><span class="ex">Fetching</span> <span class="kw">&</span> <span class="ex">writing</span> export data by pages...</span>
<span id="cb1-9"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-9" aria-hidden="true"></a><span class="ex">Listing</span> pages on remote wiki...</span>
<span id="cb1-10"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-10" aria-hidden="true"></a><span class="ex">1</span> pages found.</span>
<span id="cb1-11"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-11" aria-hidden="true"></a><span class="ex">page</span> 1/1: User:Thcipriani/common.js</span>
<span id="cb1-12"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-12" aria-hidden="true"></a> <span class="ex">Found</span> 2 revision(s)<span class="ex">.</span></span>
<span id="cb1-13"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-13" aria-hidden="true"></a><span class="ex">Namespace</span> User not found in cache, querying the wiki ...</span>
<span id="cb1-14"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-14" aria-hidden="true"></a><span class="ex">1</span>/2: <span class="ex">Revision</span> #926066306 of User:Thcipriani%2Fcommon.js</span>
<span id="cb1-15"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-15" aria-hidden="true"></a><span class="ex">2</span>/2: <span class="ex">Revision</span> #926066361 of User:Thcipriani%2Fcommon.js</span>
<span id="cb1-16"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-16" aria-hidden="true"></a><span class="ex">Searching</span> revisions...</span>
<span id="cb1-17"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-17" aria-hidden="true"></a><span class="ex">No</span> previous mediawiki revision found, fetching from beginning.</span>
<span id="cb1-18"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-18" aria-hidden="true"></a><span class="ex">Fetching</span> <span class="kw">&</span> <span class="ex">writing</span> export data by pages...</span>
<span id="cb1-19"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-19" aria-hidden="true"></a><span class="ex">Listing</span> pages on remote wiki...</span>
<span id="cb1-20"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-20" aria-hidden="true"></a><span class="ex">1</span> pages found.</span>
<span id="cb1-21"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-21" aria-hidden="true"></a><span class="ex">page</span> 1/1: User:Thcipriani/common.js</span>
<span id="cb1-22"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-22" aria-hidden="true"></a> <span class="ex">Found</span> 2 revision(s)<span class="ex">.</span></span>
<span id="cb1-23"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-23" aria-hidden="true"></a><span class="ex">1</span>/2: <span class="ex">Revision</span> #926066306 of User:Thcipriani%2Fcommon.js</span>
<span id="cb1-24"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-24" aria-hidden="true"></a><span class="ex">2</span>/2: <span class="ex">Revision</span> #926066361 of User:Thcipriani%2Fcommon.js</span>
<span id="cb1-25"><a href="https://tylercipriani.com/tags/wikimedia/#cb1-25" aria-hidden="true"></a>$ <span class="fu">git</span> checkout master</span></code></pre></div>
<p>Now I have a file in that directory, <code>User:Thcipriani%2Fcommon.js.mw</code>, that contains the contents of my <code>common.js</code> page. From here I can make slight modifications to the page and push it backup via the same git remote.</p>
<pre><code>$ 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</code></pre>
<p>I also added a <a href="https://github.com/thcipriani/common.js">github remote</a> 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.</p>
<p>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.</p>
<blockquote style="background: rgba(255, 0, 0, 0.1); border: 1px solid tomato; text-align: center;">
<h3>BIG GIANT DISCLAIMER OF DOOM</h3>
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.
</blockquote>
</section>