/** * Writes an event to a file descriptor or socket. * Takes an event ID and an event, encodes it as query string, * and writes it to the UDP / TCP address or file specified by * $wgEventLoggingFile. If $wgEventLoggingFile is not set, returns * false without logging anything. * * @see wfErrorLog * * @param string $schema: Schema name. * @param integer $revId: revision ID of schema * @param array $event: Map of event keys/vals. * @return bool: Whether the event was logged. */ function efLogServerSideEvent($schemaName, $revId, $event) { global $wgDBname, $wgEventLoggingFile; if (!$wgEventLoggingFile) { return false; } wfProfileIn(__FUNCTION__); $remoteSchema = new RemoteSchema($schemaName, $revId); $schema = $remoteSchema->get(); try { $isValid = is_array($schema) && efSchemaValidate($event, $schema); } catch (JsonSchemaException $e) { $isValid = false; } $encapsulated = array('event' => $event, 'schema' => $schemaName, 'revision' => $revId, 'clientValidated' => $isValid, 'wiki' => $wgDBname, 'recvFrom' => gethostname(), 'timestamp' => $_SERVER['REQUEST_TIME']); if (isset($_SERVER['HTTP_HOST'])) { $encapsulated['webHost'] = $_SERVER['HTTP_HOST']; } // To make the resultant JSON easily extracted from a row of // space-separated values, we replace literal spaces with unicode // escapes. This is permitted by the JSON specs. $json = str_replace(' ', '\\u0020', FormatJson::encode($encapsulated)); wfErrorLog($json . "\n", $wgEventLoggingFile); wfProfileOut(__FUNCTION__); return true; }
/** * Gets the last modified timestamp of this module. * The last modified timestamp controls caching. Because revisions are * immutable, we don't need to get the revision's timestamp. We * simply return a timestamp of 1 (one second past epoch) if we were * unable to retrieve the schema, or the revision id if successful. * This ensures that clients will retrieve the schema when it becomes * available. * @param ResourceLoaderContext $context * @return integer: Unix timestamp. */ function getModifiedTime(ResourceLoaderContext $context) { return $this->schema->get() ? $this->schema->revision : 1; }