ApiResult::setSubelementsList( $data, 'help' );
$result->addValue( null, $this->getModuleName(), $data );
} else {
+ // Show any errors at the top of the HTML
+ $transform = [
+ 'Types' => [ 'AssocAsObject' => true ],
+ 'Strip' => 'all',
+ ];
+ $errors = array_filter( [
+ 'errors' => $this->getResult()->getResultData( [ 'errors' ], $transform ),
+ 'warnings' => $this->getResult()->getResultData( [ 'warnings' ], $transform ),
+ ] );
+ if ( $errors ) {
+ $json = FormatJson::encode( $errors, true, FormatJson::UTF8_OK );
+ // Escape any "--", some parsers might interpret that as end-of-comment.
+ // The above already escaped any "<" and ">".
+ $json = str_replace( '--', '-\u002D', $json );
+ $html = "<!-- API warnings and errors:\n$json\n-->\n$html";
+ }
+
$result->reset();
$result->addValue( null, 'text', $html, ApiResult::NO_SIZE_CHECK );
$result->addValue( null, 'mime', 'text/html', ApiResult::NO_SIZE_CHECK );
$this->dieWithErrorOrDebug( [ 'apierror-mustbeposted', $this->mAction ] );
}
+ if ( $request->wasPosted() && !$request->getHeader( 'Content-Type' ) ) {
+ $this->addDeprecation(
+ 'apiwarn-deprecation-post-without-content-type', 'post-without-content-type'
+ );
+ }
+
// See if custom printer is used
$this->mPrinter = $module->getCustomPrinter();
if ( is_null( $this->mPrinter ) ) {
"apiwarn-deprecation-missingparam": "Because <var>$1</var> was not specified, a legacy format has been used for the output. This format is deprecated, and in the future the new format will always be used.",
"apiwarn-deprecation-parameter": "The parameter <var>$1</var> has been deprecated.",
"apiwarn-deprecation-parse-headitems": "<kbd>prop=headitems</kbd> is deprecated since MediaWiki 1.28. Use <kbd>prop=headhtml</kbd> when creating new HTML documents, or <kbd>prop=modules|jsconfigvars</kbd> when updating a document client-side.",
+ "apiwarn-deprecation-post-without-content-type": "A POST request was made without a <code>Content-Type</code> header. This does not work reliably.",
"apiwarn-deprecation-purge-get": "Use of <kbd>action=purge</kbd> via GET is deprecated. Use POST instead.",
"apiwarn-deprecation-withreplacement": "<kbd>$1</kbd> has been deprecated. Please use <kbd>$2</kbd> instead.",
"apiwarn-difftohidden": "Couldn't diff to r$1: content is hidden.",
"apiwarn-deprecation-missingparam": "{{doc-apierror}}\n\nParameters:\n* $1 - Parameter name.",
"apiwarn-deprecation-parameter": "{{doc-apierror}}\n\nParameters:\n* $1 - Parameter name.",
"apiwarn-deprecation-parse-headitems": "{{doc-apierror}}",
+ "apiwarn-deprecation-post-without-content-type": "{{doc-apierror}}",
"apiwarn-deprecation-purge-get": "{{doc-apierror}}",
"apiwarn-deprecation-withreplacement": "{{doc-apierror}}\n\nParameters:\n* $1 - Query string fragment that is deprecated, e.g. \"action=tokens\".\n* $2 - Query string fragment to use instead, e.g. \"action=tokens\".",
"apiwarn-difftohidden": "{{doc-apierror}}\n\nParameters:\n* $1 - Revision ID number.\n\n\"r\" is short for \"revision\". You may translate it.",