<?php

function loadSMFAPI ()
{
	global $maintenance, $wgSMFPathSSI, $wgSMFPathAPI;

    // Fix for SMF's sanitization breaking mediawiki page titles.
    // Let mediawiki do its own security

    $tempGet = $_GET;

    // 5 August 2016: This variable is used by Mediawiki's updater.
    // Store it in a temp variable so we can restore it if we need to.
    $oldMaintenance = null;

    if (!empty($maintenance)) {
        $oldMaintenance = $maintenance;
    }

    if(!require_once($wgSMFPathSSI)) {
        die("Could not load the SMF SSI");
    }

    if(!require_once($wgSMFPathAPI)) {
        die("Could not load the SMF API");
    }

    $_GET = $tempGet;

    if (!empty($oldMaintenance)) {
        $maintenance = $oldMaintenance;
    }
}

if (!defined("MW_NO_SESSION")) {
    loadSMFAPI();
}

if(!empty($user_info)) {
    $wgAuthRemoteuserUserName = $user_info['username'];

    $wgAuthRemoteuserUserPrefs = [
        'realname' => $user_info['name'],
        'email' => $user_info['email']
    ];

    $wgAuthRemoteuserUserUrls = [
        'logout' => $wgSMFURL . "/index.php?action=logout;" . $_SESSION['session_var'] . '=' . $_SESSION['session_value']
    ];
}
