[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Page MenuHomePhabricator

Audit and simplify MediaWiki initialisation code (Spring 2018)
Closed, ResolvedPublic

Description

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.

  • Patch: TODO

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:

Details

SubjectRepoBranchLines +/-
mediawiki/coremaster+3 -6
mediawiki/coremaster+53 -26
mediawiki/coremaster+13 -1
mediawiki/coremaster+8 -11
mediawiki/extensions/TitleBlacklistmaster+14 -12
mediawiki/extensions/SpamBlacklistmaster+15 -20
mediawiki/coremaster+3 -4
mediawiki/coremaster+105 -48
mediawiki/coremaster+3 -52
mediawiki/coremaster+52 -6
mediawiki/coremaster+18 -22
mediawiki/coremaster+12 -10
mediawiki/coremaster+57 -14
mediawiki/coremaster+0 -8
mediawiki/coremaster+26 -11
mediawiki/coremaster+31 -22
mediawiki/coremaster+1 -1
mediawiki/coremaster+63 -60
mediawiki/coremaster+1 -1
mediawiki/extensions/GlobalUsagemaster+2 -3
mediawiki/coremaster+1 -2
operations/mediawiki-configmaster+4 -0
mediawiki/coremaster+7 -4
mediawiki/coremaster+1 -24
mediawiki/coremaster+31 -15
mediawiki/extensions/Flowmaster+7 -9
mediawiki/coremaster+6 -12
mediawiki/coremaster+13 -16
mediawiki/coremaster+11 -3
mediawiki/coremaster+3 -10
mediawiki/coremaster+45 -47
operations/mediawiki-configmaster+13 -199
mediawiki/coremaster+1 -1
mediawiki/extensions/Wikibasemaster+6 -32
operations/mediawiki-configmaster+27 -25
mediawiki/coremaster+2 -12
operations/mediawiki-configmaster+0 -5
mediawiki/coremaster+2 -29
mediawiki/coremaster+5 -4
mediawiki/coremaster+2 -8
mediawiki/coreREL1_31+0 -2
mediawiki/coremaster+0 -2
mediawiki/coremaster+66 -51
mediawiki/coremaster+217 -214
Show related patches Customize query in gerrit

Related Objects

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

Change 533723 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Move MWDebug logic to MWDebug.php

https://gerrit.wikimedia.org/r/533723

Change 533773 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] WebRequest: Optimise WebRequest::getPathInfo()

https://gerrit.wikimedia.org/r/533773

Change 533869 had a related patch set uploaded (by Krinkle; owner: Derick Alangi):
[mediawiki/extensions/GlobalUsage@master] Avoid usage of deprecated $wgContLang global (dep in 1.32)

https://gerrit.wikimedia.org/r/533869

Change 533869 merged by jenkins-bot:
[mediawiki/extensions/GlobalUsage@master] Avoid usage of deprecated $wgContLang global (dep in 1.32)

https://gerrit.wikimedia.org/r/533869

Change 533716 merged by jenkins-bot:
[mediawiki/core@master] ProxyLookup: Optimise in_array in isConfiguredProxy()

https://gerrit.wikimedia.org/r/533716

Change 533773 merged by jenkins-bot:
[mediawiki/core@master] WebRequest: Optimise WebRequest::getPathInfo()

https://gerrit.wikimedia.org/r/533773

Change 534476 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] build: Update wikimedia/ip-set from 2.0.1 to 2.1.0

https://gerrit.wikimedia.org/r/534476

Change 534476 merged by jenkins-bot:
[mediawiki/core@master] build: Update wikimedia/ip-set from 2.0.1 to 2.1.0

https://gerrit.wikimedia.org/r/534476

Change 533723 merged by jenkins-bot:
[mediawiki/core@master] Setup: Move MWDebug logic to MWDebug.php

https://gerrit.wikimedia.org/r/533723

Change 533720 merged by jenkins-bot:
[mediawiki/core@master] Setup: Move wgActionPath logic to PathRouter

https://gerrit.wikimedia.org/r/533720

