<?php

// Protect against web entry
if ( !defined( 'MEDIAWIKI' ) ) {
    exit;
}

// Settings: database connection
$wgDBtype = "mysql";
$wgDBserver = "{{MYSQL_HOST}}";
$wgDBname = "{{MYSQL_DB}}";
$wgDBuser = "{{MYSQL_USER}}";
$wgDBpassword = "{{MYSQL_PASSWORD}}";
$wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary";
$wgDBprefix = "";

// Settings: allow raw html
$wgRawHtml = true;

// Settings: secret
$wgSecretKey = "{{SITE_SECRET_KEY}}";
$wgAuthenticationTokenVersion = "1"; // Changing this will log out all existing sessions.
$wgUpgradeKey = "{{SITE_UPGRADE_KEY}}";

// Settings: general wiki settings
$wgSitename = "{{SITE_NAME}}";
$wgMetaNamespace = "Wiki";

$wgEmergencyContact = '{{SITE_EMERGENCY_CONTACT}}';

$wgServer = 'https://' . (array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : '{{SITE_DOMAIN}}');

// Site language code, should be one of the list in ./languages/data/Names.php
$wgLanguageCode = "{{SITE_LANG}}";

// $wgDisableOutputCompression = true;
$wgScriptPath = ""; // the URL base path to the directory containing the wiki, @see https://www.mediawiki.org/wiki/Manual:Short_URL
$wgResourceBasePath = $wgScriptPath; // the URL path to static resources (images, scripts, etc.)

// The URL paths to the logo.  Make sure you change this from the default,
// or else you'll overwrite your logo when you upgrade!
$wgLogos = [
   '1x' => "$wgResourceBasePath/resources/assets/wiki.png",
//  '1x' => "$wgScriptPath/extensions/StuzersWiki/assets/images/wiki.png",
];
$wgFavicon = "$wgResourceBasePath/resources/assets/wiki.ico";

// Settings: UPO
// UPO means: this is also a user preference option
$wgEnableEmail = true;
$wgEnableUserEmail = false; # UPO

$wgPasswordSender = "";

$wgEnotifUserTalk = false; # UPO
$wgEnotifWatchlist = false; # UPO
$wgEmailAuthentication = true;

// Settings: file uploading
// To enable image uploads, make sure the 'images' directory
// is writable, then set this to true:
$wgEnableUploads = true;
$wgFileExtensions = array_merge($wgFileExtensions, [
    'doc', 'xls', 'pdf', 'ppt', 'xlsx',
]);
// $wgUseImageMagick = true;
// $wgImageMagickConvertCommand = "/usr/bin/convert";
// $wgFileExtensions = [];
// $wgMaxUploadSize = 99999;
// $wgUploadSizeWarning = 0;
// $wgVerifyMimeType = false;
$wgUseInstantCommons = false; // InstantCommons allows wiki to use images from https://commons.wikimedia.org

$wgFileExtensions = array_merge($wgFileExtensions, array('gz'));

// Periodically send a pingback to https://www.mediawiki.org/ with basic data
// about this MediaWiki instance. The Wikimedia Foundation shares this data
// with MediaWiki developers to help guide future development efforts.
$wgPingback = false;

// Time zone
$wgLocaltimezone = "Europe/Kiev";
date_default_timezone_set( $wgLocaltimezone );

// If you use ImageMagick (or any other shell command) on a
// Linux server, this will need to be set to the name of an
// available UTF-8 locale
$wgShellLocale = "C.UTF-8";

// For attaching licensing metadata to pages, and displaying an
// appropriate copyright notice / icon. GNU Free Documentation
// License and Creative Commons licenses are supported so far.
$wgRightsPage = ""; // Set to the title of a wiki page that describes your license/copyright
$wgRightsUrl = "";
$wgRightsText = "";
$wgRightsIcon = "";

// Path to the GNU diff3 utility. Used for conflict resolution.
$wgDiff3 = "/usr/bin/diff3";

// The following permissions were set based on your choice in the installer
$wgGroupPermissions['*']["createaccount"] = false;
$wgGroupPermissions['*']["edit"] = false;
$wgGroupPermissions['*']["read"] = false;
$wgGroupPermissions['user']['oathauth-enable'] = true;

// Allowed file extensions to upload
$wgFileExtensions = array_merge($wgFileExtensions, [
    "js", "css", "svg"
]);
//$wgFileBlacklist = array_diff($wgFileBlacklist, [ // @fixme
//    "js", "svg"
//]);

// $wgMimeTypes = array_merge($wgMimeTypes, [
//     "text/javascript"
// ]);
// $wgTrustedMediaFormats = array_merge($wgTrustedMediaFormats, [
//     // "TEXT",
//     // "UNKNOWN",
// ]);

// $wgStrictFileExtensions = false; // !!! Setting $wgStrictFileExtensions to false, or altering $wgFileBlacklist could result in either you or your users being exposed to security risks.

// Enable upload from URL
$wgGroupPermissions['user']['upload_by_url'] = true;

// Settings: set "/wiki" page prefix
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

// Settings: set target="_blank" for external links
$wgExternalLinkTarget = '_blank';

// Settings: enable MediaWiki:Common.js sitewide
$wgUseSiteJs = true;

//$wgImageMagickConvertCommand = "/usr/bin/convert";

