r42722 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42721‎ | r42722 | r42723 >
Date:09:29, 28 October 2008
Author:river
Status:old
Tags:
Comment:
- support OggHandler playback (currently broken)
- don't re-create files that exist
Modified paths:
  • /trunk/extensions/ABC/ABC.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ABC/ABC.php
@@ -41,6 +41,12 @@
4242 # specification or your TiMidity++ patch description for others.
4343 $abcMIDIvoice = 1;
4444
 45+# If you have the OggHandler extension installed, set this to
 46+# 'true' to embed the OggHandler below the music. This will
 47+# allow users to listen to the music on the page. To use this,
 48+# you must enable Ogg Vorbis rendering.
 49+$abcOggHandler = false;
 50+
4551 $wgExtensionCredits['parserhooks'][] = array(
4652 'name' => 'ABC',
4753 'author' => 'River Tarnell',
@@ -58,15 +64,21 @@
5965
6066 function
6167 efABCInit() {
62 -global $wgParser;
 68+global $wgParser, $wgOut, $abcOggHandler;
6369 wfLoadExtensionMessages('ABC');
6470 $wgParser->setHook( 'abc', 'efABCRender' );
 71+
 72+ if ($abcOggHandler) {
 73+ $oh = new OggHandler();
 74+ $oh->setHeaders($wgOut);
 75+ }
 76+
6577 return true;
6678 }
6779
6880 function
6981 efABCRender($input, $args, $parser) {
70 -global $abcPath, $abcURL, $abc2midi, $abctimidity;
 82+global $abcPath, $abcURL, $abc2midi, $abctimidity, $abcOggHandler;
7183 if ($abcPath == false || $abcURL == false)
7284 return 'Error: $abcPath and $abcURL must be set to use the ABC extension.';
7385
@@ -106,7 +118,7 @@
107119 if ($abc2midi && $abctimidity)
108120 if (!abcCreateVorbis($abc, $hash, $error))
109121 return str_replace("\n", "<br />", htmlspecialchars($error));
110 -
 122+
111123 /*
112124 * Succeeded to create all the output formats, return the
113125 * output. We produce an image from the PNG, and include
@@ -131,12 +143,24 @@
132144
133145 $e_dllinks = wfMsg('abcdownload') . " " .
134146 join(" " . wfMsg('abcsep') . " ", $links);
135 -
 147+
 148+ $ogghtml = "";
 149+
 150+ if ($abcOggHandler) {
 151+ $oh = new OggTransformOutput(null,
 152+ "$abcURL/$hash.ogg", false,
 153+ 250, 0, 0, false,
 154+ "$abcPath/$hash.ogg", false);
 155+ $ogghtml = $oh->toHtml(array('alt' => $title));
 156+ }
 157+
136158 $output = <<<EOF
137159 <div style="float: $float; border: solid 1px #aaaaaa; margin: 0.2em;" class="abc-music">
138160 <img src="$e_imgpath" alt="$e_title" />
139161 <div style="text-align: center">
140162 $e_dllinks
 163+ <br />
 164+ $ogghtml
141165 </div>
142166 </div>
143167 EOF;
@@ -153,6 +177,9 @@
154178 }
155179
156180 $filename = "$abcPath/$hash.abc";
 181+ if (file_exists($filename))
 182+ return true;
 183+
157184 if (($f = @fopen($filename, "w")) === false) {
158185 $last = error_get_last();
159186 $msg = $last['msg'];
@@ -190,6 +217,9 @@
191218
192219 $input = "$abcPath/$hash.abc";
193220 $output = "$abcPath/$hash.ps";
 221+
 222+ if (file_exists($output))
 223+ return true;
194224
195225 $cmd = "$abcm2ps -E $input -O $abcPath/$hash";
196226 @exec($cmd, $cmd_out, $ret);
@@ -218,7 +248,10 @@
219249
220250 $input = "$abcPath/$hash.ps";
221251 $output = "$abcPath/$hash.pdf";
222 -
 252+
 253+ if (file_exists($output))
 254+ return true;
 255+
223256 $cmd = "$abcps2pdf $input $output";
224257 @exec($cmd, $cmd_out, $ret);
225258 if ($ret != 0 || !@file_exists("$abcPath/$hash.pdf")) {
@@ -241,7 +274,10 @@
242275
243276 $input = "$abcPath/$hash.ps";
244277 $output = "$abcPath/$hash.png";
245 -
 278+
 279+ if (file_exists($output))
 280+ return true;
 281+
246282 $cmd = "$wgImageMagickConvertCommand $input $output";
247283 @exec($cmd, $cmd_out, $ret);
248284 if ($ret != 0 || !@file_exists($output)) {
@@ -264,7 +300,10 @@
265301
266302 $input = "$abcPath/$hash.abc";
267303 $output = "$abcPath/$hash.mid";
268 -
 304+
 305+ if (file_exists($output))
 306+ return true;
 307+
269308 $cmd = "$abc2midi $input -o $output";
270309 @exec($cmd, $cmd_out, $ret);
271310 if ($ret != 0 || !@file_exists($output)) {
@@ -287,7 +326,10 @@
288327
289328 $input = "$abcPath/$hash.mid";
290329 $output = "$abcPath/$hash.ogg";
291 -
 330+
 331+ if (file_exists($output))
 332+ return true;
 333+
292334 $cmd = "$abctimidity -Ei$abcMIDIvoice -Ov -id $input";
293335 @exec($cmd, $cmd_out, $ret);
294336 if ($ret != 0 || !@file_exists($output)) {

Status & tagging log