From 6e4e0f9b86f1a0be5a60799281333bcd56ed8f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 13 Sep 2024 22:13:21 +0200 Subject: [PATCH] Website: Preview the PR specified by the referer header Enables easy linking to Playground PRs from WordPress and Gutenberg GitHub PRs without interpolating the PR number in the link. This PR adds a https://playground.wordpress.net/preview-referrer-pr.php script that looks at the Referer header, extracts the repo and the PR number from it, and redirects to the relevant PR previewer. ## Testing instructions 1. Run the script on a HTTPS domain (or use my link: https://adamadam.blog/referer.php) 2. Link to that script from a WordPress develop and a Gutenberg PR 3. Click those links 4. Confirm you were redirected to /wordpress.html or /gutenberg.html with a proper `?pr=` query parameter Props to @gziolo for the idea --- .../website/public/preview-referrer-pr.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 packages/playground/website/public/preview-referrer-pr.php diff --git a/packages/playground/website/public/preview-referrer-pr.php b/packages/playground/website/public/preview-referrer-pr.php new file mode 100644 index 0000000000..08ee3af3af --- /dev/null +++ b/packages/playground/website/public/preview-referrer-pr.php @@ -0,0 +1,18 @@ +\d+)/i', $referrer, $matches)) { + $prNumber = $matches['prNumber']; + header('Location: ./gutenberg.html?pr=' . $prNumber); + exit; +} else if (preg_match('/github\.com\/WordPress\/wordpress-develop\/pull\/(?\d+)/i', $referrer, $matches)) { + $prNumber = $matches['prNumber']; + header('Location: ./wordpress.html?pr=' . $prNumber); + exit; +} else { + header('HTTP/1.1 403 Forbidden'); + echo 'Invalid referrer'; + exit; +}