* @file
*/
+use MediaWiki\Session\Session;
+use MediaWiki\Session\SessionId;
use MediaWiki\Session\SessionManager;
/**
*/
const GETHEADER_LIST = 1;
+ /**
+ * The unique request ID.
+ * @var string
+ */
+ private static $reqId;
+
/**
* Lazy-init response object
* @var WebResponse
protected $protocol;
/**
- * @var \\MediaWiki\\Session\\SessionId|null Session ID to use for this
+ * @var SessionId|null Session ID to use for this
* request. We can't save the session directly due to reference cycles not
* working too well (slow GC in Zend and never collected in HHVM).
*/
return microtime( true ) - $this->requestTime;
}
+ /**
+ * Get the unique request ID.
+ * This is either the value of the UNIQUE_ID envvar (if present) or a
+ * randomly-generated 24-character string.
+ *
+ * @return string
+ * @since 1.27
+ */
+ public static function getRequestId() {
+ if ( !self::$reqId ) {
+ self::$reqId = isset( $_SERVER['UNIQUE_ID'] )
+ ? $_SERVER['UNIQUE_ID'] : wfRandomString( 24 );
+ }
+
+ return self::$reqId;
+ }
+
+ /**
+ * Override the unique request ID. This is for sub-requests, such as jobs,
+ * that wish to use the same id but are not part of the same execution context.
+ *
+ * @param string $id
+ * @since 1.27
+ */
+ public static function overrideRequestId( $id ) {
+ self::$reqId = $id;
+ }
+
/**
* Get the current URL protocol (http or https)
* @return string
* @since 1.27
* @note For performance, keep the session locally if you will be making
* much use of it instead of calling this method repeatedly.
- * @return MediaWiki\\Session\\Session
+ * @return Session
*/
public function getSession() {
if ( $this->sessionId !== null ) {
/**
* Set the session for this request
* @since 1.27
- * @private For use by MediaWiki\\Session classes only
- * @param MediaWiki\\Session\\SessionId $sessionId
+ * @private For use by MediaWiki\Session classes only
+ * @param SessionId $sessionId
*/
- public function setSessionId( MediaWiki\Session\SessionId $sessionId ) {
+ public function setSessionId( SessionId $sessionId ) {
$this->sessionId = $sessionId;
}
/**
* Get the session id for this request, if any
* @since 1.27
- * @private For use by MediaWiki\\Session classes only
- * @return MediaWiki\\Session\\SessionId|null
+ * @private For use by MediaWiki\Session classes only
+ * @return SessionId|null
*/
public function getSessionId() {
return $this->sessionId;
* This does not necessarily mean that the user is logged in!
*
* @deprecated since 1.27, use
- * \\MediaWiki\\Session\\SessionManager::singleton()->getPersistedSessionId()
+ * \MediaWiki\Session\SessionManager::singleton()->getPersistedSessionId()
* instead.
* @return bool
*/