From: Timo Tijhof Date: Wed, 28 Aug 2019 00:20:47 +0000 (+0100) Subject: profiler: Rename Profile::setTemplated to Profile::setAllowOutput X-Git-Tag: 1.34.0-rc.0~534^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22sites_tous%22%29%20.%20%22?a=commitdiff_plain;h=bc7c85d609b9b629d73e188a5c99ead51aaf88d2;p=lhc%2Fweb%2Fwiklou.git profiler: Rename Profile::setTemplated to Profile::setAllowOutput This is set from three places: 1) SkinTemplate.php, 2) Maintenance.php, and 3) load.php. These last two are very much *not* HTML-templated output. Rename these this method pair to getAllowOutput/setAllowOutput instead, which is less confusing going forward. No known callers outside of core (updated in the next commit), but I'll keep compat for one release cycle just in case. Change-Id: I828f95332dca3c6766b2b485ffb71762542b42d7 --- diff --git a/RELEASE-NOTES-1.34 b/RELEASE-NOTES-1.34 index 5da679f8ce..932122d8ae 100644 --- a/RELEASE-NOTES-1.34 +++ b/RELEASE-NOTES-1.34 @@ -415,6 +415,9 @@ because of Phabricator reports. * ResourceLoaderContext::getConfig and ResourceLoaderContext::getLogger have been deprecated. Inside ResourceLoaderModule subclasses, use the local methods instead. Elsewhere, use the methods from the ResourceLoader class. +* The Profiler::setTemplated and Profiler::getTemplated methods have been + deprecated. Use Profiler::setAllowOutput and Profiler::getAllowOutput + instead. * The Preprocessor_DOM implementation has been deprecated. It will be removed in a future release. Use the Preprocessor_Hash implementation instead. diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 554ca084bd..0fcc97dbb2 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -33,14 +33,15 @@ use Wikimedia\Rdbms\TransactionProfiler; abstract class Profiler { /** @var string|bool Profiler ID for bucketing data */ protected $profileID = false; - /** @var bool Whether MediaWiki is in a SkinTemplate output context */ - protected $templated = false; /** @var array All of the params passed from $wgProfiler */ protected $params = []; /** @var IContextSource Current request context */ protected $context = null; /** @var TransactionProfiler */ protected $trxProfiler; + /** @var bool */ + private $allowOutput = false; + /** @var Profiler */ private static $instance = null; @@ -264,15 +265,20 @@ abstract class Profiler { } /** - * Get the content type sent out to the client. - * Used for profilers that output instead of store data. - * @return string + * Get the Content-Type for deciding how to format appended profile output. + * + * Disabled by default. Enable via setAllowOutput(). + * + * @see ProfilerOutputText * @since 1.25 + * @return string|null Returns null if disabled or no Content-Type found. */ public function getContentType() { - foreach ( headers_list() as $header ) { - if ( preg_match( '#^content-type: (\w+/\w+);?#i', $header, $m ) ) { - return $m[1]; + if ( $this->allowOutput ) { + foreach ( headers_list() as $header ) { + if ( preg_match( '#^content-type: (\w+/\w+);?#i', $header, $m ) ) { + return $m[1]; + } } } return null; @@ -281,19 +287,42 @@ abstract class Profiler { /** * Mark this call as templated or not * + * @deprecated since 1.34 Use setAllowOutput() instead. * @param bool $t */ public function setTemplated( $t ) { - $this->templated = $t; + // wfDeprecated( __METHOD__, '1.34' ); + $this->allowOutput = ( $t === true ); } /** * Was this call as templated or not * + * @deprecated since 1.34 Use getAllowOutput() instead. * @return bool */ public function getTemplated() { - return $this->templated; + // wfDeprecated( __METHOD__, '1.34' ); + return $this->getAllowOutput(); + } + + /** + * Enable appending profiles to standard output. + * + * @since 1.34 + */ + public function setAllowOutput() { + $this->allowOutput = true; + } + + /** + * Whether appending profiles is allowed. + * + * @since 1.34 + * @return bool + */ + public function getAllowOutput() { + return $this->allowOutput; } /**