diff --git a/.upgradenotes/MDL-87072-2025112103293935.yml b/.upgradenotes/MDL-87072-2025112103293935.yml new file mode 100644 index 00000000000..048707c394c --- /dev/null +++ b/.upgradenotes/MDL-87072-2025112103293935.yml @@ -0,0 +1,5 @@ +issueNumber: MDL-87072 +notes: + core: + - message: Removed $CFG->wwwrootendsinpublic flag to force users to configure their server accordingly. + type: removed diff --git a/config-dist.php b/config-dist.php index 7a33f44748c..4bf70da9b32 100644 --- a/config-dist.php +++ b/config-dist.php @@ -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 //========================================================================= diff --git a/public/lib/classes/setup.php b/public/lib/classes/setup.php index 029590c193d..47f1cbd8b1b 100644 --- a/public/lib/classes/setup.php +++ b/public/lib/classes/setup.php @@ -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. * diff --git a/public/lib/tests/setup_test.php b/public/lib/tests/setup_test.php index ea6786b37a8..82626486065 100644 --- a/public/lib/tests/setup_test.php +++ b/public/lib/tests/setup_test.php @@ -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, - ]; } }