Make ResourceLoader::makeComment a public static method
authorOri Livneh <ori@wikimedia.org>
Sun, 11 Aug 2013 07:11:17 +0000 (15:11 +0800)
committerOri Livneh <ori@wikimedia.org>
Sun, 11 Aug 2013 07:11:17 +0000 (15:11 +0800)
ResourceLoader::makeComment takes a block of text of converts it into a
/* multi-line comment block */ that is safe for inclusion in JavaScript and CSS
source code. There is no reason for the method to be protected, since it is
generic, useful, and free of side-effects.

Change-Id: Ibe45256eddee2ad30d19adcb2f1c0b0d5578e650

includes/resourceloader/ResourceLoader.php

index 1240abf..ebcdab3 100644 (file)
@@ -180,7 +180,7 @@ class ResourceLoader {
                        wfDebugLog( 'resourceloader', __METHOD__ . ": minification failed: $exception" );
                        $this->hasErrors = true;
                        // Return exception as a comment
-                       $result = $this->makeComment( $exception->__toString() );
+                       $result = self::makeComment( $exception->__toString() );
                }
 
                wfProfileOut( __METHOD__ );
@@ -460,7 +460,7 @@ class ResourceLoader {
                                        wfDebugLog( 'resourceloader', __METHOD__ . ": request for private module '$name' denied" );
                                        $this->hasErrors = true;
                                        // Add exception to the output as a comment
-                                       $errors .= $this->makeComment( "Cannot show private module \"$name\"" );
+                                       $errors .= self::makeComment( "Cannot show private module \"$name\"" );
 
                                        continue;
                                }
@@ -477,7 +477,7 @@ class ResourceLoader {
                        wfDebugLog( 'resourceloader', __METHOD__ . ": preloading module info failed: $e" );
                        $this->hasErrors = true;
                        // Add exception to the output as a comment
-                       $errors .= $this->makeComment( $e->__toString() );
+                       $errors .= self::makeComment( $e->__toString() );
                }
 
                wfProfileIn( __METHOD__ . '-getModifiedTime' );
@@ -496,7 +496,7 @@ class ResourceLoader {
                                wfDebugLog( 'resourceloader', __METHOD__ . ": calculating maximum modified time failed: $e" );
                                $this->hasErrors = true;
                                // Add exception to the output as a comment
-                               $errors .= $this->makeComment( $e->__toString() );
+                               $errors .= self::makeComment( $e->__toString() );
                        }
                }
 
@@ -517,7 +517,7 @@ class ResourceLoader {
                // Capture any PHP warnings from the output buffer and append them to the
                // response in a comment if we're in debug mode.
                if ( $context->getDebug() && strlen( $warnings = ob_get_contents() ) ) {
-                       $response = $this->makeComment( $warnings ) . $response;
+                       $response = self::makeComment( $warnings ) . $response;
                        $this->hasErrors = true;
                }
 
@@ -676,7 +676,13 @@ class ResourceLoader {
                return false; // cache miss
        }
 
-       protected function makeComment( $text ) {
+       /**
+        * Generate a CSS or JS comment block
+        *
+        * @param $text string
+        * @return string
+        */
+       public static function makeComment( $text ) {
                $encText = str_replace( '*/', '* /', $text );
                return "/*\n$encText\n*/\n";
        }
@@ -707,7 +713,7 @@ class ResourceLoader {
                                wfDebugLog( 'resourceloader', __METHOD__ . ": pre-fetching blobs from MessageBlobStore failed: $e" );
                                $this->hasErrors = true;
                                // Add exception to the output as a comment
-                               $exceptions .= $this->makeComment( $e->__toString() );
+                               $exceptions .= self::makeComment( $e->__toString() );
                        }
                } else {
                        $blobs = array();
@@ -814,7 +820,7 @@ class ResourceLoader {
                                wfDebugLog( 'resourceloader', __METHOD__ . ": generating module package failed: $e" );
                                $this->hasErrors = true;
                                // Add exception to the output as a comment
-                               $exceptions .= $this->makeComment( $e->__toString() );
+                               $exceptions .= self::makeComment( $e->__toString() );
 
                                // Register module as missing
                                $missing[] = $name;