Index: trunk/extensions/UploadWizard/generateMinifiedResources.php |
— | — | @@ -1,23 +0,0 @@ |
2 | | -<?php |
3 | | -$path = getenv( 'MW_INSTALL_PATH' ); |
4 | | -if ( strval( $path ) === '' ) { |
5 | | - $path = dirname( __FILE__ ) . '/../..'; |
6 | | -} |
7 | | -require_once( "$path/maintenance/Maintenance.php" ); |
8 | | - |
9 | | -/** |
10 | | - * Maintenance script to generate combined and minified JS and CSS for UploadWizard |
11 | | - */ |
12 | | -class UploadWizardGenerateMinifiedResources extends Maintenance { |
13 | | - public function __construct() { |
14 | | - parent::__construct(); |
15 | | - $this->mDescription = 'Generate combined and minified JS and CSS for UploadWizard'; |
16 | | - } |
17 | | - |
18 | | - public function execute() { |
19 | | - $dependencyLoader = new UploadWizardDependencyLoader(); |
20 | | - $dependencyLoader->writeOptimizedFiles(); |
21 | | - } |
22 | | -} |
23 | | -$maintClass = 'UploadWizardGenerateMinifiedResources'; |
24 | | -require_once( DO_MAINTENANCE ); |
Index: trunk/extensions/UploadWizard/UploadWizardDependencyLoader.php |
— | — | @@ -1,225 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * What's that you say? ANOTHER way to load dependencies? Everyone's doing it. |
6 | | - * |
7 | | - * Doing resource loading the old-fashioned way for now until Resource Loader or something becomes the standard. |
8 | | - * We anticipate that Resource Loader will be available sometime in late 2010 or early 2011, |
9 | | - * so we define scripts in the hooks that Resource Loader will expect, over in UploadWizardHooks.php. |
10 | | - * |
11 | | - * Since the resources are defined in PHP, it was convenient to write the minifier routines here too. |
12 | | - * We do not expect to minify on the fly in MediaWiki; those rotutines will be called by |
13 | | - * developer scripts to write minified files before committing to the source code repository. |
14 | | - * |
15 | | - * (Previously the usability projects had used Makefiles, but then had to keep dependencies in sync in |
16 | | - * PHP and the Makefile). I started to write a PHP file that then would write a Makefile and realized |
17 | | - * this was getting a bit insane. |
18 | | - * |
19 | | - * @author Neil Kandalgaonkar <neilk@wikimedia.org> |
20 | | - */ |
21 | | - |
22 | | -class UploadWizardDependencyLoader { |
23 | | - |
24 | | - const STYLES_COMBINED = 'combined.css'; |
25 | | - const SCRIPTS_COMBINED = 'combined.js'; |
26 | | - const STYLES_MINIFIED = 'combined.min.css'; |
27 | | - const SCRIPTS_MINIFIED = 'combined.min.js'; |
28 | | - |
29 | | - protected $scripts; |
30 | | - protected $inlineScripts; |
31 | | - protected $styles; |
32 | | - |
33 | | - protected $optimizedStylesFile; |
34 | | - protected $optimizedScriptsFile; |
35 | | - |
36 | | - public function __construct( $langCode = null ) { |
37 | | - $module = UploadWizardHooks::$modules['ext.uploadWizard']; |
38 | | - |
39 | | - $this->scripts = $module['scripts']; |
40 | | - |
41 | | - $this->inlineScripts = array(); |
42 | | - if ( $langCode !== null ) { |
43 | | - if ( $langCode !== 'en' && isset( $module['languageScripts'][$langCode] ) ) { |
44 | | - $this->scripts[] = $module['languageScripts'][$langCode]; |
45 | | - } |
46 | | - $this->inlineScripts[] = UploadWizardMessages::getMessagesJs( 'UploadWizard', $langCode ); |
47 | | - } |
48 | | - |
49 | | - // TODO RTL |
50 | | - $this->styles = $module['styles']; |
51 | | - |
52 | | - $dir = dirname( __FILE__ ); |
53 | | - $this->optimizedStylesFile = $dir . '/' . self::STYLES_MINIFIED; |
54 | | - $this->optimizedScriptsFile = $dir . '/' . self::SCRIPTS_MINIFIED; |
55 | | - } |
56 | | - |
57 | | - /** |
58 | | - * Writes HTML tags to load all dependencies separately. Useful when developing. |
59 | | - * @param {OutputPage} $out |
60 | | - * @param {String} $baseUrl: base URL, corresponds to the main directory of this extension. |
61 | | - */ |
62 | | - public function outputHtmlDebug( $out, $baseUrl ) { |
63 | | - foreach ( $this->scripts as $script ) { |
64 | | - $out->addScriptFile( $baseUrl . "/" . $script ); |
65 | | - } |
66 | | - foreach ( $this->inlineScripts as $script ) { |
67 | | - $out->addInlineScript( $script ); |
68 | | - } |
69 | | - // XXX RTL |
70 | | - foreach ( $this->styles as $style ) { |
71 | | - $out->addStyle( $baseUrl . "/" . $style, '', '', 'ltr' ); |
72 | | - } |
73 | | - } |
74 | | - |
75 | | - /** |
76 | | - * Writes HTML tags to load optimized dependencies. Useful in production. |
77 | | - * @param {OutputPage} $out |
78 | | - * @param {String} $baseUrl: base URL, corresponds to the main directory of this extension. |
79 | | - * @param {Boolean} $minified: if true, you get minified, otherwise, just combined. |
80 | | - */ |
81 | | - public function outputHtml( $out, $baseUrl, $minified = true ) { |
82 | | - if ( $minified ) { |
83 | | - $scriptsFile = self::SCRIPTS_MINIFIED; |
84 | | - $stylesFile = self::STYLES_MINIFIED; |
85 | | - } else { |
86 | | - $scriptsFile = self::SCRIPTS_COMBINED; |
87 | | - $stylesFile = self::STYLES_COMBINED; |
88 | | - } |
89 | | - $scriptsFile = "resources/$scriptsFile"; |
90 | | - $stylesFile = "resources/$stylesFile"; |
91 | | - |
92 | | - $out->addScriptFile( $baseUrl . "/" . $scriptsFile ); |
93 | | - // XXX RTL!? |
94 | | - $out->addStyle( $baseUrl . "/" . $stylesFile, '', '', 'ltr' ); |
95 | | - |
96 | | - // the inline scripts still go inline (they are keyed off user language) |
97 | | - foreach ( $this->inlineScripts as $script ) { |
98 | | - $out->addInlineScript( $script ); |
99 | | - } |
100 | | - } |
101 | | - |
102 | | - /** |
103 | | - * Write the concatenated and minified files for CSS and JS |
104 | | - * This is the function you want to call to regenerate all such files |
105 | | - * Not intended to be called in production or from the web. |
106 | | - * Intended to be invoked from the same directory as UploadWizard. |
107 | | - */ |
108 | | - public function writeOptimizedFiles() { |
109 | | - $extensionDir = dirname( __FILE__ ); |
110 | | - $resourceDir = "$extensionDir/resources"; |
111 | | - |
112 | | - // have to group styles by dirname, since they sometimes refer to resources by relative path. |
113 | | - $dirStyleCombinedUrls = array(); |
114 | | - $dirStyleMinifiedUrls = array(); |
115 | | - $dirStylesMap = array(); |
116 | | - foreach ( $this->styles as $style ) { |
117 | | - $dir = dirname( $style ); |
118 | | - if ( !isset( $dirStylesMap[$dir] ) ) { |
119 | | - $dirStylesMap[$dir] = array(); |
120 | | - } |
121 | | - $dirStylesMap[$dir][] = $style; |
122 | | - } |
123 | | - foreach ( $dirStylesMap as $dir => $styles ) { |
124 | | - $combined = "$dir/dir." . self::STYLES_COMBINED; |
125 | | - $this->concatenateFiles( $styles, $combined ); |
126 | | - $dirStyleCombinedUrls[] = preg_replace( '/^resources\//', '', $combined ); |
127 | | - |
128 | | - $minified = "$dir/dir." . self::STYLES_MINIFIED; |
129 | | - $this->writeMinifiedCss( $combined, $minified ); |
130 | | - $dirStyleMinifiedUrls[] = preg_replace( '/^resources\//', '', $minified ); |
131 | | - } |
132 | | - $this->writeStyleImporter( $dirStyleCombinedUrls, $resourceDir . '/' . self::STYLES_COMBINED ); |
133 | | - $this->writeStyleImporter( $dirStyleMinifiedUrls, $resourceDir . '/' . self::STYLES_MINIFIED ); |
134 | | - |
135 | | - // scripts are easy, they don't (or shouldn't) refer to other resources with relative paths |
136 | | - $scriptsCombinedFile = $resourceDir . '/' . self::SCRIPTS_COMBINED; |
137 | | - $this->concatenateFiles( $this->scripts, $scriptsCombinedFile ); |
138 | | - $this->writeMinifiedJs( $scriptsCombinedFile, $resourceDir . '/' . self::SCRIPTS_MINIFIED ); |
139 | | - } |
140 | | - |
141 | | - /** |
142 | | - * Since I couldn't figure out how to solve the CSS minification issue and how |
143 | | - * it broke relative paths for images, we'll minify one file per directory. |
144 | | - * This means we'll need a "master" file to import them all. We can use CSS @import, |
145 | | - * It's supported by browsers later than NS 4.0 or IE 4.0. |
146 | | - * @param {Array} $urls : list of urls |
147 | | - * @param {String} $outputFile : where to make this file |
148 | | - */ |
149 | | - function writeStyleImporter( $urls, $outputFile ) { |
150 | | - $fp = fopen( $outputFile, 'w' ); |
151 | | - if ( ! $fp ) { |
152 | | - print "couldn't open $outputFile for writing\n"; |
153 | | - exit; |
154 | | - } |
155 | | - foreach ( $urls as $url ) { |
156 | | - fwrite( $fp, "@import \"$url\";\n" ); |
157 | | - } |
158 | | - fclose( $fp ); |
159 | | - } |
160 | | - |
161 | | - /** |
162 | | - * Concatenates several files on the filesystem into one. |
163 | | - * @param {Array} filenames |
164 | | - * @param {String} filename to concatenate all files into. Will replace existing contents |
165 | | - */ |
166 | | - private function concatenateFiles( $files, $outputFile ) { |
167 | | - $fp = fopen( $outputFile, 'w' ); |
168 | | - if ( ! $fp ) { |
169 | | - print "couldn't open $outputFile for writing"; |
170 | | - exit; |
171 | | - } |
172 | | - foreach ( $files as $file ) { |
173 | | - fwrite( $fp, file_get_contents( $file ) ); |
174 | | - } |
175 | | - fclose( $fp ); |
176 | | - } |
177 | | - |
178 | | - /** |
179 | | - * Writes a minified version of a particular JavaScript file to the filesystem. |
180 | | - * @param {Script} input filename |
181 | | - * @param {String} filename for minified output |
182 | | - */ |
183 | | - private function writeMinifiedJs( $inputFile, $outputFile ) { |
184 | | - $fp = fopen( $outputFile, 'w' ); |
185 | | - if ( ! $fp ) { |
186 | | - print "couldn't open $outputFile for writing"; |
187 | | - exit; |
188 | | - } |
189 | | - fwrite( $fp, JSMin::minify( file_get_contents( $inputFile ) ) ); |
190 | | - fclose( $fp ); |
191 | | - } |
192 | | - |
193 | | - /** |
194 | | - * Writes a minified version of a particular CSS file to the filesystem. |
195 | | - * N.B. multiline comment removal can fail in certain situations, which you are unlikely to encounter unless |
196 | | - * you nest comments, or put comment sequences inside values |
197 | | - * @param {Script} input filename |
198 | | - * @param {String} filename for minified output |
199 | | - */ |
200 | | - private function writeMinifiedCss( $inputFile, $outputFile ) { |
201 | | - $contents = file_get_contents( $inputFile ); |
202 | | - |
203 | | - // remove leading and trailing spaces |
204 | | - $contents = preg_replace( '/^\s*|\s*$/m', '', $contents ); |
205 | | - |
206 | | - // remove whitespace immediately after a separator |
207 | | - $contents = preg_replace( '/([:{;,])\s*/', '$1', $contents ); |
208 | | - |
209 | | - // remove whitespace immediately before an open-curly |
210 | | - $contents = preg_replace( '/\s*\{/', '{', $contents ); |
211 | | - |
212 | | - // remove /* ... */ comments, potentially on multiple lines |
213 | | - // CAUTION: gets edge cases wrong, like nested or quoted comments. |
214 | | - // Not for use with nuclear reactors. |
215 | | - $contents = preg_replace( '/\/\*.*?\*\//s', '', $contents ); |
216 | | - |
217 | | - $fp = fopen( $outputFile, 'w' ); |
218 | | - if ( ! $fp ) { |
219 | | - print "couldn't open $outputFile for writing"; |
220 | | - exit; |
221 | | - } |
222 | | - fwrite( $fp, $contents ); |
223 | | - fclose( $fp ); |
224 | | - } |
225 | | - |
226 | | -} |
Index: trunk/extensions/UploadWizard/UploadWizard.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | * |
14 | 14 | * @author Neil Kandalgaonkar <neil@wikimedia.org> |
15 | 15 | * @license GPL v2 or later |
16 | | - * @version 0.1.1 |
| 16 | + * @version 1.1 |
17 | 17 | */ |
18 | 18 | |
19 | 19 | /* Configuration */ |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | 'path' => __FILE__, |
25 | 25 | 'name' => 'Upload Wizard', |
26 | 26 | 'author' => 'Neil Kandalgaonkar', |
27 | | - 'version' => '0.1.1', |
| 27 | + 'version' => '1.1', |
28 | 28 | 'descriptionmsg' => 'uploadwizard-desc', |
29 | 29 | 'url' => 'http://www.mediawiki.org/wiki/Extension:UploadWizard' |
30 | 30 | ); |
— | — | @@ -39,10 +39,8 @@ |
40 | 40 | foreach ( array( 'SpecialUploadWizard', |
41 | 41 | 'UploadWizardMessages', |
42 | 42 | 'UploadWizardHooks', |
43 | | - 'UploadWizardTutorial', |
44 | | - 'UploadWizardDependencyLoader' |
45 | | - //, 'ApiTitleCheck' |
46 | | - ) as $module ) { |
| 43 | + 'UploadWizardTutorial' |
| 44 | + ) as $module ) { |
47 | 45 | $wgAutoloadLocalClasses[$module] = $wgUpwizDir . "/" . $module . ".php"; |
48 | 46 | } |
49 | 47 | |