* @ingroup HTTP
*/
class WebRequest {
- protected $data, $headers = array();
+ protected $data, $headers = [];
/**
* Flag to make WebRequest::getHeader return an array of values.
// PATH_INFO is mangled due to http://bugs.php.net/bug.php?id=31892
// And also by Apache 2.x, double slashes are converted to single slashes.
// So we will use REQUEST_URI if possible.
- $matches = array();
+ $matches = [];
if ( !empty( $_SERVER['REQUEST_URI'] ) ) {
// Slurp out the path portion to examine...
$url = $_SERVER['REQUEST_URI'];
global $wgActionPaths;
if ( $wgActionPaths ) {
- $router->add( $wgActionPaths, array( 'action' => '$key' ) );
+ $router->add( $wgActionPaths, [ 'action' => '$key' ] );
}
global $wgVariantArticlePath, $wgContLang;
if ( $wgVariantArticlePath ) {
$router->add( $wgVariantArticlePath,
- array( 'variant' => '$2' ),
- array( '$2' => $wgContLang->getVariants() )
+ [ 'variant' => '$2' ],
+ [ '$2' => $wgContLang->getVariants() ]
);
}
- Hooks::run( 'WebRequestPathInfoRouter', array( $router ) );
+ Hooks::run( 'WebRequestPathInfoRouter', [ $router ] );
$matches = $router->parse( $path );
}
$proto = self::detectProtocol();
$stdPort = $proto === 'https' ? 443 : 80;
- $varNames = array( 'HTTP_HOST', 'SERVER_NAME', 'HOSTNAME', 'SERVER_ADDR' );
+ $varNames = [ 'HTTP_HOST', 'SERVER_NAME', 'HOSTNAME', 'SERVER_ADDR' ];
$host = 'localhost';
$port = $stdPort;
foreach ( $varNames as $varName ) {
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() {
+ static $reqId;
+
+ if ( !$reqId ) {
+ $reqId = isset( $_SERVER['UNIQUE_ID'] )
+ ? $_SERVER['UNIQUE_ID'] : wfRandomString( 24 );
+ }
+
+ return $reqId;
+ }
+
/**
* Get the current URL protocol (http or https)
* @return string
if ( substr( $path, 0, $baseLen ) == $base ) {
$raw = substr( $path, $baseLen );
if ( $raw !== '' ) {
- $matches = array( 'title' => rawurldecode( $raw ) );
+ $matches = [ 'title' => rawurldecode( $raw ) ];
if ( $key ) {
$matches[$key] = $keyValue;
}
}
}
}
- return array();
+ return [];
}
/**
$names = array_keys( $this->data );
}
- $retVal = array();
+ $retVal = [];
foreach ( $names as $name ) {
$value = $this->getGPCVal( $this->data, $name, null );
if ( !is_null( $value ) ) {
* @param array $exclude
* @return array
*/
- public function getValueNames( $exclude = array() ) {
+ public function getValueNames( $exclude = [] ) {
return array_diff( array_keys( $this->getValues() ), $exclude );
}
$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
+ */
+ public function getSessionId() {
+ return $this->sessionId;
+ }
+
/**
* Returns true if the request has a persistent session.
* This does not necessarily mean that the user is logged in!
}
/**
- * Return the path and query string portion of the request URI.
+ * Return the path and query string portion of the main request URI.
* This will be suitable for use as a relative link in HTML output.
*
* @throws MWException
* @return string
*/
- public function getRequestURL() {
+ public static function getGlobalRequestURL() {
if ( isset( $_SERVER['REQUEST_URI'] ) && strlen( $_SERVER['REQUEST_URI'] ) ) {
$base = $_SERVER['REQUEST_URI'];
} elseif ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] )
}
}
+ /**
+ * Return the path and query string portion of the request URI.
+ * This will be suitable for use as a relative link in HTML output.
+ *
+ * @throws MWException
+ * @return string
+ */
+ public function getRequestURL() {
+ return self::getGlobalRequestURL();
+ }
+
/**
* Return the request URI with the canonical service and hostname, path,
* and query string. This will be suitable for use as an absolute link
* @return string
*/
public function appendQueryValue( $key, $value ) {
- return $this->appendQueryArray( array( $key => $value ) );
+ return $this->appendQueryArray( [ $key => $value ] );
}
/**
$offset = 0;
}
- return array( $limit, $offset );
+ return [ $limit, $offset ];
}
/**
* @throws HttpError
* @return bool
*/
- public function checkUrlExtension( $extWhitelist = array() ) {
+ public function checkUrlExtension( $extWhitelist = [] ) {
$extWhitelist[] = 'php';
if ( IEUrlExtension::areServerVarsBad( $_SERVER, $extWhitelist ) ) {
if ( !$this->wasPosted() ) {
// http://www.thefutureoftheweb.com/blog/use-accept-language-header
$acceptLang = $this->getHeader( 'Accept-Language' );
if ( !$acceptLang ) {
- return array();
+ return [];
}
// Return the language codes in lower case
);
if ( !count( $lang_parse[1] ) ) {
- return array();
+ return [];
}
$langcodes = $lang_parse[1];
}
# Allow extensions to improve our guess
- Hooks::run( 'GetIP', array( &$ip ) );
+ Hooks::run( 'GetIP', [ &$ip ] );
if ( !$ip ) {
throw new MWException( "Unable to determine IP." );