Skip to content

Commit

Permalink
Website: Default to the kitchen sink extension bundle
Browse files Browse the repository at this point in the history
Many reported issues are caused by Playground defaulting to the
"light" PHP build. It saves 6MB of initial downloads, but it confuses
new users with issues like [broken image editing](#1190).

This PR changes the PHP bundle loaded by default to the "kitchen sink"
one that ships with PHP extensions like finfo, GD, libxml.

 ## Testing instructions

* Confirm the e2e tests passed.
* Go to local Playground
* Visit "/phpinfo.php" in Playground, confirm libxml is enabled (the
  output should contain --enable-xmlreader)
* Open Playground configuration modal, uncheck the additional PHP
  extensions, confirm your choice
* Confirm phpinfo.php now reports libxmls is disabled
* Interact with that modal again, turn on the PHP extensions, confirm
  libxml is loaded again

CC @flexseth @dmsnell @bgrgicak @brandonpayton
  • Loading branch information
adamziel committed Apr 3, 2024
1 parent d0a0726 commit 99ba52b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/docs/site/docs/08-query-api/01-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You can go ahead and try it out. The Playground will automatically install the t
| `php` | `8.0` | Loads the specified PHP version. Supported values: `7.0`, `7.1`, `7.2`, `7.3`, `7.4`, `8.0`, `8.1`, `8.2`, `8.3`, `latest` |
| `wp` | `latest` | Loads the specified WordPress version. Supported values: `6.0`, `6.1`, `6.2`, `6.3`, `6.4`, `latest`, `nightly`, `beta` |
| `blueprint-url` | | The URL of the Blueprint that will be used to configure this Playground instance. |
| `php-extension-bundle` | | Loads a bundle of PHP extensions. Supported bundles: `kitchen-sink` (for gd, mbstring, iconv, openssl, libxml, xml, dom, simplexml, xmlreader, xmlwriter) |
| `php-extension-bundle` | | Loads a bundle of PHP extensions. Supported bundles: `kitchen-sink` (for finfo, gd, mbstring, iconv, openssl, libxml, xml, dom, simplexml, xmlreader, xmlwriter), `light` (saves 6MB of downloads, loads none of the above extensions) |
| `networking` | `yes` or `no` | Enables or disables the networking support for Playground. Defaults to `no` |
| `plugin` | | Installs the specified plugin. Use the plugin name from the plugins directory URL, e.g. for a URL like `https://wordpress.org/plugins/wp-lazy-loading/`, the plugin name would be `wp-lazy-loading`. You can pre-install multiple plugins by saying `plugin=coblocks&plugin=wp-lazy-loading&…`. Installing a plugin automatically logs the user in as an admin |
| `theme` | | Installs the specified theme. Use the theme name from the themes directory URL, e.g. for a URL like `https://wordpress.org/themes/disco/`, the theme name would be `disco`. Installing a theme automatically logs the user in as an admin |
Expand Down
3 changes: 2 additions & 1 deletion packages/docs/site/docs/09-blueprints-api/03-data-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ The `preferredVersions` property, unsurprisingly, declares the preferred of PHP

The `phpExtensionBundles` property is an array of PHP extension bundles to load. The following bundles are supported:

- `kitchen-sink`: Installs `gd`, `mbstring`, `iconv`, `openssl`, `libxml`, `xml`, `dom`, `simplexml`, `xmlreader`, `xmlwriter`
- `kitchen-sink`: Default choice. Installs `gd`, `mbstring`, `iconv`, `openssl`, `libxml`, `xml`, `dom`, `simplexml`, `xmlreader`, `xmlwriter`
- `light`: Saves 6MB of downloads, loads none of the above extensions.

## Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
},
"SupportedPHPExtensionBundle": {
"type": "string",
"const": "kitchen-sink"
"enum": ["kitchen-sink", "light"]
},
"StepDefinition": {
"type": "object",
Expand Down
12 changes: 9 additions & 3 deletions packages/playground/blueprints/src/lib/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ export function compileBlueprint(
});
}

if (!blueprint.phpExtensionBundles) {
blueprint.phpExtensionBundles = [];
}
// Default to the "kitchen sink" PHP extensions bundle if no
// other bundles are specified.
if (blueprint.phpExtensionBundles.length === 0) {
blueprint.phpExtensionBundles.push('kitchen-sink');
}

