#!/bin/bash

## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -o errexit
set -o nounset
set -o errtrace
set -o pipefail

usage() {
  printf '%s\n' "Usage: ${0##*/} [WIKI] [OUTPUT_DIR] [FETCHER]
Defaults:
  WIKI=${default_wiki_url}
  OUTPUT_DIR=${default_output_dir}
  FETCHER=${default_fetcher}
Example:
  ${0##*/}
  ${0##*/} ${default_wiki_url}
  ${0##*/} ${default_wiki_url} ${default_output_dir}
  ${0##*/} ${default_wiki_url} ${default_output_dir} ${default_fetcher}" >&2
  exit 1
}

default_wiki_url="https://www.whonix.org/w"
default_output_dir="$HOME/derivative-backup/whonix-wiki-backup"
default_fetcher="mw-wiki-fetch-backup"
if [[ "${1-}" =~ (-h|--help) ]]; then
  usage
fi

wiki_url="${1-"${default_wiki_url}"}"
output_dir="${2-"${default_output_dir}"}"
fetcher="${3-"${default_fetcher}"}"

mw-process-all-pages --namespace-extra-list="274 500" --article-sanity-test="Widget:CodeSelect" "${wiki_url}" "${fetcher}" "${output_dir}"
