Index: trunk/extensions/Score/Score.body.php |
— | — | @@ -151,31 +151,33 @@ |
152 | 152 | */ |
153 | 153 | public static function render( $code, array $args, Parser $parser, PPFrame $frame ) { |
154 | 154 | try { |
| 155 | + $options = array(); |
| 156 | + |
155 | 157 | /* Score language selection */ |
156 | 158 | if ( array_key_exists( 'lang', $args ) ) { |
157 | | - $lang = $args['lang']; |
| 159 | + $options['lang'] = $args['lang']; |
158 | 160 | } else { |
159 | | - $lang = 'lilypond'; |
| 161 | + $options['lang'] = 'lilypond'; |
160 | 162 | } |
161 | | - if ( !in_array( $lang, self::$supportedLangs ) ) { |
162 | | - throw new ScoreException( wfMessage( 'score-invalidlang', $lang ) ); |
| 163 | + if ( !in_array( $options['lang'], self::$supportedLangs ) ) { |
| 164 | + throw new ScoreException( wfMessage( 'score-invalidlang', $options['lang'] ) ); |
163 | 165 | } |
164 | 166 | |
165 | 167 | /* Midi rendering? */ |
166 | 168 | if ( array_key_exists( 'midi', $args ) ) { |
167 | | - $linkMidi = $args['midi']; |
| 169 | + $options['midi'] = $args['midi']; |
168 | 170 | } else { |
169 | | - $linkMidi = false; |
| 171 | + $options['midi'] = false; |
170 | 172 | } |
171 | 173 | |
172 | 174 | /* Raw rendering? */ |
173 | 175 | if ( array_key_exists( 'raw', $args ) ) { |
174 | | - $rawLilypond = $args['raw']; |
| 176 | + $options['raw'] = $args['raw']; |
175 | 177 | } else { |
176 | | - $rawLilypond = false; |
| 178 | + $options['raw'] = false; |
177 | 179 | } |
178 | 180 | |
179 | | - $html = self::generateHTML( $code, $lang, $linkMidi, $rawLilypond ); |
| 181 | + $html = self::generateHTML( $code, $options ); |
180 | 182 | } catch ( ScoreException $e ) { |
181 | 183 | $html = "$e"; |
182 | 184 | } |
— | — | @@ -187,15 +189,16 @@ |
188 | 190 | * Generates the HTML code for a score tag. |
189 | 191 | * |
190 | 192 | * @param $code score code. |
191 | | - * @param $lang score language the code is in. |
192 | | - * @param $linkMidi whether to generate a link to a MIDI file. |
193 | | - * @param $rawLilypond whether to assume raw LilyPond code (ignored if $lang is not 'lilypond'). |
| 193 | + * @param $options array of music rendering options. Available options keys are: |
| 194 | + * * lang: score language, |
| 195 | + * * midi: whether to link to a MIDI file, |
| 196 | + * * raw: whether to assume raw LilyPond code. |
194 | 197 | * |
195 | 198 | * @return HTML. |
196 | 199 | * |
197 | 200 | * @throws ScoreException if an error occurs. |
198 | 201 | */ |
199 | | - private static function generateHTML( $code, $lang, $linkMidi, $rawLilypond ) { |
| 202 | + private static function generateHTML( $code, $options ) { |
200 | 203 | global $wgUploadDirectory, $wgUploadPath; |
201 | 204 | |
202 | 205 | /* Various paths and file names */ |
— | — | @@ -221,8 +224,8 @@ |
222 | 225 | } |
223 | 226 | |
224 | 227 | /* Generate PNG and MIDI files if necessary */ |
225 | | - if ( ( !file_exists( $image ) && !file_exists( $multi1 ) ) || ( $linkMidi && !file_exists( $midi ) ) ) { |
226 | | - self::generatePngAndMidi( $code, $lang, $linkMidi, $rawLilypond, $filePrefix ); |
| 228 | + if ( ( !file_exists( $image ) && !file_exists( $multi1 ) ) || ( $options['midi'] && !file_exists( $midi ) ) ) { |
| 229 | + self::generatePngAndMidi( $code, $options, $filePrefix ); |
227 | 230 | } |
228 | 231 | |
229 | 232 | /* return output link(s) */ |
— | — | @@ -244,7 +247,7 @@ |
245 | 248 | self::debug( "No output images $image or $multi1!\n" ); |
246 | 249 | $link = 'No image'; |
247 | 250 | } |
248 | | - if ( $linkMidi ) { |
| 251 | + if ( $options['midi'] ) { |
249 | 252 | $link = Html::rawElement( 'a', array( 'href' => $midiPath ), $link ); |
250 | 253 | } |
251 | 254 | |
— | — | @@ -255,14 +258,12 @@ |
256 | 259 | * Generates score PNG file(s) and possibly a MIDI file. |
257 | 260 | * |
258 | 261 | * @param $code score code. |
259 | | - * @param $lang language the score code is in. |
260 | | - * @param $generateMidi whether to generate a MIDI file. |
261 | | - * @param $rawLilypond whether to assume raw LilyPond code (ignored if $lang is not 'lilypond'). |
| 262 | + * @param $options rendering options, see Score::generateHTML() for explanation. |
262 | 263 | * @param $filePrefix prefix for the generated files. |
263 | 264 | * |
264 | 265 | * @throws ScoreException on error. |
265 | 266 | */ |
266 | | - private static function generatePngAndMidi( $code, $lang, $generateMidi, $rawLilypond, $filePrefix ) { |
| 267 | + private static function generatePngAndMidi( $code, $options, $filePrefix ) { |
267 | 268 | global $wgTmpDirectory, $wgLilyPond, $wgScoreTrim; |
268 | 269 | |
269 | 270 | wfProfileIn( __METHOD__ ); |
— | — | @@ -301,11 +302,11 @@ |
302 | 303 | $factoryMultiTrimmedFormat = "$factoryDirectory/file-%d-trimmed.png"; |
303 | 304 | |
304 | 305 | /* Determine which LilyPond code to use */ |
305 | | - if ( $lang == 'lilypond' ) { |
306 | | - if ( $rawLilypond ) { |
| 306 | + if ( $options['lang'] == 'lilypond' ) { |
| 307 | + if ( $options['raw'] ) { |
307 | 308 | $lilypondCode = $code; |
308 | 309 | } else { |
309 | | - $lilypondCode = self::embedLilypondCode( $code, $generateMidi ); |
| 310 | + $lilypondCode = self::embedLilypondCode( $code, $options ); |
310 | 311 | } |
311 | 312 | } else { |
312 | 313 | wfSuppressWarnings(); |
— | — | @@ -313,7 +314,7 @@ |
314 | 315 | wfRestoreWarnings(); |
315 | 316 | if ( $lilypondCode === false ) { |
316 | 317 | /* (re-)generate .ly file */ |
317 | | - $lilypondCode = self::generateLilypond( $code, $lang, $filePrefix, $factoryDirectory ); |
| 318 | + $lilypondCode = self::generateLilypond( $code, $options, $filePrefix, $factoryDirectory ); |
318 | 319 | } |
319 | 320 | } |
320 | 321 | |
— | — | @@ -392,13 +393,13 @@ |
393 | 394 | * Embeds simple LilyPond code in a score block. |
394 | 395 | * |
395 | 396 | * @param $lilypondCode |
396 | | - * @param $renderMidi |
| 397 | + * @param $options |
397 | 398 | * |
398 | 399 | * @return Raw lilypond code. |
399 | 400 | * |
400 | 401 | * @throws ScoreException if determining the LilyPond version fails. |
401 | 402 | */ |
402 | | - private static function embedLilypondCode( $lilypondCode, $renderMidi ) { |
| 403 | + private static function embedLilypondCode( $lilypondCode, $options ) { |
403 | 404 | /* Get LilyPond version if we don't know it yet */ |
404 | 405 | if ( self::$lilypondVersion === null ) { |
405 | 406 | self::getLilypondVersion(); |
— | — | @@ -418,7 +419,7 @@ |
419 | 420 | . "\\score {\n" |
420 | 421 | . $lilypondCode |
421 | 422 | . "\t\\layout { }\n" |
422 | | - . ( $renderMidi ? "\t\\midi { }\n" : "" ) |
| 423 | + . ( $options['midi'] ? "\t\\midi { }\n" : "" ) |
423 | 424 | . "}\n"; |
424 | 425 | return $raw; |
425 | 426 | } |
— | — | @@ -427,7 +428,7 @@ |
428 | 429 | * Generates LilyPond code. |
429 | 430 | * |
430 | 431 | * @param $code score code. |
431 | | - * @param $lang language the score code is in (a supported language other than 'lilypond'). |
| 432 | + * @param $options rendering options, see Score::generateHTML() for explanation. |
432 | 433 | * @param $filePrefix prefix for the generated file. |
433 | 434 | * @param $factoryDirectory directory of the working environment. |
434 | 435 | * |
— | — | @@ -435,10 +436,10 @@ |
436 | 437 | * |
437 | 438 | * @throws ScoreException if an error occurs. |
438 | 439 | */ |
439 | | - private static function generateLilypond( $code, $lang, $filePrefix, $factoryDirectory ) { |
| 440 | + private static function generateLilypond( $code, $options, $filePrefix, $factoryDirectory ) { |
440 | 441 | $ly = "$filePrefix.ly"; |
441 | 442 | |
442 | | - switch ( $lang ) { |
| 443 | + switch ( $options['lang'] ) { |
443 | 444 | case 'ABC': |
444 | 445 | $lilypondCode = self::generateLilypondFromAbc( $code, $factoryDirectory ); |
445 | 446 | break; |