This commit is contained in:
Andrew Nicols
2025-11-25 08:04:09 +08:00
4 changed files with 6 additions and 35 deletions
@@ -0,0 +1,5 @@
issueNumber: MDL-87072
notes:
core:
- message: Removed $CFG->wwwrootendsinpublic flag to force users to configure their server accordingly.
type: removed
-7
View File
@@ -175,13 +175,6 @@ $CFG->dboptions = [
$CFG->wwwroot = 'http://example.com/moodle';
// Generally it is not advisable to use a wwwroot that ends in 'public'.
// This is because the 'public' directory is used to serve web-accessible content.
// Moodle looks for any URL which ends in 'public' and assumes that it is a misconfiguration.
// In the event that there is a need to have a wwwroot that ends in 'public', the
// following setting can be used to override this check.
$CFG->wwwrootendsinpublic = false;
//=========================================================================
// 3. DATA FILES LOCATION
//=========================================================================
+1 -13
View File
@@ -38,27 +38,15 @@ class setup {
throw new moodle_exception('wwwrootslash', 'error');
}
if (!$this->can_wwwroot_end_in_public() && $this->does_wwwroot_end_in_public()) {
if ($this->does_wwwroot_end_in_public()) {
// The wwwroot should not end in /public as this may suggest a misconfiguration.
// There may be legitimate sites out there that currently do this but it is not recommended.
// Where a site _does_ need to do this, then they can set the $CFG->wwwrootendsinpublic var to true.
throw new moodle_exception('wwwrootpublic', 'error');
}
return true;
}
/**
* Whether the wwwroot is allowed to end in public.
*
* @return bool
*/
protected function can_wwwroot_end_in_public(): bool {
global $CFG;
return property_exists($CFG, 'wwwrootendsinpublic') && $CFG->wwwrootendsinpublic;
}
/**
* Detect whether the wwwroot ends in /public.
*
-15
View File
@@ -29,7 +29,6 @@ final class setup_test extends \advanced_testcase {
#[\PHPUnit\Framework\Attributes\DataProvider('wwwroot_validity_provider')]
public function test_wwwroot_ends_in_slash(
string $wwwroot,
bool $mayendinpublic,
bool $valid,
?string $exceptionstring = null,
): void {
@@ -37,7 +36,6 @@ final class setup_test extends \advanced_testcase {
$this->resetAfterTest(true);
$CFG->wwwroot = $wwwroot;
$CFG->wwwrootendsinpublic = $mayendinpublic;
if (!$valid) {
$this->expectException(\core\exception\moodle_exception::class);
@@ -56,19 +54,16 @@ final class setup_test extends \advanced_testcase {
foreach (['https', 'http'] as $protocol) {
yield "Valid {$protocol} wwwroot on root domain" => [
"{$protocol}://example.com",
false,
true,
];
yield "Valid {$protocol} wwwroot on sub domain" => [
"{$protocol}://moodle.example.com",
false,
true,
];
yield "Valid {$protocol} wwwroot on directory" => [
"{$protocol}://example.com/moodle",
false,
true,
];
}
@@ -76,35 +71,25 @@ final class setup_test extends \advanced_testcase {
yield "Root domain ends in slash" => [
"https://example.com/",
false,
false,
get_string('wwwrootslash', 'error'),
];
yield "Sub domain ends in slash" => [
"https://moodle.example.com/",
false,
false,
get_string('wwwrootslash', 'error'),
];
yield "Directory ends in slash" => [
"https://example.com/moodle/",
false,
false,
get_string('wwwrootslash', 'error'),
];
yield "Directory ends in public and should not" => [
"https://example.com/public",
false,
false,
get_string('wwwrootpublic', 'error'),
];
yield "Directory ends in public and is allowed to" => [
"https://example.com/public",
true,
true,
];
}
}