#!/usr/bin/env bash

# {{ ansible_managed }}

# Install current Wikipedia anti-spam blacklist

blacklist="https://meta.wikimedia.org/wiki/Spam_blacklist?action=raw"
wordblock_file="{{ dokuwiki__git_checkout + '/conf/wordblock.local.conf' }}"

dokuwiki_farm="{{ dokuwiki__farm | bool | lower }}"
dokuwiki_farm_path="{{ dokuwiki__farm_path }}"
read -r -a dokuwiki_farm_animals <<< "{{ dokuwiki__farm_animals | join(' ') }}"

if type curl > /dev/null 2>&1 ; then
    curl --silent "${blacklist}" | grep -v '<pre>' > "${wordblock_file}"

    if [ "${dokuwiki_farm}" = "true" ] ; then
        for animal in "${dokuwiki_farm_animals[@]}" ; do
            if ! [ -h "${dokuwiki_farm_path}/${animal}/conf/wordblock.local.conf" ] ; then
                ln -s "${wordblock_file}" "${dokuwiki_farm_path}/${animal}/conf/wordblock.local.conf"
            fi
        done
    fi
fi
