Page MenuHomePhabricator

Allow previewing a specific page when editing site JS/CSS (e.g. Common.css, Vector.js)
Closed, ResolvedPublic

Description

When one edits templates, there is a small box below the edit area which allows one to preview any page as it would look like after submitting the changes (from the TemplateSandbox extension)

Preview page with this template
Page title: [______________________________] [Show preview]

A similar feature should be made for Common.css/js and similar css/js pages which affect the whole wiki.

Event Timeline

He7d3r raised the priority of this task from to Needs Triage.
He7d3r updated the task description. (Show Details)
He7d3r subscribed.
Legoktm set Security to None.

This is something of an interesting idea, although it's expanding the scope of TemplateSandbox beyond transclusions. It would require that there be some way to tell ResourceLoader to use arbitrary text in place of the on-wiki js or css page it would normally use, which might be difficult since RL's work actually happens outside of the parse.

The ResourceLoaderUserModule class takes an excludepage parameter that removes it from the RL module and then the new JavaScript content is embedded in the page source (see OutputPage L3090).

The ResourceLoaderUserModule class takes an excludepage parameter that removes it from the RL module and then the new JavaScript content is embedded in the page source (see OutputPage L3090).

Yeah, I see that. I'm going to have to generalize it heavily to make it useful for this.

Would moving it to the parent ResourceLoaderWikiModule class be enough?

The part that really needs generalization is how OutputPage currently has special exceptions for the 'user' and 'user.styles' modules and edits of user JS/CSS in order to set that parameter. The plan I'm working on at the moment is roughly:

  • ResourceLoaderContext is able to map Titles to Content, something like ParserOptions does for the Parser with getCurrentRevisionCallback().
    • Actually it's DerivativeResourceLoaderContext that will do this, the ResourceLoaderContext version will be hard-coded for "no mappings".
  • ResourceLoaderClientHtml asks each module whether it uses the mappings in the context object that it's using for the request. If so, it embeds the whole module exactly as it does already for 'private' modules.
  • OutputPage no longer does any special casing. It just gets the Title-to-Content mapping injected by EditPage or TemplateSandbox and passes it into the RL context it passes to ResourceLoaderClientHtml.

I've already got some code started for this plan, although I went a wrong direction (passing an array of Title ⇒ Content instead of a callback for the first bullet) that I need to fix.

Change 340768 had a related patch set uploaded (by Anomie):
[mediawiki/core] Generalize ResourceLoader 'excludepage' functionality

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

Change 340769 had a related patch set uploaded (by Anomie):
[mediawiki/extensions/TemplateSandbox] Use new OutputPage::addContentOverride to allow previewing edits to JS/CSS

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

Change 340768 merged by jenkins-bot:
[mediawiki/core@master] Generalize ResourceLoader 'excludepage' functionality

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

Change 340769 merged by jenkins-bot:
[mediawiki/extensions/TemplateSandbox@master] Use new OutputPage::addContentOverride to allow previewing edits to JS/CSS

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

With the two patches merged, the functionality now exists, although there is no UI for it the way there is for the template editing page (Special:TemplateStyle works, and so does previewing the edited page itself). Should that be tracked here or in a separate task?

Could go either way. If you want to track it here, though, remove me as the assignee please. At least until a plan is made.

Change 808539 had a related patch set uploaded (by D3r1ck01; author: Derick Alangi):

[mediawiki/core@master] RL: Remove usage of `->getVal( 'excludepage' )`

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

Change 808539 merged by jenkins-bot:

[mediawiki/core@master] ResourceLoader: Remove support for UserModule "excludepage" parameter

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