Managing MediaWiki Pages with Git
Why version‑control a wiki?
MediaWiki stores its content in a database, which makes bulk edits, history inspection and offline work cumbersome. By mirroring a wiki with git‑remote‑mediawiki you get a full Git repository of every page, can edit with any editor, and push changes back to the live site.
Prerequisites
- Git (≥ 1.8.3) installed.
- Perl modules
MediaWiki::APIandDateTime::Format::ISO8601(plusLWP::Protocol::httpsfor HTTPS).
On Debian‑based systems these are provided by libmediawiki-api-perl, libdatetime-format-iso8601-perl and perl-lwp-protocol-https. On macOS use cpan and on Gentoo emerge dev-perl/MediaWiki-API dev-perl/DateTime-Format-ISO8601.
Installing git‑remote‑mediawiki
# Clone the Git source (or download the contrib directory)
git clone https://github.com/git/git.git
cd git/contrib/mw-to-git
# Build and install the helper scripts
make install
# Ensure the executable is on Git's exec path
sudo cp git-remote-mediawiki $(git --exec-path)/git-remote-mediawiki
chmod +x $(git --exec-path)/git-remote-mediawiki
# Add Perl libraries to PERL5LIB
export PERL5LIB=$PWD/perl:$PWD
Cloning a wiki
Once the helper is installed, clone any MediaWiki instance with a mediawiki:: URL.
git clone mediawiki::https://example.org/w/ my-wiki
cd my-wiki
The repository now contains one file per page (including the main namespace by default). Use normal Git commands to edit, commit and push.
Typical workflow
# edit locally with your favourite editor
git commit -am "Fix typo in Home page"
# incorporate any changes made on the server
git pull --rebase
# send your edits back to the wiki
git push
Running git pull --rebase after each push keeps the local history aligned with the remote MediaWiki revisions.
Partial or shallow imports
If you only need a subset of pages, limit the clone:
git clone -c remote.origin.pages='Main_Page Help:Contents' \
mediawiki::https://example.org/w/ partial-wiki
To fetch only the latest revision of each page (useful for large wikis), enable a shallow import:
git -c remote.origin.shallow=true clone \
mediawiki::https://example.org/w/ shallow-wiki
Authentication
For wikis that require a login, store credentials in the repo config (the file is kept private).
git init auth-wiki
chmod 600 .git/config
git remote add origin mediawiki::https://example.org/w/
git config remote.origin.mwLogin 'UserName'
git config remote.origin.mwPassword 'Secret'
git pull # now you can push as well
Push behaviour
By default a push updates MediaWiki metadata so future pulls know which revisions originated from your repository. If you prefer a dumb push that leaves the server untouched, set:
git config remote.origin.dumbPush true
Then run git push followed by git pull --rebase to re‑import any missing revisions.
Handling uploads
To synchronize uploaded files (images, PDFs, …) enable the two options below:
git config --bool remote.origin.mediaimport true
git config --bool remote.origin.mediaexport true
After a pull, the images/ directory will contain the wiki’s uploads; after a push, new files added locally are uploaded to the wiki.
Fetch strategies
The default strategy (by_page) queries each page for changes – fast when only a few pages are tracked. For a mostly static wiki with many pages, switch to revision‑based fetching:
git config remote.origin.fetchStrategy by_rev
This makes git pull run in constant time regardless of page count.
SSL certificates
If the wiki uses a self‑signed certificate, either disable verification for a single command:
PERL_LWP_SSL_VERIFY_HOSTNAME=0 git pull
or trust the certificate explicitly:
openssl s_client -showcerts -connect wiki.example.com:443 Save the output to certs.pem and run:
HTTPS_CA_FILE=certs.pem git pull
Summary
Git‑remote‑mediawiki turns a MediaWiki installation into a regular Git repository. After a one‑time setup you can edit pages offline, keep a clean history, cherry‑pick changes, and even version control uploaded media. The workflow mirrors standard Git usage, so any existing tooling (hooks, CI, code review) can be applied to wiki content as well.