This is a tracking task for various miscellaneous tasks relating to MediaWiki PHP set-up code. It will be resolved when the sub tasks added during Spring 2018, are resolved.
Goals:
* Reduce maintenance overhead by addressing Technical-Debt.
* Make the code easier to contribute to by simplifying it and improving its documentation.
* Improve startup performance, especially for stateless requests (api.php, load.php) and read-only routes.
Sub tasks:
[x] Understand current initialisation logic.
[ ] Understand current initialisation requirements.
[ ] Understand current initialisation performance.
[ ] Improve and simplify initialisation performance in a way that continues to satisfy current requirements.
### Current code (Feb 2018)
From: `/w/{entrypoint}.php`:
* include PHPVersionCheck
* include WebStart
## ~~WebStart: assert php-env mbstring.func_overload~~ {nav icon=check}
## WebStart: emit header `X-Content-Type-Options: nosniff`
## ~~WebStart: global set $wgRequestTime~~ {nav icon=check}
## ~~WebStart: global unset $IP~~ {nav icon=check}
## WebStart: define `MEDIAWIKI`
## WebStart: global set $IP
## WebStart: include Setup
### ~~Setup: global set $wgProfiler~~ {nav icon=check}
### ~~Setup: include StartProfiler (conditional)~~ {nav icon=check}
### Setup: include AutoLoader
### Setup: include Defines
### Setup: include DefaultSettings
### Setup: include GlobalFunctions
### Setup: include vendor/autoload (conditional)
### Setup: assert `vendor`
### Setup: php-env add `HeaderCallback`
### Setup: include LocalSettings
## ~~WebStart: include OutputHandler (conditional)~~ {nav icon=check}
## WebStart: register ob_start wfOutputHandler (conditional)
### ~~OutputHandler: handle ValidateAllHtml (conditional)~~ {nav icon=check}
### OutputHandler: handle compression (conditional)
### OutputHandler: emit header Content-Length (conditional)
## WebStart: include Setup //[continued]//
### Setup: process `Profiler` (implicit)
### Setup: process `ExtensionRegistry`
### Setup: php-env ensure `mb_internal_encoding( .. )`
### Setup: php-env ensure `LC_ALL=..`
### Setup: process mw-config (DefaultSettings, LocalSettings, shortcuts, derivatives, deprecations, normalising)
### Setup: process `MWDebug`
### Setup: process `MediaWikiServices`
### Setup: define `MW_SERVICE_BOOTSTRAP_COMPLETE`
### Setup: php-env add `MWExceptionHandler`
### Setup: include UtfNormalUtil
### Setup: Setup: assert validity of $wgArticlePath {nav icon=comment}
### Setup: process mw-config phase2 (more defaults, shortcuts, normalising) {nav icon=comment}
### Setup: php-env ensure wfMemoryLimit
### Setup: process singletons (wgMemc, messageMemc, parserMemc)
### Setup: process hooks for `SetupAfterCache`
### Setup: process singletons phase2 (wgContLang, wgAuth)
### Setup: php-env add `MediaWiki\Session`
### Setup: process singletons phase3 (wgUser, wgLang, wgOut, wgParser, wgTitle)
### Setup: process hooks for wgExtensionFunctions
### Setup: process Pingback
#### Issues
> 1: WebStart: assert php-env mbstring.func_overload
Unsure why this is in WebStart instead of Setup. Is it fine to apply this to CLI?
* Patch: <https://gerrit.wikimedia.org/r/427272> / 5c94aed0c3ab1 {nav icon=check, name=Merged}
> 3: WebStart: global set $wgRequestTime
Deprecated since MediaWiki 1.25.
* Remove usage: <https://gerrit.wikimedia.org/r/304465> / 06ba5ca383 {nav icon=check, name=Merged}
* Actual removal: <https://gerrit.wikimedia.org/r/427274> / 6fe856c4bd79 {nav icon=check, name=Merged}
> 4: WebStart: global unset $IP
This sanity `unset()` seems redundant. It's unconditionally re-assigned two lines down. Can it be removed?
* Patch: <https://gerrit.wikimedia.org/r/427267> / 3aa0b0567f {nav icon=check, name=Merged}
> 7A: Setup: global set $wgProfiler
> 7B: Setup: include StartProfiler (conditional)
Seems like this could be folded into DefaultSettings.php, with the StartProfiler include moved down a few lines. Should be safe given we don't reference it after DefaultSettings and LocalSettings load.
* Patch: <https://gerrit.wikimedia.org/r/420268> / 5209adff6cf {nav icon=check, name=Merged}
> 8: WebStart: include OutputHandler (conditional)
This (conditionally) includes a file that creates additional global functions. Should be safe to merge with GlobalFunctions and just load always. Alternatively, given this is after the autoloader, perhaps better as a class. That way also has the benefit of 1) keeping the private functions really private and 2) still only loading the file when needed.
* Patch: <https://gerrit.wikimedia.org/r/420223> / 665e9b7bf2 {nav icon=check, name=Merged}
> 9A: OutputHandler: handle ValidateAllHtml (conditional)
See also T191670.
* Patch: <https://gerrit.wikimedia.org/r/425093> / 0da97e7a03 {nav icon=check, name=Merged}
> 10K: Setup: assert validity of $wgArticlePath
Seems like this belongs to the "mw-config process" section that ended a few lines earlier.
* Patch: {nav icon=bell-o, name=TODO}
> 10L: Setup: process mw-config phase2 (more defaults, shortcuts, normalising)
Unsure why this is separate from the earlier "mw-config process" section.
* Patch: {nav icon=bell-o, name=TODO}
### Misc ideas and themes
(Early draft with ideas for different directions we could take.)
* Reduce number of manually included files.
** Centralise all global functions (remove OutputHandler.php?).
** Maybe move remaining unconditional includes to `composer.json`. We did this already for `includes/compat/Timestamp.php`. Doing so would automatically include them in Setup.php at `vendor/autoload.php`.
* Reduce amount of commonly executed code:
** Re-evaluate the way we normalise global configuration variables in Setup.php. We currently do it unconditionally because we want convenient access to them without needing to re-normalise at each call site. However, we are actively reducing use of global variables, typically using them (or the Config proxy) only in ServiceWiring.php and/or the constructor of a service class. Such class seems like a better place to perform normalisation than Setup.php. Benefits of doing so:
1. Still written and run from one place (just in the relevant class instead of Setup.php)
2. No longer unconditional on all requests.
3. **Testable** - the code for supporting older configuration formats can be covered with unit tests.
4. Maintained in context of the associated feature.
** Continue deprecating (some) global functions in favour auto-loaded class methods.
** Maybe start deprecating some constants in favour of auto-loaded class constants.