Example #1
0
/**
 * Detects the presence of a nobots template or one that denies editing by ours
 *
 * @access    public
 * @param    Wiki $wiki Wiki class
 * @param    string $text Text of the page to check (default: '')
 * @param    string $pgUsername Username to search for in the template (default: null)
 * @param    string|null $optout Text to search for in the optout= parameter. (default: null)
 * @param    string|null $taskname (default: null)
 * @return    bool                    True on match of an appropriate nobots template
 */
function checkExclusion(Wiki $wiki, $text = '', $pgUsername = null, $optout = null, $taskname = null)
{
    if (!$wiki->get_nobots()) {
        return false;
    }
    if (in_string("{{nobots}}", $text)) {
        return true;
    }
    if (in_string("{{bots}}", $text)) {
        return false;
    }
    if (preg_match('/\\{\\{bots\\s*\\|\\s*allow\\s*=\\s*(.*?)\\s*\\}\\}/i', $text, $allow)) {
        if ($allow[1] == "all") {
            return false;
        }
        if ($allow[1] == "none") {
            return true;
        }
        $allow = array_map('trim', explode(',', $allow[1]));
        if (!is_null($pgUsername) && in_array(trim($pgUsername), $allow)) {
            return false;
        }
        return true;
    }
    if (preg_match('/\\{\\{(no)?bots\\s*\\|\\s*deny\\s*=\\s*(.*?)\\s*\\}\\}/i', $text, $deny)) {
        if ($deny[2] == "all") {
            return true;
        }
        if ($deny[2] == "none") {
            return false;
        }
        $allow = array_map('trim', explode(',', $deny[2]));
        if (!is_null($pgUsername) && in_array(trim($pgUsername), $allow) || !is_null($taskname) && in_array(trim($taskname), $allow)) {
            return true;
        }
        return false;
    }
    if (!is_null($optout) && preg_match('/\\{\\{(no)?bots\\s*\\|\\s*optout\\s*=\\s*(.*?)\\s*\\}\\}/i', $text, $allow)) {
        if ($allow[1] == "all") {
            return true;
        }
        $allow = array_map('trim', explode(',', $allow[2]));
        if (in_array(trim($optout), $allow)) {
            return true;
        }
        return false;
    }
    return false;
}