Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote to prod #3145

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions www/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if (Util::getSetting('cp_auth')) {
error_log($e->getMessage());
$route = "/";
$message = "There was a problem with you account. Please reach out to customer service." .
"Error number: 2000";
"Error number: 2000";

$host = Util::getSetting('host');
if (Util::getSetting('php_sessions')) {
Expand All @@ -65,7 +65,7 @@ if (Util::getSetting('cp_auth')) {
$message = "";
if (is_a($e, PortalException::class)) {
$message = "There was a problem with you account. Please reach out to customer service." .
"Error number: {$e->getErrorNumber()}";
"Error number: {$e->getErrorNumber()}";
} else {
$message = $e->getMessage();
}
Expand Down Expand Up @@ -375,7 +375,7 @@ if ($supportsAuth && $supportsCPAuth) {
require_once INCLUDES_PATH . '/common/AttachUser.php';
require_once INCLUDES_PATH . '/common/AttachSignupClient.php';
require_once INCLUDES_PATH . '/common/AttachBannerMessageManager.php';
// require_once INCLUDES_PATH . '/common/CheckCSRF.php';
// require_once INCLUDES_PATH . '/common/CheckCSRF.php';
}

// Load the test-specific data
Expand Down Expand Up @@ -531,7 +531,7 @@ if (strlen($id)) {
$controlTestUrlGenerator = UrlGenerator::create(FRIENDLY_URLS, "", $metaInfo['experiment']['control_id'], 0, 0);
$controlTestHref = $controlTestUrlGenerator->resultSummary();

$experimentResultsHref = "/video/compare.php?tests=" . $id . ',' . $metaInfo['experiment']['control_id'];
$experimentResultsHref = "/video/compare.php?tests=" . $id . ',' . $metaInfo['experiment']['control_id'] . ($req_fp ? "&fp=1" : '');
$experimentTestHref = "/result/" . $id;

$experimentOptsUrlGenerator = UrlGenerator::create(FRIENDLY_URLS, "", $id, 0, 0);
Expand Down Expand Up @@ -567,5 +567,6 @@ if (is_file(SETTINGS_PATH . '/custom_common.inc.php')) {
require_once INCLUDES_PATH . '/experiments/user_access.inc';

$request_context->setReadOnly(
!is_null($request_context->getUser()) && $request_context->getUser() && $request_context->getUser()->newPortalExperience()
isset($req_fp) ||
!is_null($request_context->getUser()) && $request_context->getUser() && $request_context->getUser()->newPortalExperience()
);
186 changes: 105 additions & 81 deletions www/include/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,29 @@ abstract class UrlGenerator
protected $step;
protected $baseUrl;
protected $testId;
protected $fp;

protected function __construct($baseUrl, $testId, $run, $cached, $step = 1)
{
global $req_fp;

$this->baseUrl = rtrim(strval($baseUrl), "/");
$this->testId = $testId;
$this->run = intval($run);
$this->cached = $cached ? true : false;
$this->step = $step;
$this->fp = $req_fp;
}

/**
* @param bool $friendlyUrls If the URL should be friendly (via mod_rewrite) or standard
* @param string $baseUrl URL base for the server (like http://my.wpt.server)
* @param string $testId ID of the test
* @param int $run Run number
* @param bool $cached True if cached run, false otherwise
* @param int $step The step number (1 by default)
* @return FriendlyUrlGenerator|StandardUrlGenerator A UrlGenerator for friendly or standard URLs
*/
/**
* @param bool $friendlyUrls If the URL should be friendly (via mod_rewrite) or standard
* @param string $baseUrl URL base for the server (like http://my.wpt.server)
* @param string $testId ID of the test
* @param int $run Run number
* @param bool $cached True if cached run, false otherwise
* @param int $step The step number (1 by default)
* @return FriendlyUrlGenerator|StandardUrlGenerator A UrlGenerator for friendly or standard URLs
*/
public static function create($friendlyUrls, $baseUrl, $testId, $run, $cached, $step = 1)
{
if ($friendlyUrls) {
Expand All @@ -42,127 +46,132 @@ public static function create($friendlyUrls, $baseUrl, $testId, $run, $cached, $
}
}

/**
* @param string $page Result page to generate the URL for
* @param string $extraParams|null Extra parameters to append (without '?' or '&' at start)
* @return string The generated URL
*/
/**
* @param string $page Result page to generate the URL for
* @param string $extraParams|null Extra parameters to append (without '?' or '&' at start)
* @return string The generated URL
*/
abstract public function resultPage($page, $extraParams = null);

/**
* @param string $image Image name to generate the thumbnail URL for
* @return string The generated URL
*/
/**
* @param string $image Image name to generate the thumbnail URL for
* @return string The generated URL
*/
abstract public function thumbnail($image);

/**
* @param string $image Generated image name to generate the URL for
* @return string The generated URL
*/
/**
* @param string $image Generated image name to generate the URL for
* @return string The generated URL
*/
abstract public function generatedImage($image);

/**
* @param bool $connectionView True for a connection view waterfall, false for the normal one.
* @param int $width Width of the generated image
* @param bool $withMime True if MIME data should be generated, false otherwise
* @return string The generated URL
*/
/**
* @param bool $connectionView True for a connection view waterfall, false for the normal one.
* @param int $width Width of the generated image
* @param bool $withMime True if MIME data should be generated, false otherwise
* @return string The generated URL
*/
abstract public function waterfallImage($connectionView, $width, $withMime);

/**
* @param string $extraParams|null Extra parameters to append (without '?' or '&' at start)
* @return string The generated URL
*/
/**
* @param string $extraParams|null Extra parameters to append (without '?' or '&' at start)
* @return string The generated URL
*/
abstract public function resultSummary($extraParams = null);

/**
* @return string The generated URL
*/
/**
* @return string The generated URL
*/
abstract public function optimizationChecklistImage();

/**
* @param string $file The name of the file to get with the URL
* @param string $video If it's a video-related file, this can be set to the corresponding video directory name
* @return string The generated URL
*/
/**
* @param string $file The name of the file to get with the URL
* @param string $video If it's a video-related file, this can be set to the corresponding video directory name
* @return string The generated URL
*/
public function getFile($file, $video = "")
{
$videoParam = $video ? "&video=" . $video : "";
$url = $this->baseUrl . "/getfile.php?test=" . $this->testId . $videoParam . "&file=" . $file;
return $url;
}

/**
* @param string $file The name of the file to get with the URL
* @return string The generated URL
*/
/**
* @param string $file The name of the file to get with the URL
* @return string The generated URL
*/
public function getGZip($file)
{
$compressedParam = (substr($file, -3) == ".gz") ? "&compressed=1" : "";
$url = $this->baseUrl . "/getgzip.php?test=" . $this->testId . $compressedParam . "&file=" . $file;
return $url;
}

/**
* @param string|int $requestNumber The request number to identify the response body
* @return string The generated URL
*/
/**
* @param string|int $requestNumber The request number to identify the response body
* @return string The generated URL
*/
public function responseBodyWithRequestNumber($requestNumber)
{
return $this->baseUrl . "/response_body.php?" . $this->urlParams() . "&request=" . strval($requestNumber);
$fpParam = $this->fp ? "&fp=$this->fp" : "";
return $this->baseUrl . "/response_body.php?" . $this->urlParams() . "&request=" . strval($requestNumber) . $fpParam;
}

/**
* @param int $bodyId The body ID to identify the response body
* @return string The generated URL
*/
/**
* @param int $bodyId The body ID to identify the response body
* @return string The generated URL
*/
public function responseBodyWithBodyId($bodyId)
{
return $this->baseUrl . "/response_body.php?" . $this->urlParams() . "&bodyid=" . strval($bodyId);
$fpParam = $this->fp ? "&fp=$this->fp" : "";
return $this->baseUrl . "/response_body.php?" . $this->urlParams() . "&bodyid=" . strval($bodyId) . $fpParam;
}

/**
* @param string $end Optional. A specific "end" to use for video creation
* @return string The generated URL to create a video
*/
/**
* @param string $end Optional. A specific "end" to use for video creation
* @return string The generated URL to create a video
*/
public function createVideo($end = null)
{
$tests = $this->testId . "-r:" . $this->run . "-c:" . ($this->cached ? 1 : 0);
$tests .= ($this->step > 1) ? ("-s:" . $this->step) : "";
$tests .= $end ? "-e:$end" : "";
$tests .= $this->fp ? "&fp=$this->fp" : "";
return $this->baseUrl . "/video/view.php?tests=" . $tests;
}

/**
* @param string $end Optional. A specific "end" to use for filmstrip view
* @return string The generated URL for the filmstrip view
*/
/**
* @param string $end Optional. A specific "end" to use for filmstrip view
* @return string The generated URL for the filmstrip view
*/
public function filmstripView($end = null)
{
$tests = $this->testId . "-r:" . $this->run . "-c:" . ($this->cached ? 1 : 0);
$tests .= ($this->step > 1) ? ("-s:" . $this->step) : "";
$tests .= $end ? "-e:$end" : "";
$tests .= $this->fp ? "&fp=$this->fp" : "";
return $this->baseUrl . "/video/compare.php?tests=" . $tests;
}


/**
* @param string $end Optional. A specific "end" to use for filmstrip view
* @return string The generated URL for the filmstrip view
*/
/**
* @param string $end Optional. A specific "end" to use for filmstrip view
* @return string The generated URL for the filmstrip view
*/
public function filmstripImage($end = null)
{
$tests = $this->testId . "-r:" . $this->run . "-c:" . ($this->cached ? 1 : 0);
$tests .= ($this->step > 1) ? ("-s:" . $this->step) : "";
$tests .= $end ? "-e:$end" : "";
$tests .= $this->fp ? "&fp=$this->fp" : "";
return $this->baseUrl . "/video/filmstrip.php?tests=" . $tests;
}

/**
* @param string $frame The thumbnail name
* @param int $fit Maximum size of the thumbnail
* @return string The URL for a thumbnail of the video frame
*/
/**
* @param string $frame The thumbnail name
* @param int $fit Maximum size of the thumbnail
* @return string The URL for a thumbnail of the video frame
*/
public function videoFrameThumbnail($frame, $fit, $options = null)
{
$file = "video_" . rtrim(strtolower($this->underscorePrefix()), "_") . "/" . $frame;
Expand All @@ -173,19 +182,19 @@ public function videoFrameThumbnail($frame, $fit, $options = null)
return $url;
}

/**
* @return string The generated URL to download all video frames
*/
/**
* @return string The generated URL to download all video frames
*/
public function downloadVideoFrames()
{
return $this->baseUrl . "/video/downloadFrames.php?" . $this->urlParams();
}

/**
* @param string $page Step-independent Result page to generate the URL for
* @param string $extraParams|null Extra parameters to append (without '?' or '&' at start)
* @return string The generated URL
*/
/**
* @param string $page Step-independent Result page to generate the URL for
* @param string $extraParams|null Extra parameters to append (without '?' or '&' at start)
* @return string The generated URL
*/
public function stepDetailPage($page, $extraParams = null)
{
$extraParams = $extraParams ? ("&" . $extraParams) : "";
Expand All @@ -201,7 +210,8 @@ protected function underscorePrefix()
protected function urlParams()
{
$stepParam = $this->step > 1 ? ("&step=" . $this->step) : "";
return "test=" . $this->testId . "&run=" . $this->run . ($this->cached ? "&cached=1" : "") . $stepParam;
$fpParam = $this->fp ? "&fp=$this->fp" : "";
return "test=" . $this->testId . "&run=" . $this->run . ($this->cached ? "&cached=1" : "") . $stepParam . $fpParam;
}
}

Expand All @@ -213,6 +223,7 @@ public function resultPage($page, $extraParams = null)
if ($this->cached) {
$url .= "cached/";
}
$extraParams = $this->prepareExtraParams($extraParams);
if ($extraParams != null) {
$url .= "?" . $extraParams;
}
Expand Down Expand Up @@ -241,7 +252,7 @@ public function generatedImage($image)
{
$parts = explode("_", $this->testId);
$testPath = substr($parts[0], 0, 2) . "/" . substr($parts[0], 2, 2) . "/" . substr($parts[0], 4, 2) .
"/" . $parts[1];
"/" . $parts[1];
if (sizeof($parts) > 2) {
$testPath .= "/" . $parts[2];
}
Expand All @@ -251,6 +262,7 @@ public function generatedImage($image)
public function resultSummary($extraParams = null)
{
$url = $this->baseUrl . "/result/" . $this->testId . "/";
$extraParams = $this->prepareExtraParams($extraParams);
if ($extraParams != null) {
$url .= "?" . $extraParams;
}
Expand All @@ -269,6 +281,17 @@ public function optimizationChecklistImage()
{
return $this->generatedImage("optimization");
}

private function prepareExtraParams($extraParams = null)
{
if (!$this->fp) {
return $extraParams;
}

return $extraParams
? ("fp=$this->fp&" . $extraParams)
: "fp=$this->fp";
}
}

class StandardUrlGenerator extends UrlGenerator
Expand Down Expand Up @@ -298,6 +321,7 @@ public function generatedImage($image)
public function resultSummary($extraParams = null)
{
$extraParams = $extraParams ? ("&" . $extraParams) : "";
$extraParams .= $this->fp ? "&fp=$this->fp" : "";
return $this->baseUrl . "/results.php?test=" . $this->testId . $extraParams;
}

Expand Down
Loading