r107695 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107694‎ | r107695 | r107696 >
Date:03:06, 31 December 2011
Author:grafzahl
Status:deferred
Tags:score 
Comment:
Allow overriding of generated OGG files
Modified paths:
  • /trunk/extensions/Score/README (modified) (history)
  • /trunk/extensions/Score/Score.body.php (modified) (history)
  • /trunk/extensions/Score/Score.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Score/Score.i18n.php
@@ -37,6 +37,7 @@
3838 'score-desc' => 'Adds a tag for rendering musical scores with LilyPond',
3939 'score-getcwderr' => 'Unable to obtain current working directory',
4040 'score-invalidlang' => 'Invalid score language lang="$1". Currently recognised languages are lang="lilypond" (the default) and lang="ABC".',
 41+ 'score-invalidoggoverride' => 'The file you specified with override_ogg is invalid. Please specify the file name only, omit <nowiki>[[…]]</nowiki> and the "File:" prefix.',
4142 'score-noabcinput' => 'ABC source file $1 could not be created.',
4243 'score-nofactory' => 'Failed to create LilyPond factory directory.',
4344 'score-noinput' => 'Failed to create LilyPond input file $1.',
@@ -47,6 +48,7 @@
4849 'score-novorbislink' => 'Unable to generate Ogg/Vorbis link: $1',
4950 'score-oggconversionerr' => 'Unable to convert MIDI to Ogg/Vorbis:
5051 $1',
 52+ 'score-oggoverridenotfound' => 'The file you specified with override_ogg does not exist.',
5153 'score-page' => 'Page $1',
5254 'score-pregreplaceerr' => 'PCRE regular expression replacement failed',
5355 'score-readerr' => 'Unable to read file $1.',
@@ -57,6 +59,7 @@
5860 Set <code>$wgScoreTrim=false</code> if this problem persists.',
5961 'score-versionerr' => 'Unable to obtain LilyPond version:
6062 $1',
 63+ 'score-vorbisoverrideogg' => 'You cannot request Ogg/Vorbis rendering and specify override_ogg at the same time.',
6164 );
6265
6366 /** Message documentation (Message documentation) */
@@ -69,6 +72,7 @@
7073 'score-desc' => '{{desc}}',
7174 'score-getcwderr' => 'Displayed if the extension cannot obtain the current working directory.',
7275 'score-invalidlang' => 'Displayed if the lang="…" attribute contains an unrecognised score language. $1 is the unrecognised language.',
 76+ 'score-invalidoggoverride' => 'Displayed if the file specified with the override_ogg="…" attribute is invalid.',
7377 '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.',
7478 'score-nofactory' => 'Displayed if the LilyPond/ImageMagick working directory cannot be created.',
7579 'score-noinput' => 'Displayed if the LilyPond input file cannot be created. $1 is the path to the input file.',
@@ -78,6 +82,7 @@
7983 'score-notexecutable' => 'Displayed if LilyPond binary cannot be executed. $1 is the path to the LilyPond binary.',
8084 'score-novorbislink' => 'Displayed if an Ogg/Vorbis link could not be generated. $1 is the explanation why.',
8185 'score-oggconversionerr' => 'Displayed if the MIDI to Ogg/Vorbis conversion failed. $1 is the error (generally big block of text in a pre tag)',
 86+ 'score-oggoverridenotfound' => 'Displayed if the file specified with the override_ogg="…" attribute could not be found.',
8287 'score-page' => 'The word "Page" as used in pagination. $1 is the page number',
8388 'score-pregreplaceerr' => 'Displayed if a PCRE regular expression replacement failed.',
8489 'score-readerr' => 'Displayed if the extension could not read a file. $1 is the path to the file that could not be read.',
@@ -85,6 +90,7 @@
8691 'score-renameerr' => 'Displayed if moving the resultant files from the working environment to the upload directory fails.',
8792 '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)',
8893 'score-versionerr' => 'Displayed if the extension failed to obtain the version string of LilyPond. $1 is the LilyPond stdout output generated by the attempt.',
 94+ 'score-vorbisoverrideogg' => 'Displayed if both vorbis="1" and override_ogg="…" were specified.',
