resourceloader: Refactor module links output
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 14 Nov 2013 16:54:19 +0000 (17:54 +0100)
committerOri.livneh <ori@wikimedia.org>
Fri, 4 Apr 2014 01:57:29 +0000 (01:57 +0000)
commit0088c506bb86d93055a4a335f78ed74c3a754173
tree0bfcdfc279eba4ed100974646f5c631ae14c6aaf
parent49bc9d3e1ead9b56b5cfed3de4b4bdeaaefc2567
resourceloader: Refactor module links output

Changes:

* Removed hardcoded logic in OutputPage regarding modules
  being "enabled".
  Previously we would always output state=loading and use
  $wgAllowUserJs (and others) to decide whether to output
  state=ready or makeResourceLoaderLink.

  Now, we no longer unconditionally output state=loading and
  simply always call makeResourceLoaderLink. That method takes
  care of checking whether modules are enabled and non-empty
  and returns state=ready when that is the case.

  This cleans up cases where the duplicated and incomplete logic
  in OutputPage thought the module was non-empty but turned out
  to be empty and thus would output both state=loading and later
  state=ready for the same module.

* Clean up documentation for makeResourceLoaderLink (inconsistent
  ordering of type hint and $var, and @return was missing the fact
  that the returned html can also contain <link>).

* makeResourceLoaderLink now returns an array of html and module
  states. This allows the consumer of this method to combine the
  states in 1 larger script tag on top of multiple
  makeResourceLoaderLink calls (e.g. one state script followed
  by multiple <script src=load.php>).
  This isn't to reduce html output, but to make sure we inform
  mw.loader about modules before the <script src=load.php>.
  If we were to mix/alternate the state script and load.php
  requests (which are blocking in html), it is possible for those
  scripts to request other modules. We need to prevent duplicate
  loading of modules we already know are going to be requested
  by the HTML output futher down.

* Removed spurious new line.

Example of change in HTML output:

* The output has been reduced from:
  - loader.state( site: loading, user: loading, user.groups: loading )
  - loader.load( .. )
  - <script src="load.php?modules=site ..">
  - loader.state( user: ready, user.groups: ready )

  to:
  - loader.state( site: loading, user: ready, user.groups: ready )
  - loader.load( .. )
  - <script src="load.php?modules=site ..">

Change-Id: I91754ce5fae3d05b4bfa7372372eba81ee2fc579
includes/OutputPage.php