<?php
+use Wikimedia\Rdbms\DBQueryError;
use Wikimedia\TestingAccessWrapper;
/**
* @param int $status Expected response status
* @param array $options Array of options:
* post => true Request is a POST
- * cdn => true CDN is enabled ($wgUseSquid)
+ * cdn => true CDN is enabled ($wgUseCdn)
*/
public function testCheckConditionalRequestHeaders(
$headers, $conditions, $status, $options = []
$priv->mInternalMode = false;
if ( !empty( $options['cdn'] ) ) {
- $this->setMwGlobals( 'wgUseSquid', true );
+ $this->setMwGlobals( 'wgUseCdn', true );
}
// Can't do this in TestSetup.php because Setup.php will override it
}
public static function provideCheckConditionalRequestHeaders() {
- global $wgSquidMaxage;
+ global $wgCdnMaxAge;
$now = time();
return [
[ [ 'If-Modified-Since' => 'a potato' ],
[ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 200 ],
- // Anything before $wgSquidMaxage seconds ago should be considered
+ // Anything before $wgCdnMaxAge seconds ago should be considered
// expired.
'If-Modified-Since with CDN post-expiry' =>
- [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgSquidMaxage * 2 ) ],
- [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgSquidMaxage * 3 ) ],
+ [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgCdnMaxAge * 2 ) ],
+ [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgCdnMaxAge * 3 ) ],
200, [ 'cdn' => true ] ],
'If-Modified-Since with CDN pre-expiry' =>
- [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgSquidMaxage / 2 ) ],
- [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgSquidMaxage * 3 ) ],
+ [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgCdnMaxAge / 2 ) ],
+ [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgCdnMaxAge * 3 ) ],
304, [ 'cdn' => true ] ],
];
}
MWExceptionHandler::getRedactedTraceAsString( $dbex )
)->inLanguage( 'en' )->useDatabase( false )->text();
+ // The specific exception doesn't matter, as long as it's namespaced.
+ $nsex = new MediaWiki\ShellDisabledError();
+ $nstrace = wfMessage( 'api-exception-trace',
+ get_class( $nsex ),
+ $nsex->getFile(),
+ $nsex->getLine(),
+ MWExceptionHandler::getRedactedTraceAsString( $nsex )
+ )->inLanguage( 'en' )->useDatabase( false )->text();
+
$apiEx1 = new ApiUsageException( null,
StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) );
TestingAccessWrapper::newFromObject( $apiEx1 )->modulePath = 'foo+bar';
$apiEx1->getStatusValue()->warning( new ApiRawMessage( 'Another warning', 'sv-warn2' ) );
$apiEx1->getStatusValue()->fatal( new ApiRawMessage( 'Another error', 'sv-error2' ) );
+ $badMsg = $this->getMockBuilder( ApiRawMessage::class )
+ ->setConstructorArgs( [ 'An error', 'ignored' ] )
+ ->setMethods( [ 'getApiCode' ] )
+ ->getMock();
+ $badMsg->method( 'getApiCode' )->willReturn( "bad\nvalue" );
+ $apiEx2 = new ApiUsageException( null, StatusValue::newFatal( $badMsg ) );
+
return [
[
$ex,
[
'code' => 'internal_api_error_InvalidArgumentException',
'text' => "[$reqId] Exception caught: Random exception",
+ 'data' => [
+ 'errorclass' => InvalidArgumentException::class,
+ ],
]
],
'trace' => $trace,
'code' => 'internal_api_error_DBQueryError',
'text' => "[$reqId] Exception caught: A database query error has occurred. " .
"This may indicate a bug in the software.",
+ 'data' => [
+ 'errorclass' => DBQueryError::class,
+ ],
]
],
'trace' => $dbtrace,
'servedby' => wfHostname(),
]
],
+ [
+ $nsex,
+ [ 'existing-error', 'internal_api_error_MediaWiki\ShellDisabledError' ],
+ [
+ 'warnings' => [
+ [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ],
+ ],
+ 'errors' => [
+ [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ],
+ [
+ 'code' => 'internal_api_error_MediaWiki\ShellDisabledError',
+ 'text' => "[$reqId] Exception caught: " . $nsex->getMessage(),
+ 'data' => [
+ 'errorclass' => MediaWiki\ShellDisabledError::class,
+ ],
+ ]
+ ],
+ 'trace' => $nstrace,
+ 'servedby' => wfHostname(),
+ ]
+ ],
[
$apiEx1,
[ 'existing-error', 'sv-error1', 'sv-error2' ],
'servedby' => wfHostname(),
]
],
+ [
+ $apiEx2,
+ [ 'existing-error', '<invalid-code>' ],
+ [
+ 'warnings' => [
+ [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ],
+ ],
+ 'errors' => [
+ [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ],
+ [ 'code' => "bad\nvalue", 'text' => 'An error' ],
+ ],
+ 'docref' => "See $doclink for API usage. Subscribe to the mediawiki-api-announce mailing " .
+ "list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> " .
+ "for notice of API deprecations and breaking changes.",
+ 'servedby' => wfHostname(),
+ ]
+ ]
];
}