User:Jibec/git-script.sh

This linux script aim to facilitate the export of mediawiki core and a list of extension.

Since 1.19, mediawiki is using Git and the extension distributor doesn't work anymore. There is not svn-export functionality and you don't have systematic branches for each git repositories. This is particularly scary when you're not a pro-developer since Wikimedia Foundation decided to have a two week deployment window. How to limit risks to have core and extensions not compatible ?

If your website is not updated directly through Git or don't have ssh/shell access, you may be interested to extract archives from mediawiki Git repos and upload them to your host.

How to use

edit
  1. set tag variable with REL1_XX where XX is the release version (1.20 is REL1_20, 1_19 is REL1_19, ...)
  2. set scriptPath to mach the folder where you are
  3. set extensions variable with the extension names you use on your wiki
  4. run the script :
    ./git-script.sh
    
  5. a folder will be created with core and extensions archives
  6. upload them to your webserver and unzip them

Code

edit
#!/bin/bash

# This script extract a mediawiki branch and selected extension in a zip archive
# if the branch doesn't exist for the extension, it will use _master_.
# I created this script to compensate the lack of extension distributor for git
# see https://bugzilla.wikimedia.org/show_bug.cgi?id=38188
# 
# You'll find howto and updates on mediawiki.org :
# https://www.mediawiki.org/wiki/User:Jibec/git-script.sh

# git help with mediawiki : https://www.mediawiki.org/wiki/Download_from_Git

# branch you want to extract
# to get the list : git branch -r | sort -V
tag="REL1_20"
tagClean=${tag/\//-} # it replaces "/" by "-", usefull for wmf extracts
# change this to match where you run the script
scriptPath="/home/jb/Sites/mediawiki-git"
preparation=${scriptPath}/preparation-${tagClean} 
# list of extensions to extract
extensions=(CategoryTree Cite ConfirmEdit Gadgets InputBox Interwiki Nuke
           ParserFunctions Renameuser SubPageList3 Vector WikiEditor UploadWizard
           DynamicPageList EmailCapture WikiLove PageTriage)
tagExt=""

printf "\n ** Destination folder creation\n"
mkdir $preparation

printf "\n ** Mediawiki update and archive creation\n"
   # if the directory does not exist, it mean we have to make a first git clone
   if [ ! -d "${scriptPath}/core/" ]; then
     mkdir ${scriptPath}/core/
     git clone https://gerrit.wikimedia.org/r/mediawiki/core.git
   fi
cd ${scriptPath}/core
git pull
git checkout ${tag}
git archive ${tag} | bzip2 > ${preparation}/${tagClean}.tar.bz2
cd ${scriptPath}

printf "\n ** Extensions update et archive creation\n"
cd ${scriptPath}
for extension in "${extensions[@]}"
do 
   printf "\n  * $extension \n"
   # if the directory does not exist, it mean we have to make a first git clone
   if [ ! -d "${scriptPath}/${extension}/" ]; then
     mkdir ${scriptPath}/${extension}/
     git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/${extension}.git
   fi
   cd $scriptPath/$extension/
   
   git pull
   
   # if the branch doesn't exist, use master (usefull for wmf extracts)
   if git show-ref --verify --quiet refs/remotes/origin/$tag; then
      tagExt=$tag
   else
      tagExt="master"
   fi
   
   printf " v $tagExt \n"
   git checkout $tagExt
   git archive $tagExt --prefix=$extension/ | bzip2 > $preparation/extension-$extension.tar.bz2

   cd $scriptPath
done

printf "\n ** Done.\n"