<?php
# Sequence if wiki initialization:
#   1. basic_config.inc - bare minimum of defitionitions to allow the following steps 
#   2. <wiki>/config.inc - wiki specific configuration, also defined wanted extensions
#   3. final_config.inc - final, system wide and farm-related configuration
#   4. extensions_config.inc - configure individual extensions and enable them as wanted
#


#-------------------------------------------------------------------------
# Extension:LDAP authentication
# see http://www.mediawiki.org/wiki/Ldap#External_Links
# see http://wiki.laub-home.de/wiki/MediaWiki_an_ein_ActiveDirectory_anbinden
#
# valid for >= 1.36
if (1|$wfLMSLdapExtension)
{
  if (0) # enable debug
  {
    $wgDebugLogGroups['PluggableAuth'] = '/tmp/ldap.log';
    $wgDebugLogGroups['MediaWiki\\Extension\\LDAPProvider\\Client'] = '/tmp/ldap.log';
    $wgDebugLogGroups['LDAPGroups'] =  '/tmp/ldap.log';
    $wgDebugLogGroups['LDAPAuthentication2'] =  '/tmp/ldap.log';
    $wgDebugLogGroups['LDAPAuthorization'] = '/tmp/ldap.log';
  }

  $LDAPAuthentication2AllowLocalLogin = false; #true;
  $LDAPAuthentication2UsernameNormalizer = 'strtolower';

  $LDAPProviderDefaultDomain = 'plm';
#  $wgPluggableAuth_EnableAutoLogin = true; # verlangt https?


  $wgEmailConfirmToEdit = false;
  
  // Load LDAP Config from JSON
  $ldapJsonFile = "$siteDir/../default/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");
    }
  }

  wfLoadExtension( 'PluggableAuth' );
  wfLoadExtension( 'LDAPProvider' );
  wfLoadExtension( 'LDAPAuthentication2' );

  $LDAPProviderDefaultDomain = "plm";
  $LDAPProviderDomainConfigs = $ldapJsonFile;
  $wgPluggableAuth_ButtonLabel = "Log In";
}


#-------------------------------------------------------------------------
# Extension: various
#
wfLoadExtension( 'Variables' );
wfLoadExtension( 'intersection' ); # replaces former CategoryTree extension
$wgUseAjax = true;



#-------------------------------------------------------------------------
# Include php statements (extension implemented by LMS/RSC
require_once("$IP/extensions/runphp.php");

#-------------------------------------------------------------------------
# Wysiwyg editor
#require_once("$IP/extensions/FCKeditor/FCKeditor.php");

#-------------------------------------------------------------------------
# AdminLinks
#include_once("$IP/extensions/AdminLinks/AdminLinks.php");
wfLoadExtension( 'AdminLinks' );

#-------------------------------------------------------------------------
# ReplaceText
require_once( "$IP/extensions/ReplaceText/ReplaceText.php" );
$wgGroupPermissions['sysop']['replacetext'] = true;

#-------------------------------------------------------------------------
# DataTransfer
#include_once("$IP/extensions/DataTransfer/DataTransfer.php");
###$wgGroupPermissions['user']['datatransferimport'] = true;


#-------------------------------------------------------------------------
# enable math rendering
# NOTE: For newer MediaWiki versions (1.18+) Math is provided as a separate extension and requires an
# extra service or delegates to an external service.
# Therefore we switch to SimpleMathJax which works out of the box.

#---- Math ----
#$wgUseTeX         = true;
#$wgTexvc          = "$IP/math/texvc";
#wfLoadExtension( 'Math' );
#$wgMathDisableTexFilter = true;
#$wgDBmysql5 = false;
#$wgDefaultUserOptions['math'] = 'png';
#$wgDefaultUserOptions['math'] = 'source';
#$wgDefaultUserOptions['math'] = 'mathml';
#$wgMathFullRestbaseURL = 'https://en.wikipedia.org/api/rest_';
#$wgMathMathMLUrl = 'https://mathoid-beta.wmflabs.org/';

#--- Math replacement ---
wfLoadExtension( 'SimpleMathJax' );
$wgSmjScale = 1.3;


#-------------------------------------------------------------------------
# Extension:Lockdown
# ref http://www.mediawiki.org/wiki/Extension:Lockdown
require_once( "$IP/extensions/Lockdown/Lockdown.php" );

#-------------------------------------------------------------------------
# CSO iframe extension
#deprecated#include ("$IP/extensions/CSO_iFrame.php");


#-------------------------------------------------------------------------
#if ($wfLMSPollExtension)
#	require_once("$IP/extensions/Poll/Poll.php");

