Index: trunk/extensions/Score/Score.i18n.php |
— | — | @@ -27,50 +27,53 @@ |
28 | 28 | |
29 | 29 | /* English */ |
30 | 30 | $messages['en'] = array( |
31 | | - 'score-abc2lynotexecutable' => 'ABC to LilyPond converter could not be executed.', |
| 31 | + 'score-abc2lynotexecutable' => 'ABC to LilyPond converter could not be executed: $1 is not an executable file. Make sure <code>$wgAbc2Ly</code> is set correctly.', |
32 | 32 | 'score-abcconversionerr' => 'Unable to convert ABC file to LilyPond format: |
33 | 33 | $1', |
34 | | - 'score-noabcinput' => 'ABC source file could not be created', |
35 | | - 'score-chdirerr' => 'Unable to change directory', |
| 34 | + 'score-chdirerr' => 'Unable to change to directory $1', |
36 | 35 | 'score-cleanerr' => 'Unable to clean out old files before re-rendering', |
37 | 36 | 'score-compilererr' => 'Unable to compile LilyPond input file: |
38 | 37 | $1', |
39 | 38 | 'score-desc' => 'Adds a tag for rendering musical scores with LilyPond', |
40 | 39 | 'score-getcwderr' => 'Unable to obtain current working directory', |
41 | | - 'score-invalidlang' => 'Invalid score language specified. Currently recognised languages are lang="lilypond" (the default) and lang="ABC".', |
42 | | - 'score-nooutput' => 'Failed to create LilyPond image directory', |
| 40 | + 'score-invalidlang' => 'Invalid score language lang="$1". Currently recognised languages are lang="lilypond" (the default) and lang="ABC".', |
| 41 | + 'score-noabcinput' => 'ABC source file $1 could not be created.', |
| 42 | + 'score-nooutput' => 'Failed to create LilyPond image directory $1', |
43 | 43 | 'score-nofactory' => 'Failed to create LilyPond factory directory', |
44 | | - 'score-noinput' => 'Failed to create LilyPond input file', |
45 | | - 'score-notexecutable' => 'Could not execute LilyPond. Make sure <code>$wgLilyPond</code> is set correctly.', |
| 44 | + 'score-noinput' => 'Failed to create LilyPond input file $1.', |
| 45 | + 'score-notexecutable' => 'Could not execute LilyPond: $1 is not an executable file. Make sure <code>$wgLilyPond</code> is set correctly.', |
46 | 46 | 'score-page' => 'Page $1', |
47 | 47 | 'score-pregreplaceerr' => 'PCRE regular expression replacement failed', |
48 | | - 'score-readerr' => 'Unable to read file', |
| 48 | + 'score-readerr' => 'Unable to read file $1', |
49 | 49 | 'score-renameerr' => 'Error moving score files to upload directory', |
50 | | - 'score-trimerr' => 'Image could not be trimmed. Set $wgScoreTrim=false if this problem persists.', |
51 | | - 'score-versionerr' => 'Unable to obtain LilyPond version.', |
| 50 | + 'score-trimerr' => 'Image could not be trimmed: |
| 51 | +$1 |
| 52 | +Set <code>$wgScoreTrim=false</code> if this problem persists.', |
| 53 | + 'score-versionerr' => 'Unable to obtain LilyPond version: |
| 54 | +$1', |
52 | 55 | ); |
53 | 56 | |
54 | 57 | /** Message documentation (Message documentation) */ |
55 | 58 | $messages['qqq'] = array( |
56 | | - 'score-abc2lynotexecutable' => 'Displayed if the ABC to LilyPond converter could not be executed.', |
| 59 | + 'score-abc2lynotexecutable' => 'Displayed if the ABC to LilyPond converter could not be executed. $1 is the path to the abc2ly binary.', |
57 | 60 | 'score-abcconversionerr' => 'Displayed if the ABC to LilyPond conversion failed. $1 is the error (generally big block of text in a pre tag)', |
58 | | - 'score-noabcinput' => 'Displayed if an ABC source file could not be created for lang="ABC".', |
59 | | - 'score-chdirerr' => 'Displayed if the extension cannot change its working directory.', |
| 61 | + 'score-chdirerr' => 'Displayed if the extension cannot change its working directory. $1 is the path to the target directory.', |
60 | 62 | 'score-cleanerr' => 'Displayed if an old file cleanup operation fails.', |
61 | 63 | 'score-compilererr' => 'Displayed if the LilyPond code could not be compiled. $1 is the error (generally big block of text in a pre tag)', |
62 | 64 | 'score-desc' => '{{desc}}', |
63 | | - 'score-getcwderr' => 'Displayed if the extension cannot obtain the CWD.', |
64 | | - 'score-invalidlang' => 'Displayed if the lang="…" attribute contains an unrecognised score language.', |
65 | | - 'score-nooutput' => 'Displayed if the LilyPond image/midi dir cannot be created.', |
| 65 | + 'score-getcwderr' => 'Displayed if the extension cannot obtain the current working directory.', |
| 66 | + 'score-invalidlang' => 'Displayed if the lang="…" attribute contains an unrecognised score language. $1 is the unrecognised language.', |
| 67 | + 'score-noabcinput' => 'Displayed if an ABC source file could not be created for lang="ABC". $1 is the path to the file that could not be created.', |
| 68 | + 'score-nooutput' => 'Displayed if the LilyPond image/midi dir cannot be created. $1 is the name of the directory.', |
66 | 69 | 'score-nofactory' => 'Displayed if the LilyPond/ImageMagick working directory cannot be created.', |
67 | | - 'score-noinput' => 'Displayed if the LilyPond input file cannot be created.', |
68 | | - 'score-notexecutable' => "Displayed if LilyPond binary can't be executed.", |
| 70 | + 'score-noinput' => 'Displayed if the LilyPond input file cannot be created. $1 is the path to the input file.', |
| 71 | + 'score-notexecutable' => 'Displayed if LilyPond binary cannot be executed. $1 is the path to the LilyPond binary.', |
69 | 72 | 'score-page' => 'The word "Page" as used in pagination. $1 is the page number', |
70 | 73 | 'score-pregreplaceerr' => 'Displayed if a PCRE regular expression replacement failed.', |
71 | | - 'score-readerr' => 'Displayed if the extension could not read a file', |
| 74 | + 'score-readerr' => 'Displayed if the extension could not read a file. $1 is the path to the file that could not be read.', |
72 | 75 | 'score-renameerr' => 'Displayed if moving the resultant files from the working environment to the upload directory fails.', |
73 | | - 'score-trimerr' => 'Displayed if the extension failed to trim an output image.', |
74 | | - 'score-versionerr' => 'Displayed if the extension failed to obtain the version string of LilyPond.', |
| 76 | + 'score-trimerr' => 'Displayed if the extension failed to trim an output image. $1 is the error (generally big block of text in a pre tag)', |
| 77 | + 'score-versionerr' => 'Displayed if the extension failed to obtain the version string of LilyPond. $1 is the LilyPond stdout output generated by the attempt.', |
75 | 78 | ); |
76 | 79 | |
77 | 80 | /** Danish (Dansk) |
Index: trunk/extensions/Score/Score.body.php |
— | — | @@ -32,10 +32,16 @@ |
33 | 33 | */ |
34 | 34 | class ScoreException extends Exception { |
35 | 35 | /** |
| 36 | + * Error message parameters |
| 37 | + */ |
| 38 | + private $parameters; |
| 39 | + |
| 40 | + /** |
36 | 41 | * Empty constructor. |
37 | 42 | */ |
38 | | - public function __construct( $message, $code = 0, Exception $previous = null ) { |
39 | | - parent::__construct( $message, $code, $previous ); |
| 43 | + public function __construct( $message ) { |
| 44 | + $this->parameters = array_slice( func_get_args(), 1 ); |
| 45 | + parent::__construct( $message ); |
40 | 46 | } |
41 | 47 | |
42 | 48 | /** |
— | — | @@ -48,7 +54,13 @@ |
49 | 55 | return Html::rawElement( |
50 | 56 | 'span', |
51 | 57 | array( 'class' => 'error' ), |
52 | | - wfMessage( $this->getMessage() )->inContentLanguage()->parse() |
| 58 | + call_user_func_array( array( |
| 59 | + wfMessage( $this->getMessage() ) |
| 60 | + ->inContentLanguage(), |
| 61 | + 'params' |
| 62 | + ), |
| 63 | + $this->parameters ) |
| 64 | + ->parse() |
53 | 65 | ); |
54 | 66 | } |
55 | 67 | } |
— | — | @@ -71,9 +83,9 @@ |
72 | 84 | * parameter, the error message returned from the binary. |
73 | 85 | * @param $callErrMsg Raw error message returned by the binary. |
74 | 86 | */ |
75 | | - public function __construct( $message, $callErrMsg, $code = 0, Exception $previous = null ) { |
| 87 | + public function __construct( $message, $callErrMsg ) { |
76 | 88 | $this->callErrMsg = $callErrMsg; |
77 | | - parent::__construct( $message, $code, $previous ); |
| 89 | + parent::__construct( $message ); |
78 | 90 | } |
79 | 91 | |
80 | 92 | /** |
— | — | @@ -83,10 +95,14 @@ |
84 | 96 | * @return error message HTML. |
85 | 97 | */ |
86 | 98 | public function __toString() { |
87 | | - return wfMessage( $this->getMessage() ) |
88 | | - ->inContentLanguage() |
89 | | - ->rawParams( Html::rawElement( 'pre', array(), strip_tags( $this->callErrMsg ) ) ) |
90 | | - ->parse(); |
| 99 | + return Html::rawElement( |
| 100 | + 'span', |
| 101 | + array( 'class' => 'error' ), |
| 102 | + wfMessage( $this->getMessage() ) |
| 103 | + ->inContentLanguage() |
| 104 | + ->rawParams( Html::rawElement( 'pre', array(), strip_tags( $this->callErrMsg ) ) ) |
| 105 | + ->parse() |
| 106 | + ); |
91 | 107 | } |
92 | 108 | } |
93 | 109 | |
— | — | @@ -110,19 +126,19 @@ |
111 | 127 | global $wgLilyPond; |
112 | 128 | |
113 | 129 | if ( !is_executable( $wgLilyPond ) ) { |
114 | | - throw new ScoreException( 'score-notexecutable' ); |
| 130 | + throw new ScoreException( 'score-notexecutable', $wgLilyPond ); |
115 | 131 | } |
116 | 132 | |
117 | | - $cmd = wfEscapeShellArg( $wgLilyPond ) . ' --version'; |
| 133 | + $cmd = wfEscapeShellArg( $wgLilyPond ) . ' --version 2>&1'; // FIXME: 2>&1 is not portable |
118 | 134 | $stdout = wfShellExec( $cmd, $rc ); |
119 | 135 | if ( $rc != 0 ) { |
120 | | - throw new ScoreException( 'score-versionerr' ); |
| 136 | + throw new ScoreCallException( 'score-versionerr', $stdout ); |
121 | 137 | } |
122 | 138 | |
123 | 139 | $n = sscanf( $stdout, 'GNU LilyPond %s', self::$lilypondVersion ); |
124 | 140 | if ( $n != 1 ) { |
125 | 141 | self::$lilypondVersion = null; |
126 | | - throw new ScoreException( 'score-versionerr' ); |
| 142 | + throw new ScoreCallException( 'score-versionerr', $stdout ); |
127 | 143 | } |
128 | 144 | } |
129 | 145 | |
— | — | @@ -180,7 +196,7 @@ |
181 | 197 | } |
182 | 198 | $rc = file_put_contents( $lilypondFile, $lilypondCode ); |
183 | 199 | if ( $rc === false ) { |
184 | | - throw new ScoreException( 'score-noinput' ); |
| 200 | + throw new ScoreException( 'score-noinput', $lilypondFile ); |
185 | 201 | } |
186 | 202 | break; |
187 | 203 | case 'ABC': |
— | — | @@ -188,7 +204,7 @@ |
189 | 205 | self::runAbc2Ly( $code, $factoryDirectory ); |
190 | 206 | break; |
191 | 207 | default: |
192 | | - throw new ScoreException( 'score-invalidlang' ); |
| 208 | + throw new ScoreException( 'score-invalidlang', $lang ); |
193 | 209 | } |
194 | 210 | |
195 | 211 | $html = self::runLilypond( $factoryDirectory, $renderMidi, $altText ); |
— | — | @@ -258,12 +274,12 @@ |
259 | 275 | /* Create ABC input file */ |
260 | 276 | $rc = file_put_contents( $abcFile, ltrim( $code ) ); // abc2ly is picky about whitespace at the start of the file |
261 | 277 | if ( $rc === false ) { |
262 | | - throw new ScoreException( 'score-noabcinput' ); |
| 278 | + throw new ScoreException( 'score-noabcinput', $abcFile ); |
263 | 279 | } |
264 | 280 | |
265 | 281 | /* Convert to LilyPond file */ |
266 | 282 | if ( !is_executable( $wgAbc2Ly ) ) { |
267 | | - throw new ScoreException( 'score-abc2lynotexecutable' ); |
| 283 | + throw new ScoreException( 'score-abc2lynotexecutable', $wgAbc2Ly ); |
268 | 284 | } |
269 | 285 | |
270 | 286 | $cmd = wfEscapeShellArg( $wgAbc2Ly ) |
— | — | @@ -283,7 +299,7 @@ |
284 | 300 | /* The output file has a tagline which should be removed in a wiki context */ |
285 | 301 | $lyData = file_get_contents( $lyFile ); |
286 | 302 | if ( $lyData === false ) { |
287 | | - throw new ScoreException( 'score-readerr' ); |
| 303 | + throw new ScoreException( 'score-readerr', $lyFile ); |
288 | 304 | } |
289 | 305 | $lyData = preg_replace( '/^(\s*tagline\s*=).*/m', '$1 ##f', $lyData ); |
290 | 306 | if ( $lyData === null ) { |
— | — | @@ -291,7 +307,7 @@ |
292 | 308 | } |
293 | 309 | $rc = file_put_contents( $lyFile, $lyData ); |
294 | 310 | if ( $rc === false ) { |
295 | | - throw new ScoreException( 'score-noinput' ); |
| 311 | + throw new ScoreException( 'score-noinput', $lyFile ); |
296 | 312 | } |
297 | 313 | } |
298 | 314 | |
— | — | @@ -322,7 +338,7 @@ |
323 | 339 | $lilypondDir = 'lilypond'; |
324 | 340 | $md5 = md5_file( $lilypondFile ); |
325 | 341 | if ( $md5 === false ) { |
326 | | - throw new ScoreException( 'score-noinput' ); |
| 342 | + throw new ScoreException( 'score-noinput', $lilypondFile ); |
327 | 343 | } |
328 | 344 | $rel = $lilypondDir . '/' . $md5; // FIXME: Too many files in one directory? |
329 | 345 | $filePrefix = "$wgUploadDirectory/$rel"; |
— | — | @@ -370,7 +386,7 @@ |
371 | 387 | if ( !file_exists( "$wgUploadDirectory/$lilypondDir" ) ) { |
372 | 388 | $rc = wfMkdirParents( "$wgUploadDirectory/$lilypondDir", null, __METHOD__ ); |
373 | 389 | if ( !$rc ) { |
374 | | - throw new ScoreException( 'score-nooutput' ); |
| 390 | + throw new ScoreException( 'score-nooutput', $lilypondDir ); |
375 | 391 | } |
376 | 392 | } |
377 | 393 | |
— | — | @@ -381,10 +397,10 @@ |
382 | 398 | } |
383 | 399 | $rc = chdir( $factoryDirectory ); |
384 | 400 | if ( !$rc ) { |
385 | | - throw new ScoreException( 'score-chdirerr' ); |
| 401 | + throw new ScoreException( 'score-chdirerr', $factoryDirectory ); |
386 | 402 | } |
387 | 403 | if ( !is_executable( $wgLilyPond ) ) { |
388 | | - throw new ScoreException( 'score-notexecutable' ); |
| 404 | + throw new ScoreException( 'score-notexecutable', $wgLilyPond ); |
389 | 405 | } |
390 | 406 | $cmd = wfEscapeShellArg( $wgLilyPond ) |
391 | 407 | . " -dsafe='#t' -dbackend=eps --png --header=texidoc " |
— | — | @@ -393,7 +409,7 @@ |
394 | 410 | $output = wfShellExec( $cmd, $rc2 ); |
395 | 411 | $rc = chdir( $oldcwd ); |
396 | 412 | if ( !$rc ) { |
397 | | - throw new ScoreException( 'score-chdir' ); |
| 413 | + throw new ScoreException( 'score-chdirerr', $oldcwd ); |
398 | 414 | } |
399 | 415 | if ( $rc2 != 0 ) { |
400 | 416 | throw new ScoreCallException( 'score-compilererr', $output ); |
— | — | @@ -486,10 +502,11 @@ |
487 | 503 | $cmd = wfEscapeShellArg( $wgImageMagickConvertCommand ) |
488 | 504 | . ' -trim ' |
489 | 505 | . wfEscapeShellArg( $source ) . ' ' |
490 | | - . wfEscapeShellArg( $dest ); |
491 | | - wfShellExec( $cmd, $rc ); |
| 506 | + . wfEscapeShellArg( $dest ) |
| 507 | + . ' 2>&1'; // FIXME: not portable |
| 508 | + $output = wfShellExec( $cmd, $rc ); |
492 | 509 | if ( $rc != 0 ) { |
493 | | - throw new ScoreException( 'score-trimerr' ); |
| 510 | + throw new ScoreCallException( 'score-trimerr', $output ); |
494 | 511 | } |
495 | 512 | } |
496 | 513 | |