-
Notifications
You must be signed in to change notification settings - Fork 2
/
LocalSettings.php
613 lines (517 loc) · 19.9 KB
/
LocalSettings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
<?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(PHP_SAPI != 'cli'){
session_start();
if(phpversion() < 5.4){
error_reporting(E_ALL);
}
else{
error_reporting(E_ALL ^ E_STRICT);
}
ini_set("display_errors", 1);
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
}
if(!isset($_GET['embed'])){
header('X-Frame-Options: SAMEORIGIN');
}
date_default_timezone_set('America/Edmonton');
if( defined( 'MW_INSTALL_PATH' ) ) {
$IP = MW_INSTALL_PATH;
} else {
$IP = dirname( __FILE__ );
}
if(!defined('TESTING')){
if(file_exists("$IP/test.tmp")){
define("TESTING", true);
}
else{
define("TESTING", false);
}
}
define("EOT", "9999-01-01"); // End of Time
$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" );
require_once( "$IP/config/Config.php" );
## Path settings
$wgSitename = $config->getValue("siteName");
$wgScriptPath = $config->getValue("path");
## Database settings
$wgDBtype = $config->getValue("dbType");
$wgDBserver = $config->getValue("dbServer");
$wgDBname = $config->getValue("dbName");
$wgTestDBname = $config->getValue("dbTestName");
## Database credentials
$wgDBuser = $config->getValue("dbUser");
$wgDBpassword = $config->getValue("dbPassword");
$wgDBadminuser = $config->getValue("dbUser");
$wgDBadminpassword = $config->getValue("dbPassword");
## From MediaWiki manual:
## "This value is used to generate a persistent cookie
## for authentication that is resilient to spoofing."
$wgSecretKey = "7b32642dd51dcddf7a65fa3bea2757256caebc0220154c52ec8aebea1b87d7bf";
## Mailing List settings
$wgListAdmins = $config->getValue("listAdmins");
$wgListAdminPassword = $config->getValue("listAdminPassword");
$wgFavicon = "$wgServer$wgScriptPath/favicon.ico";
if(TESTING && !defined('INIT_TESTING')){
$wgDBname = $wgTestDBname;
}
# 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;
## 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
$wgScriptExtension = ".php";
## UPO means: this is also a user preference option
$wgEnableEmail = true;
$wgEnableUserEmail = true; # UPO
$wgEmergencyContact = $config->getValue('supportEmail');
$wgPasswordSender = $config->getValue('supportEmail');
$wgEnotifUserTalk = true; # UPO
$wgEnotifWatchlist = true; # UPO
$wgEmailAuthentication = true;
$wgEnableParserLimitReporting = false;
$wgAdditionalMailParams = "-f {$config->getValue('supportEmail')}";
if(TESTING){
$wgEnableEmail = false;
$wgEnableUserEmail = false; # UPO
$wgEmailAuthentication = false;
$wgEnotifUserTalk = false; # UPO
$wgEnotifWatchlist = false; # UPO
}
# MySQL specific settings
$wgDBprefix = "mw_";
# 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
define('CACHE_APC', 'apc_shared');
if(!TESTING){
if(extension_loaded('apc') && ini_get('apc.enabled')){
$wgMainCacheType = CACHE_APC;
$wgMessageCacheType = CACHE_APC;
$wgParserCacheType = CACHE_APC;
}
}
$wgDisableCounters = true;
$wgJobRunRate = 0.01;
$wgSessionsInObjectCache = true;
$wgEnableSidebarCache = true;
if($config->getValue('localizationCache') != ""){
if(!file_exists($config->getValue('localizationCache')) &&
is_writable($config->getValue('localizationCache'))){
mkdir($config->getValue('localizationCache'));
}
if(file_exists($config->getValue('localizationCache'))){
$wgCacheDirectory = $config->getValue('localizationCache');
$wgUseLocalMessageCache = true;
}
}
## To enable image uploads, make sure the 'images' directory
## is writable, then set this to true:
$wgEnableUploads = true;
$wgUseImageMagick = true;
$wgImageMagickConvertCommand = "/usr/bin/convert";
$wgCopyUploadsFromSpecialUpload = true;
## 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 = "en";
## Please edit Credentials.php to configure $wgSecretKey.
#$wgSecretKey = "";
## Default skin: you can change the default skin. Use the internal symbolic
## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
require_once "$IP/skins/{$config->getValue('skin')}/cavendish.php";
$wgDefaultSkin = "{$config->getValue('skin')}";
$wgAllowUserSkin = false;
## 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
$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__ ) ) );
/*
require_once("$IP/Swift/lib/swift_required.php");
require_once("$IP/extensions/Widgets/Widgets.php");
$wgGroupPermissions['sysop']['editwidgets'] = true;
*/
require_once("$IP/extensions/AnnokiControl/AnnokiControl.php");
$wgRestrictDisplayTitle = false;
$wgLocalTZoffset = date_default_timezone_set("MST") / 60;
$wgRawHtml = true;
$wgEnableUploads = true;
$wgMaxUploadSize = 1024*1024*50;
ini_set('upload_max_filesize', $wgMaxUploadSize);
$wgFileExtensions = array( 'png', 'jpg', 'jpeg', 'gif', 'tif', 'tiff', 'svg', 'psd', 'pdf', 'ppt', 'pptx', 'ods', 'odt', 'odp', 'doc', 'docx', 'xls', 'xlsx', 'tgz', 'zip', 'rar', 'flv', 'mov', 'avi', 'mpeg', 'ogv', 'mp4', 'mkv', 'm4v', 'mp3', 'flac', 'ogg', 'wmv', 'wav', 'txt');
$wgVerifyMimeType = false;
$wgAllowCopyUploads = true;
$wgAllowTitlesInSVG = true;
$wgMaxShellMemory = 402400;
$wgPasswordReminderResendTime = 0.1666; // ~ 10 minutes
$wgEditPageFrameOptions = 'SAMEORIGIN';
$wgImpersonating = false;
$wgDelegating = false;
$wgRealUser;
if (($key = array_search('application/zip', $wgMimeTypeBlacklist)) !== false) {
unset($wgMimeTypeBlacklist[$key]);
}
// Whether or not to show custom deprication notices
define("DEBUG", true);
$wgRoleValues = array(INACTIVE => 0,
HQP => 1,
EXTERNAL => 2,
AG => 2,
NI => 5,
AR => 5,
CI => 6,
CHAMP => 7,
PARTNER => 7,
PS => 8,
PA => 8, // Might eventually be merged with PS
PL => 9,
TL => 11,
TC => 11,
APL => 11,
TC => 11,
EDI => 12,
COMMITTEE => 12,
EVALUATOR => 12,
ASD => 13,
SD => 13,
STAFF => 16,
MANAGER => 17,
ADMIN => 100);
$wgRoles = ($config->hasValue('wgRoles')) ?
$config->getValue('wgRoles') :
array(HQP, PS, EXTERNAL, AG, AR, CI, CHAMP, PARTNER, PL, ASD, SD, STAFF, MANAGER, ADMIN);
$wgAllRoles = ($config->hasValue('wgAllRoles')) ?
$config->getValue('wgAllRoles') :
array(HQP, PS, STUDENT, EXTERNAL, AG, AR, CI, PA, PL, APL, TL, TC, EVALUATOR, CHAMP, PARTNER, ASD, SD, STAFF, MANAGER, ADMIN);
foreach($config->getValue('committees') as $role => $roleDef){
define($role, $role);
$wgRoleValues[$role] = $wgRoleValues[COMMITTEE];
$wgRoles[] = $role;
$wgAllRoles[] = $role;
}
foreach($config->getValue('roleAliases') as $alias => $role){
define($alias, $alias);
$wgRoleValues[$alias] = $wgRoleValues[$role];
$wgRoles[] = $alias;
$wgAllRoles[] = $alias;
$config->setValue('roleDefs', array_merge($config->getValue('roleDefs'), array($alias => $alias)));
}
$config->setValue('roleDefs', array_merge($config->getValue('roleDefs'), $config->getValue('committees')));
function unaccentChars($str){
$str = str_replace('š', 's', $str);
$str = str_replace('Š', 'S', $str);
return strtolower(strtr(utf8_decode($str),
utf8_decode('àáâãäåçèéêëìíîïñòóôõöøùúûüýÿÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'),
'aaaaaaceeeeiiiinoooooouuuuyyAAAAAACEEEEIIIINOOOOOUUUUY'));
}
// Encodes a large json object (usually arrays)
// It still returns a string, but constructs it incrementally
function large_json_encode($data){
$string = "";
if(is_object($data)){
$string .= "{";
}
else{
$string .= "[";
}
$first = true;
foreach($data as $key => $item){
if ($first) {
$first = false;
} else {
$string .= ",";
}
if(is_object($data)){
$string .= "$key:";
}
$string .= json_encode($item);
}
if(is_object($data)){
$string .= "}";
}
else{
$string .= "]";
}
return $string;
}
function array_clean(array $haystack){
foreach ($haystack as $key => $value) {
if (is_array($value)) {
$haystack[$key] = array_clean($value);
} elseif (is_string($value)) {
$value = trim($value);
}
if (!$value) {
unset($haystack[$key]);
}
}
return $haystack;
}
// https://arjunphp.com/flatten-nested-arrays-using-php/
function array_flatten($array, $prefix = '') {
$result = array();
foreach($array as $key=>$value) {
if(is_array($value)) {
$result = $result + array_flatten($value, $prefix . $key . '.');
}
else {
$result[$prefix.$key] = $value;
}
}
return $result;
}
function str_replace_first($search, $replace, $subject) {
$pos = strpos($subject, $search);
if ($pos !== false) {
$subject = substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
}
function str_replace_last($search, $replace, $subject) {
$pos = strrpos($subject, $search);
if($pos !== false) {
$subject = substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
}
function str_replace_every_other($needle, $replace, $haystack, &$count=null, $replace_first=true) {
$count = 0;
$offset = strpos($haystack, $needle);
//If we don't replace the first, go ahead and skip it
if (!$replace_first) {
$offset += strlen($needle);
$offset = strpos($haystack, $needle, $offset);
}
while ($offset !== false) {
$haystack = substr_replace($haystack, $replace, $offset, strlen($needle));
$count++;
$offset += strlen($replace);
$offset = strpos($haystack, $needle, $offset);
if ($offset !== false) {
$offset += strlen($needle);
$offset = strpos($haystack, $needle, $offset);
}
}
return $haystack;
}
function flatten(array $array) {
$return = array();
array_walk_recursive($array, function($a) use (&$return) { $return[] = $a; });
return $return;
}
function adjustBrightness($hex, $steps) {
// Steps should be between -255 and 255. Negative = darker, positive = lighter
$steps = max(-255, min(255, $steps));
// Normalize into a six character long hex string
$hex = str_replace('#', '', $hex);
if (strlen($hex) == 3) {
$hex = str_repeat(substr($hex,0,1), 2).str_repeat(substr($hex,1,1), 2).str_repeat(substr($hex,2,1), 2);
}
// Split into three parts: R, G and B
$color_parts = str_split($hex, 2);
$return = '#';
foreach ($color_parts as $color) {
$color = hexdec($color); // Convert to decimal
$color = max(0,min(255,$color + $steps)); // Adjust color
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
}
return $return;
}
// A function to return the Roman Numeral, given an integer
function rome($num){
// Make sure that we only use the integer portion of the value
$n = intval($num);
$result = '';
// Declare a lookup array that we will use to traverse the number:
$lookup = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400,
'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40,
'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1);
foreach ($lookup as $roman => $value){
// Determine the number of matches
$matches = intval($n / $value);
// Store that many characters
$result .= str_repeat($roman, $matches);
// Substract that from the number
$n = $n % $value;
}
// The Roman numeral should be built, return it
return $result;
}
/**
* Returns a 'human readable' date from the given string
* @param string $time The time in db timestamp format 'YYYY-MM-DD hh-mm-ss'
* @param strin $format How to format the data (defaults to 'F j, Y')
* @return string The date in the format 'F j, Y'
*/
function time2date($time, $format='F j, Y'){
$strtime = strtotime($time);
return date($format, $strtime);
}
function currentTimeStamp(){
return date('Y-m-d H:i:s', time());
}
/**
* Returns a HTML comment with the elapsed time since request.
* This method has no side effects.
* @return string
*/
function wfReportTimeOld() {
global $wgRequestTime, $wgShowHostnames;
$now = wfTime();
$elapsed = $now - $wgRequestTime;
$mem = memory_get_peak_usage(true);
$bytes = array(1 => 'B', 2 => 'KiB', 3 => 'MiB', 4 => 'GiB');
$ind = 1;
while ($mem > 1024 && $ind < count($bytes)) {
$mem = $mem / 1024;
$ind++;
}
return $wgShowHostnames
? sprintf( "<!-- Served by %s in %01.3f secs (%01.1f %s used). -->", wfHostname(), $elapsed, $mem, $bytes[$ind] )
: sprintf( "<!-- Served in %01.3f secs (%01.1f %s used). -->", $elapsed, $mem, $bytes[$ind] );
}
// http://stackoverflow.com/questions/4757061/which-ics-parser-written-in-php-is-good
function icsToArray($icsFile) {
$icsFile = str_replace("\r", "", $icsFile);
$icsFile = str_replace("\n ", "", $icsFile);
$icsData = explode("BEGIN:", $icsFile);
foreach($icsData as $key => $value) {
$data = explode("\n", $value);
if($data[0] == "VEVENT"){
$icsDatesMeta[$key] = explode("\n", $value);
}
}
foreach($icsDatesMeta as $key => $value) {
foreach($value as $subKey => $subValue) {
if ($subValue != "") {
if ($key != 0 && $subKey == 0) {
$icsDates[$key]["BEGIN"] = $subValue;
} else {
$subValueArr = explode(":", $subValue, 2);
$value = @$subValueArr[0];
if(strstr($value, ";") !== false){
$values = explode(";", $value);
$array = array();
foreach($values as $k => $val){
if(strstr($val, "=") !== false){
$val = explode("=", $val);
$array[$val[0]] = str_replace('\n', "\n",
str_replace('\,', ',',
str_replace('\;', ';', $val[1])));
}
}
$array['VALUE'] = str_replace('\n', "\n",
str_replace('\,', ',',
str_replace('\;', ';', $subValueArr[1])));
$icsDates[$key][$values[0]][] = $array;
}
else{
$icsDates[$key][$value] = str_replace('\n', "\n",
str_replace('\,', ',',
str_replace('\;', ';', $subValueArr[1])));
}
}
}
}
}
return $icsDates;
}
function sanitizeInput($str){
$str = str_replace("&", "&", $str);
$str = str_replace("<", "<", $str);
$str = str_replace(">", ">", $str);
$str = str_replace("\"", """, $str);
$str = str_replace("'", "'", $str);
$str = str_replace("/", "/", $str);
return $str;
}
function knatsort(&$arr){return uksort($arr,function($a, $b){return strnatcmp($a,$b);});}
// https://gist.github.com/MarxBro/f08a8768f06f57cff4e627cb4a9a4630
function recursive_implode($glue, $array, $include_keys = false, $trim_all = true){
$glued_string = '';
// Recursively iterates array and adds key/value to glued string
array_walk_recursive($array, function($value, $key) use ($glue, $include_keys, &$glued_string)
{
$include_keys and $glued_string .= $key.$glue;
$glued_string .= $value.$glue;
});
// Removes last $glue from string
strlen($glue) > 0 and $glued_string = substr($glued_string, 0, -strlen($glue));
// Trim ALL whitespace
$trim_all and $glued_string = preg_replace("/(\s)/ixsm", '', $glued_string);
return (string) $glued_string;
}
function encrypt($plaintext, $ignoreError=false){
if(!isset($_SERVER['ENC_KEY'])){
if($ignoreError){ return $plaintext; }
throw new Exception('ENC_KEY not defined');
}
$plaintext = str_pad($plaintext, 50, "\0", STR_PAD_LEFT); // Pad so that the response can't be inferred from the length of the encrypted string
$key = $_SERVER['ENC_KEY'];
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($plaintext, $cipher, $key, 0, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary=true);
$ciphertext = base64_encode( $iv.$hmac.$ciphertext_raw );
return $ciphertext;
}
function decrypt($ciphertext, $ignoreError=false){
if(!isset($_SERVER['ENC_KEY'])){
if($ignoreError){ return $ciphertext; }
throw new Exception('ENC_KEY not defined');
}
$key = $_SERVER['ENC_KEY'];
$c = base64_decode($ciphertext);
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = substr($c, 0, $ivlen);
$hmac = substr($c, $ivlen, $sha2len=32);
$ciphertext_raw = substr($c, $ivlen+$sha2len);
$original_plaintext = openssl_decrypt($ciphertext_raw, $cipher, $key, 0, $iv);
$original_plaintext = ltrim($original_plaintext, "\0");
return $original_plaintext;
}
?>