Page MenuHomePhabricator

Figure out the best way to inject RandomGameUnit CSS into output
Closed, ResolvedPublic

Description

Right now there are ~60 lines of CSS, usually labeled /** Casual Game **/, bundled with various skins (due to historical reasons) but not with the RandomGameUnit extension, which is absurd as well as a Performance-Team issue, since we send out those extra 60 lines of CSS to everyone everywhere if they happen to be using one of the relevant skins.
Likewise, then there's a related, similar issue: since this CSS is skin and not extension-specific as it should be, it means that the parser hook output will look bad on skins which do not bundle this CSS!

Basically we'll want something like Change-Id: I9c0f1375b5f15b83fe3bc4859841735bfbe0a0df, only for RandomGameUnit. But wait, there's more! (Hence this task.)

RandomGameUnit::registerTag() is the function which registers the <randomgameunit> parser hook (=hooked into ParserFirstCallInit). The callback which renders the HTML is RandomGameUnit::getRandomGameUnit() (originally called wfGetRandomGameUnit) and its signature looks like this:

public static function getRandomGameUnit( $input = '', $argsv = array() ) {

There is no third $parser argument, which means we can't use the same techique as in RandomFeaturedUser to inject the ResourceLoader module into the parser output, and $input as well as $argsv -- despite that both are unused in the function -- have default values. Why, you might ask? Because RandomGameUnit::getRandomGameUnit() has external callers, as witnessed by a quick grep:

./extensions/BlogPage/BlogPageClass.php:                return RandomGameUnit::getRandomGameUnit();
./extensions/LinkFilter/LinkPage.php:                   return RandomGameUnit::getRandomGameUnit();
./extensions/LinkFilter/SpecialLinksHome.php:                   return RandomGameUnit::getRandomGameUnit();
./skins/Nimbus/Nimbus.skin.php:                         echo RandomGameUnit::getRandomGameUnit();

In BlogPage::getRandomCasualGame(), we can simply use $this->getContext->getOutput()->addModuleStyles( 'name of our brand new yet-to-be-created RL module' ); to inject the CSS; the same fix should work for LinkPage::getRandomCasualGame(), too; LinksHome::getRandomCasualGame() seems completely unused and might need to be removed; but we're then left with the Nimbus skin, which, as the grep results above show, uses echo to output the HTML.
How do we inject a ResourceLoader module into the output in a BaseTemplate's execute()?

cc @Legoktm & @matmarex for comments

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

In the NimbusTemplate? $this->skin->getOutput()->addModuleStyles(...);

Change 359464 had a related patch set uploaded (by Jack Phoenix; owner: Jack Phoenix):
[mediawiki/extensions/RandomGameUnit@master] Version 2.5 -- add CSS to the output of the parser hook if and when possible

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

Change 359465 had a related patch set uploaded (by Jack Phoenix; owner: Jack Phoenix):
[mediawiki/extensions/BlogPage@master] Load RandomGameUnit CSS when appropriate

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

Change 359468 had a related patch set uploaded (by Jack Phoenix; owner: Jack Phoenix):
[mediawiki/extensions/LinkFilter@master] Load RandomGameUnit CSS when appropriate

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

Change 359469 had a related patch set uploaded (by Jack Phoenix; owner: Jack Phoenix):
[mediawiki/skins/Nimbus@master] Load RandomGameUnit CSS when appropriate

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

Change 359464 merged by jenkins-bot:
[mediawiki/extensions/RandomGameUnit@master] Version 2.5 -- add CSS to the output of the parser hook if and when possible

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

Change 359468 merged by jenkins-bot:
[mediawiki/extensions/LinkFilter@master] Load RandomGameUnit CSS when appropriate

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

Change 359465 merged by jenkins-bot:
[mediawiki/extensions/BlogPage@master] Load RandomGameUnit CSS when appropriate

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

Change 359469 merged by jenkins-bot:
[mediawiki/skins/Nimbus@master] Load RandomGameUnit CSS when appropriate

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

ashley claimed this task.
ashley removed a project: Patch-For-Review.

This should now be fixed. Thanks for the help, @Legoktm!