GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (4873)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

plugins/mediawiki/www/LocalSettings.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 * Copyright (C) 2010 Roland Mas, Olaf Lenz
4
 * Copyright (c) Enalean, 2014. All rights reserved
5
 *
6
 * This file is part of Tuleap.
7
 *
8
 * Tuleap is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 2 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * Tuleap is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with Tuleap. If not, see <http://www.gnu.org/licenses/
20
 */
21
22
/** This contains the local settings for Mediawiki as used in the
23
 *  Mediawiki plugin of Tuleap.
24
 */
25
26
/* C style inclusion guard. Yes, I know. Don’t comment on it. */
27
if (!isset($fusionforge_plugin_mediawiki_LocalSettings_included)) {
28
$fusionforge_plugin_mediawiki_LocalSettings_included = true;
29
30
// Force include of HTTPRequest here instead of relying on autoload for this
31
// very specific class. Problems come from mediawiki inclusion: mediawiki also
32
// have an HttpRequest class (but no longer used, in a .old file) and in MW,
33
// But this class is referenced in MW autoloader (loaded before Tuleap one)
34
// so when tuleap stuff in pre.php instanciate HTTPRequest (like logger) it instanciate
35
// mediawiki HttpRequest instead of the Tuleap one.
36
// This is a short term hack, in a longer term we should namespace tuleap HTTPRequest
37
// But wait for PHP5.3 min compat.
38
39
require_once('common/include/Codendi_Request.class.php');
40
require_once('common/include/HTTPRequest.class.php');
41
require_once 'pre.php';
42
require_once 'plugins_utils.php';
43
require_once 'common/user/UserManager.class.php';
44
require_once 'common/project/Group.class.php';
45
require_once __DIR__.'/../include/MediawikiFusionForgeProjectNameRetriever.php';
46
require_once __DIR__.'/../include/MediawikiDao.class.php';
47
require_once __DIR__.'/../include/MediawikiLanguageDao.php';
48
require_once __DIR__.'/../include/MediawikiUserGroupsMapper.class.php';
49
require_once __DIR__.'/../include/MediawikiSiteAdminResourceRestrictor.php';
50
require_once MEDIAWIKI_BASE_DIR.'/MediawikiManager.class.php';
51
require_once MEDIAWIKI_BASE_DIR.'/MediawikiLanguageManager.php';
52
require_once MEDIAWIKI_BASE_DIR.'/MediawikiMLEBExtensionManagerLoader.php';
53
54
/**
55
 * HACK
56
 */
57
require_once MEDIAWIKI_BASE_DIR.'/../../fusionforge_compat/include/fusionforge_compatPlugin.class.php';
58
$ff_plugin = new fusionforge_compatPlugin();
59
$ff_plugin->loaded();
60
$manager                = new MediawikiManager(new MediawikiDao());
61
$language_manager       = new MediawikiLanguageManager(new MediawikiLanguageDao());
62
$project_name_retriever = new MediawikiFusionForgeProjectNameRetriever();
63
$project_manager        = ProjectManager::instance();
64
65
$forbidden_permissions = array(
66
    'editmyusercss',
67
    'editmyuserjs',
68
    'viewmyprivateinfo',
69
    'editmyprivateinfo'
70
);
71
72
$read_permissions = array(
73
    'read',
74
    'viewmywatchlist',
75
    'editmywatchlist'
76
);
77
78
$write_permissions = array(
79
    'edit',
80
    'createpage',
81
    'move',
82
    'createtalk',
83
    'writeapi'
84
);
85
86
//Trust Mediawiki security
87
$xml_security = new XML_Security();
88
$xml_security->enableExternalLoadOfEntities();
89
90
sysdebug_lazymode(true);
91
92
$wgServer = HTTPRequest::instance()->getServerUrl();
93
94
if (! isset($fusionforgeproject)) {
95
    $fusionforgeproject = null;
96
}
97
98
$fusionforgeproject = $project_name_retriever->getFusionForgeProjectName($fusionforgeproject);
99
100
$group = $project_manager->getProjectByUnixName($fusionforgeproject);
101
102
if (!isset($is_tuleap_mediawiki_123)) {
103
    $is_tuleap_mediawiki_123 = false;
104
105
    $restrictor_dao = new MediawikiSiteAdminResourceRestrictorDao();
106
    if ($restrictor_dao->isMediawiki123(MediawikiSiteAdminResourceRestrictor::RESOURCE_ID, $fusionforgeproject)) {
107
        $is_tuleap_mediawiki_123 = true;
108
    }
109
}
110
111
$IP = '/usr/share/mediawiki-tuleap';
112
if ($is_tuleap_mediawiki_123) {
113
    $IP = '/usr/share/mediawiki-tuleap-123';
114
}
115
116
$gconfig_dir = forge_get_config('mwdata_path', 'mediawiki');
117
$project_dir = forge_get_config('projects_path', 'mediawiki') . "/"
118
	. $group->getID() ;
119
120
if (! is_dir($project_dir)) {
121
    $project_dir = forge_get_config('projects_path', 'mediawiki') . "/" . $group->getUnixName();
122
    if (! is_dir($project_dir)) {
123
        exit_error (sprintf(_('Mediawiki for project %s not created yet, please wait for a few minutes.'), $group->getPublicName().' : '.$project_dir)) ;
124
    }
125
}
126
127
$path = array( $IP, "$IP/includes", "$IP/languages" );
128
set_include_path( implode( PATH_SEPARATOR, $path ) . PATH_SEPARATOR . get_include_path() );
129
130
require_once( "$IP/includes/AutoLoader.php" );
131
require_once( "$IP/includes/Defines.php" );
132
require_once( "$IP/includes/DefaultSettings.php" );
133
134
if ( $wgCommandLineMode ) {
135
    if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
136
            die( "This script must be run from the command line\n" );
137
    }
138
}
139
140
$wgSitename         = $group->getPublicName() . " Wiki";
141
$wgScriptPath       = "/plugins/mediawiki/wiki/$fusionforgeproject" ;
142
$wgEmergencyContact = forge_get_config('admin_email');
143
$wgPasswordSender   = forge_get_config('admin_email');
144
$wgDBtype           = "forge";
145
$wgDBserver         = forge_get_config('database_host') ;
146
147
if (forge_get_config('mw_dbtype', 'mediawiki') == 'mysql') {
148
    // At the time writing schema in mysql is synonym for database
149
    $dao      = new MediawikiDao();
150
    $wgDBname = $dao->getMediawikiDatabaseName($group, false);
0 ignored issues
show
It seems like $group defined by $project_manager->getPro...me($fusionforgeproject) on line 100 can be null; however, MediawikiDao::getMediawikiDatabaseName() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
151
    if (! $wgDBname) {
152
        exit_error (sprintf(_('Mediawiki for project %s cannot be found, please contact your system admininistrators.'), $fusionforgeproject.':'.$project_dir)) ;
153
    }
154
    $wgDBprefix = 'mw';
155
} else {
156
    $wgDBname = forge_get_config('database_name');
157
}
158
159
$wgDBuser           = forge_get_config('database_user') ;
160
$wgDBpassword       = forge_get_config('database_password') ;
161
$wgDBadminuser      = forge_get_config('database_user') ;
162
$wgDBadminpassword  = forge_get_config('database_password') ;
163
$wgDBport           = forge_get_config('database_port') ;
164
$wgDBmwschema       = str_replace ('-', '_', "plugin_mediawiki_$fusionforgeproject") ;
165
$wgDBts2schema      = str_replace ('-', '_', "plugin_mediawiki_$fusionforgeproject") ;
166
$wgMainCacheType    = CACHE_NONE;
167
$wgMemCachedServers = array();
168
$wgEnableParserCache = false;
169
170
//$wgEnableUploads = forge_get_config('enable_uploads', 'mediawiki');
171
$wgEnableUploads             = true;
172
$wgUploadDirectory           = "$project_dir/images";
173
$wgUseImageMagick            = true;
174
$wgImageMagickConvertCommand = "/usr/bin/convert";
175
$wgLocalInterwiki            = $wgSitename;
176
$wgShowExceptionDetails      = true ;
177
178
$user       = UserManager::instance()->getCurrentUser();
179
$mw_service = $group->getService(MediaWikiPlugin::SERVICE_SHORTNAME);
180
181
$used_language = $language_manager->getUsedLanguageForProject($group);
0 ignored issues
show
It seems like $group defined by $project_manager->getPro...me($fusionforgeproject) on line 100 can be null; however, MediawikiLanguageManager...sedLanguageForProject() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
182
if ($used_language) {
183
    $wgLanguageCode  = substr($used_language, 0, 2);
184
} else if ($mw_service && $mw_service->userIsAdmin($user)) {
185
    header('Location: /plugins/mediawiki/forge_admin?group_id='. $group->getID() .'&pane=language&nolang=1');
186
    die();
187
} else {
188
    $wgLanguageCode  = substr($user->getLocale(), 0, 2);
189
}
190
191
$wgHtml5          = false;
192
$wgStyleDirectory = forge_get_config('codendi_dir').forge_get_config('mw_style_path', 'mediawiki');
193
$wgWellFormedXml  = true;
194
$wgLogo           = "";
195
196
$GLOBALS['sys_dbhost']         = forge_get_config('database_host') ;
197
$GLOBALS['sys_dbport']         = forge_get_config('database_port') ;
198
$GLOBALS['sys_dbname']         = forge_get_config('database_name') ;
199
$GLOBALS['sys_dbuser']         = forge_get_config('database_user') ;
200
$GLOBALS['sys_dbpasswd']       = forge_get_config('database_password') ;
201
$GLOBALS['sys_plugins_path']   = forge_get_config('plugins_path') ;
202
$GLOBALS['sys_urlprefix']      = forge_get_config('url_prefix') ;
203
$GLOBALS['sys_use_ssl']        = forge_get_config('use_ssl') ;
204
$GLOBALS['sys_default_domain'] = forge_get_config('web_host') ;
205
$GLOBALS['sys_custom_path']    = forge_get_config('custom_path') ;
206
$GLOBALS['gfwww']              = $gfwww ;
207
$GLOBALS['gfplugins']          = $gfplugins ;
208
$GLOBALS['sys_lang']           = forge_get_config('default_language') ;
209
$GLOBALS['sys_urlroot']        = forge_get_config('url_root');
210
$GLOBALS['sys_session_key']    = forge_get_config('session_key');
211
$GLOBALS['sys_session_expire'] = forge_get_config('session_expire');
212
$GLOBALS['REMOTE_ADDR']        = getStringFromServer('REMOTE_ADDR') ;
213
$GLOBALS['HTTP_USER_AGENT']    = getStringFromServer('HTTP_USER_AGENT') ;
214
215
216
if ($is_tuleap_mediawiki_123) {
217
    require_once 'DatabaseForgeMysql123.php';
218
} else {
219
    require_once("$IP/includes/Exception.php");
220
    require_once("$IP/includes/db/Database.php");
221
    require_once 'DatabaseForgeMysql.php';
222
}
223
224
function TuleapMediawikiAuthentication($user, &$result) {
225
    global $fusionforgeproject, $wgGroupPermissions ;
226
227
    session_set();
0 ignored issues
show
The call to the function session_set() seems unnecessary as the function has no side-effects.
Loading history...
228
229
    if (session_loggedin()) {
230
            $tuleap_user    = session_get_user();
231
            $group          = group_get_object_by_name($fusionforgeproject);
232
            $madiawiki_name = ucfirst($tuleap_user->getUnixName()) ;
233
            $mediawiki_user = User::newFromName($madiawiki_name);
234
235
            if ($mediawiki_user->getID() == 0) {
236
                    $mediawiki_user->addToDatabase();
237
                    $mediawiki_user->setPassword(User::randomPassword());
238
                    $mediawiki_user->setRealName($tuleap_user->getRealName());
239
                    $mediawiki_user->setToken();
240
                    $mediawiki_user->loadFromDatabase();
241
            }
242
243
            $user->mId = $mediawiki_user->getID();
244
            $user->loadFromId() ;
245
            $user = manageMediawikiGroupsForUser($user, $tuleap_user, $group);
0 ignored issues
show
It seems like $group defined by group_get_object_by_name($fusionforgeproject) on line 231 can be null; however, manageMediawikiGroupsForUser() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
246
247
            $user->setCookies();
248
            $user->saveSettings();
249
            wfSetupSession();
250
    } else {
251
            $user->logout ();
252
    }
253
254
    $result = true;
255
    return true ;
256
}
257
258
/**
259
 * On every page load, the user's permissions are recalculated. They are based
260
 * upon the groups to which the user belongs.
261
 */