/**
* Download WP-CLI. {{{
* Hardcoding this in the compilt() function is a temporary solution
Expand All @@ -145,9 +154,6 @@ export function compileBlueprint(
(step) => typeof step === 'object' && step?.step === 'wp-cli'
);
if (wpCliStepIndex !== undefined && wpCliStepIndex > -1) {
if (!blueprint.phpExtensionBundles) {
blueprint.phpExtensionBundles = [];
}
if (!blueprint.phpExtensionBundles.includes('kitchen-sink')) {
blueprint.phpExtensionBundles.push('kitchen-sink');
console.warn(
Expand Down
20 changes: 16 additions & 4 deletions packages/playground/website/cypress/e2e/query-api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,26 @@ describe('Query API', () => {
});

describe('option `php-extension-bundle`', () => {
it('should load the specified PHP extensions', () => {
it('should load XMLWriter with the kitchen sink extension bundle', () => {
cy.visit('/?php-extension-bundle=kitchen-sink&url=/phpinfo.php');
cy.wordPressDocument()
.its('body')
.should('contain', '--enable-xmlwriter');
});

it('should not load XMLWriter with the light extension bundle', () => {
cy.visit('/?php-extension-bundle=light&url=/phpinfo.php');
cy.wordPressDocument()
.its('body')
.should('contain', '--disable-xmlwriter');
});

it('should default to the light extension bundle', () => {
cy.visit('/?url=/phpinfo.php');
cy.wordPressDocument()
.its('body')
.should('contain', '--disable-xmlwriter');
});
});

describe('option `networking`', () => {
Expand All @@ -73,9 +87,7 @@ describe('Query API', () => {
* @see https://github.com/WordPress/wordpress-playground/pull/1045
*/
it('should enable networking when requested AND the kitchen sink extension bundle is enabled', () => {
cy.visit(
'/?php-extension-bundle=kitchen-sink&networking=yes&url=/wp-admin/plugin-install.php'
);
cy.visit('/?networking=yes&url=/wp-admin/plugin-install.php');
cy.wordPressDocument()
.find('.plugin-card')
.should('have.length.above', 4);
Expand Down
11 changes: 1 addition & 10 deletions packages/playground/website/src/lib/resolve-blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ export async function resolveBlueprint() {
if (query.get('networking') === 'yes') {
features['networking'] = true;
}
let extensionBundles = query.getAll('php-extension-bundle') || [];
if (!extensionBundles.length) {
extensionBundles = ['kitchen-sink'];
} else if (
extensionBundles.length === 1 &&
extensionBundles[0] === 'light'
) {
extensionBundles = [];
}
blueprint = makeBlueprint({
php: query.get('php') || '8.0',
wp: query.get('wp') || 'latest',
Expand All @@ -74,7 +65,7 @@ export async function resolveBlueprint() {
features,
plugins: query.getAll('plugin'),
landingPage: query.get('url') || undefined,
phpExtensionBundles: extensionBundles,
phpExtensionBundles: query.getAll('php-extension-bundle') || [],
importSite: query.get('import-site') || undefined,
importContent: query.get('import-content') || undefined,
});
Expand Down
4 changes: 1 addition & 3 deletions packages/playground/website/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ const currentConfiguration: PlaygroundConfiguration = {
wp: blueprint.preferredVersions?.wp || 'latest',
php: resolveVersion(blueprint.preferredVersions?.php, SupportedPHPVersions),
storage: storage || 'none',
withExtensions: blueprint.phpExtensionBundles
? blueprint.phpExtensionBundles.length > 0
: false,
withExtensions: blueprint.phpExtensionBundles?.[0] !== 'light',
withNetworking: blueprint.features?.networking || false,
resetSite: false,
};
Expand Down

2 comments on commit 99ba52b

@flexseth
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave some room in the Advanced Administration pages for admins who want to limit what their Playground users can do. There may be some use cases for locking down file editing for simplicity when teaching.

Info added to the spreadsheet

@adamziel
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now they could embed Playground on a separate HTML page to avoid exposing the UI controls. UI tools to do that would be cool, but they're not a priority for now.

Please sign in to comment.