r68375 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68374‎ | r68375 | r68376 >
Date:20:36, 21 June 2010
Author:catrope
Status:deferred
Tags:
Comment:
resourceloader: Drop $m prefix from class members, reorganize message grabbing to conform to spec, minor fixes
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -38,13 +38,13 @@
3939 public static $modules = array(
4040 );
4141
42 - private $mScripts = array();
43 - private $mStyles = array();
44 - private $mMessages = array();
 42+ private $scripts = array();
 43+ private $styles = array();
 44+ private $loadedModules = array();
4545
46 - private $mUseJSMin = true;
47 - private $mUseCSSMin = true;
48 - private $mUseCSSJanus = true;
 46+ private $useJSMin = true;
 47+ private $useCSSMin = true;
 48+ private $useCSSJanus = true;
4949
5050
5151 /**
@@ -53,25 +53,23 @@
5454 * @param $module string Module name
5555 */
5656 public function addModule( $module ) {
57 - $this->mScripts[] = self::$modules[$module]['script'];
58 - if ( isset( $module['style'] ) ) {
59 - $this->mStyles[] = self::$modules[$module]['script'];
 57+ $this->loadedModules[] = $module;
 58+ $this->scripts[] = self::$modules[$module]['script'];
 59+ if ( isset( self::$modules[$module]['style'] ) ) {
 60+ $this->styles[] = self::$modules[$module]['script'];
6061 }
61 - if ( isset( $module['messages'] ) ) {
62 - $this->mMessages = array_merge( $this->mMessages, self::$modules[$module]['messages'] );
63 - }
6462 }
6563
6664 public function setUseJSMin( $use ) {
67 - $this->mUseJSMin = $use;
 65+ $this->useJSMin = $use;
6866 }
6967
7068 public function setUseCSSMin( $use ) {
71 - $this->mUseCSSMin = $use;
 69+ $this->useCSSMin = $use;
7270 }
7371
7472 public function setUseCSSJanus( $use ) {
75 - $this->mUseCSSJanus = $use;
 73+ $this->useCSSJanus = $use;
7674 }
7775
7876 private function getStyleJS( $styles ) {
@@ -79,10 +77,10 @@
8078 foreach ( $styles as $style ) {
8179 // TODO: file_get_contents() errors?
8280 $css = file_get_contents( $style );
83 - if ( $this->mUseCSSJanus ) {
 81+ if ( $this->useCSSJanus ) {
8482 $css = $this->cssJanus( $css );
8583 }
86 - if ( $this->mUseCSSMin ) {
 84+ if ( $this->useCSSMin ) {
8785 $css = $this->cssMin( $css );
8886 }
8987 $escCss = Xml::escapeJsString( $css );
@@ -91,30 +89,26 @@
9290 return $retval;
9391 }
9492
95 - private function getMessagesJS( $messages ) {
96 - $msgs = array();
97 - foreach ( $messages as $message ) {
98 - $escKey = Xml::escapeJsString( $message );
99 - $escValue = Xml::escapeJsString( wfMsg( $message ) );
100 - $msgs[] = "'$escKey': '$escValue'";
101 - }
102 - return "mw.addMessages( {\n" . implode( ",\n", $msgs ) . "\n} );\n";
 93+ private function getMessagesJS( $modules ) {
 94+ return "mw.addMessages( {\n" .
 95+ implode( ",\n", array_map( array( 'MessageBlobStore', 'get' ), $modules ) ) .
 96+ "\n} );";
10397 }
10498
10599 public function getOutput() {
106 - $this->mScripts = array_unique( $this->mScripts );
107 - $this->mStyles = array_unique( $this->mStyles );
108 - $this->mMessages = array_unique( $this->mMessages );
 100+ $this->scripts = array_unique( $this->scripts );
 101+ $this->styles = array_unique( $this->styles );
 102+ $this->loadedModules = array_unique( $this->loadedModules );
109103 $retval = '';
110104
111 - foreach ( $this->mScripts as $script ) {
 105+ foreach ( $this->scripts as $script ) {
112106 // TODO: file_get_contents() errors?
113107 $retval .= file_get_contents( $script );
114108 }
115 - $retval .= $this->getStyleJS( $this->mStyles );
116 - $retval .= $this->getMessagesJS( $this->mMessages );
 109+ $retval .= $this->getStyleJS( $this->styles );
 110+ $retval .= $this->getMessagesJS( $this->loadedModules );
117111
118 - if ( $this->mUseJSMin ) {
 112+ if ( $this->useJSMin ) {
119113 $retval = $this->jsMin( $retval );
120114 }
121115 return $retval;
@@ -135,3 +129,15 @@
136130 return $css;
137131 }
138132 }
 133+
 134+class MessageBlobStore {
 135+ /**
 136+ * Get the message blob for a module
 137+ * @param $module string Module name
 138+ * @return string An incomplete JSON object (i.e. without the {} ) with messages keys and their values.
 139+ */
 140+ public static function get( $module ) {
 141+ // TODO: Implement
 142+ return '';
 143+ }
 144+}
\ No newline at end of file

Status & tagging log