private function sassProcessing() { global $IP, $wgSassExecutable, $wgDevelEnvironment; wfProfileIn(__METHOD__); $tempDir = sys_get_temp_dir(); //replace \ to / is needed because escapeshellcmd() replace \ into spaces (?!!) $tempOutFile = str_replace('\\', '/', tempnam($tempDir, 'Sass')); $tempDir = str_replace('\\', '/', $tempDir); $params = urldecode(http_build_query($this->mParams, '', ' ')); $cmd = "{$wgSassExecutable} {$IP}/{$this->mOid} {$tempOutFile} --cache-location {$tempDir}/sass -r {$IP}/extensions/wikia/SASS/wikia_sass.rb {$params}"; $escapedCmd = escapeshellcmd($cmd) . " 2>&1"; $sassResult = shell_exec($escapedCmd); if ($sassResult != '') { Wikia::log(__METHOD__, false, "commandline error: " . $sassResult . " -- Full commandline was: {$escapedCmd}", true); Wikia::log(__METHOD__, false, "Full commandline was: {$escapedCmd}", true); Wikia::log(__METHOD__, false, AssetsManager::getRequestDetails(), true); if (file_exists($tempOutFile)) { unlink($tempOutFile); } if (!empty($wgDevelEnvironment)) { $exceptionMsg = "Problem with SASS processing: {$sassResult}"; } else { $exceptionMsg = 'Problem with SASS processing. Check the PHP error log for more info.'; } throw new Exception("/* {$exceptionMsg} */"); } $this->mContent = file_get_contents($tempOutFile); unlink($tempOutFile); wfProfileOut(__METHOD__); }
public function __construct(WebRequest $request) { parent::__construct($request); global $IP; if (strpos($this->mOid, '..') !== false) { throw new Exception('File path must not contain \'..\'.'); } if (endsWith($this->mOid, '.js', false)) { $this->mContentType = AssetsManager::TYPE_JS; } else { if (endsWith($this->mOid, '.css', false)) { $this->mContentType = AssetsManager::TYPE_CSS; } else { throw new Exception('Requested file must be .css or .js.'); } } $filePath = $IP . '/' . $this->mOid; if (file_exists($filePath)) { $this->mContent = file_get_contents($filePath); } else { $requestDetails = AssetsManager::getRequestDetails(); Wikia::log(__METHOD__, false, "file '{$filePath}' doesn't exist ({$requestDetails})", true); throw new Exception('File does not exist'); } }
function __construct($message) { // add referer and user agent info to the exception message $details = AssetsManager::getRequestDetails(); $message .= " ({$details})"; parent::__construct($message); }
public static function serve(WebRequest $request) { try { switch ($request->getText('type')) { case 'one': $builder = new AssetsManagerOneBuilder($request); break; case 'group': $builder = new AssetsManagerGroupBuilder($request); break; case 'groups': $builder = new AssetsManagerGroupsBuilder($request); break; case 'sass': $builder = new AssetsManagerSassBuilder($request); break; default: Wikia::log(__METHOD__, false, "Unknown type: {$_SERVER['REQUEST_URI']}", true); Wikia::log(__METHOD__, false, AssetsManager::getRequestDetails(), true); throw new Exception('Unknown type.'); } } catch (Exception $e) { header('HTTP/1.1 404 Not Found'); echo $e->getMessage(); return; } $headers = array(); if ($builder->getContentType()) { $headers['Content-Type'] = $builder->getContentType(); } // BugId:31327 $headers['Vary'] = $builder->getVary(); $cacheDuration = $builder->getCacheDuration(); if ($cacheDuration > 0) { $headers['Expires'] = gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime($cacheDuration . ' seconds')); $headers['X-Pass-Cache-Control'] = $builder->getCacheMode() . ', max-age=' . $cacheDuration; $headers['Cache-Control'] = $builder->getCacheMode() . ', max-age=' . $cacheDuration; } $headers['Last-Modified'] = gmdate('D, d M Y H:i:s \\G\\M\\T'); foreach ($headers as $k => $v) { header($k . ': ' . $v); } echo $builder->getContent(); }
/** * Returns assets array for particular group. If group does not exists in config then returns empty array * * @author Inez Korczyński <*****@*****.**> */ protected function getGroupAssets($groupName) { $this->load(); if (is_string($groupName) && isset($this->mConfig[$groupName])) { return $this->mConfig[$groupName]['assets']; } else { $requestDetails = AssetsManager::getRequestDetails(); Wikia::log(__METHOD__, false, "group '{$groupName}' doesn't exist ({$requestDetails})", true); return array(); } }
public static function serve(WebRequest $request) { $type = $request->getText('type'); try { switch ($type) { case 'one': $builder = new AssetsManagerOneBuilder($request); break; case 'group': $builder = new AssetsManagerGroupBuilder($request); break; case 'groups': $builder = new AssetsManagerGroupsBuilder($request); break; case 'sass': $builder = new AssetsManagerSassBuilder($request); break; case 'sasses': $builder = new AssetsManagerSassesBuilder($request); break; default: Wikia::log(__METHOD__, false, "Unknown type: {$_SERVER['REQUEST_URI']}", true); Wikia::log(__METHOD__, false, AssetsManager::getRequestDetails(), true); throw new Exception('Unknown type.'); } } catch (Exception $e) { header('HTTP/1.1 404 Not Found'); echo $e->getMessage(); return; } // do not log illegal request type (one/group/groups/sass supported only) - not to pollute // logs Transaction::setEntryPoint(Transaction::ENTRY_POINT_ASSETS_MANAGER); if (function_exists('newrelic_disable_autorum')) { newrelic_disable_autorum(); } $headers = array(); if ($builder->getContentType()) { $headers['Content-Type'] = $builder->getContentType(); } // BugId:31327 $headers['Vary'] = $builder->getVary(); $cacheDuration = $builder->getCacheDuration(); // render the response try { $content = $builder->getContent(); } catch (Exception $e) { // return HTTP 503 in case of SASS processing error (BAC-592) // Varnish will cache such response for 5 seconds header('HTTP/1.1 503'); // log exception messages \Wikia\Logger\WikiaLogger::instance()->error('AssetsManagerServer::serve failed', ['type' => $type, 'exception' => $e]); // emit full message on devboxes only global $wgDevelEnvironment; $content = !empty($wgDevelEnvironment) ? $msg = $e->getMessage() : '/* SASS processing failed! */'; } if ($cacheDuration > 0) { $headers['Cache-Control'] = 'public, max-age=' . $cacheDuration['server']; $headers['X-Pass-Cache-Control'] = 'public, max-age=' . $cacheDuration['client']; } $headers['Last-Modified'] = gmdate('D, d M Y H:i:s \\G\\M\\T'); // Add X-Served-By and X-Backend-Response-Time response headers to MediaWiki pages // See BAC-550 for details // @macbre global $wgRequestTime; $headers['X-Served-By'] = wfHostname(); $headers['X-Backend-Response-Time'] = round(microtime(true) - $wgRequestTime, 3); foreach ($headers as $k => $v) { header($k . ': ' . $v); } echo $content; }