Merge "collation: Move first-letters-root to includes/collation/data"
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index f324eff..03d2952 100644 (file)
@@ -24,8 +24,6 @@
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
 use Wikimedia\Timestamp\TimestampException;
-use Wikimedia\Rdbms\DBQueryError;
-use Wikimedia\Rdbms\DBError;
 
 /**
  * This is the main API class, used for both external and internal processing.
@@ -165,7 +163,7 @@ class ApiMain extends ApiBase {
        /**
         * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
         *
-        * @param IContextSource|WebRequest $context If this is an instance of
+        * @param IContextSource|WebRequest|null $context If this is an instance of
         *    FauxRequest, errors are thrown and no printing occurs
         * @param bool $enableWrite Should be set to true if the api may modify data
         */
@@ -246,8 +244,7 @@ class ApiMain extends ApiBase {
                        // for uselang=user (see T85635).
                } else {
                        if ( $uselang === 'content' ) {
-                               global $wgContLang;
-                               $uselang = $wgContLang->getCode();
+                               $uselang = MediaWikiServices::getInstance()->getContentLanguage()->getCode();
                        }
                        $code = RequestContext::sanitizeLangCode( $uselang );
                        $this->getContext()->setLanguage( $code );
@@ -267,8 +264,7 @@ class ApiMain extends ApiBase {
                        if ( $errorLangCode === 'uselang' ) {
                                $errorLang = $this->getLanguage();
                        } elseif ( $errorLangCode === 'content' ) {
-                               global $wgContLang;
-                               $errorLang = $wgContLang;
+                               $errorLang = MediaWikiServices::getInstance()->getContentLanguage();
                        } else {
                                $errorLangCode = RequestContext::sanitizeLangCode( $errorLangCode );
                                $errorLang = Language::factory( $errorLangCode );
@@ -486,7 +482,7 @@ class ApiMain extends ApiBase {
         * @return ApiFormatBase
         */
        public function createPrinterByName( $format ) {
-               $printer = $this->mModuleMgr->getModule( $format, 'format' );
+               $printer = $this->mModuleMgr->getModule( $format, 'format', /* $ignoreCache */ true );
                if ( $printer === null ) {
                        $this->dieWithError(
                                [ 'apierror-unknownformat', wfEscapeWikiText( $format ) ], 'unknown_format'
@@ -535,11 +531,9 @@ class ApiMain extends ApiBase {
                        $this->executeAction();
                        $runTime = microtime( true ) - $t;
                        $this->logRequest( $runTime );
-                       if ( $this->mModule->isWriteMode() && $this->getRequest()->wasPosted() ) {
-                               MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
-                                       'api.' . $this->mModule->getModuleName() . '.executeTiming', 1000 * $runTime
-                               );
-                       }
+                       MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
+                               'api.' . $this->mModule->getModuleName() . '.executeTiming', 1000 * $runTime
+                       );
                } catch ( Exception $e ) {
                        $this->handleException( $e );
                        $this->logRequest( microtime( true ) - $t, $e );
@@ -813,7 +807,7 @@ class ApiMain extends ApiBase {
         * Attempt to validate the value of Access-Control-Request-Headers against a list
         * of headers that we allow the follow up request to send.
         *
-        * @param string $requestedHeaders Comma seperated list of HTTP headers
+        * @param string $requestedHeaders Comma separated list of HTTP headers
         * @return bool True if all requested headers are in the list of allowed headers
         */
        protected static function matchRequestedHeaders( $requestedHeaders ) {
@@ -1040,9 +1034,7 @@ class ApiMain extends ApiBase {
                        $config = $this->getConfig();
                        $class = preg_replace( '#^Wikimedia\\\Rdbms\\\#', '', get_class( $e ) );
                        $code = 'internal_api_error_' . $class;
-                       if ( ( $e instanceof DBQueryError ) && !$config->get( 'ShowSQLErrors' ) ) {
-                               $params = [ 'apierror-databaseerror', WebRequest::getRequestId() ];
-                       } else {
+                       if ( $config->get( 'ShowExceptionDetails' ) ) {
                                if ( $e instanceof ILocalizedException ) {
                                        $msg = $e->getMessageObject();
                                } elseif ( $e instanceof MessageSpecifier ) {
@@ -1051,7 +1043,10 @@ class ApiMain extends ApiBase {
                                        $msg = wfEscapeWikiText( $e->getMessage() );
                                }
                                $params = [ 'apierror-exceptioncaught', WebRequest::getRequestId(), $msg ];
+                       } else {
+                               $params = [ 'apierror-exceptioncaughttype', WebRequest::getRequestId(), get_class( $e ) ];
                        }
+
                        $messages[] = ApiMessage::create( $params, $code );
                }
                return $messages;
@@ -1115,9 +1110,7 @@ class ApiMain extends ApiBase {
                                )
                        );
                } else {
-                       if ( $config->get( 'ShowExceptionDetails' ) &&
-                               ( !$e instanceof DBError || $config->get( 'ShowDBErrorBacktrace' ) )
-                       ) {
+                       if ( $config->get( 'ShowExceptionDetails' ) ) {
                                $result->addContentValue(
                                        $path,
                                        'trace',
@@ -1616,7 +1609,7 @@ class ApiMain extends ApiBase {
        /**
         * Log the preceding request
         * @param float $time Time in seconds
-        * @param Exception $e Exception caught while processing the request
+        * @param Exception|null $e Exception caught while processing the request
         */
        protected function logRequest( $time, $e = null ) {
                $request = $this->getRequest();