<?php

# This file was automatically generated by the MediaWiki installer.
# If you make manual changes, please keep track in case you need to
# recreate them later.
#
# See includes/DefaultSettings.php for all configurable settings
# and their default values, but don't forget to make changes in _this_
# file, not there.
#
# Further documentation for configuration settings may be found at:
# http://www.mediawiki.org/wiki/Manual:Configuration_settings

# If you customize your file layout, set $IP to the directory that contains
# the other MediaWiki files. It will be used as a base to locate files.
#
#
if( defined( 'MW_INSTALL_PATH' ) ) {
	$IP = MW_INSTALL_PATH;
} else {
	$IP = dirname( __FILE__ );
}

$path = array( $IP, "$IP/includes", "$IP/languages" );
set_include_path( implode( PATH_SEPARATOR, $path ) . PATH_SEPARATOR . get_include_path() );

require_once( "$IP/includes/DefaultSettings.php" );

# If PHP's memory limit is very low, some operations may fail.
ini_set( 'memory_limit', '20M' );

if ( $wgCommandLineMode ) {
	if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
		die( "This script must be run from the command line\n" );
	}
}
## Uncomment this to disable output compression
# $wgDisableOutputCompression = true;
$wgServer           = "https://wiki.sapian.com.co";
$wgSitename         = "Wiki Sapian";

## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
## For more information on customizing the URLs please see:
## http://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath       = "";
$wgScriptExtension  = ".php";

## UPO means: this is also a user preference option

$wgEnableEmail      = true;
$wgEnableUserEmail  = true; # UPO

$wgEmergencyContact = "sebastian.rojo@sapian.com.co";
$wgPasswordSender = "sebastian.rojo@sapian.com.co";

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

## Database settings
$wgDBtype           = "mysql";
$wgDBserver         = "mariadb-primary.dbs.svc.cluster.local";
$wgDBname           = "wiki";
$wgDBuser           = "wiki";
$wgDBpassword       = "EiN4VeeLi7nua9";

# MySQL specific settings
$wgDBprefix         = "";

# MySQL table options to use during installation or update
$wgDBTableOptions   = "ENGINE=InnoDB, DEFAULT CHARSET=binary";

# Experimental charset support for MySQL 4.1/5.0.
$wgDBmysql5 = true;

## Shared memory settings
$wgMainCacheType = CACHE_NONE;
$wgMemCachedServers = array();

## To enable image uploads, make sure the 'images' directory
## is writable, then set this to true:
$wgEnableUploads       = true;
$wgUseImageMagick = true;
$wgImageMagickConvertCommand = "/usr/bin/convert";

## 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 = "en_US.utf8";

## If you want to use image uploads under safe mode,
## create the directories images/archive, images/thumb and
## images/temp, and make them all writable. Then uncomment
## this, if it's not already uncommented:
# $wgHashedUploadDirectory = false;

## If you have the appropriate support software installed
## you can enable inline LaTeX equations:
$wgUseTeX           = false;

$wgLocalInterwiki   = strtolower( $wgSitename );

$wgLanguageCode = "es";

$wgSecretKey = "00304dcaf442485a6d1299f9488337644ba04f34e77da2d9bd6b339556b69b5b";

## Default skin: you can change the default skin. Use the internal symbolic
## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
#wfLoadSkin( 'CologneBlue' );
wfLoadSkin( 'Modern' );
wfLoadSkin( 'MonoBook' );
wfLoadSkin( 'Vector' );
wfLoadSkin( 'Material' );


$wgDefaultSkin = 'Vector';

## 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.
# $wgEnableCreativeCommonsRdf = true;
$wgRightsPage = ""; # Set to the title of a wiki page that describes your license/copyright
$wgRightsUrl = "";
$wgRightsText = "";
$wgRightsIcon = "";
# $wgRightsCode = ""; # Not yet used

#$wgLogo = "/logo_sapian.png";
#$wgLogo = "$wgScriptPath/images/logo_sapian.png";
$wgLogo = "$wgScriptPath/images/Logo_circular_wiki_2017-01-26_31dpi.png";
$wgDiff3 = "/usr/bin/diff3";

# When you make changes to this configuration file, this will make
# sure that cached pages are cleared.
$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'svg', 'mp3', 'ogg', 'avi', 'swf', 'pdf', 'zip', 'doc', 'xls', 'odf','ods');
$wgUploadDirectory = "{$IP}/images";
$wgShowExceptionDetails = true;


#require_once("$IP/extensions/ImportUsers/SpecialImportUsers.php");
#require_once("$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php");
#require_once "$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php";

#==== Editors ====
#require_once("$IP/extensions/WYSIWYG/WYSIWYG.php");
#require_once("$IP/extensions/WikiEditor/WikiEditor.php");
#require_once("$IP/extensions/FCKeditor/FCKeditor.php");
#require_once "$IP/extensions/VisualEditor/VisualEditor.php";

