Skip to content

Commit 4de0b7f

Browse files
authored
Merge branch 'main' into sesskey
2 parents 0cadf06 + 7913acd commit 4de0b7f

File tree

18 files changed

+258
-15
lines changed

18 files changed

+258
-15
lines changed

data/moodle-contributors.txt

+3
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ Hunkler
469469
Hunt
470470
Huong
471471
Hutchinson
472+
Huynh
472473
Hämmerle
473474
Hübler
474475
ISHIKAWA
@@ -871,6 +872,7 @@ Pinto
871872
Pisarev
872873
Piton
873874
Platts
875+
Poder
874876
Poggenpohl
875877
Pollak
876878
Poltawski
@@ -1157,6 +1159,7 @@ Walker
11571159
Wallis
11581160
Wandachowicz
11591161
Ward
1162+
Warwicker
11601163
Watson
11611164
Webster
11621165
Wedekind

docs/apis/_files/classes-dir.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import DefaultDescription from './classes-dir.mdx';
2121

2222
export default (initialProps: Props): ComponentFileSummary => (
2323
<ComponentFileSummary
24+
refreshedDuringPurge
2425
filepath="/classes/"
2526
summary="Autoloaded classes"
2627
defaultDescription={DefaultDescription}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- markdownlint-disable first-line-heading -->
2+
Details of legacy classes that have been moved to the classes directory to support autoloading but are not yet named properly.
3+
4+
:::note
5+
6+
Adding classes to `db/legacyclasses.php` is only necessary when the class is part of a _public_ API, or the class name cannot be changed.
7+
8+
:::
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (c) Moodle Pty Ltd.
3+
*
4+
* Moodle is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Moodle is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
import React from 'react';
18+
import { ComponentFileSummary } from '../../_utils';
19+
import type { Props } from '../../_utils';
20+
import DefaultDescription from './db-legacyclasses-php.mdx';
21+
22+
const defaultExample = `
23+
defined('MOODLE_INTERNAL') || die;
24+
25+
$legacyclasses = [
26+
'old_class_name' => 'path/within/classes/directory.php',
27+
28+
// Examples:
29+
\\coding_exception::class => 'exception/coding_exception.php',
30+
\\moodle_exception::class => 'exception/moodle_exception.php',
31+
32+
// Example loading a class from a different subsystem.
33+
// This should typically only be used in core.
34+
\\cache::class => [
35+
'core_cache', // The name of the subsystem to load from.
36+
'cache.php', // The file name within that filesystem's classes directory.
37+
],
38+
];
39+
`;
40+
41+
export default (initialProps: Props): ComponentFileSummary => (
42+
<ComponentFileSummary
43+
refreshedDuringPurge
44+
defaultExample={defaultExample}
45+
defaultDescription={DefaultDescription}
46+
filepath="/db/legacyclasses.php"
47+
summary="Legacy classes"
48+
examplePurpose="Legacy classes"
49+
{...initialProps}
50+
/>
51+
);

docs/apis/_files/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import DbInstallPHP from './db-install-php';
2626
import DbInstallXML from './install-xml';
2727
import DbMessagesPHP from './db-messages-php';
2828
import DbMobilePHP from './db-mobile-php';
29+
import DbLegacyclassesPHP from './db-legacyclasses-php';
2930
import DbRenamedclassesPHP from './db-renamedclasses-php';
3031
import DbServicesPHP from './db-services-php';
3132
import DbTasksPHP from './db-tasks-php';
@@ -57,6 +58,7 @@ export {
5758
DbInstallXML,
5859
DbMessagesPHP,
5960
DbMobilePHP,
61+
DbLegacyclassesPHP,
6062
DbRenamedclassesPHP,
6163
DbServicesPHP,
6264
DbTasksPHP,

docs/apis/commonfiles/index.mdx

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
DbInstallPHP,
1818
DbInstallXML,
1919
DbMessagesPHP,
20+
DbLegacyclassesPHP,
2021
DbRenamedclassesPHP,
2122
DbServicesPHP,
2223
DbTasksPHP,
@@ -99,6 +100,10 @@ import extraLangDescription from '../_files/lang-extra.md';
99100

100101
<DbRenamedclassesPHP />
101102

103+
### db/legacyclasses.php
104+
105+
<DbLegacyclassesPHP />
106+
102107
### classes/
103108

104109
<ClassesDir />

docs/apis/subsystems/check/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Checks are broken down into types, which roughly map to a step in the life cycle
5555

5656
Available from _/admin/environment.php_, environmental checks make sure that a Moodle instance is fully configured.
5757

58-
This page is a potential candidate to move to the new Check API but it slightly more complex than the other checks so hasn't been tackled yet. It would be a deeper change and this is intrinsically part of the install and upgrade system. It is not as critical to refactor as it is already possible for a plugin to declare its own checks, via either declarative [Environment checking](https://docs.moodle.org/dev/Environment_checking) or programmatically with a custom check:
58+
This page is a potential candidate to move to the new Check API but it slightly more complex than the other checks so it hasn't been tackled yet. It would be a deeper change and this is intrinsically part of the install and upgrade system. It is not as critical to refactor as it is already possible for a plugin to declare its own checks, via either declarative [Environment checking](https://docs.moodle.org/dev/Environment_checking) or programmatically with a custom check:
5959

6060
### Configuration checks
6161

docs/apis/subsystems/output/index.md

+97-2
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ Please note that this function is a stripped version of the full `format_text()`
278278

279279
Some interesting parameters for this function are:
280280

281-
- `striplinks`: Set to `false` to remove all links after the text has been processed by filters. Used when we want to show the text inside menus, page titles, etc. (Default is `true`)
281+
- `striplinks`: Set to `false` to keep all links after the text has been processed by filters. Used when we want to show the text inside menus, page titles, etc. (Default is `true`)
282282
- `options`
283283
- `options->context`: Context (id or object) for applying filters. If context is not specified it will be taken from `$PAGE->context` and may potentially result in displaying the same text differently on different pages. For example, all module-related information should have module context even when it appears in course-level reports, all course-related information such as name and description should have course context even when they are displayed on the front page or system pages.
284284
- `options->escape`: Set to `false` if you do not want to escape HTML entities. (Default is `true`)
285-
- `options->filter`: Set to `false` if you want to allow filters to process the text. This is ignored by `FORMAT_PLAIN` for which filters are never applied. (Default to `true`)
285+
- `options->filter`: Set to `false` if you do not want to allow filters to process the text. This is ignored by `FORMAT_PLAIN` for which filters are never applied. (Default is `true`)
286286

287287
### Simple elements rendering
288288

@@ -346,6 +346,101 @@ In the standard Boost theme this method will output a span using the [Bootstrap
346346
<span class="sr-only">Contents</span>
347347
```
348348

349+
### Other
350+
351+
#### Progress Bars
352+
353+
There are two types of progress bars you can use in Moodle.
354+
355+
##### Standard Progress Bars
356+
357+
The first is the old standard progress bar which updates as the page loads (ie. the page won't fully load until the progress bar is finished). It can be used to render the current process on the page, or via cli to render the progress of a script.
358+
359+
Example:
360+
361+
```php
362+
<?php
363+
define('NO_OUTPUT_BUFFERING', true); // Required if not used via cli.
364+
require 'config.php';
365+
366+
$PAGE->set_context(context_system::instance());
367+
$PAGE->set_url('/');
368+
369+
echo $OUTPUT->header();
370+
371+
$pb = new \core\output\progress_bar('bar', 500);
372+
$pb->create();
373+
$num_tasks = 500; // the number of tasks to be completed.
374+
for($cur_task = 0; $cur_task <= $num_tasks; $cur_task++)
375+
{
376+
for ($i=0; $i<100000; $i++)
377+
{
378+
;;;
379+
}
380+
$pb->update($cur_task, $num_tasks, 'this is'. $cur_task . 'h');
381+
}
382+
383+
echo $OUTPUT->footer();
384+
```
385+
386+
##### Stored Progress Bars
387+
388+
The other type of progress bar you can use is a stored progress bar, which can be used to store and update the progress of a long-running task in the database, and render live updates to the web page via AJAX web service polling.
389+
390+
It can be implemented into a CLI script. Example:
391+
392+
```php
393+
<?php
394+
395+
define('CLI_SCRIPT', true);
396+
397+
require_once('config.php');
398+
require_once($CFG->libdir . '/clilib.php');
399+
400+
$num_tasks = 5000; // the number of tasks to be completed.
401+
402+
$progress = new \core\output\stored_progress_bar('example-cli-bar');
403+
$progress->start();
404+
405+
for($cur_task = 0; $cur_task <= $num_tasks; $cur_task++)
406+
{
407+
$progress->update($cur_task, $num_tasks, 'this is '. $cur_task . '/' . $num_tasks);
408+
}
409+
410+
mtrace('DONE');
411+
```
412+
413+
Or a scheduled or adhoc task, via a trait. Example:
414+
415+
```php
416+
class stored_progress_scheduled_task_example extends \core\task\scheduled_task {
417+
418+
use \core\task\stored_progress_task_trait;
419+
420+
public function execute() {
421+
422+
// This simulates a specific count of iterations the task will do, e.g. x number of courses to loop through and do something.
423+
$iterations = 100;
424+
425+
$this->start_stored_progress(); // This creates the stored progress record for the named task.
426+
427+
for ($i = 1; $i <= $iterations; $i++) {
428+
429+
// Here we just update and tell it which one we are on and it will work out % from those.
430+
$this->progress->update($i, $iterations, 'i am at ' . $i . ' of ' . $iterations);
431+
sleep(1);
432+
433+
}
434+
435+
return true;
436+
437+
}
438+
439+
}
440+
```
441+
442+
With the stored progress bars, you can update the progress either via iterations, by passing in the total amount expected and then the current iteration, using `->update()`(see: previous example), this will calculate the percentage complete for you. Or you can use `->update_full()` to manually set the percentage complete.
443+
349444
## See also
350445

351446
- [HTML Guidelines](https://docs.moodle.org/dev/HTML_Guidelines)

docs/devupdate.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ https://yourmoodlesite/badges/edit.php?courseid=x&mode=new
3535

3636
#### `ABORT_AFTER_CONFIG`
3737

38-
<Since version="4.4" issueNumber="MDL-80275" />
38+
<Since version="4.5" issueNumber="MDL-80275" />
3939

4040
Prior to Moodle 4.5 only a small number of classes were compatible with scripts using the `ABORT_AFTER_CONFIG` constant.
4141

@@ -47,6 +47,27 @@ Please note that the same limitations regarding access to the Database, Session,
4747

4848
:::
4949

50+
#### Autoloading legacy classes
51+
52+
<Since version="4.5" issueNumber="MDL-81919" />
53+
54+
The Moodle class autoloader is now able to load legacy classes defined in the relevant `db/legacyclasses.php`. Files should only contain a single class.
55+
56+
```php title="Example entry in lib/db/legacyclasses.php"
57+
$legacyclasses = [
58+
// The legacy \moodle_exception class can be loaded from lib/classes/exception/moodle_exception.php.
59+
\moodle_exception::class => 'exception/moodle_exception.php',
60+
61+
// The legacy \cache class can be loaded from cache/classes/cache.php.
62+
\cache::class => [
63+
'core_cache',
64+
'cache.php',
65+
],
66+
];
67+
```
68+
69+
See MDL-81919 for further information on the rationale behind this change.
70+
5071
### SMS API
5172

5273
A new SMS API was introduced. See the [SMS API documentation](./apis/subsystems/sms/index.md) for more information.
@@ -142,3 +163,11 @@ class core_renderer extends \core_renderer {
142163
</TabItem>
143164

144165
</Tabs>
166+
167+
### Refactoring BS4 features dropped in BS5 using a "bridge"
168+
169+
<Since version="4.5" issueNumber="MDL-79917" />
170+
171+
Some of the Bootstrap 4 classes will be deprecated or dropped in its version 5. To prepare for this, some of the current Bootstrap 4 classes usages have been replaced with version 5 compatible classes using a "bridge". This will help us to upgrade to Bootstrap 5 in the future.
172+
173+
See more information in [Bootstrap 5 migration](./guides/bs5migration/index.md).

docs/guides/bs5migration/index.md

+30
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,33 @@ The `.no-gutters` grid class has been replaced with `.g-0`.
248248
```
249249

250250
</ValidExample>
251+
252+
### Close button
253+
254+
The `.close` class has been replaced with `.btn-close`.
255+
256+
<InvalidExample title="Don't">
257+
258+
```html
259+
<div class="alert alert-warning alert-dismissible" role="alert">
260+
I'm an alert.
261+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
262+
<span aria-hidden="true">&times;</span>
263+
</button>
264+
</div>
265+
```
266+
267+
</InvalidExample>
268+
269+
<ValidExample title="Do">
270+
271+
```html
272+
<div class="alert alert-warning alert-dismissible" role="alert">
273+
I'm an alert.
274+
<button type="button" class="btn-close" data-dismiss="alert" aria-label="Close">
275+
<span aria-hidden="true">&times;</span>
276+
</button>
277+
</div>
278+
```
279+
280+
</ValidExample>

general/development/policies/codingstyle/index.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,21 @@ All functions and methods should have a complete docblock like this:
19361936

19371937
You must include a description even if it appears to be obvious from the `@param` and/or `@return` lines.
19381938

1939-
An exception is made for overridden methods which make no change to the meaning of the parent method and maintain the same arguments/return values. In this case you should omit the comment completely. Use of the `@inheritdoc` or `@see` tags is explicitly forbidden as a replacement for any complete docblock.
1939+
An exception is made for overridden methods which make no change to the meaning of the parent method and maintain the same arguments/return values. In this case you should omit the comment completely, and apply the `#[\Override]` attribute. This can safely be applied in older versions of PHP before the attribute was supported. Use of the `@inheritdoc` or `@see` tags is explicitly forbidden as a replacement for any complete docblock.
1940+
1941+
<ValidExample>
1942+
1943+
```php
1944+
class example implements templatable {
1945+
1946+
#[\Override]
1947+
public function export_for_template(renderer_base $output) {
1948+
return ['foo' => 'bar'];
1949+
}
1950+
}
1951+
```
1952+
1953+
</ValidExample>
19401954

19411955
### Defines
19421956

@@ -2056,6 +2070,10 @@ To get the full list of exception types, search for the regular expression 'clas
20562070

20572071
Where appropriate, you should create new subclasses of moodle_exception for use in your code.
20582072

2073+
<Since version="4.5" issueNumber="MDL-81903" />
2074+
2075+
If you create a custom exception class it *may* live in the `classes/exception/` directory, and be namespaced in `<plugin>/exception/`
2076+
20592077
A few notable exception types:
20602078

20612079
- `moodle_exception`: base class for exceptions in Moodle. Use this when a more specific type is not appropriate.

general/development/tools/behat/writing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ In PhpStorm or IntelliJ you can install the behat extension. Then you get auto c
113113

114114
Most of the steps requires values, there are methods to provide values to steps, the method depends on the step specification.
115115

116-
- **A string/text** is the most common case, the texts are wrapped between double quotes (`"` character) you have to replace the info about the expected value for your value; for example something like **I press "BUTTON_STRING"** should become **I press "Save and return to course"**. If you want to add a string which contains a " character, you can escape it with \", for example **I fill the "Name" field with "Alan alias \"the legend\""**. You can identify this steps because they ends with **_STRING**
116+
- **A string/text** is the most common case, the texts are wrapped between double quotes (`"` character) you have to replace the info about the expected value for your value; for example something like **I press "BUTTON_STRING"** should become **I press "Save and return to course"**. If you want to add a string which contains a " character, you can escape it with a backslash `\"`, for example **I fill the "Name" field with "Alan alias \\"the legend\\""**. You can identify this steps because they ends with **_STRING**
117117
- **A number** some steps requires numbers as values, to be more specific an undetermined number of digits from 0 to 9 (Natural numbers + 0) you can identify them because the expected value info string ends with **_NUMBER**
118118
- **A table**; is a relation between values, the most common use of it is to fill forms. The steps which requires tables are easily identifiable because they finish with **:** The steps description gives info about what the table columns must contain, for example **Fills a moodle form with field/value data**. Here you don't need to escape the double quotes if you want to include them as part of the value.
119119
- **A PyString** is a multiline string, most commonly used to fill out forms when a newline is required. Like steps with tables, steps which require PyStrings will end with ":"

project-words.txt

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ langindex
195195
lastaccess
196196
lastname
197197
lastruntime
198+
legacyclasses
198199
locallib
199200
loglevel
200201
mainmenu

versioned_docs/version-4.1/guides/javascript/modal/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ We highly recommend declaring the _template_ as a static property on the class t
145145

146146
```javascript title="mod/example/amd/src/my_modal.js"
147147
import Modal from 'core/modal';
148-
import ModalFactory from 'core/modal_factory';
148+
import ModalRegistry from 'core/modal_registry';
149149

150150
export default class MyModal extends Modal {
151151
static TYPE = "mod_example/my_modal";

0 commit comments

Comments
 (0)