Jump to content

Git-Mediawiki Local Editing 260223

From Game in the Brain Wiki

Git-Mediawiki: Local Editing with Opencode

A guide to using Git-Mediawiki to clone a MediaWiki as a Git repository, enabling offline editing with opencode and syncing changes back to the wiki.

Overview

Git-Mediawiki bridges Git and MediaWiki, allowing you to:

  • Clone a MediaWiki as a Git repository
  • Edit pages locally with any text editor
  • Track changes with Git version control
  • Sync back to the wiki with git push/pull

This enables opencode (which cannot use MediaWiki API/bots) to edit wiki content through local files.

Prerequisites

  • Git 1.8.3+
  • Perl 5 with modules:
    • MediaWiki::API (0.39+)
    • DateTime::Format::ISO8601
    • LWP::Protocol::https (for HTTPS)

Installation

Debian/Ubuntu

sudo apt-get install libmediawiki-api-perl libdatetime-format-iso8601-perl liblwp-protocol-https-perl

Install Git-Mediawiki

cd /path/to/projects
git clone https://github.com/Git-Mediawiki/Git-Mediawiki.git
sudo cp Git-Mediawiki/git-remote-mediawiki /usr/lib/git-core/
sudo cp Git-Mediawiki/git-mw /usr/lib/git-core/
sudo chmod +x /usr/lib/git-core/git-remote-mediawiki /usr/lib/git-core/git-mw

Configure Environment

Add to ~/.bashrc:

export PERL5LIB=/path/to/Git-Mediawiki:$PERL5LIB

Then: source ~/.bashrc

Cloning the Wiki

Basic Clone

git clone mediawiki::https://wiki.gi7b.org/ wiki-gi7b-org

With Authentication

mkdir wiki-gi7b-org && cd wiki-gi7b-org
chmod 600 .git/config
git init
git remote add origin mediawiki::https://wiki.gi7b.org/
git config remote.origin.mwLogin 'YourUsername'
git config remote.origin.mwPassword 'YourPassword'
git pull

Partial Clone

# Specific pages
git clone -c remote.origin.pages='Page_One Page_Two' mediawiki::https://wiki.gi7b.org/

# By category
git clone -c remote.origin.categories='Documentation' mediawiki::https://wiki.gi7b.org/

# Latest revision only (faster)
git clone -c remote.origin.shallow=true mediawiki::https://wiki.gi7b.org/

Daily Workflow

1. Pull Latest Changes

cd wiki-gi7b-org
export PERL5LIB=/path/to/Git-Mediawiki:$PERL5LIB
git pull --rebase

2. Edit Pages

Edit .mw files with opencode or any editor:

opencode Open_Source.mw

3. Review Changes

git status
git diff

4. Commit

git add .
git commit -m "Updated page description"

5. Push to Wiki

git push

6. Rebase

git pull --rebase

Repository Structure

Each .mw file represents a wiki page:

  • File names = wiki titles (spaces become underscores)
  • Format = MediaWiki markup
  • Full history available via git log

Advanced Configuration

Fetch Strategy

# For active wikis with few tracked pages (default)
git config remote.origin.fetchStrategy by_page

# For wikis with many pages but low activity
git config remote.origin.fetchStrategy by_rev

Media Files

git config --bool remote.origin.mediaimport true
git config --bool remote.origin.mediaexport true

Dumb Push Mode

For consistent commit hashes across clones:

git config mediawiki.dumbPush true

Troubleshooting

SSL Certificate Issues

# Insecure (testing only)
PERL_LWP_SSL_VERIFY_HOSTNAME=0 git pull

# Secure (download cert)
echo | openssl s_client -showcerts -connect wiki.gi7b.org:443 > certs.pem
HTTPS_CA_FILE=certs.pem git pull

Missing PERL5LIB

If you see "Can't locate Git/Mediawiki.pm":

export PERL5LIB=/path/to/Git-Mediawiki:$PERL5LIB

Tips for Opencode Workflow

  • Always pull before starting edits
  • Make commits atomic (one logical change per commit)
  • Use descriptive commit messages (become wiki edit summaries)
  • Push frequently to avoid conflicts
  • Keep PERL5LIB exported in your shell

See Also

References