Generalize ResourceLoader 'excludepage' functionality
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 28 Feb 2017 20:52:17 +0000 (15:52 -0500)
committerKrinkle <krinklemail@gmail.com>
Wed, 25 Apr 2018 00:37:08 +0000 (00:37 +0000)
commit3f1142045f51328197239aa62882881003bb9cdb
tree41dfca0695c482b3ee9084d9c318ab13da9909ad
parent72886445ff1ecfc812b9335f5682fcb0434b0292
Generalize ResourceLoader 'excludepage' functionality

There has long been a hack for previewing edits to user JS/CSS, where
OutputPage would pass an 'excludepage' parameter to
ResourceLoaderUserModule to tell it not to load one particular page and
would instead embed that page statically. That's nice, but there are
other places where we could use the same thing.

This patch generalizes it:
* DerivativeResourceLoaderContext may now contain a callback for mapping
  titles to replacement Content objects.
* ResourceLoaderWikiModule::getContent() uses the overrides, and
  requests embedding when they're used. All subclasses in Gerrit should
  pick it up automatically.
* OutputPage gains methods for callers to add to the override mapping,
  which it passes on to RL. It loses a bunch of the special casing it
  had for the 'user' and 'user.styles' modules.
* EditPage sets the overrides on OutputPage when doing the preview, as
  does ApiParse for prop=headhtml. TemplateSandbox does too in I83fa0856.
* OutputPage::userCanPreview() gets less specific to editing user CSS
  and JS, since RL now handles the embedding based on the actual
  modules' dependencies and EditPage only requests it on preview.

ApiParse also gets a new hook to support TemplateSandbox's API
integration (used in I83fa0856).

Bug: T112474
Change-Id: Ib9d2ce42931c1de8372e231314a1f672d7e2ac0e
15 files changed:
RELEASE-NOTES-1.32
docs/hooks.txt
includes/EditPage.php
includes/OutputPage.php
includes/api/ApiParse.php
includes/resourceloader/DerivativeResourceLoaderContext.php
includes/resourceloader/ResourceLoaderClientHtml.php
includes/resourceloader/ResourceLoaderContext.php
includes/resourceloader/ResourceLoaderUserModule.php
includes/resourceloader/ResourceLoaderUserStylesModule.php
includes/resourceloader/ResourceLoaderWikiModule.php
tests/phpunit/includes/OutputPageTest.php
tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderContextTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php