Change 538350 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Move wgArticlePath validation to its main consumer (PathRouter)

https://gerrit.wikimedia.org/r/538350

Change 538350 merged by jenkins-bot:
[mediawiki/core@master] Setup: Move wgArticlePath validation to its main consumer (PathRouter)

https://gerrit.wikimedia.org/r/538350

Change 579594 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Improve section docs to better explain the pre-config setup

https://gerrit.wikimedia.org/r/579594

Change 579598 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Move wgSkipSkins appendix to Skin::getAllowedSkins

https://gerrit.wikimedia.org/r/579598

Change 579594 merged by jenkins-bot:
[mediawiki/core@master] Setup: Improve section docs to better explain the pre-config setup

https://gerrit.wikimedia.org/r/579594

Change 579598 merged by jenkins-bot:
[mediawiki/core@master] Setup: Move wgSkipSkins appendix to Skin::getAllowedSkins

https://gerrit.wikimedia.org/r/579598

Change 579755 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Remove compat for $wgUseSquid and friends

https://gerrit.wikimedia.org/r/579755

Change 579762 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] languages: Move default $wgNamespaceAliases to MessagesEn.php

https://gerrit.wikimedia.org/r/579762

Change 579769 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Remove compat for $wgDisableCounters

https://gerrit.wikimedia.org/r/579769

Change 579781 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Remove $wgContLanguageCode

https://gerrit.wikimedia.org/r/579781

Change 579755 merged by jenkins-bot:
[mediawiki/core@master] Setup: Remove compat for $wgUseSquid and friends

https://gerrit.wikimedia.org/r/579755

Change 579762 merged by jenkins-bot:
[mediawiki/core@master] languages: Move default $wgNamespaceAliases to MessagesEn.php

https://gerrit.wikimedia.org/r/579762

Change 579769 merged by jenkins-bot:
[mediawiki/core@master] Setup: Remove compat for $wgDisableCounters

https://gerrit.wikimedia.org/r/579769

Change 579815 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[operations/mediawiki-config@master] [WIP] Remove "Cache-control: no-cache" hack from CommonSettings.php

https://gerrit.wikimedia.org/r/579815

Change 579781 merged by jenkins-bot:
[mediawiki/core@master] Remove $wgContLanguageCode

https://gerrit.wikimedia.org/r/579781

Change 533699 merged by jenkins-bot:
[mediawiki/extensions/SpamBlacklist@master] Remove use of internal $messageMemc variable

https://gerrit.wikimedia.org/r/533699

Change 533698 merged by jenkins-bot:
[mediawiki/extensions/TitleBlacklist@master] Remove use of internal $messageMemc variable

https://gerrit.wikimedia.org/r/533698

Change 582947 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] WebRequest: Avoid unused wfRandomString() call

https://gerrit.wikimedia.org/r/582947

Change 582947 merged by jenkins-bot:
[mediawiki/core@master] WebRequest: Avoid unused wfRandomString() call

https://gerrit.wikimedia.org/r/582947

Change 588172 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Document the responsibilities of entry points

https://gerrit.wikimedia.org/r/588172

Change 588172 merged by jenkins-bot:
[mediawiki/core@master] Setup: Document the responsibilities of entry points

https://gerrit.wikimedia.org/r/588172

@Krinkle would part of this be reducing the number of global functions?

Change 593365 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] upload: Move MinUploadChunkSize logic from Setup.php to ApiUpload

https://gerrit.wikimedia.org/r/593365

Change 593365 merged by jenkins-bot:
[mediawiki/core@master] upload: Move MinUploadChunkSize logic from Setup.php to ApiUpload

https://gerrit.wikimedia.org/r/593365

Krinkle removed a project: Patch-For-Review.

Declaring this done. I've gone through WebStart and Setup.php top to bottom.

I've removed a bunch of stuff. Optimised a bunch of stuff. And documented what's left in the header of those two files.

Everything there now seems trivial, and appropiate to exist in that early code. With the exception of some exensive legacy singleton and recent regressions. Those are tracked in the below tasks:

From the task description: