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:

  • Understand current initialisation logic.
  • Understand current initialisation requirements.
  • Understand current initialisation performance. – T233886#5532734
  • Improve and simplify initialisation performance in a way that continues to satisfy current requirements.

Current code (Feb 2018)

From: /w/{entrypoint}.php:

  • include PHPVersionCheck
    • PHPVersionCheck::checkRequiredPHPVersion()
    • PHPVersionCheck::checkVendorExistence()
    • PHPVersionCheck::checkExtensionExistence()
  • include WebStart
    1. WebStart: assert php-env mbstring.func_overload
    2. WebStart: emit header X-Content-Type-Options: nosniff
    3. WebStart: global set $wgRequestTime
    4. WebStart: global unset $IP
    5. WebStart: define MEDIAWIKI
    6. WebStart: global set $IP
    7. WebStart: include Setup
      1. Setup: global set $wgProfiler
      2. Setup: include StartProfiler (conditional)
      3. Setup: include AutoLoader
      4. Setup: include Defines
      5. Setup: include DefaultSettings
      6. Setup: include GlobalFunctions
      7. Setup: include vendor/autoload (conditional)
      8. Setup: assert vendor
      9. Setup: php-env add HeaderCallback
      10. Setup: include LocalSettings
    8. WebStart: include OutputHandler (conditional)
    9. WebStart: register ob_start wfOutputHandler (conditional)
      1. OutputHandler: handle ValidateAllHtml (conditional)
      2. OutputHandler: handle compression (conditional)
      3. OutputHandler: emit header Content-Length (conditional)
    10. WebStart: include Setup [continued]
      1. Setup: process Profiler (implicit)
      2. Setup: process ExtensionRegistry
      3. Setup: php-env ensure mb_internal_encoding( .. )
      4. Setup: php-env ensure LC_ALL=..
      5. Setup: process mw-config phase1/2 (DefaultSettings, LocalSettings, shortcuts, derivatives, deprecations, normalising)
      6. Setup: process MWDebug
      7. Setup: process MediaWikiServices
      8. Setup: define MW_SERVICE_BOOTSTRAP_COMPLETE
      9. Setup: php-env add MWExceptionHandler
      10. Setup: include UtfNormalUtil
      11. Setup: Setup: assert validity of $wgArticlePath
      12. Setup: process mw-config phase2/2 (more defaults, shortcuts, normalising)
      13. Setup: php-env ensure wfMemoryLimit
      14. Setup: process singletons phase1/3 (wgMemc, messageMemc, parserMemc)
      15. Setup: process hooks for SetupAfterCache
      16. Setup: process singletons phase2/3 (wgContLang, wgAuth)
      17. Setup: php-env add MediaWiki\Session
      18. Setup: process singletons phase3/3 (wgUser, wgLang, wgOut, wgParser, wgTitle)
      19. Setup: process hooks for wgExtensionFunctions
      20. 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?

3: WebStart: global set $wgRequestTime

Deprecated since MediaWiki 1.25.

4: WebStart: global unset $IP

This sanity unset() seems redundant. It's unconditionally re-assigned two lines down. Can it be removed?

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.

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.

9A: OutputHandler: handle ValidateAllHtml (conditional)

See also T191670.

10A: Setup: process Profiler

10J: Setup: include UtfNormalUtil

10K: Setup: assert validity of $wgArticlePath

10L: Setup: process mw-config phase2 (more defaults, shortcuts, normalising)

Unsure why this is separate from the earlier "mw-config process" section.

10N: Setup: process singletons phase1/3 (wgMemc, messageMemc, parserMemc)


General ideas and themes (Original task description):

  • Reduce number of manually included files.
  • 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.

Related follow-up work: