profiler: Rename Profile::setTemplated to Profile::setAllowOutput
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 28 Aug 2019 00:20:47 +0000 (01:20 +0100)
committerKrinkle <krinklemail@gmail.com>
Wed, 28 Aug 2019 01:10:56 +0000 (01:10 +0000)
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

RELEASE-NOTES-1.34
includes/profiler/Profiler.php

index 5da679f..932122d 100644 (file)
@@ -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.
index 554ca08..0fcc97d 100644 (file)
@@ -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;
        }
 
        /**