<?php

$smf_session_data = [];

if (!defined("MW_NO_SESSION")) {
    // 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");
    }

    // Clear SMF session data before starting MW session
    if (!empty($user_info) && $user_info['id']) {
        $smf_session_data = $_SESSION;
        session_destroy();
    }

    $_GET = $tempGet;

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

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

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

    $wgAuthRemoteuserUserUrls = [
        'logout' => $wgSMFPath."/index.php?action=logout;sesc=" . session_id()
    ];
}