8995 );
9096
9197 /** Danish (Dansk)
Index: trunk/extensions/Score/README
@@ -83,6 +83,17 @@
8484 Effect: If set to 1, the rendered image(s) will be embedded into a hyperlink
8585 to an appropriate MIDI file.
8686
 87+* Attribute: override_ogg
 88+ Allowed values: Known file name, that is, if override_ogg="name" is given,
 89+ [[File:name]] is not a redlink.
 90+ Effect: Embeds the media specified by the file name in the HTML below the
 91+ score image(s). This is an alternative to the vorbis attribute (see
 92+ below). It can, for example, be useful if you have a suitable
 93+ Ogg/Vorbis file of superior quality compared with the auto-generated
 94+ Ogg/Vorbis file the vorbis attribute yields. Of course, you can still
 95+ omit both attributes in this case and add the file manually to the
 96+ page, if you prefer.
 97+
8798 * Attribute: raw
8899 Allowed valued: 0 (default), 1
89100 Effect: If set to 1, the score code is interpreted as a complete LilyPond
Index: trunk/extensions/Score/Score.body.php
@@ -204,6 +204,20 @@
205205 throw new ScoreException( wfMessage( 'score-invalidlang', $options['lang'] ) );
206206 }
207207
 208+ /* Override OGG file? */
 209+ if ( array_key_exists( 'override_ogg', $args ) ) {
 210+ $t = Title::newFromText( $args['override_ogg'], NS_FILE );
 211+ if ( is_null( $t ) ) {
 212+ throw new ScoreException( wfMessage( 'score-invalidoggoverride' ) );
 213+ }
 214+ if ( !$t->isKnown() ) {
 215+ throw new ScoreException( wfMessage( 'score-oggoverridenotfound' ) );
 216+ }
 217+ $options['override_ogg'] = $args['override_ogg'];
 218+ } else {
 219+ $options['override_ogg'] = false;
 220+ }
 221+
208222 /* Vorbis rendering? */
209223 if ( array_key_exists( 'vorbis', $args ) ) {
210224 $options['vorbis'] = $args['vorbis'];
@@ -213,6 +227,9 @@
214228 if ( $options['vorbis'] && !( class_exists( 'OggHandler' ) && class_exists( 'OggAudioDisplay' ) ) ) {
215229 throw new ScoreException( wfMessage( 'score-noogghandler' ) );
216230 }
 231+ if ( $options['vorbis'] && ( $options['override_ogg'] !== false ) ) {
 232+ throw new ScoreException( wfMessage( 'score-vorbisoverrideogg' ) );
 233+ }
217234
218235 /* Midi rendering? */
219236 if ( array_key_exists( 'midi', $args ) ) {
@@ -228,7 +245,7 @@
229246 $options['raw'] = false;
230247 }
231248
232 - $html = self::generateHTML( $code, $options );
 249+ $html = self::generateHTML( $parser, $code, $options );
233250 } catch ( ScoreException $e ) {
234251 $html = "$e";
235252 }
@@ -239,6 +256,7 @@
240257 /**
241258 * Generates the HTML code for a score tag.
242259 *
 260+ * @param $parser Parser MediaWiki parser.
243261 * @param $code score code.
244262 * @param $options array of music rendering options. Available options keys are:
245263 * * lang: score language,
@@ -250,7 +268,7 @@
251269 *
252270 * @throws ScoreException if an error occurs.
253271 */
254 - private static function generateHTML( $code, $options ) {
 272+ private static function generateHTML( &$parser, $code, $options ) {
255273 global $wgUploadDirectory, $wgUploadPath, $wgTmpDirectory, $wgOut;
256274
257275 $prof = new ScopedProfiling( __METHOD__ );
@@ -328,6 +346,13 @@
329347 throw new ScoreException( wfMessage( 'score-novorbislink', $e->getMessage() ), 0, $e );
330348 }
331349 }
 350+ if ( $options['override_ogg'] ) {
 351+ try {
 352+ $link .= $parser->recursiveTagParse( "[[File:{$options['override_ogg']}]]" );
 353+ } catch ( Exception $e ) {
 354+ throw new ScoreException( wfMessage( 'score-novorbislink', $e->getMessage() ), 0, $e );
 355+ }
 356+ }
332357 } catch ( Exception $e ) {
333358 self::eraseFactory( $factoryDirectory );
334359 throw $e;

Follow-up revisions

RevisionCommit summaryAuthorDate
r107696Follow-up r107695: strict checking on override_ogg might be requiredgrafzahl03:14, 31 December 2011

Status & tagging log