#-------------------------------------------------------------------------
# Semantic extensions
#

# Add forms support
#if ($wfLMSFormExtension)
	#require_once("$IP/extensions/Form/Form.php");
if ($wfLMSCategoryTreeExtension)
	wfLoadExtension( 'CategoryTree' );


# Semantic Wiki
if (0&$wfLMSSemantikiMediaWikiExtension) {
	include_once("$IP/extensions/SemanticMediaWiki/SemanticMediaWiki.php");
	enableSemantics('example.org');
    }

if (0&$wfLMSSemanticFormsExtension)
	#include_once("$IP/extensions/SemanticForms/includes/SF_Settings.php");
	include_once("$IP/extensions/SemanticForms/SemanticForms.php");

if (0&$wfLMSSemantikDrilldownExtension)
	include_once("$IP/extensions/SemanticDrilldown/SemanticDrilldown.php");

if ($wfLMSSimpleCalendar)
	include("$IP/extensions/SimpleCalendar.php");

if ($wfLMSCalendar)
	require_once("$IP/extensions/Calendar.php");

if ($wfLMSSpecialEvents)
	require_once("$IP/extensions/SpecialEvents.php");


##########################################################################
# Extensions bundeled with mediawikis since 1.21 
#

#-------------------------------------------------------------------------
###RSC### require_once("$IP/extensions/Cite/Cite.php");

#-------------------------------------------------------------------------
# Provides CAPTCHA techniques to protect against spam and password-guessing
if (IsSet($wfLMSConfirmEdit) && $wfLMSConfirmEdit)
	require_once("$IP/extensions/ConfirmEdit/ConfirmEdit.php");

#-------------------------------------------------------------------------
# Lets users select custom CSS and JavaScript gadgets in their preferences
if (IsSet($wfLMSGadgets) && $wfLMSGadgets)
	require_once("$IP/extensions/Gadgets/Gadgets.php");

#-------------------------------------------------------------------------
# Allows client-side clickable image maps using <imagemap> tag
#require_once("$IP/extensions/ImageMap/ImageMap.php");
wfLoadExtension( 'ImageMap' );

#-------------------------------------------------------------------------
# Allow inclusion of predefined HTML forms
if (IsSet($wfLMSInputBox) && $wfLMSInputBox)
	require_once("$IP/extensions/InputBox/InputBox.php");

#-------------------------------------------------------------------------
#Manipulation if interwiki entries
#
wfLoadExtension( 'Interwiki' );
$wgGroupPermissions['*']['interwiki'] = false;
$wgGroupPermissions['sysop']['interwiki'] = true;

#-------------------------------------------------------------------------
# Keeps the localised messages as up to date as possible
if (IsSet($wfLMSLocalisationUpdate) && $wfLMSLocalisationUpdate)
	require_once("$IP/extensions/LocalisationUpdate/LocalisationUpdate.php");

#-------------------------------------------------------------------------
#Gives administrators the ability to mass delete pages
if (IsSet($wfLMSNuke) && $wfLMSNuke)
	require_once("$IP/extensions/Nuke/Nuke.php");

#-------------------------------------------------------------------------
# enable #ifxxx in remplates
if ($wfLMSParserFunctions)
{
# bundled with Mediawiki since 2.18
	wfLoadExtension( 'ParserFunctions' );
	$wgPFEnableStringFunctions = true;
}

#-------------------------------------------------------------------------
# enable UNC file paths (requires ParserFunction
# see http://www.mediawiki.org/wiki/UNC_links
# see http://www.mediawiki.org/wiki/Manual:$wgUrlProtocols
$wgUrlProtocols[] = "file://";

#-------------------------------------------------------------------------
# Handler for viewing PDF files in image mode.
#require_once("$IP/extensions/PdfHandler/PdfHandler.php");
wfLoadExtension( 'PdfHandler' );
$wgPdfHandlerDpi=25;

#-------------------------------------------------------------------------
# Adds <poem> tag for poem formatting
if (IsSet($wfLMSPoem) && $wfLMSPoem)
	require_once("$IP/extensions/Poem/Poem.php");

#-------------------------------------------------------------------------
# Adds a special page to rename a user (need renameuser right)
if (IsSet($wfLMSRenameuser) && $wfLMSRenameuser)
	require_once("$IP/extensions/Renameuser/Renameuser.php");

#-------------------------------------------------------------------------
# Adds a simple spam/bot check to forms
if (IsSet($sfLMSSimpleAntiSpam) && $sfLMSSimpleAntiSpam)
	require_once("$IP/extensions/SimpleAntiSpam/SimpleAntiSpam.php");

