Benutzer:Andreas Plank/Wiki-Skripte

From Open Source Ecology - Germany
Jump to: navigation, search

Extensionen herunterladen und extrahieren

BASH Skript download_and_extract_wiki_extensions.sh zum Herunterladen von Extensionen in das Benutzerverzeichnis ~/tmp und extrahieren in den Wiki-Ordner $wikiExtPath

Hinweise:

#!/bin/bash
# description: What does it do? dowload and extract a standard Wiki extension
#    EXTURL stores the extension name and the download URL you can find the tar.gz URL e.g. at 
#    https://www.mediawiki.org/wiki/Special:ExtensionDistributor/MassEditRegex
#    https://www.mediawiki.org/wiki/Special:ExtensionDistributor?extdistname=MassEditRegex&extdistversion=REL1_31
# requires:    ~/tmp

### Variables Start
wikiExtPath=/apps/mediawiki/www/extensions/
declare -A EXTURL # associative array
# find the tar.gz URL e.g. at https://www.mediawiki.org/wiki/Special:ExtensionDistributor/MassEditRegex
# EXTURL[CategoryTree]=https://extdist.wmflabs.org/dist/extensions/CategoryTree-REL1_31-c24e5ed.tar.gz
EXTURL[Arrays]=https://extdist.wmflabs.org/dist/extensions/Arrays-REL1_31-4a04cd6.tar.gz
# EXTURL[Cite]=https://extdist.wmflabs.org/dist/extensions/Cite-REL1_31-20e26df.tar.gz
# EXTURL[CodeMirror]=https://extdist.wmflabs.org/dist/extensions/CodeMirror-REL1_31-a435d54.tar.gz
# EXTURL[ConfirmEdit]=https://extdist.wmflabs.org/dist/extensions/ConfirmEdit-REL1_31-b52469c.tar.gz
# EXTURL[DismissableSiteNotice]=https://extdist.wmflabs.org/dist/extensions/DismissableSiteNotice-REL1_31-73a6b72.tar.gz
# EXTURL[Echo]=https://extdist.wmflabs.org/dist/extensions/Echo-REL1_31-ed7f8f4.tar.gz
EXTURL[EventLogging]=https://extdist.wmflabs.org/dist/extensions/EventLogging-REL1_31-3fddc40.tar.gz
# EXTURL[Gadgets]=https://extdist.wmflabs.org/dist/extensions/Gadgets-REL1_31-bac29ae.tar.gz
# EXTURL[InputBox]=https://extdist.wmflabs.org/dist/extensions/InputBox-REL1_31-dfec261.tar.gz
# EXTURL[WikimediaMessages]=https://extdist.wmflabs.org/dist/extensions/WikimediaMessages-REL1_31-a600cfd.tar.gz
# EXTURL[MassEditRegex]=https://extdist.wmflabs.org/dist/extensions/MassEditRegex-REL1_31-fcc91e5.tar.gz
# EXTURL[MsCalendar]=https://extdist.wmflabs.org/dist/extensions/MsCalendar-REL1_31-4cb0d01.tar.gz
# EXTURL[MsUpload]=https://extdist.wmflabs.org/dist/extensions/MsUpload-REL1_31-2e2efd5.tar.gz
# EXTURL[Nuke]=https://extdist.wmflabs.org/dist/extensions/Nuke-REL1_31-c6ec842.tar.gz
# EXTURL[SemanticInternalObjects]=https://extdist.wmflabs.org/dist/extensions/SemanticInternalObjects-REL1_31-2b195cf.tar.gz
# EXTURL[Thanks]=https://extdist.wmflabs.org/dist/extensions/Thanks-REL1_31-a845a46.tar.gz
# EXTURL[UserMerge]=https://extdist.wmflabs.org/dist/extensions/UserMerge-REL1_31-a641f0c.tar.gz
EXTURL[UploadWizard]=https://extdist.wmflabs.org/dist/extensions/UploadWizard-REL1_31-1ba0e4e.tar.gz
# EXTURL[Variables]=https://extdist.wmflabs.org/dist/extensions/Variables-REL1_31-872663b.tar.gz