// Settings: skin
wfLoadSkin("Vector");
$wgDefaultSkin = "vector";
wfLoadSkin("MinervaNeue");
$wgMFDefaultSkinClass = 'SkinMinerva';

// BEGIN: load extensions
$extensions = [
    "RequireJS",
    "CategoryTree",
    "Cite",
    // "ImageMap",
    "MultimediaViewer",
    // "Nuke",
    // "Renameuser",
    "ReplaceText",
    "ParserFunctions",
    "SyntaxHighlight_GeSHi",
    "Poem",
    // "MsUpload",
    // "WikiEditor",
    "MobileFrontend",
    "FontAwesome",
    // "Echo",
    // "CodeMirror",
    // "CodeEditor",
    // "CharInsert",
    // "TemplateStyles",
    "TimedMediaHandler",
    // "RevisionSlider",
    "Scribunto",
    // "ExpandableContent",
    "MonacoEditor",
    // "Spoilers",
    // "AutoCreateCategoryPages",
    // "CiteThisPage",
    // "TitleBlacklist",
    // "Disambiguator",
    "OATHAuth",
    // "EmbedVideo",
    "UserFunctions",
	"DynamicSidebar",
	"Mpdf",
	"Elastica",
	"CirrusSearch",
	"AdvancedSearch",
	"PageImages",
	"TextExtracts",
	"Popups",
];
foreach($extensions as $extension){
    $json_file = "$wgExtensionDirectory/$extension/extension.json";
    if( file_exists($json_file) ){
        wfLoadExtension($extension);
    }else{
        require_once "$wgExtensionDirectory/$extension/$extension.php";
    }
}
// END: load extensions

$wgScribuntoDefaultEngine = 'luastandalone';
// $wgMaxShellMemory = 204800; # in KB
// $wgScribuntoEngineConf['luastandalone']['memoryLimit'] = 209715200; # bytes
// $wgScribuntoEngineConf['luastandalone']['errorFile'] = "$IP/err.log";
// $wgScribuntoEngineConf['luastandalone']['luaPath'] = '/usr/bin/lua5.1';
$wgScribuntoUseGeSHi = true;
$wgScribuntoUseCodeEditor = true;

// Hide user toolbar settings
$wgHiddenPrefs[] = 'usebetatoolbar';

// Configure "MsUpload", extension
$wgMSU_useDragDrop = true;
$wgMSU_showAutoCat = true;
$wgMSU_checkAutoCat = true;
$wgMSU_useMsLinks = false;

$wgShowExceptionDetails = true;

// Custom URL protocols
$wgUrlProtocols[] = "grid://";

// Shared memory settings
$wgMainCacheType = CACHE_ACCEL; // CACHE_NONE
$wgMessageCacheType = CACHE_ACCEL;
$wgCacheDirectory = "$IP/cache";
$wgUseLocalMessageCache = true;
$wgParserCacheType = CACHE_DB;
$wgMemCachedServers = [];
$wgUseGzip = true;
$wgEnableSidebarCache = true;

// NO DB HITS!
$wgDisableCounters = true;
$wgMiserMode = true;

// Text cache
$wgCompressRevisions = false; // use with care (see talk page)
$wgRevisionCacheExpiry = 3*24*3600;
$wgParserCacheExpireTime = 14*24*3600;
$wgEnableSidebarCache = true;

$wgCapitalLinks = true; // @todo http://192.168.0.60/wiki/Special:WantedPages

// Defautl user settings
$wgDefaultUserOptions['watchdefault'] = false;

// Sidebar
$wgEnableSidebarCache = false;

// Dynamic sidebar
$wgDynamicSidebarUseUserpages = true;
$wgDynamicSidebarUseGroups = true;
$wgDynamicSidebarUseCategories = true;

// User parser functions
$wgUFEnabledPersonalDataFunctions = [
        'ip',
        'nickname',
        'realname',
        'useremail',
        'username',
];
$wgUFAllowedNamespaces = [
        NS_MEDIAWIKI => true,
        NS_MAIN => true,
        NS_USER => true,
];

$wgPFEnableStringFunctions = true;

//$wgMpdfTab = true;
$wgMpdfToolboxLink = true;

// $wgObjectCaches['redis'] = [
//    'class'                => 'RedisBagOStuff',
//    'servers'              => [ '127.0.0.1:6379' ],
//    // 'connectTimeout'    => 1,
//    // 'persistent'        => false,
//    // 'password'          => 'secret',
//    // 'automaticFailOver' => true,
// ];

//$wgMainCacheType = CACHE_NONE;
// $wgMainCacheType = 'redis';
// $wgSessionCacheType = 'redis';

// Not widely tested
// $wgMessageCacheType = 'redis';
// $wgParserCacheType = 'redis';
// $wgLanguageConverterCacheType = 'redis';

//$wgJobTypeConf['default'] = [
//    'class'          => 'JobQueueRedis',
//    'redisServer'    => '127.0.0.1:6379',
//    'redisConfig'    => [],
//    'claimTTL'       => 3600,
//    'daemonized'     => true
// ];

// unset( $wgFooterIcons['poweredby'] );

// BEGIN: file changes
// /includes/libs/mime/mime.types
// text/plain txt js
// END: file changes

//$wgWhitelistRead = [
//    "Main Page", "MediaWiki:Common.css", "MediaWiki:Common.js"
//];