Index: trunk/extensions/Score/Score.i18n.php |
— | — | @@ -37,26 +37,29 @@ |
38 | 38 | $messages['en'] = array( |
39 | 39 | 'score-chdirerr' => 'Unable to change directory', |
40 | 40 | 'score-cleanerr' => 'Unable to clean out old files before re-rendering', |
41 | | - 'score-compilererr' => 'Unable to compile LilyPond input file:', |
| 41 | + 'score-compilererr' => 'Unable to compile LilyPond input file: |
| 42 | +$1', |
42 | 43 | 'score-desc' => 'MediaWiki tag extension for rendering musical scores with LilyPond', |
43 | 44 | 'score-getcwderr' => 'Unable to obtain current working directory', |
44 | 45 | 'score-nooutput' => 'Failed to create LilyPond image dir', |
45 | 46 | 'score-nofactory' => 'Failed to create LilyPond factory dir', |
46 | 47 | 'score-noinput' => 'Failed to create LilyPond input file', |
47 | | - 'score-page' => 'Page', |
| 48 | + 'score-page' => 'Page $1', |
48 | 49 | 'score-renameerr' => 'Error moving score files to upload directory', |
49 | 50 | 'score-trimerr' => 'Image could not be trimmed. Set $wgScoreTrim=false if this problem persists.', |
| 51 | + 'score-notexecutable' => 'Could not execute LilyPond. Make sure <code>$wgLilyPond</code> is set correctly.', |
50 | 52 | ); |
51 | 53 | |
52 | 54 | /* Descriptish */ |
53 | 55 | $messages['qqq'] = array( |
54 | 56 | 'score-chdirerr' => 'Displayed if the extension cannot change its working directory.', |
55 | 57 | 'score-cleanerr' => 'Displayed if an old file cleanup operation fails.', |
56 | | - 'score-compilererr' => 'Displayed if the LilyPond code could not be compiled.', |
| 58 | + 'score-compilererr' => 'Displayed if the LilyPond code could not be compiled. $1 is the error (generally big block of text in a pre tag)', |
57 | 59 | 'score-desc' => '{{desc}}', |
58 | 60 | 'score-getcwderr' => 'Displayed if the extension cannot obtain the CWD.', |
59 | 61 | 'score-noinput' => 'Displayed if the LilyPond input file cannot be created.', |
60 | | - 'score-page' => 'The word "Page" as used in pagination.', |
| 62 | + 'score-page' => 'The word "Page" as used in pagination. $1 is the page number', |
61 | 63 | 'score-renameerr' => 'Displayed if moving the resultant files from the working environment to the upload directory fails.', |
62 | 64 | 'score-trimerr' => 'Displayed if the extension failed to trim an output image.', |
| 65 | + 'score-notexecutable' => 'Displayed if LilyPond binary can\'t be executed.', |
63 | 66 | ); |
Index: trunk/extensions/Score/Score.php |
— | — | @@ -42,8 +42,11 @@ |
43 | 43 | * Configuration |
44 | 44 | */ |
45 | 45 | |
46 | | -/* Whether to trim the score images. Requires ImageMagick. Default is yes. */ |
47 | | -$wgScoreTrim = true; |
| 46 | +/* Whether to trim the score images. Requires ImageMagick. |
| 47 | + * Default is $wgUseImageMagick and set in efScoreExtension */ |
| 48 | +$wgScoreTrim = null; |
| 49 | +/* Path of lilypond executable */ |
| 50 | +$wgLilyPond = '/usr/bin/lilypond'; |
48 | 51 | |
49 | 52 | /* |
50 | 53 | * Extension credits |
— | — | @@ -72,20 +75,12 @@ |
73 | 76 | * @return true if initialisation was successful, false otherwise. |
74 | 77 | */ |
75 | 78 | function efScoreExtension( Parser &$parser ) { |
76 | | - global $wgUseImageMagick, $wgLilyPond, $wgScoreTrim; |
| 79 | + global $wgUseImageMagick, $wgScoreTrim; |
77 | 80 | |
78 | | - if ( !is_executable( $wgLilyPond ) ) { |
79 | | - wfDebugLog( 'Score', "Set LilyPond file \$wgLilyPond=$wgLilyPond is not executable.\n" ); |
80 | | - return false; |
| 81 | + if ( $wgScoreTrim === null ) { |
| 82 | + // Default to if we use Image Magick, since it requires Image Magick. |
| 83 | + $wgScoreTrim = $wgUseImageMagick; |
81 | 84 | } |
82 | | - if ( !isset( $wgScoreTrim ) ) { |
83 | | - wfDebugLog( 'Score', "Required global variable \$wgScoreTrim not set.\n" ); |
84 | | - return false; |
85 | | - } |
86 | | - if ( $wgScoreTrim && !$wgUseImageMagick ) { |
87 | | - wfDebugLog( 'Score', "Score trimming requested, but ImageMagick is unavailable.\n" ); |
88 | | - return false; |
89 | | - } |
90 | 85 | |
91 | 86 | $parser->setHook( 'score', 'Score::render' ); |
92 | 87 | |
Index: trunk/extensions/Score/Score.body.php |
— | — | @@ -54,6 +54,7 @@ |
55 | 55 | * @return Image link HTML, and possibly anchor to MIDI file. |
56 | 56 | */ |
57 | 57 | public static function render( $lilypondCode, array $args, Parser $parser, PPFrame $frame ) { |
| 58 | + |
58 | 59 | if ( array_key_exists( 'midi', $args ) ) { |
59 | 60 | $renderMidi = $args['midi']; |
60 | 61 | } else { |
— | — | @@ -190,6 +191,9 @@ |
191 | 192 | if ( !$rc ) { |
192 | 193 | throw new ScoreException( 'score-chdirerr' ); |
193 | 194 | } |
| 195 | + if ( !is_executable( $wgLilyPond ) ) { |
| 196 | + throw new ScoreException( 'score-notexecutable' ); |
| 197 | + } |
194 | 198 | $cmd = $wgLilyPond |
195 | 199 | . " -dsafe='#t' -dbackend=eps --png --header=texidoc " |
196 | 200 | . wfEscapeShellArg( $lilypondFile ) |
— | — | @@ -202,8 +206,11 @@ |
203 | 207 | if ( $rc2 != 0 ) { |
204 | 208 | self::eraseFactory( $factoryDirectory ); |
205 | 209 | wfProfileOut( __METHOD__ ); |
206 | | - $msg = wfMsgHtml( 'score-compilererr' ) |
207 | | - . ' <pre>' . strip_tags( $output ) . "\n</pre>\n"; |
| 210 | + $msg = wfMessage( 'score-compilererr' ) |
| 211 | + ->inContentLanguage() |
| 212 | + ->rawParams( |
| 213 | + ' <pre>' . strip_tags( $output ) . "\n</pre>\n" |
| 214 | + ); |
208 | 215 | return $msg; |
209 | 216 | } |
210 | 217 | |
— | — | @@ -248,23 +255,37 @@ |
249 | 256 | } catch (ScoreException $e) { |
250 | 257 | self::eraseFactory( $factoryDirectory ); |
251 | 258 | wfProfileOut( __METHOD__ ); |
252 | | - return wfMsgHtml( $e->getMessage() ); |
| 259 | + return Html::rawElement( |
| 260 | + 'span', |
| 261 | + array( 'class' => 'error' ), |
| 262 | + wfMessage( $e->getMessage() )->inContentLanguage()->parse() |
| 263 | + ); |
253 | 264 | } |
254 | 265 | wfProfileOut( __METHOD__ ); |
255 | 266 | } |
256 | 267 | |
257 | 268 | /* return output link(s) */ |
258 | 269 | if ( file_exists( $image ) ) { |
| 270 | + if ( $altText ) { |
| 271 | + $alt = $altText; |
| 272 | + } else { |
| 273 | + $alt = wfMessage( 'score-page' )->inContentLanguage()->numParams( '1' )->plain(); |
| 274 | + } |
259 | 275 | $link = Html::rawElement('img', array( |
260 | 276 | 'src' => $imagePath, |
261 | | - 'alt' => ( $altText ? $altText : wfMsg('score-page') . ' 1' ) |
| 277 | + 'alt' => $alt, |
262 | 278 | )); |
263 | 279 | } elseif ( file_exists( $multi1 ) ) { |
264 | 280 | $link = ''; |
265 | 281 | for ($i = 1; file_exists( sprintf( $multiFormat, $i ) ); ++$i ) { |
| 282 | + if ( $altText ) { |
| 283 | + $alt = $altText; |
| 284 | + } else { |
| 285 | + $alt = wfMessage( 'score-page' )->inContentLanguage()->numParams( $i )->plain(); |
| 286 | + } |
266 | 287 | $link .= Html::rawElement( 'img', array( |
267 | 288 | 'src' => sprintf( $multiPathFormat, $i ), |
268 | | - 'alt' => wfMsg('score-page') . " $i" |
| 289 | + 'alt' => $alt, |
269 | 290 | )); |
270 | 291 | } |
271 | 292 | } else { |