r69563 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69562‎ | r69563 | r69564 >
Date:19:41, 19 July 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Resolves remaining issues noted in CR comments on r69432.
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)
  • /branches/resourceloader/phase3/load.php (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -15,7 +15,8 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 * http://www.gnu.org/copyleft/gpl.html
1818 *
19 - * @author Roan Kattouw, Trevor Parscal
 19+ * @author Roan Kattouw
 20+ * @author Trevor Parscal
2021 */
2122
2223 /*
@@ -113,10 +114,10 @@
114115 $missing = array_diff( $modules, array_keys( $blobs ) );
115116 foreach ( $missing as $module ) {
116117 // Build message blob for module messages
117 - $messages = isset( static::$modules[$module]['messages'] ) ?
118 - array_keys( static::$modules[$module]['messages'] ) : false;
 118+ $messages = isset( self::$modules[$module]['messages'] ) ?
 119+ array_keys( self::$modules[$module]['messages'] ) : false;
119120 if ( $messages ) {
120 - foreach ( ResourceLoader::$modules[$module]['messages'] as $key ) {
 121+ foreach ( self::$modules[$module]['messages'] as $key ) {
121122 $messages[$encKey] = wfMsgExt( $key, array( 'language' => $lang ) );
122123 }
123124 $blob = json_encode( $messages );
@@ -166,14 +167,14 @@
167168 if ( is_array( $module ) && empty( $options ) ) {
168169 $success = true;
169170 foreach ( $module as $name => $options ) {
170 - if ( !static::register( $name, $options ) ) {
 171+ if ( !self::register( $name, $options ) ) {
171172 $success = false;
172173 }
173174 }
174175 return $success;
175176 }
176177 // Disallow duplicate registrations
177 - if ( isset( static::$modules[$module] ) ) {
 178+ if ( isset( self::$modules[$module] ) ) {
178179 // A module has already been registered by this name
179180 return false;
180181 }
@@ -203,13 +204,12 @@
204205 // Style file does not exist
205206 return false;
206207 }
207 - static::$modules[$module] = $options;
 208+ self::$modules[$module] = $options;
208209 }
209210 /*
210211 * Outputs a response to a resource load-request, including a content-type header
211212 *
212 - * @param array $modules module names to include in the request
213 - * @param array $options options which affect the content of the response (optional)
 213+ * @param WebRequest $request web request object to respond to
214214 *
215215 * $options format:
216216 * array(
@@ -223,12 +223,12 @@
224224 public static function respond( WebRequest $request ) {
225225 global $wgUser, $wgLang, $wgDefaultSkin;
226226 // Fallback on system settings
227 - $parameters = array_merge( array(
 227+ $parameters = array(
228228 'user' => $request->getBool( 'user', $wgUser->isLoggedIn() ),
229229 'lang' => $request->getVal( 'lang', $wgLang->getCode() ),
230230 'skin' => $request->getVal( 'skin', $wgDefaultSkin ),
231231 'debug' => $request->getBool( 'debug' ),
232 - ) );
 232+ );
233233 // Get the direction from the requested language
234234 if ( !isset( $parameters['dir'] ) ) {
235235 $lang = $wgLang->factory( $parameters['lang'] );
@@ -237,12 +237,8 @@
238238 // Get modules - filtering out any we don't know about
239239 $modules = array();
240240 foreach ( explode( '|', $request->getVal( 'modules' ) ) as $module ) {
241 - if ( isset( static::$modules[$module] ) ) {
242 - if ( static::$modules[$module]['debug'] ) {
243 - if ( $parameters['debug'] ) {
244 - $modules[] = $module;
245 - }
246 - } else {
 241+ if ( isset( self::$modules[$module] ) ) {
 242+ if ( !self::$modules[$module]['debug'] || $parameters['debug'] ) {
247243 $modules[] = $module;
248244 }
249245 }
@@ -251,8 +247,8 @@
252248 ob_start();
253249 // Output raw modules first
254250 foreach ( $modules as $module ) {
255 - if ( static::$modules[$module]['raw'] ) {
256 - readfile( static::$modules[$module]['script'] );
 251+ if ( self::$modules[$module]['raw'] ) {
 252+ readfile( self::$modules[$module]['script'] );
257253 echo "\n";
258254 }
259255 }
@@ -285,22 +281,23 @@
286282 */
287283 }
288284 // Output non-raw modules
289 - $blobs = static::messages( $parameters['lang'], $modules );
 285+ $blobs = self::messages( $parameters['lang'], $modules );
290286 foreach ( $modules as $module ) {
291 - if ( !static::$modules[$module]['raw'] ) {
 287+ if ( !self::$modules[$module]['raw'] ) {
292288 // Script
293 - $script = file_get_contents( static::$modules[$module]['script'] );
 289+ $script = file_get_contents( self::$modules[$module]['script'] );
294290 if ( !$parameters['debug'] ) {
295 - $script = static::filter( 'strip-debug', $script );
 291+ $script = self::filter( 'strip-debug', $script );
296292 }
297293 // Style
298 - $style = static::$modules[$module]['style'] ? file_get_contents( static::$modules[$module]['style'] ) : '';
 294+ $style = self::$modules[$module]['style'] ? file_get_contents( self::$modules[$module]['style'] ) : '';
299295 if ( $style !== '' ) {
300296 if ( $parameters['dir'] == 'rtl' ) {
301 - $style = static::filter( 'flip-css', $style );
 297+ $style = self::filter( 'flip-css', $style );
302298 }
303299 $style = Xml::escapeJsString(
304 - static::filter( 'minify-css', $style, static::$modules[$module]['style'] )
 300+ $parameters['debug'] ?
 301+ $style : self::filter( 'minify-css', $style, self::$modules[$module]['style'] )
305302 );
306303 }
307304 // Messages
@@ -315,7 +312,7 @@
316313 if ( $parameters['debug'] ) {
317314 ob_end_flush();
318315 } else {
319 - echo static::filter( 'minify-js', ob_get_clean() );
 316+ echo self::filter( 'minify-js', ob_get_clean() );
320317 }
321318 }
322319 }
\ No newline at end of file
Index: branches/resourceloader/phase3/load.php
@@ -15,7 +15,8 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 * http://www.gnu.org/copyleft/gpl.html
1818 *
19 - * @author Roan Kattouw, Trevor Parscal
 19+ * @author Roan Kattouw
 20+ * @author Trevor Parscal
2021 *
2122 */
2223

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r69432Refactored the ResourceLoader class, integrated the MessageBlobStore function...tparscal18:39, 16 July 2010

Comments

#Comment by Catrope (talk | contribs)   20:08, 19 July 2010
+			if ( isset( self::$modules[$module] ) ) {
+				if ( !self::$modules[$module]['debug'] || $parameters['debug'] ) {
 					$modules[] = $module;
 				}
 			}

You can just use && instead of a nested if here.

Status & tagging log