### Variables End

# get extensionList
extensionList=""
for thisExt in "${!EXTURL[@]}";
do
  [[ -z ${extensionList// /} ]] && extensionList="$thisExt" || extensionList="$extensionList $thisExt"
  # test if extension matches in URL
  if [[ ${EXTURL[$thisExt]} != *${thisExt}* ]];then
    echo -e "\033[0;31m# WARNING ${thisExt} does not match in ${EXTURL[$thisExt]}\033[0m"
  fi
done

# prompt before starting
echo -e "\033[0;32m##########################\033[0m"
echo -e "\033[0;32m# Extract ${#EXTURL[@]} Extensions ...\033[0m"
echo -e "\033[0;32m#   $extensionList\033[0m"
echo -e "\033[0;32m# ... to $wikiExtPath ?\033[0m"
echo -en "\033[0;32m# yes or no (default: no)\033[0m "

read yesno
if [[ -z ${yesno// /} ]];then yesno="no"; fi
case $yesno in
  [yY]|[yY][eE][sS])
    echo "# continue ..."
  ;;
  [nN]|[nN][oO])
    echo "### Stop";
    exit 1
  ;;
  *) 
    if [[ -z ${yesno// /} ]];then
      echo -e "\033[0;32m### Stop\033[0m"
    else
      echo "### Wrong input „${yesno}“ (Stop)"
    fi
    exit 1
  ;;
esac

i_ext=1
for thisExt in "${!EXTURL[@]}";
do
  # go to local tmp user directory
  if ! [[ -d ~/tmp ]];then mkdir ~/tmp; echo "# Created user directory ~/tmp";fi
  cd ~/tmp
  echo "### Step $i_ext of ${#EXTURL[@]}"
  echo "# Download $thisExt to `pwd`…"
  wget --no-verbose "${EXTURL[$thisExt]}"
  if [[ -d "${wikiExtPath}${thisExt}" ]];then
    # last modification timed as backup date e.g. MassEditRegex_2017-09-22
    modDate=$(stat -c %y "${wikiExtPath}${thisExt}")
    modDate=${modDate%% *} # remove from 1st space to the end in date time: 2017-09-22 00:12:10.000000000 +0200
    thisBackupPath="${wikiExtPath}${thisExt}_${modDate}"
    echo "# Back up $thisExt to ${thisBackupPath} …"
    mv "${wikiExtPath}${thisExt}" "${thisBackupPath}";
  fi
  echo "# Extract tar archive ${EXTURL[$thisExt]##*/} to ${wikiExtPath} …"
  tar -xzf "${EXTURL[$thisExt]##*/}" -C "${wikiExtPath}"
  i_ext=$(( i_ext + 1 ))
done

MediaWiki Language Extension Bundle herunterladen und extrahieren

BASH Skript download_and_extract_MLEB_extensions.sh zum Herunterladen von https://www.mediawiki.org/wiki/MediaWiki_Language_Extension_Bundle in das Benutzerverzeichnis ~/tmp und extrahieren in den Wiki-Ordner $wikiExtPath

Hinweise:

#!/bin/bash
# download_and_extract_MLEB_extensions.sh
# Documentation: https://www.mediawiki.org/wiki/MediaWiki_Language_Extension_Bundle
# MLEB extracts to ./extensions/Babel ./extensions/Translate etc.
# the dowload package is extracted to tempPath (home user directory ~/tmp)

### variables start
# modify according to your needs
mwLangExtBundlebUrl=https://translatewiki.net/mleb/MediaWikiLanguageExtensionBundle-2018.07.tar.bz2
labelOldMLEB="MLEB-2018.04"
wikiExtPath=/apps/mediawiki/www/extensions/
tempPath=~/tmp/
### variables end

# prompt before starting
echo -e "\033[0;32m##########################\033[0m"
echo -e "\033[0;32m# Download $mwLangExtBundlebUrl to ${tempPath} ...\033[0m"
echo -e "\033[0;32m# * back up old extensions Babel_$labelOldMLEB cldr_$labelOldMLEB Translate_$labelOldMLEB etc.\033[0m"
if [[ -d ${tempPath}extensions ]]; then 
  echo -e "\033[0;32m# * \033[0;31mremove ${tempPath}extensions\033[0;32m and extract MLEB to ${tempPath} \033[0m"
else
  echo -e "\033[0;32m# * extract MLEB into $tempPath copy to $wikiExtPath ?\033[0m"
fi
echo -en "\033[0;32m# yes or no (default: no)\033[0m "

read yesno
if [[ -z ${yesno// /} ]];then yesno="no"; fi
case $yesno in
  [yY]|[yY][eE][sS])
    echo "# continue ..."
  ;;
  [nN]|[nN][oO])
    echo "### Stop";
    exit 1
  ;;
  *) 
    if [[ -z ${yesno// /} ]];then
      echo -e "\033[0;32m### Stop\033[0m"
    else
      echo "### Wrong input „${yesno}“ (Stop)"
    fi
    exit 1
  ;;
esac


cd "${tempPath}"
if [[ -d extensions ]]; then 
  echo "# remove extensions folder ..."; 
  rm -R extensions; 
fi
echo "# Download ${mwLangExtBundlebUrl} to ${tempPath} …"
wget --no-verbose "${mwLangExtBundlebUrl}"
echo "# Extract ${mwLangExtBundlebUrl##*/} …"
tar -xjf ${mwLangExtBundlebUrl##*/}  -C  "${tempPath}"

for thisMLEBextension in "${tempPath}/extensions/"*;do
  if [[ -d "$wikiExtPath${thisMLEBextension##*/}" ]];then
    echo "# Back up in $wikiExtPath: ${thisMLEBextension##*/} ->  ${thisMLEBextension##*/}_${labelOldMLEB} ..."
    mv "$wikiExtPath${thisMLEBextension##*/}" "$wikiExtPath${thisMLEBextension##*/}_${labelOldMLEB}"
  fi
  echo "# Copy ${thisMLEBextension##*/} to $wikiExtPath${thisMLEBextension##*/} ..."
  cp --preserve --recursive "$thisMLEBextension" "$wikiExtPath${thisMLEBextension##*/}"
done

Some extensions of MediWiki are managed by composer, a snmall PHP script. This tool is intended to manage dependencies and needed versions of software components, such as MediaWiki extensions. It needs a basic configuration file (composer.json in the wiki root folder) and installation or removal of extensions is done on the command line.

Documentation:


Extensions via Composer (PHP)

Step 0: First install of PHP composer tool itself to a local shared bin-directory:

if ! [[ -d ~/bin ]];then mkdir ~/bin; fi; # create user home bin directory
cd ~/bin # go to personal home bin directory
wget https://getcomposer.org/composer.phar

Step 1: Manage your required extensions in file composer.local.json in the root wiki folder and not in composer.json wich is the basic setup shipped by the Mediawiki installation.

Step 2: add extension

Add an extension

Read the documentation of the extension what kind of version you need and so forth, the extension’s documentation should describe it sufficiently.

It is recommended to manage additional extensions in a separate file, read composer.local.json-sample, so use composer.local.json to add your extensions there:

{
  "extra": {
    "merge-plugin": {
      "include": [
        "extensions/SyntaxHighlight_GeSHi/composer.json"
      ]
    }
  },
  "require": {
    "mediawiki/image-map": "dev-REL1_30",
    "mediawiki/graph-viz": "~3.1",
    "mediawiki/semantic-media-wiki": "~2.5",
    "mediawiki/open-layers": "dev-master",
    "mediawiki/semantic-result-formats": "~2.5",
    "mediawiki/semantic-compound-queries": "~1.1",
    "mediawiki/page-forms": "4.*",
    "mediawiki/maps": "4.*"
  }
}

Step 3: update extensions.

It’s rather recommended to use the extra composer.local.json than the “require”-command that will update your composer.json shipped by wiki software that may get overwritten the next wiki code update.

Update extensions

# update only a single extension and their dependencies
cd /apps/mediawiki/www/extensions/
php ~/bin/composer.phar update --no-dev mediawiki/graph-viz

# update all extensions and their dependencies
cd /apps/mediawiki/www/extensions/
php ~/bin/composer.phar update --no-dev

Remove an extension

Note AP: not sure if remove command works also for composer.local.json

See https://getcomposer.org/doc/03-cli.md#remove

cd /apps/mediawiki/www/extensions/
php ~/bin/composer.phar remove 'mediawiki/semantic-maps'

Self Update of composer

php ~/bin/composer.phar self-update

SemanticMediaWiki installierern oder aktualisieren

Extension:SemanticMediaWiki installieren via composer, d.h. in composer.local.json eintragen: ...

  require: {
    "mediawiki/semantic-media-wiki": "~2.5",
    "mediawiki/open-layers": "dev-master",
    "mediawiki/semantic-result-formats": "~2.5",
    "mediawiki/semantic-compound-queries": "~1.1",
    "mediawiki/page-forms": "4.*",
    "mediawiki/maps": "4.*"
  }
...

Extension:SemanticInternalObjects via download_and_extract_wiki_extensions.sh

Einstellungen in LocalSettings.php

// Define constants for my additional namespaces.
define("NS_CALENDAR", 3000); // This MUST be even.
define("NS_CALENDAR_TALK", 3001); // This MUST be the following odd integer.
$wgContentNamespaces[] = NS_CALENDAR;

switch($wgLanguageCode) {// depending on Wikis default language
  case "de":
  case "de-formal":
  case "de-at":
  case "de-ch":
  $wgExtraNamespaces[NS_CALENDAR]      = "Kalender";# becomes ns:kalender as Wiki-Code
  $wgExtraNamespaces[NS_CALENDAR_TALK] = "Kalender_Diskussion"; // Note underscores in the namespace name.
  break;
  default:
  $wgExtraNamespaces[NS_CALENDAR]      = "Calendar"; # becomes ns:calendar as Wiki-Code
  $wgExtraNamespaces[NS_CALENDAR_TALK] = "Calendar_talk"; // Note underscores in the namespace name.
  break;
}

# somewhere near the bottom
############################################
# Extension:SemanticMediaWiki & Co
############################################

enableSemantics( parse_url( $wgServer, PHP_URL_HOST ) );
  $smwgEnabledEditPageHelp=false; # suppress SMW help text in WikiEditor
  wfLoadExtension( 'PageForms' );
    # $wgPageFormsLinkAllRedLinksToForms = true;
  wfLoadExtension( 'OpenLayers' ); # @require SMW
  # Extension:Maps
  $GLOBALS['egMapsDefaultService'] = 'openlayers';
  $GLOBALS['egMapsAvailableServices'] = [
    'openlayers',
    'leaflet',
  ];
  $smwgEnabledFulltextSearch=true; // default: false
  $smwgNamespacesWithSemanticLinks[NS_CALENDAR] = true;
  $smwgNamespacesWithSemanticLinks[NS_CALENDAR_TALK] = false;
  $smwgNamespacesWithSemanticLinks[NS_PROFILE] = true;
  $smwgNamespacesWithSemanticLinks[NS_TASK] = true;
  $srfgFirstDayOfWeek = 'Monday';
  /**
   * Extension SemanticInternalObjects
   * for n-ary subobject relations
   */
  include_once("$IP/extensions/SemanticInternalObjects/SemanticInternalObjects.php");

Datenbank aktualisieren:

cd /apps/mediawiki/www/
php maintenance/update.php --conf ./LocalSettings.php

Useful One liner commands

Move Patterns of Directories to Anther Directory

It does not remove the folder when there is already an identical target folder

# one liner to move all *_2017*/ of extensions to /apps/mediawiki-bak/www/extensions/
cd /apps/mediawiki/www/extensions/ && \
for thisDir in  *_2017*/; do \
  if ! [[ -d /apps/mediawiki-bak/www/extensions/"$thisDir" ]]; \
  then echo "Move $thisDir ..."; \
  mv "$thisDir" /apps/mediawiki-bak/www/extensions/; \
  fi; \
done;