Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -38,13 +38,13 @@ |
39 | 39 | public static $modules = array( |
40 | 40 | ); |
41 | 41 | |
42 | | - private $mScripts = array(); |
43 | | - private $mStyles = array(); |
44 | | - private $mMessages = array(); |
| 42 | + private $scripts = array(); |
| 43 | + private $styles = array(); |
| 44 | + private $loadedModules = array(); |
45 | 45 | |
46 | | - private $mUseJSMin = true; |
47 | | - private $mUseCSSMin = true; |
48 | | - private $mUseCSSJanus = true; |
| 46 | + private $useJSMin = true; |
| 47 | + private $useCSSMin = true; |
| 48 | + private $useCSSJanus = true; |
49 | 49 | |
50 | 50 | |
51 | 51 | /** |
— | — | @@ -53,25 +53,23 @@ |
54 | 54 | * @param $module string Module name |
55 | 55 | */ |
56 | 56 | 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']; |
60 | 61 | } |
61 | | - if ( isset( $module['messages'] ) ) { |
62 | | - $this->mMessages = array_merge( $this->mMessages, self::$modules[$module]['messages'] ); |
63 | | - } |
64 | 62 | } |
65 | 63 | |
66 | 64 | public function setUseJSMin( $use ) { |
67 | | - $this->mUseJSMin = $use; |
| 65 | + $this->useJSMin = $use; |
68 | 66 | } |
69 | 67 | |
70 | 68 | public function setUseCSSMin( $use ) { |
71 | | - $this->mUseCSSMin = $use; |
| 69 | + $this->useCSSMin = $use; |
72 | 70 | } |
73 | 71 | |
74 | 72 | public function setUseCSSJanus( $use ) { |
75 | | - $this->mUseCSSJanus = $use; |
| 73 | + $this->useCSSJanus = $use; |
76 | 74 | } |
77 | 75 | |
78 | 76 | private function getStyleJS( $styles ) { |
— | — | @@ -79,10 +77,10 @@ |
80 | 78 | foreach ( $styles as $style ) { |
81 | 79 | // TODO: file_get_contents() errors? |
82 | 80 | $css = file_get_contents( $style ); |
83 | | - if ( $this->mUseCSSJanus ) { |
| 81 | + if ( $this->useCSSJanus ) { |
84 | 82 | $css = $this->cssJanus( $css ); |
85 | 83 | } |
86 | | - if ( $this->mUseCSSMin ) { |
| 84 | + if ( $this->useCSSMin ) { |
87 | 85 | $css = $this->cssMin( $css ); |
88 | 86 | } |
89 | 87 | $escCss = Xml::escapeJsString( $css ); |
— | — | @@ -91,30 +89,26 @@ |
92 | 90 | return $retval; |
93 | 91 | } |
94 | 92 | |
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} );"; |
103 | 97 | } |
104 | 98 | |
105 | 99 | 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 ); |
109 | 103 | $retval = ''; |
110 | 104 | |
111 | | - foreach ( $this->mScripts as $script ) { |
| 105 | + foreach ( $this->scripts as $script ) { |
112 | 106 | // TODO: file_get_contents() errors? |
113 | 107 | $retval .= file_get_contents( $script ); |
114 | 108 | } |
115 | | - $retval .= $this->getStyleJS( $this->mStyles ); |
116 | | - $retval .= $this->getMessagesJS( $this->mMessages ); |
| 109 | + $retval .= $this->getStyleJS( $this->styles ); |
| 110 | + $retval .= $this->getMessagesJS( $this->loadedModules ); |
117 | 111 | |
118 | | - if ( $this->mUseJSMin ) { |
| 112 | + if ( $this->useJSMin ) { |
119 | 113 | $retval = $this->jsMin( $retval ); |
120 | 114 | } |
121 | 115 | return $retval; |
— | — | @@ -135,3 +129,15 @@ |
136 | 130 | return $css; |
137 | 131 | } |
138 | 132 | } |
| 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 |