} elseif ( $this->section == 'new' ) {
// Nothing *to* preview for new sections
return false;
- } elseif ( ( $request->getVal( 'preload' ) !== null || $this->mTitle->exists() )
+ } elseif ( ( $request->getCheck( 'preload' ) || $this->mTitle->exists() )
&& $this->context->getUser()->getOption( 'previewonfirst' )
) {
// Standard preference behavior
$this->scrolltop = $request->getIntOrNull( 'wpScrolltop' );
- if ( $this->textbox1 === '' && $request->getVal( 'wpTextbox1' ) === null ) {
+ if ( $this->textbox1 === '' && !$request->getCheck( 'wpTextbox1' ) ) {
// wpTextbox1 field is missing, possibly due to being "too big"
// according to some filter rules such as Suhosin's setting for
// suhosin.request.max_value_length (d'oh)
case self::AS_SUCCESS_NEW_ARTICLE:
$query = $resultDetails['redirect'] ? 'redirect=no' : '';
if ( $extraQueryRedirect ) {
- if ( $query === '' ) {
- $query = $extraQueryRedirect;
- } else {
- $query .= '&' . $extraQueryRedirect;
+ if ( $query !== '' ) {
+ $query .= '&';
}
+ $query .= $extraQueryRedirect;
}
$anchor = $resultDetails['sectionanchor'] ?? '';
$out->redirect( $this->mTitle->getFullURL( $query ) . $anchor );
);
if ( $resultDetails['redirect'] ) {
- if ( $extraQuery == '' ) {
- $extraQuery = 'redirect=no';
- } else {
- $extraQuery = 'redirect=no&' . $extraQuery;
+ if ( $extraQuery !== '' ) {
+ $extraQuery = '&' . $extraQuery;
}
+ $extraQuery = 'redirect=no' . $extraQuery;
}
if ( $extraQueryRedirect ) {
- if ( $extraQuery === '' ) {
- $extraQuery = $extraQueryRedirect;
- } else {
- $extraQuery .= '&' . $extraQueryRedirect;
+ if ( $extraQuery !== '' ) {
+ $extraQuery .= '&';
}
+ $extraQuery .= $extraQueryRedirect;
}
$out->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
return $wgParser->guessLegacySectionNameFromWikiText( $text );
}
// Meanwhile, real browsers get real anchors
- return $wgParser->guessSectionNameFromWikiText( $text );
+ $name = $wgParser->guessSectionNameFromWikiText( $text );
+ // With one little caveat: per T216029, fragments in HTTP redirects need to be urlencoded,
+ // otherwise Chrome double-escapes the rest of the URL.
+ return '#' . urlencode( mb_substr( $name, 1 ) );
}
/**
$request = $this->getRequest();
// JSONP mode
- if ( $request->getVal( 'callback' ) !== null ) {
+ if ( $request->getCheck( 'callback' ) ) {
$this->lacksSameOriginSecurity = true;
return true;
}
$logCtx = [
'$schema' => '/mediawiki/api/request/0.0.1',
'meta' => [
+ 'request_id' => WebRequest::getRequestId(),
'id' => UIDGenerator::newUUIDv1(),
- 'dt' => gmdate( 'c' ),
+ 'dt' => wfTimestamp( TS_ISO_8601 ),
'domain' => $this->getConfig()->get( 'ServerName' ),
'stream' => 'mediawiki.api-request'
],
'http' => [
'method' => $request->getMethod(),
- 'client_ip' => $request->getIP(),
- 'request_headers' => []
+ 'client_ip' => $request->getIP()
],
'database' => wfWikiID(),
'backend_time_ms' => (int)round( $time * 1000 ),
- 'params' => []
];
// If set, these headers will be logged in http.request_headers.
- // A http.request_headers entry should not be set if the header was not provided.
- if ( $request->getHeader( 'User-agent' ) ) {
- $logCtx['http']['request_headers']['user-agent'] = $request->getHeader( 'User-agent' );
- }
- if ( $request->getHeader( 'Api-user-agent' ) ) {
- $logCtx['http']['request_headers']['api-user-agent'] = $request->getHeader( 'Api-user-agent' );
+ $httpRequestHeadersToLog = [ 'accept-language', 'referer', 'user-agent' ];
+ foreach ( $httpRequestHeadersToLog as $header ) {
+ if ( $request->getHeader( $header ) ) {
+ // Set the header in http.request_headers
+ $logCtx['http']['request_headers'][$header] = $request->getHeader( $header );
+ }
}
- $logCtx['meta']['request_id'] =
- $logCtx['http']['request_headers']['x-request-id'] = WebRequest::getRequestId();
-
if ( $e ) {
$logCtx['api_error_codes'] = [];
foreach ( $this->errorMessagesFromException( $e ) as $msg ) {
/**
* Entry point
*
- * @param string $par
+ * @param string|null $par
*/
public function execute( $par ) {
$request = $this->getRequest();
// parameter, but also as part of the primary url. This can have PII implications
// in releasing page view data. As such issue a 301 redirect to the correct
// URL.
- if ( strlen( $par ) && !strlen( $term ) ) {
+ if ( $par !== null && $par !== '' && $term === '' ) {
$query = $request->getValues();
unset( $query['title'] );
// Strip underscores from title parameter; most of the time we'll want
$this->load();
// TODO: This performs database actions on GET request, which is going to
// be a problem for our multi-datacenter work.
- if ( !is_null( $request->getVal( 'nsRemember' ) ) ) {
+ if ( $request->getCheck( 'nsRemember' ) ) {
$this->saveNamespaces();
// Remove the token from the URL to prevent the user from inadvertently
// exposing it (e.g. by pasting it into a public wiki page) or undoing
}
$this->searchEngineType = $request->getVal( 'srbackend' );
- if (
- !$request->getVal( 'fulltext' ) &&
- $request->getVal( 'offset' ) === null
- ) {
+ if ( !$request->getVal( 'fulltext' ) && !$request->getCheck( 'offset' ) ) {
$url = $this->goResult( $term );
if ( $url !== null ) {
// successful 'go'