262
function manageMediawikiGroupsForUser(User $mediawiki_user, PFUser $tuleap_user, Group $group) {
263
    $groups_mapper    = new MediawikiUserGroupsMapper(new MediawikiDao(), new User_ForgeUserGroupPermissionsDao());
264
    $mediawiki_groups = $groups_mapper->defineUserMediawikiGroups($tuleap_user, $group);
265
266
    foreach ($mediawiki_groups['removed'] as $group_to_remove) {
267
        $mediawiki_user->removeGroup($group_to_remove);
268
    }
269
270
    foreach ($mediawiki_groups['added'] as $group_to_add) {
271
        $mediawiki_user->addGroup($group_to_add);
272
    }
273
274
    return $mediawiki_user;
275
}
276
277
function customizeMediawikiGroupsRights(
278
    array $wgGroupPermissions,
279
    MediawikiManager $manager,
280
    $fusionforgeproject,
281
    array $forbidden_permissions,
282
    array $read_permissions,
283
    array $write_permissions
284
) {
285
    $tuleap_user = session_get_user();
286
287
    $wgGroupPermissions = removeUnwantedRights($wgGroupPermissions, $forbidden_permissions);
288
    $wgGroupPermissions = removeAllGroupsReadWriteRights($wgGroupPermissions, $read_permissions, $write_permissions);
289
    $wgGroupPermissions = addReadPermissionForUser(
290
        $tuleap_user,
291
        $manager,
292
        $fusionforgeproject,
293
        $wgGroupPermissions,
294
        $read_permissions
295
    );
296
    $wgGroupPermissions = addWritePermissionForUser(
297
        $tuleap_user,
298
        $manager,
299
        $fusionforgeproject,
300
        $wgGroupPermissions,
301
        $write_permissions
302
    );
303
304
    return $wgGroupPermissions;
305
}
306
307
function addReadPermissionForUser(PFUser $tuleap_user, MediawikiManager $manager, $fusionforgeproject, array $wgGroupPermissions, array $read_permissions) {
308
    $group = group_get_object_by_name($fusionforgeproject);
309
310
    if (! $manager->userCanRead($tuleap_user, $group)) {
0 ignored issues
show
It seems like $group defined by group_get_object_by_name($fusionforgeproject) on line 308 can be null; however, MediawikiManager::userCanRead() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
311
        return $wgGroupPermissions;
312
    }
313
314
    foreach ($read_permissions as $read_permission) {
315
        $wgGroupPermissions['*'][$read_permission] = true;
316
    }
317
318
    return $wgGroupPermissions;
319
}
320
321
function addWritePermissionForUser(PFUser $tuleap_user, MediawikiManager $manager, $fusionforgeproject, array $wgGroupPermissions, array $write_permissions) {
322
    $group = group_get_object_by_name($fusionforgeproject);
323
324
    if (! $manager->userCanWrite($tuleap_user, $group)) {
0 ignored issues
show
It seems like $group defined by group_get_object_by_name($fusionforgeproject) on line 322 can be null; however, MediawikiManager::userCanWrite() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
325
        return $wgGroupPermissions;
326
    }
327
328
    foreach ($write_permissions as $write_permission) {
329
        $wgGroupPermissions['*'][$write_permission] = true;
330
    }
331
332
    return $wgGroupPermissions;
333
}
334
335
function removeAllGroupsReadWriteRights(array $wgGroupPermissions, array $read_permissions, array $write_permissions) {
336
    $permissions = array_merge($read_permissions, $write_permissions);
337
338
    foreach ($permissions as $permission) {
339
        $wgGroupPermissions['*'][$permission]          = false;
340
        $wgGroupPermissions['user'][$permission]       = false;
341
        $wgGroupPermissions['bot'][$permission]        = false;
342
        $wgGroupPermissions['bureaucrat'][$permission] = false;
343
        $wgGroupPermissions['sysop'][$permission]      = false;
344
    }
345
346
    return $wgGroupPermissions;
347
}
348
349
function removeUnwantedRights(array $wgGroupPermissions, array $forbidden_permissions) {
350
    $wgGroupPermissions['bureaucrat']['userrights'] = false;
351
    $wgGroupPermissions['*']['createaccount']       = false;
352
353
    foreach ($forbidden_permissions as $forbidden_permission) {
354
        $wgGroupPermissions['*'][$forbidden_permission]          = false;
355
        $wgGroupPermissions['user'][$forbidden_permission]       = false;
356
        $wgGroupPermissions['bot'][$forbidden_permission]        = false;
357
        $wgGroupPermissions['bureaucrat'][$forbidden_permission] = false;
358
        $wgGroupPermissions['sysop'][$forbidden_permission]      = false;
359
    }
360
361
    return $wgGroupPermissions;
362
}
363
364
function NoLinkOnMainPage(&$personal_urls){
365
    unset($personal_urls['anonlogin']);
366
    unset($personal_urls['anontalk']);
367
    unset($personal_urls['logout']);
368
    unset($personal_urls['login']);
369
    return true;
370
}
371
372
$wgHooks['PersonalUrls'][]='NoLinkOnMainPage';
373
374
if (isset($_SERVER['SERVER_SOFTWARE'])) {
375
	class SpecialForgeRedir extends SpecialPage {
376
		var $dstappendself = false;
377
378
		function getTitle($subpage="") {
379
			return 'SpecialForgeRedir';
380
		}
381
382
		function getRedirect($subpage="") {
383
			return $this;
384
		}
385
386
		function getRedirectQuery() {
387
			return $this;
388
		}
389
390
		function getFullUrl() {
391
			$u = $this->dst;
392
			if ($this->dstappendself) {
393
				$u .= urlencode(getStringFromServer('REQUEST_URI'));
394
			}
395
			return util_make_url($u);
396
		}
397
	}
398
399
	class SpecialForgeRedirLogin extends SpecialForgeRedir {
400
		var $dstappendself = true;
401
		var $dst = '/account/login.php?return_to=';
402
	}
403
404
	class SpecialForgeRedirCreateAccount extends SpecialForgeRedir {
405
		var $dst = '/account/register.php';
406
	}
407
408
	class SpecialForgeRedirResetPass extends SpecialForgeRedir {
409
		var $dst = '/account/lostpw.php';
410
	}
411
412
	class SpecialForgeRedirLogout extends SpecialForgeRedir {
413
		var $dstappendself = true;
414
		var $dst = '/account/logout.php?return_to=';
415
	}
416
417
	function DisableLogInOut(&$mList) {
418
		$mList['Userlogin'] = 'SpecialForgeRedirLogin';
419
		$mList['CreateAccount'] = 'SpecialForgeRedirCreateAccount';
420
		$mList['Resetpass'] = 'SpecialForgeRedirResetPass';
421
		$mList['Userlogout'] = 'SpecialForgeRedirLogout';
422
		return true;
423
	}
424
	$GLOBALS['wgHooks']['SpecialPage_initList'][] = 'DisableLogInOut';
425
}
426
427
$GLOBALS['wgHooks']['UserLoadFromSession'][] = 'TuleapMediawikiAuthentication';
428
429
if (! $is_tuleap_mediawiki_123) {
430
    //@see http://stackoverflow.com/questions/16893589/prevent-users-from-changing-their-passwords-in-mediawiki
431
    // Disallow password reset on password reset page
432
    $GLOBALS['wgHooks']['UserLoginMailPassword'][] = 'MailPasswordIsAllowed';
433
    function MailPasswordIsAllowed ( $username, $error ) {
434
        $error = wfMsg( 'resetpass_forbidden' );
435
        return false;
436
    }
437
438
    //Disallow password change on password change page (referred by link in user preferences):
439
    $GLOBALS['wgHooks']['PrefsPasswordAudit'][] = 'ChangePasswordIsAllowed';
440
    function ChangePasswordIsAllowed ( $user ) {
441
        throw new PasswordError( wfMsg( 'resetpass_forbidden' ));
442
        return false;
0 ignored issues
show
return false; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
443
    }
444
445
    //Hide password change link in user preferences:
446
    $GLOBALS['wgHooks']['GetPreferences'][] = 'HidePreferenceOptions';
447
    function HidePreferenceOptions ( $mw_user, &$preferences ) {
448
        global $user;
449
450
        $preferences['emailaddress']['default'] = $user->getEmail();
451
        unset($preferences['emailauthentication']);
452
        unset($preferences['password']);
453
454
        return true;
455
    }
456
}
457
458
$wgGroupPermissions = customizeMediawikiGroupsRights(
459
    $wgGroupPermissions,
460
    $manager,
461
    $fusionforgeproject,
462
    $forbidden_permissions,
463
    $read_permissions,
464
    $write_permissions
465
);
466
467
$wgFavicon     = '/images/icon.png' ;
468
$wgBreakFrames = false ;
469
470
if (forge_get_config('unbreak_frames', 'mediawiki')) {
471
	$wgEditPageFrameOptions = false;
472
}
473
474
ini_set ('memory_limit', '100M') ;
475
476
// LOAD THE SITE-WIDE AND PROJECT-SPECIFIC EXTRA-SETTINGS
477
if (is_file(forge_get_config('config_path')."/plugins/mediawiki/LocalSettings.php")) {
478
    include(forge_get_config('config_path')."/plugins/mediawiki/LocalSettings.php");
479
}
480
481
// debian style system-wide mediawiki extensions
482
if (is_file("/etc/mediawiki-extensions/extensions.php")) {
483
    include '/etc/mediawiki-extensions/extensions.php';
484
}
485
486
if (file_exists("$wgUploadDirectory/.wgLogo.png")) {
487
    $wgLogo = "$wgScriptPath/images/.wgLogo.png";
488
}
489
490
// forge global settings
491
if (is_file("$gconfig_dir/ForgeSettings.php")) {
492
    include ("$gconfig_dir/ForgeSettings.php") ;
493
}
494
// project specific settings
495
if (is_file("$project_dir/ProjectSettings.php")) {
496
    include ("$project_dir/ProjectSettings.php") ;
497
}
498
499
}
500
501
// Add Tuleap Skin
502
if ($is_tuleap_mediawiki_123) {
503
    $wgDefaultSkin    = 'tuleap123';
504
    $wgAutoloadClasses['Tuleap123'] = __DIR__."/skins/Tuleap123/Tuleap123.php";
505
    $wgValidSkinNames['tuleap123'] = 'Tuleap123';
506
    require_once $wgAutoloadClasses['Tuleap123'];
507
} else {
508
    $wgDefaultSkin    = 'tuleap';
509
    $wgAutoloadClasses['Tuleap'] = dirname(__FILE__)."/skins/Tuleap/Tuleap.php";
510
    $wgValidSkinNames['tuleap'] = 'Tuleap';
511
    require_once dirname(__FILE__)."/skins/Tuleap/Tuleap.php";
512
}
513
514
// ParserFunctions Extension inclusion
515
require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );
516
$wgPFEnableStringFunctions = true;
517
518
// SyntaxHighlight_GeSHi Extension inclusion
519
require_once "$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php";
520
521
// PdfBook Extension inclusion
522
require_once("$IP/extensions/PdfBook/PdfBook.php");
523
$wgPdfBookTab = true;
524
525
// Labeled Section Transclusion
526
require_once("$IP/extensions/LabeledSectionTransclusion/lst.php");
527
require_once("$IP/extensions/LabeledSectionTransclusion/lsth.php");
528
// CategoryTree
529
$wgUseAjax = true;
530
require_once("$IP/extensions/CategoryTree/CategoryTree.php");
531
532
// Cite
533
require_once "$IP/extensions/Cite/Cite.php";
534
535
// ImageMap
536
require_once "$IP/extensions/ImageMap/ImageMap.php";
537
538
// InputBox
539
require_once "$IP/extensions/InputBox/InputBox.php";
540
541
// UNC_links
542
$wgUrlProtocols = array(
543
    'http://',
544
    'https://',
545
    'ftp://',
546
    'ftps://', // If we allow ftp:// we should allow the secure version.
547
    'ssh://',
548
    'sftp://', // SFTP > FTP
549
    'irc://',
550
    'ircs://', // @bug 28503
551
    'xmpp:', // Another open communication protocol
552
    'sip:',
553
    'sips:',
554
    'gopher://',
555
    'telnet://', // Well if we're going to support the above.. -ævar
556
    'nntp://', // @bug 3808 RFC 1738
557
    'worldwind://',
558
    'mailto:',
559
    'tel:', // If we can make emails linkable, why not phone numbers?
560
    'sms:', // Likewise this is standardized too
561
    'news:',
562
    'svn://',
563
    'git://',
564
    'mms://',
565
    'bitcoin:', // Even registerProtocolHandler whitelists this along with mailto:
566
    'magnet:', // No reason to reject torrents over magnet: when they're allowed over http://
567
    'urn:', // Allow URNs to be used in Microdata/RDFa <link ... href="urn:...">s
568
    'geo:', // urls define geo locations, they're useful in Microdata/RDFa and for coordinates
569
    '//', // for protocol-relative URLs
570
);
571
572
if ($manager->isCompatibilityViewEnabled($group)) {
0 ignored issues
show
It seems like $group defined by $project_manager->getPro...me($fusionforgeproject) on line 100 can be null; however, MediawikiManager::isCompatibilityViewEnabled() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
573
    // WikiEditor Extension inclusion
574
    require_once("$IP/extensions/WikiEditor/WikiEditor.php");
575
576
    # Enables use of WikiEditor by default but still allow users to disable it in preferences
577
    $wgDefaultUserOptions['usebetatoolbar'] = 1;
578
    $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
579
580
    # Displays the Preview and Changes tabs
581
    $wgDefaultUserOptions['wikieditor-preview'] = 1;
582
583
    # Displays the Publish and Cancel buttons on the top right side
584
    $wgDefaultUserOptions['wikieditor-publish'] = 1;
585
}
586
587
// TuleapArtLinks Extension inclusion
588
require_once dirname(__FILE__) .'/../extensions/TuleapArtLinks/TuleapArtLinks.php';
589
$wgTuleapArtLinksGroupId = $group->getGroupId();
590
591
$mleb_manager_loader = new MediawikiMLEBExtensionManagerLoader();
592
$mleb_manager        = $mleb_manager_loader->getMediawikiMLEBExtensionManager();
593
594
if ($mleb_manager->isMLEBExtensionAvailableForProject($group) || (isset($IS_RUNNING_UPDATE) && $IS_RUNNING_UPDATE)) {
0 ignored issues
show
It seems like $group defined by $project_manager->getPro...me($fusionforgeproject) on line 100 can be null; however, MediawikiMLEBExtensionMa...onAvailableForProject() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
595
596
    $mleb_path = forge_get_config('extension_mleb_path', 'mediawiki');
597
598
    # Babelww
599
    require_once $mleb_path."/extensions/Babel/Babel.php";
600
601
    # CLDR
602
    require_once $mleb_path."/extensions/cldr/cldr.php";
603
604
    # CleanChanges
605
    require_once $mleb_path."/extensions/CleanChanges/CleanChanges.php";
606
    $wgCCTrailerFilter                = true;
607
    $wgCCUserFilter                   = false;
608
    $wgDefaultUserOptions['usenewrc'] = 1;
609
610
    # LocalisationUpdate
611
    require_once $mleb_path."/extensions/LocalisationUpdate/LocalisationUpdate.php";
612
    $wgLocalisationUpdateDirectory = $mleb_path."/cache";
613
614
    # Translate
615
    require_once $mleb_path."/extensions/Translate/Translate.php";
616
    $wgGroupPermissions['user']['translate']               = true;
617
    $wgGroupPermissions['user']['translate-messagereview'] = true;
618
    $wgGroupPermissions['user']['translate-groupreview']   = true;
619
    $wgGroupPermissions['user']['translate-import']        = true;
620
    $wgGroupPermissions['sysop']['pagetranslation']        = true;
621
    $wgGroupPermissions['sysop']['translate-manage']       = true;
622
    $wgExtraLanguageNames['qqq']                           = 'Message documentation'; # No linguistic content. Used for documenting messages
623
624
    require_once $mleb_path."/extensions/UniversalLanguageSelector/UniversalLanguageSelector.php";
625
    $GLOBALS['wgTranslatePageTranslationULS'] = true;
626
}
627