#require_once("$IP/extensions/PdfExport/PdfExport.php");
#require_once("$IP/extensions/LdapAuthentication/LdapAuthentication.php");
require_once("$IP/extensions/ParserFunctions/ParserFunctions.php");
#require_once("$IP/extensions/Collection/Collection.php");

$wgPFEnableStringFunctions = true;
// $wgGroupPermissions['*']['createaccount'] = true;
// $wgGroupPermissions['*']['autocreateaccount'] = true;
// $wgGroupPermissions['*']['edit'] = false;
// $wgGroupPermissions['*']['read'] = false;
// $wgWhitelistRead = array("Portada", "Especial:Userlogin");

/*LDAP
$wgAuth = new LdapAuthenticationPlugin();
$wgLDAPDebug = 9;
$wgDebugLogGroups['ldap'] = '/var/log/wiki_ldap.log';

//Nombres de los dominios que utilizarás.
$wgLDAPDomainNames = array("SAPIAN.COM.CO");

//Asociación entre nombre de dominio y nombre DNS de la máquina donde se va a validar.
//$wgLDAPServerNames = array("SAPIAN.COM.CO"=>"sbs.sapian.com.co");
$wgLDAPServerNames = array("SAPIAN.COM.CO"=>"ipa-02-med-host.sapian.com.co");

//Podemos permitir la convivencia de autenticación local del wiki con LDAP.
$wgLDAPUseLocal = true;

  //Encriptación en las solicitudes LDAP.
  $wgLDAPEncryptionType = array("SAPIAN.COM.CO"=>"ssl");

  //Le decimos cual es la base de la consulta
  $wgLDAPBaseDNs = array("SAPIAN.COM.CO"=>"dc=sapian,dc=com,dc=co");
  $wgLDAPSearchAttributes = array("SAPIAN.COM.CO"=>"uid");
  //$wgLDAPSearchStrings= array("SAPIAN.COM.CO"=>"uid=USER-NAME,ou=Users,ou=Accounts,dc=sapian,dc=com,dc=co");

  //Utilizamos los grupos LDAP para las directivas de grupo:
  $wgLDAPGroupsPrevail = array("SAPIAN.COM.CO"=>true);
  $wgLDAPGroupNameAttribute = array("SAPIAN.COM.CO"=>"cn");

  //User and password used for proxyagent access.
  //Please use a user with limited access, NOT your directory manager!
  $wgLDAPProxyAgent = array(
  "SAPIAN.COM.CO"=>"uid=mediawiki,cn=sysaccounts,cn=etc,dc=sapian,dc=com,dc=co"
  );
  $wgLDAPProxyAgentPassword = array(
  "SAPIAN.COM.CO"=>"Ooghia6shoox5ieghaongeequae2ienohpuureiTeiwaetha"
  );

$wgLDAPDisableAutoCreate = array(
  'SAPIAN.COM.CO' => false
);

$wgCollectionPODPartners = array(
    'pediapress' => array(
        'name' => 'PediaPress',
        'url' => 'http://pediapress.com/',
        'posturl' => 'http://pediapress.com/api/collections/',
        'infopagetitle' => 'coll-order_info_article',
    ),
);

 */

#$wgDefaultUserOptions['usebetatoolbar'] = 1;
#$wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
#$wgDefaultUserOptions['wikieditor-preview'] = 1;


require_once "$IP/extensions/ContributionScores/ContributionScores.php";
$wgContribScoreIgnoreBots = true;          // Exclude Bots from the reporting - Can be omitted.
$wgContribScoreIgnoreBlockedUsers = true;  // Exclude Blocked Users from the reporting - Can be omitted.
$wgContribScoresUseRealName = true;        // Use real user names when available - Can be omitted. Only for MediaWiki 1.19 and later.
$wgContribScoreDisableCache = false;       // Set to true to disable cache for parser function and inclusion of table.

//Each array defines a report - 7,50 is "past 7 days" and "LIMIT 50" - Can be omitted.
$wgContribScoreReports = array(
    array(7,50),
    array(30,50),
    array(0,50));

$wgDebugLogFile = "/var/log/mediawiki.log";

// Enable by default for everybody
$wgDefaultUserOptions['visualeditor-enable'] = 1;

// Don't allow users to disable it
$wgHiddenPrefs[] = 'visualeditor-enable';

// OPTIONAL: Enable VisualEditor's experimental code features
$wgDefaultUserOptions['visualeditor-enable-experimental'] = 1;

$wgVirtualRestConfig['modules']['parsoid'] = array(
  // URL to the Parsoid instance
  // Use port 8142 if you use the Debian package
  'url' => 'http://localhost:8142',
  // Parsoid "domain", see below (optional)
  'domain' => 'wiki.sapian.com.co',
  // Parsoid "prefix", see below (optional)
  'prefix' => 'wiki'
);

//$wfLoadExtension( 'SyntaxHighlight_GeSHi' );
//$wgReadOnly = 'Upgrading to MediaWiki 1.28.2';
$wgShowDBErrorBacktrace = true;

