Backfill release notes for Iaf531795
[lhc/web/wiklou.git] / includes / api / ApiErrorFormatter.php
index c52b731..c637752 100644 (file)
@@ -112,7 +112,7 @@ class ApiErrorFormatter {
         * Add warnings and errors from a StatusValue object to the result
         * @param string|null $modulePath
         * @param StatusValue $status
-        * @param string[] $types 'warning' and/or 'error'
+        * @param string[]|string $types 'warning' and/or 'error'
         */
        public function addMessagesFromStatus(
                $modulePath, StatusValue $status, $types = [ 'warning', 'error' ]
@@ -160,6 +160,9 @@ class ApiErrorFormatter {
                if ( $exception instanceof ILocalizedException ) {
                        $msg = $exception->getMessageObject();
                        $params = [];
+               } elseif ( $exception instanceof MessageSpecifier ) {
+                       $msg = Message::newFromSpecifier( $exception );
+                       $params = [];
                } else {
                        // Extract code and data from the exception, if applicable
                        if ( $exception instanceof UsageException ) {
@@ -176,7 +179,8 @@ class ApiErrorFormatter {
                        } else {
                                $msg = new RawMessage( '$1' );
                                if ( !isset( $options['code'] ) ) {
-                                       $options['code'] = 'internal_api_error_' . get_class( $exception );
+                                       $class = preg_replace( '#^Wikimedia\\\Rdbms\\\#', '', get_class( $exception ) );
+                                       $options['code'] = 'internal_api_error_' . $class;
                                }
                        }
                        $params = [ wfEscapeWikiText( $exception->getMessage() ) ];
@@ -253,7 +257,7 @@ class ApiErrorFormatter {
                $ret = preg_replace( '!</?(var|kbd|samp|code)>!', '"', $text );
 
                // Strip tags and decode.
-               $ret = html_entity_decode( strip_tags( $ret ), ENT_QUOTES | ENT_HTML5 );
+               $ret = Sanitizer::stripAllTags( $ret );
 
                return $ret;
        }
@@ -357,9 +361,8 @@ class ApiErrorFormatter {
  * @deprecated Only for backwards compatibility, do not use
  * @ingroup API
  */
-// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
+// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
 class ApiErrorFormatter_BackCompat extends ApiErrorFormatter {
-       // @codingStandardsIgnoreEnd
 
        /**
         * @param ApiResult $result Into which data will be added