X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiFormatBase.php;h=c5f2fcfaa7567fba788f35dae8e3fc47d36acd2d;hp=06eaa19ca40ca20b4f9b66e28ea5c9ca3e34cff7;hb=c75f0e95c9888489961548c72ef24786c43838aa;hpb=732b5e2745ca8f6153e19cc10c3c9acb1b2a6331 diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 06eaa19ca4..c5f2fcfaa7 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -64,6 +64,26 @@ abstract class ApiFormatBase extends ApiBase { */ abstract public function getMimeType(); + /** + * Return a filename for this module's output. + * @note If $this->getIsWrappedHtml() || $this->getIsHtml(), you'll very + * likely want to fall back to this class's version. + * @since 1.27 + * @return string Generally this should be "api-result.$ext", and must be + * encoded for inclusion in a Content-Disposition header's filename parameter. + */ + public function getFilename() { + if ( $this->getIsWrappedHtml() ) { + return 'api-result-wrapped.json'; + } elseif ( $this->getIsHtml() ) { + return 'api-result.html'; + } else { + $exts = MimeMagic::singleton()->getExtensionsForType( $this->getMimeType() ); + $ext = $exts ? strtok( $exts, ' ' ) : strtolower( $this->mFormat ); + return "api-result.$ext"; + } + } + /** * Get the internal format name * @return string @@ -192,6 +212,13 @@ abstract class ApiFormatBase extends ApiBase { if ( $apiFrameOptions ) { $this->getMain()->getRequest()->response()->header( "X-Frame-Options: $apiFrameOptions" ); } + + // Set a Content-Disposition header so something downloading an API + // response uses a halfway-sensible filename (T128209). + $filename = $this->getFilename(); + $this->getMain()->getRequest()->response()->header( + "Content-Disposition: inline; filename=\"{$filename}\"" + ); } /**