wfLoadExtension( 'VisualEditor' );
wfLoadExtension( 'YouTube' );
$wgDefaultUserOptions['visualeditor-enable'] = 1;
$wgVirtualRestConfig['modules']['parsoid'] = array(
    // URL to the Parsoid instance
    // Use port 8142 if you use the Debian package
    'url' => 'http://wiki-01-med-guest.sapian.com.co:8000',
    // Parsoid "domain", see below (optional)
    'domain' => 'sapian',
    // Parsoid "prefix", see below (optional)
    'prefix' => 'sapian'
);

$wgSessionsInObjectCache = true;
$wgVirtualRestConfig['modules']['parsoid']['forwardCookies'] = true;

//When set to true, users can bring in an inline image from an external URL. They do this simply by sticking the full URL into the wiki text (without any other surrounding markup being required) That is the direct URL to an image resource on another website.
$wgAllowExternalImages = true;

wfLoadExtension( 'SyntaxHighlight_GeSHi' );

// Intergratio to keycloack
wfLoadExtension( 'PluggableAuth' );
//$wgPluggableAuth_EnableAutoLogin = true;
$wgPluggableAuth_EnableLocalLogin = true;
$wgPluggableAuth_EnableLocalProperties = true;
$wgPluggableAuth_ButtonLabel  = "login accounts.sapian.cloud";


// wfLoadExtension( 'OpenIDConnect' );
//
// //$wgOpenIDConnect_UseRealNameAsUserName = true;
// //$wgOpenIDConnect_MigrateUsersByUserName  = true;
// //$wgOpenIDConnect_UseEmailNameAsUserName = true;
// //$wgOpenIDConnect_MigrateUsersByEmail = true;
//
// $wgOpenIDConnect_Config['https://accounts.sapian.cloud/auth/realms/sapian.com.co/'] = [
//         'clientID' => 'mediawiki-sapian-com-co',
// 	'clientsecret' => 'dced64bf-d7f0-44a2-be44-5c3eff7df304',
// 	'name' => "Sapian Accounts Server",
// 	'icon' => "https://www.sapian.com.co/wp-content/uploads/2020/04/SapianMaterialDesign_logo_open_solutions_72dpi.png"
//     ];
//
// //error_reporting( -1 );
// //ini_set( 'display_errors', 1 );
// wfLoadExtension( 'LDAPAuthentication2' );

// Safe IP or not (for bypassing external login via AD)
$safeIPs = array('127.0.0.1','localhost');
$ipsVars = array('HTTP_X_FORWARDED_FOR','HTTP_X_REAL_IP','REMOTE_ADDR');
foreach ($ipsVars as $ipsVar) {
 if (isset($_SERVER[$ipsVar]) && mb_strlen($_SERVER[$ipsVar]) > 3 ) { $wikiRequestIP = $_SERVER[$ipsVar]; break; }
}
$wikiRequestSafe = (isset($wikiRequestIP) && ( in_array($wikiRequestIP,$safeIPs) ));

// Create Wiki-Group 'engineering' from default user group
$wgGroupPermissions['engineering'] = $wgGroupPermissions['user'];

$wgEmailConfirmToEdit = false;
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['read'] = false;
$wgGroupPermissions['*']['createaccount'] = false;
$wgGroupPermissions['sysop']['createaccount'] = false;
$wgGroupPermissions['*']['autocreateaccount'] = true;
$wgBlockDisablesLogin = true;

$ldapJsonFile = "/etc/mediawiki-ldap/ldap.json";
$ldapConfig = false;
if (is_file($ldapJsonFile) && is_dir("$IP/extensions/LDAPProvider")) {
  $testJson = @json_decode(file_get_contents($ldapJsonFile),true);
  if (is_array($testJson)) {
    $ldapConfig = true;
  } else {
    error_log("Found invalid JSON in file: $IP/ldap.json");
  }
}

// Activate Extension
if ( $ldapConfig ) {

	$wgUserrightsInterwikiDelimiter = "%";
	$wgInvalidUsernameCharacters = "%:";

  wfLoadExtension( 'PluggableAuth' );
  wfLoadExtension( 'LDAPProvider' );
  wfLoadExtension( 'LDAPAuthentication2' );
  wfLoadExtension( 'LDAPAuthorization' );
  wfLoadExtension( 'LDAPUserInfo' );
  wfLoadExtension( 'LDAPGroups' );

  $LDAPProviderDomainConfigs = $ldapJsonFile;
  $wgPluggableAuth_ButtonLabel = "Log In via ldap.accounts.sapian.cloud";

  if ($wikiRequestSafe) { $LDAPAuthentication2AllowLocalLogin = true; }
}

$wgSMTP = [
    'host'     => 'exim', // could also be an IP address. Where the SMTP server is located
    'IDHost'   => 'wiki.sapian.com.co',      // Generally this will be the domain name of your website (aka mywiki.org)
    'port'     => 25,                 // Port to use when connecting to the SMTP server
    'auth'     => false               // Should we use SMTP authentication (true or false)
];
