From 2332eedfa1ed29e756c4e190635a2e6084d24a5b Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Sun, 11 Aug 2013 15:11:17 +0800 Subject: [PATCH] Make ResourceLoader::makeComment a public static method 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 | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 1240abf399..ebcdab33c1 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -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; -- 2.20.1