#-------------------------------------------------------------------------
# Regex-based anti-spam tool allowing to blacklist URLs in pages and email addresses for registered users
if (IsSet($sfLMSSpamBlacklist) && $sfLMSSpamBlacklist)
	require_once("$IP/extensions/SpamBlacklist/SpamBlacklist.php");

#-------------------------------------------------------------------------
# Syntax Hightlighting
# NOTE: we have a geshi directoriy in the extension, this is the real
# hightlighter. Here we install handlers for different tags. They will
# call geshi directly then.

# extension to allow <source ...>
wfLoadExtension( 'SyntaxHighlight_GeSHi' );

## extension to allow <code ...>
#deprecated#include("$IP/extensions/GeshiCodeTag.php");

#-------------------------------------------------------------------------
# Allows administrators to forbid creation of pages and user accounts per a blacklist and whitelist
if (IsSet($sfLMSTitleBlacklist) && $sfLMSTitleBlacklist)
	require_once("$IP/extensions/TitleBlacklist/TitleBlacklist.php");

#-------------------------------------------------------------------------
# Provides an extendable wikitext editing interface and many feature-providing modules
wfLoadExtension( 'WikiEditor' );

# Enables use of WikiEditor by default but still allow users to disable it in preferences
$wgDefaultUserOptions['usebetatoolbar'] = 1;
$wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
 
# Displays the Preview and Changes tabs
$wgDefaultUserOptions['wikieditor-preview'] = 0;
  
# Displays the Publish and Cancel buttons on the top right side
$wgDefaultUserOptions['wikieditor-publish'] = 0;

# Displays a navigation column (summary) on the right side
$wgDefaultUserOptions['usenavigabletoc'] = 0;


#-------------------------------------------------------------------------
# augment user names with their real name
if (IsSet($wfLMSRealnames) && $wfLMSRealnames)
{
	wfLoadExtension( 'Realnames' );

	$wgRealnamesStyles['mystyle'] = '$1$2$4 [$3]';
	$wgRealnamesLinkStyle = "mystyle";
	$wgRealnamesBareStyle = "mystyle";

	#$wgRealnamesReplacements['title'] = FALSE;
	#$wgRealnamesReplacements['personnal'] = FALSE;
}

#-------------------------------------------------------------------------
# This extension lets a wiki include external static text content from the various sources
if (IsSet($sfLMSSecureInclude) && $sfLMSSecureInclude)
{
wfLoadExtension( 'SecureInclude' );


# Including local paths requires to uncomment the following line
# $wg_include_allowed_features['local'] = true;
$wg_include_allowed_parent_paths = $_SERVER['DOCUMENT_ROOT'];
$wg_include_disallowed_regex = array('/.*LocalSettings.php/', '/.*\.conf/', '/.*\/\.ht/');
 
# Including remote URLs requires to uncomment the following line
# $wg_include_allowed_features['remote'] = true;
$wg_include_allowed_url_regexp = array('/^http:\/\/.*$/');
$wg_include_disallowed_url_regexp = array('/^.*:\/\/intranet/');

#$wg_include_allowed_features['highlight'] = true;
$wg_include_allowed_features['local'] = true;
$wg_include_allowed_features['remote'] = true;
$wg_include_allowed_features['iframe'] = true;
#$wg_include_allowed_features['noesc'] = true;
$wg_include_allowed_features['wikitext'] = true;

}


#-------------------------------------------------------------------------
# The MsUpload extension allows users to upload multiple files from the
# edit interface, including by drag & drop files.
if (IsSet($wfLMSMsUpload) && $wfLMSMsUpload)
{
#require_once "$IP/extensions/MsUpload/MsUpload.php";

#-- Some options with their defaults
# $wgMSU_showAutoCat = true; // If true, files uploaded while editing a category will be added to that category
# $wgMSU_checkAutoCat = true; // Whether the checkbox for the above mentioned case is checked by default
# $wgMSU_imgParams = '400px'; // The default parameters for inserted images
# $wgMSU_useDragDrop = true; // Should the drag & drop area be shown?
# $wgMSU_useMsLinks = false; // Should we allow to insert links in the style of the Extension:MsLinks?

#-- more options

$wgEnableAPI = true; // Enable the API
$wgEnableWriteAPI = true; // Enable the API
$wgEnableUploads = true; // Enable uploads
$wgAllowJavaUploads = true; // Solves problem with Office 2007 and newer files (docx, xlsx, etc.)
$wgGroupPermissions['user']['upload'] = true; // Allow regular users to upload files


}


